view src/create_cmdidxs.vim @ 32721:94f4a488412e v9.0.1683

Updated runtime files Commit: https://github.com/vim/vim/commit/6efb1980336ff324e9c57a4e282530b952fca816 Author: Christian Brabandt <cb@256bit.org> Date: Thu Aug 10 05:44:25 2023 +0200 Updated runtime files This is a collection of various PRs from github that all require a minor patch number: 1) https://github.com/vim/vim/pull/12612 Do not conflate dictionary key with end of block 2) https://github.com/vim/vim/pull/12729: When saving and restoring 'undolevels', the constructs `&undolevels` and `:set undolevels` are problematic. The construct `&undolevels` reads an unpredictable value; it will be the local option value (if one has been set), or the global option value (otherwise), making it unsuitable for saving a value for later restoration. Similarly, if a local option value has been set for 'undolevels', temporarily modifying the option via `:set undolevels` changes the local value as well as the global value, requiring extra work to restore both values. Saving and restoring the option value in one step via the construct `:let &undolevels = &undolevels` appears to make no changes to the 'undolevels' option, but if a local option has been set to a different value than the global option, it has the unintended effect of changing the global 'undolevels' value to the local value. Update the documentation to explain these issues and recommend explicit use of global and local option values when saving and restoring. Update some unit tests to use `g:undolevels`. 3) https://github.com/vim/vim/pull/12702: Problem: Pip requirements files are not recognized. Solution: Add a pattern to match pip requirements files. 4) https://github.com/vim/vim/pull/12688: Add indent file and tests for ABB Rapid 5) https://github.com/vim/vim/pull/12668: Use Lua 5.1 numeric escapes in tests and add to CI Only Lua 5.2+ and LuaJIT understand hexadecimal escapes in strings. Lua 5.1 only supports decimal escapes: > A character in a string can also be specified by its numerical value > using the escape sequence \ddd, where ddd is a sequence of up to three > decimal digits. (Note that if a numerical escape is to be followed by a > digit, it must be expressed using exactly three digits.) Strings in Lua > can contain any 8-bit value, including embedded zeros, which can be > specified as '\0'. To make sure this works with Lua 5.4 and Lua 5.1 change the Vim CI to run with Lua 5.1 as well as Lua 5.4 6) https://github.com/vim/vim/pull/12631: Add hurl filetype detection 7) https://github.com/vim/vim/pull/12573: Problem: Files for haskell persistent library are not recognized Solution: Add pattern persistentmodels for haskell persistent library closes: #12612 closes: #12729 closes: #12702 closes: #12688 closes: #12668 closes: #12631 closes: #12573 Co-authored-by: lacygoill <lacygoill@lacygoill.me> Co-authored-by: Michael Henry <drmikehenry@drmikehenry.com> Co-authored-by: ObserverOfTime <chronobserver@disroot.org> Co-authored-by: KnoP-01 <knosowski@graeffrobotics.de> Co-authored-by: James McCoy <jamessan@jamessan.com> Co-authored-by: Jacob Pfeifer <jacob@pfeifer.dev> Co-authored-by: Borys Lykah <lykahb@fastmail.com>
author Christian Brabandt <cb@256bit.org>
date Thu, 10 Aug 2023 06:30:06 +0200
parents 72ce5ca82a75
children
line wrap: on
line source

" This script generates the tables cmdidxs1[] and cmdidxs2[][] which,
" given a Ex command, determine the first value to probe to find
" a matching command in cmdnames[] based on the first character
" and the first 2 characters of the command.
" This is used to speed up lookup in cmdnames[].
"
" Script should be run every time new Ex commands are added in Vim,
" from the src/vim directory, since it reads commands from "ex_cmds.h".

let cmds = []
let skipped_cmds = 0

let lines = readfile('ex_cmds.h')
let idx = 0
while idx < len(lines)
  let line = lines[idx]
  if line =~ '^EXCMD(CMD_'
    let m = matchlist(line, '^EXCMD(CMD_\S*,\s*"\([a-z][^"]*\)"')
    if len(m) >= 2
      let cmds += [ m[1] ]
    else
      let skipped_cmds += 1
    endif

    let idx += 1
    let flags = lines[idx]
    let idx += 1
    let addr_type = lines[idx]

    if flags =~ '\<EX_RANGE\>'
      if addr_type =~ 'ADDR_NONE'
        echoerr 'ex_cmds.h:' .. (idx - 1) .. ': Using EX_RANGE with ADDR_NONE: ' .. line
      endif
    else
      if addr_type !~ 'ADDR_NONE'
        echoerr 'ex_cmds.h:' .. (idx - 1) .. ': Missing ADDR_NONE: ' .. line
      endif
    endif

    if flags =~ '\<EX_DFLALL\>' && (addr_type =~ 'ADDR_OTHER' || addr_type =~ 'ADDR_NONE')
      echoerr 'ex_cmds.h:' .. (idx - 1) .. ': Missing misplaced EX_DFLALL: ' .. line
    endif
  endif
  let idx += 1
endwhile

let cmdidxs1 = {}
let cmdidxs2 = {}

for i in range(len(cmds) - 1, 0, -1)
  let cmd = cmds[i]
  let c1 = cmd[0] " First character of command
  let c2 = cmd[1] " Second character of command (if any)

  let cmdidxs1{c1} = i
  if c2 >= 'a' && c2 <= 'z'
    let cmdidxs2{c1}{c2} = i
  endif
endfor

let output =  [ '/* Automatically generated code by create_cmdidxs.vim' ]
let output += [ ' *' ]
let output += [ ' * Table giving the index of the first command in cmdnames[] to lookup' ]
let output += [ ' * based on the first letter of a command.' ]
let output += [ ' */' ]
let output += [ 'static const unsigned short cmdidxs1[26] =' ]
let output += [ '{' ]

let a_to_z = map(range(char2nr('a'), char2nr('z')), 'nr2char(v:val)')
for c1 in a_to_z
  let line = '  /* ' . c1 . ' */ ' . cmdidxs1{c1} . ((c1 == 'z') ? '' : ',')
  let output += [ line ]
endfor
let output += [ '};' ]
let output += [ '' ]
let output += [ '/*' ]
let output += [ ' * Table giving the index of the first command in cmdnames[] to lookup' ]
let output += [ ' * based on the first 2 letters of a command.' ]
let output += [ ' * Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they' ]
let output += [ ' * fit in a byte.' ]
let output += [ ' */' ]
let output += [ 'static const unsigned char cmdidxs2[26][26] =' ]
let output += [ '{ /*         a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t   u   v   w   x   y   z */' ]

for c1 in a_to_z
  let line = '  /* ' . c1 . ' */ {'
  for c2 in a_to_z
    if exists('cmdidxs2{c1}{c2}')
      let line .= printf('%3d', cmdidxs2{c1}{c2} - cmdidxs1{c1})
    else
      let line .= '  0'
    endif
    let line .= (c2 == 'z') ? '' : ','
  endfor
  let line .= ' }' . ((c1 == 'z') ? '' : ',')
  let output += [ line ]
endfor

let output += [ '};' ]
let output += [ '' ]
let output += [ 'static const int command_count = ' . (len(cmds) + skipped_cmds) . ';' ]

call writefile(output, "ex_cmdidxs.h")
quit