Loading...
Searching...
No Matches
Nhi1Shortcut

A tool to access a file in the vim editor by creating a shortcut from file-name and directory-name

‍The basic problem in a project with a lot of files and a lot of directories is to find a way to navigate quickly and easily.

Two tools are used for this:

  1. Nhi1Tags, A tool to generate the .tags file to navigaet in source-code and documentation
  2. Nhi1Shortcut, A tool to access a file in the vim editor by creating a shortcut from file-name and directory-name

using: Nhi1Shortcut

Files involved :
.../.shortcut                       local shortcut database for directory "..."
.../.shortcutignore                 ignore file/pattern for directory "..."
etc/shortcut.local                  shortcut extension (example: test "db" lookup)
sbin/vim-shortcut.tcl               shortcut integration into "vim"
theCompiler/src/lng_Shortcut.tcl    frontend of the shortcut tool
theCompiler/src/lib_Shortcut.tcl    backend of the shortcut tool
The tool Nhi1Shortcut tool creates a file called .shortcut with a simple TCL array using
mapping : array set fileA { shortcut → filename ... }
The navigation is done using the vim extension vim-shortcut.tcl :
" open file based on return from 'vim-key-2-file.tcl'
" optional … popup_notification on ERROR or WARNING
" cd DIR | e FILE
func! SC_exec(init)
execute system("$NHI1_HOME/sbin/vim-shortcut.tcl " ..
\ shellescape(expand('%')) .. ' ' ..
\ shellescape(a:init)
\ )
endfunc
" CTRL+e
" nnoremap ␅ :call SC_exec(inputdialog("SC>")) <CR>
" call it from commandline (:E ...) and extern (vim -c ':E ...')
command! -nargs=1 E call SC_exec('<args>')
Calling a shortcut is done with :E ... or <CTRL-E>...
The shortcut itself is a mix of upper and lower case letters :
  • upper = directory-shortcut
  • lower = file-shortcut
The directory has some predefined token :
starting with :
switch $curK {
T { DIR $env(NHI1_HOME) ; # top }
U { DIR [file dirname $DIR] ; # up }
H { DIR [pwd] ; # pwd }
C { continue ; # current }
}
second with :
array set topA [list \
K $env(theKernel_SRCDIR) \
L $env(theLink_SRCDIR) \
O $env(theConfig_SRCDIR) \
Q $env(theSq3Lite_SRCDIR) \
B $env(theBrain_SRCDIR) \
G $env(theGuard_SRCDIR) \
C $env(theCompiler_SRCDIR) \
I $env(theLib_SRCDIR) \
D $env(docs_SRCDIR) \
E $env(example_SRCDIR) \
]
following with :
array set dirA {
A {"" main "" atl}
C {"" c }
D {"" docs }
G {"" go "" gen}
H {"" php }
J {"" jv }
M {"" man "" myoo}
P {"" public "" pl }
R {"" rb }
S {"" cs }
T {E tests "" tcl}
U {"" .. }
V {"" vb }
X {"" cc }
Y {"" py }
}
  1. if multiple items per char are available the first match is used.
  2. directory can be skipped if current position is searched.
  3. reference is always the current (open) file directory.
  4. an absolute position always start with T
  5. an relative position start with "", C, U or dirA follewd by file-shortcut
The filename part is read from the file .shortcut in the directory :
Example file docs/main/.shortcut :
array set fileA {
id index.doc
pd pages.doc
nld Nhi1Label.doc
nsd Nhi1Shortcut.doc
ned Nhi1Exec.doc
ntd Nhi1Tags.doc
rd rb.doc
sd cs.doc
jd jv.doc
ad atl.doc
}
# BEGIN-mark - created by 'lng_Shortcut.tcl ' - DO NOT change
# $NHI1_HOME/docs/main
array set fileA {
d Doxyfile.main
mc main.config
md main.doc
l .labelignore
s .shortcut
v .vimrc
}
# END-mark - created by 'lng_Shortcut.tcl ' - DO NOT change
# vim: syntax=tcl
  • the first array fileA is written be the user
  • the second array fileA is written be the Nhi1Shortcut tool
The usage of the Nhi1Shortcut tool :
␛[38;1;36mpInit                                    -> PINIT[#0] -> +++ use              : lang<lng>       : api<Shortcut>        : top<lng_Shortcut.tcl>␛[0;m
␛[38;1;36m                                         -> PINIT[#0] -> argv<-h>␛[0;m
usage: Nhi1Shortcut ?options...? 
  options:
    ^-(?:i|meta)(?:=(.*))?$   |  set META file for inpout   :  default: value from -|mk|mq|lc|sq3|...
    ^-(mk|mq|lc|sq3)$         |  set LIBRARY                :  
  
  filter options
    ^-(?:f|func)(?:=(.*))?$   |  filter FUNCEXPR            :  all kind of objects (-ff/-ffunc = stonger)
    ^-(?:c|class)(?:=(.*))?$  |  filter CLASSEXPR           :  filter by class name
    ^-show-filter$            |  show filter data           :  API_IGNORE_* and API_ALLOW_*
  
  profiling options
    ^-profile$                |  use prfiling               :  
    ^-profile-key$            |  set profile key            :  default: exclusiveRuntime
                                   compileTime, nonCompileTime, avgExclusiveTime, calls
                                   totalRuntime, exclusiveRuntime, avgRuntime
    ^-profile-pat$            |  filter result              :  default: *
  
  TASK options
    ^-ignore(?:=(.*))?$       |  ignore=TASK,TASK,...       :  use -h to get list
    ^-only(?:=(.*))?$         |  only=TASK,TASK,...         :  use -h to get list
  
  debug options
    ^-trace(?:=(.*))?$        |  trace VARIABLE on WRITE    :  discover modification
    ^-force$                  |  use META code              :  disable the cache
    ^-erase-all$              |  erase generated code       :  apply to target file(s)
    ^-warning-as-error$       |  raise an ERROR on WARNING  :  
    ^-(d+)$                   |  incr DEBUG level           :  -d -dd -ddd ...
    ^-(v+)$                   |  incr VERBOSE level         :  -v -vv -vvv ...
    ^-(s+)$                   |  always print to STDOUT     :  BOOLEAN
    ^-(?:w|write)$            |  always write               :  BOOLEAN
    ^-tcl-trace$              |  enable TCL trace           :  
  
  misc options
    ^-(h|help)$               |  get this help              :  
    ^-dependency$             |  write dependency tree      :  used for MAKE
    ^-attribute(?:=(.*))?$$   |  attribute KEY=VAL          :  modify the attributeDEF database
    ^-recompile               |  recompile 'imeta' file     :  'imeta' reuired: -mk,-mq,...

  lng_Shortcut options:

    -do-lib ...... LIB ....... DO the 'project' directory (default: no)
    -do-example .. EXAMPLE ... DO the 'example' directory (default: no)
    -do-docs ..... DOCS ...... DO the 'docs' directory (default: no)
    -do-the ...... THE ....... DO the 'theX' directory (default: no)
    -create-missing .......... create missing files as empty
    -all ..................... DO all above
    -local ................... just do local directory

    -sc-write ................ DO write file '.shortcutignore'
    -sc-no-deep .............. DON'T use parallel directories also
    -diff .................... DO the 'diff' at the end (default: no)
    -(tcl|atl|py|pl|rb|php|c|cc|cs|jv|go|vb) ... chose language
    -(mk|mq|lc|sq3) ............................ chose namespace

  supported '-ignore' args:

    IGNORE(#usage)<list> , IGNORE(#only)<EMPTY> , IGNORE<array|P|#group,*>
      IGNORE(#usage) = <list>
        | DOCS | EXAMPLE | LIB
      IGNORE = <array|P|#group,*>
        | #group,all-lng | tcl atl cc cs vb jv rb php pl c go py
        | #group,all-me  | FUNC_S
        | #group,all-ns  | mk mq lc sq3
        | #group,all-tsk | LIB EXAMPLE DOCS TESTS THE

Simple Example : create the shortcut for a LIB (library) using package mk (theKernel) target language py (python)
> Nhi1Shortcut -only=LIB,mk,py
pInit                                    -> PINIT[#0] -> +++ use              : lang<lng>       : api<Shortcut>        : top<lng_Shortcut.tcl>
                                         -> PINIT[#0] ->                      : argv<-only=LIB,mk,py>
Do                                       -> LIB start
  GLOBAL                                   -> LIB project: mk
  cache_close                              -> write file -> fn<.../NHI1/theKernel/py/.shortcut>
Do                                       -> LIB end