From a5b8e7695198d7f373e1c297321aaa4eb75421dc Mon Sep 17 00:00:00 2001 From: nygren Date: Fri, 28 Dec 2018 10:48:21 -0800 Subject: [PATCH 1/7] Additions for .hpp file support and split screen key mappings. --- plugin/autoload_cscope.vim | 92 +++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/plugin/autoload_cscope.vim b/plugin/autoload_cscope.vim index 6e8d96d..488a5fd 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/autoload_cscope.vim @@ -1,7 +1,41 @@ " Vim global plugin for autoloading cscope databases. +" Save this file as ~/.vim/plugin/autoload_cscope.vim present +" so you can invoke vim in subdirectories and still get cscope.out loaded. " Last Change: Wed Jan 26 10:28:52 Jerusalem Standard Time 2011 " Maintainer: Michael Conrad Tadpol Tilsra -" Revision: 0.5 +" Revision: 0.5 (plus the below) +" With additions from ckelau & ufengzh for .cpp suffix files +" With additions from Code-Monky & ckelau for .java suffix files +" See pull requests at https://github.com/vim-scripts/autoload_cscope.vim +" With additions from Jason Duell's cscope settings by Dan Nygren +" With additions for .hpp suffix files by Dan Nygren + + +""""""""""""" Jason Duell's cscope/vim key mappings +" (From http://cscope.sourceforge.net/cscope_maps.vim with light edits. ) +" The following maps all invoke one of the following cscope search types: +" +" 's' symbol: find all references to the token under cursor +" 'g' global: find global definition(s) of the token under cursor +" 'c' calls: find all calls to the function name under cursor +" 't' text: find all instances of the text under cursor +" 'e' egrep: egrep search for the word under cursor +" 'f' file: open the filename under cursor +" 'i' includes: find files that include the filename under cursor +" 'd' called: find functions that function under cursor calls +" +" Below are the maps: one set that just jumps to your search result, and one +" that splits the existing vim window horizontally and displays your search +" result in the new window. +" +" I've used CTRL-\ and CTRL-_ as the starting keys for these maps, as it's +" unlikely that you need their default mappings. +" +" To do the first type of search, hit 'CTRL-\', followed by one of the +" cscope search types above (s,g,c,t,e,f,i,d). The result of your cscope +" search will be displayed in the current window. You can use CTRL-T to +" go back to where you were before the search. +" if exists("loaded_autoload_cscope") finish @@ -65,7 +99,7 @@ endfunc " Cycle_macros_menus " if there are cscope connections, activate that stuff. " Else toss it out. -" TODO Maybe I should move this into a seperate plugin? +" TODO Maybe I should move this into a separate plugin? let s:menus_loaded = 0 function s:Cycle_macros_menus() if g:autocscope_menus != 1 @@ -80,12 +114,27 @@ function s:Cycle_macros_menus() set cst silent! map s :cs find s =expand("") silent! map g :cs find g =expand("") +" cscope's global function definition search does not work with +" '__attribute__((unused))' in function definitions because cscope +" cannot tolerate arbitrary use of () characters in the argument list. +" (Dan Nygren) silent! map d :cs find d =expand("") silent! map c :cs find c =expand("") silent! map t :cs find t =expand("") silent! map e :cs find e =expand("") silent! map f :cs find f =expand("") silent! map i :cs find i =expand("") +" Addition from Jason Duell's cscope settings (Dan Nygren) +" Split screen horizontally with CTRL underscore + silent! map s :scs find s =expand("") + silent! map g :scs find g =expand("") + silent! map c :scs find c =expand("") + silent! map t :scs find t =expand("") + silent! map e :scs find e =expand("") + silent! map f :scs find f =expand("") + silent! map i :scs find i ^=expand("")$ + silent! map d :scs find d =expand("") +" End Split screen horizontally if has("menu") nmenu &Cscope.Find.Symbols \ :cs find s =expand("") @@ -171,14 +220,53 @@ function s:Cycle_csdb() endif endfunc +" By default, cscope examines C (.c & .h), lex (.l), and yacc (.y) source files. +" Additions made for C++ source files (.cc, .cpp, .hpp). +" Additions made for Java source files (.java). " auto toggle the menu augroup autoload_cscope au! au BufEnter *.[chly] call Cycle_csdb() | call Cycle_macros_menus() au BufEnter *.cc call Cycle_csdb() | call Cycle_macros_menus() + au BufEnter *.[ch]pp call Cycle_csdb() | call Cycle_macros_menus() + au BufEnter *.java call Cycle_csdb() | call Cycle_macros_menus() au BufUnload *.[chly] call Unload_csdb() | call Cycle_macros_menus() au BufUnload *.cc call Unload_csdb() | call Cycle_macros_menus() + au BufUnload *.[ch]pp call Cycle_csdb() | call Cycle_macros_menus() + au BufUnload *.java call Cycle_csdb() | call Cycle_macros_menus() augroup END let &cpo = s:save_cpo +" Addition from Jason Duell's cscope settings +" """"""""""""" key map timeouts +" " +" " By default Vim will only wait 1 second for each keystroke in a mapping. +" " You may find that too short with the above typemaps. If so, you should +" " either turn off mapping timeouts via 'notimeout'. +" " +" "set notimeout +" " +" " Or, you can keep timeouts, by uncommenting the timeoutlen line below, +" " with your own personal favorite value (in milliseconds): +" " +" "set timeoutlen=4000 +set timeoutlen=2000 +" " +" " Either way, since mapping timeout settings by default also set the +" " timeouts for multicharacter 'keys codes' (like ), you should also +" " set ttimeout and ttimeoutlen: otherwise, you will experience strange +" " delays as vim waits for a keystroke after you hit ESC (it will be +" " waiting to see if the ESC is actually part of a key code like ). +" " +" "set ttimeout +set ttimeout +" " +" " personally, I find a tenth of a second to work well for key code +" " timeouts. If you experience problems and have a slow terminal or network +" " connection, set it higher. If you don't set ttimeoutlen, the value for +" " timeoutlent (default: 1000 = 1 second, which is sluggish) is used. +" " +" "set ttimeoutlen=100 +set ttimeoutlen=100 +" From 6300ef3ab39302550530b798f5efe4382a8e601b Mon Sep 17 00:00:00 2001 From: nygren Date: Wed, 2 Feb 2022 16:03:09 -0800 Subject: [PATCH 2/7] Overhaul to meld multiple authors' code into a single cohesive structure. --- README | 16 +-- cheatsheet.txt | 26 ++++ plugin/autoload_cscope.vim | 242 ++++++++++++++++++++++++++++--------- 3 files changed, 217 insertions(+), 67 deletions(-) create mode 100644 cheatsheet.txt diff --git a/README b/README index b70c423..9f2d03b 100644 --- a/README +++ b/README @@ -1,9 +1,11 @@ -This is a mirror of http://www.vim.org/scripts/script.php?script_id=157 - -This plugin will automatically load cscope.out databases into vim when you open a C file. (headers included) - -It does a search starting at the directory that the file is in, and checking the parent directories until it find the cscope.out file. The idea being that you can start editing a source file deep in a project dir, and it will find the correct cscope database a couple dirs up. - -This version also creates some macros and a menu that can be useful. If you don't like them, you can set g:autocscope_menus to 0 and they won't load. +This Vim plugin is based on prior work from a number of authors. See the +autoload_cscope.vim file header for details. +This plugin will automatically load cscope.out databases (created separately) +into Vim when you open a file. +It performs a search starting at the directory that the edited file is in, +checking the parent directories until it finds the cscope.out file. Therefore +you can start editing a file deep in a project directory, and it will find the +correct Cscope database. Keystroke macros and a pull down menu are provided to +invoke the Cscope functions. diff --git a/cheatsheet.txt b/cheatsheet.txt new file mode 100644 index 0000000..7c67ef4 --- /dev/null +++ b/cheatsheet.txt @@ -0,0 +1,26 @@ +"""""""""""""" Jason Duell's Cscope/Vim Key Mappings Cheat Sheet """"""""""""""" +" (From http://cscope.sourceforge.net/cscope_maps.vim with light edits. ) +" The following maps all invoke one of the following Cscope search types: +" +" 's' symbol: find all references to the token under cursor +" 'g' global: find global definition(s) of the token under cursor +" 'c' calls: find all calls to the function name under cursor +" 't' text: find all instances of the text under cursor +" 'e' egrep: egrep search for the word under cursor +" 'f' file: open the filename under cursor +" 'i' includes: find files that include the filename under cursor +" 'd' called: find functions that function under cursor calls +" +" Below are the maps: one set that just jumps to your search result, one +" that splits the existing vim window horizontally and displays your search +" result in the new window, and one that does the same thing except vertically. +" +" CTRL-\ (Control Backslash) and for the splits CTRL-_ (Control Underscore, +" i.e. CTRL-Shift-Dash) are the starting keys for these maps. +" +" To do the first type of search, hit 'CTRL-\', followed by one of the Cscope +" search types above (s,g,c,t,e,f,i,d). You can use CTRL-t to go back to where +" you were before the search. The second and third types of search use CTRL-_ +" and CTRL-_ twice respectively. The result of your Cscope search will be +" displayed in the current window. +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/plugin/autoload_cscope.vim b/plugin/autoload_cscope.vim index 488a5fd..022b83b 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/autoload_cscope.vim @@ -1,48 +1,118 @@ -" Vim global plugin for autoloading cscope databases. -" Save this file as ~/.vim/plugin/autoload_cscope.vim present -" so you can invoke vim in subdirectories and still get cscope.out loaded. -" Last Change: Wed Jan 26 10:28:52 Jerusalem Standard Time 2011 -" Maintainer: Michael Conrad Tadpol Tilsra -" Revision: 0.5 (plus the below) +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" autoload_cscope.vim: Vim global plugin for autoloading Cscope databases +" +" Based on revision: 0.5 of autoload_cscope.vim by Michael Conrad Tadpol Tilsra +" https://www.vim.org/scripts/script.php?script_id=157 +" With additions from Jason Duell's cscope_macros.vim 2.0.0 +" https://www.vim.org/scripts/script.php?script_id=51 +" http://cscope.sourceforge.net/cscope_maps.vim " With additions from ckelau & ufengzh for .cpp suffix files " With additions from Code-Monky & ckelau for .java suffix files -" See pull requests at https://github.com/vim-scripts/autoload_cscope.vim -" With additions from Jason Duell's cscope settings by Dan Nygren " With additions for .hpp suffix files by Dan Nygren +" With additions for Python and Go by xin3liang +" See pull requests at https://github.com/vim-scripts/autoload_cscope.vim +" With additions for automatically updating cscope database after saves by Flynn +" https://vim.fandom.com/wiki/Script:157 +" CC BY-SA license +" +" Combined by: Dan Nygren +" Email: nygren@msss.com +" Permanent Email: dan.nygren@gmail.com +" Copyright (c) 2022 Dan Nygren. +" BSD 0-clause license, "Zero Clause BSD", SPDX: 0BSD +" +" Save this file as ~/.vim/plugin/autoload_cscope.vim so you can invoke +" vim/gvim in subdirectories and still get cscope.out loaded. It performs a +" search starting at the directory that the edited file is in, checking the +" parent directories until it finds the cscope.out file. Therefore you can +" start editing a file deep in a project directory, and it will find the +" correct Cscope database. +" A prerequisite for use is that a Cscope database has been generated. Cscope +" can be executed on the command line, or a script like cscope_db_gen can be +" used to generate the database. See https://github.com/dnygren/cscope_db_gen +" for an example of how to generate a Cscope database for C/C++. +" This plugin also adds a Cscope selection to gvim's menu bar. +" +" CALL SEQUENCE Place in ~/.vim/plugin directory to call +" +" EXAMPLES N/A +" +" TARGET SYSTEM Unix vim / gvim +" +" DEVELOPED ON Linux +" +" CALLS cscope, cscope_db_gen +" +" CALLED BY vim / gvim +" +" INPUTS autocscope_auto_update, loaded_autoload_cscope +" +" OUTPUTS (Parameters modified, include global/static data) +" +" RETURNS (Type and meaning of return value, if any) +" +" ERROR HANDLING (Describe how errors are handled) +" +" SECURE CODING (List methods used to prevent exploits against this code) +" +" WARNINGS 1) A Cscope database must exist in a parent directory. +" 2) Cscope's global function definition search does not work +" with '__attribute__((unused))' in function definitions because +" Cscope cannot tolerate arbitrary use of () characters in the +" argument list. +" (N. Describe anything a maintainer should be aware of) +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -""""""""""""" Jason Duell's cscope/vim key mappings +"""""""""""""" Jason Duell's Cscope/Vim Key Mappings Cheat Sheet """"""""""""""" " (From http://cscope.sourceforge.net/cscope_maps.vim with light edits. ) -" The following maps all invoke one of the following cscope search types: +" The following maps all invoke one of the following Cscope search types: " -" 's' symbol: find all references to the token under cursor -" 'g' global: find global definition(s) of the token under cursor -" 'c' calls: find all calls to the function name under cursor -" 't' text: find all instances of the text under cursor -" 'e' egrep: egrep search for the word under cursor -" 'f' file: open the filename under cursor +" 's' symbol: find all references to the token under cursor +" 'g' global: find global definition(s) of the token under cursor +" 'c' calls: find all calls to the function name under cursor +" 't' text: find all instances of the text under cursor +" 'e' egrep: egrep search for the word under cursor +" 'f' file: open the filename under cursor " 'i' includes: find files that include the filename under cursor -" 'd' called: find functions that function under cursor calls +" 'd' called: find functions that function under cursor calls " -" Below are the maps: one set that just jumps to your search result, and one +" Below are the maps: one set that just jumps to your search result, one " that splits the existing vim window horizontally and displays your search -" result in the new window. +" result in the new window, and one that does the same thing except vertically. " -" I've used CTRL-\ and CTRL-_ as the starting keys for these maps, as it's -" unlikely that you need their default mappings. -" -" To do the first type of search, hit 'CTRL-\', followed by one of the -" cscope search types above (s,g,c,t,e,f,i,d). The result of your cscope -" search will be displayed in the current window. You can use CTRL-T to -" go back to where you were before the search. +" CTRL-\ (Control Backslash) and for the splits CTRL-_ (Control Underscore, +" i.e. CTRL-Shift-Dash) are the starting keys for these maps. " +" To do the first type of search, hit 'CTRL-\', followed by one of the Cscope +" search types above (s,g,c,t,e,f,i,d). You can use CTRL-t to go back to where +" you were before the search. The second and third types of search use CTRL-_ +" and CTRL-_ twice respectively. The result of your Cscope search will be +" displayed in the current window. +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" If this script is already loaded, skip loading the script again. if exists("loaded_autoload_cscope") - finish + finish endif let loaded_autoload_cscope = 1 -" requirements, you must have these enabled or this is useless. +" If set to 1, it will auto update your cscope/gtags database and reset the +" Cscope connection when a file is saved. +if !exists("g:autocscope_auto_update") + let g:autocscope_auto_update = 1 +endif + +" If set to 1, the menu and macros will be loaded. Set value something other +" than 1 if they are not wanted. +if !exists("g:autocscope_menus") + let g:autocscope_menus = 1 +endif + +" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +" ^^^^^^^^^^ Place code that may need modification above this point. ^^^^^^^^^^ +" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +" Vim must have these enabled or this plugin is useless. if( !has('cscope') || !has('modify_fname') ) finish endif @@ -50,13 +120,6 @@ endif let s:save_cpo = &cpo set cpo&vim -" If you set this to anything other than 1, the menu and macros will not be -" loaded. Useful if you have your own that you like. Or don't want my stuff -" clashing with any macros you've made. -if !exists("g:autocscope_menus") - let g:autocscope_menus = 1 -endif - "== " windowdir " Gets the directory for the file in the current window @@ -65,7 +128,7 @@ endif function s:windowdir() if winbufnr(0) == -1 let unislash = getcwd() - else + else let unislash = fnamemodify(bufname(winbufnr(0)), ':p:h') endif return tr(unislash, '\', '/') @@ -97,7 +160,7 @@ endfunc " "== " Cycle_macros_menus -" if there are cscope connections, activate that stuff. +" if there are Cscope connections, activate that stuff. " Else toss it out. " TODO Maybe I should move this into a separate plugin? let s:menus_loaded = 0 @@ -112,29 +175,35 @@ function s:Cycle_macros_menus() let s:menus_loaded = 1 set csto=0 set cst +" Update the cheat sheet if the mappings are changed. silent! map s :cs find s =expand("") silent! map g :cs find g =expand("") -" cscope's global function definition search does not work with -" '__attribute__((unused))' in function definitions because cscope -" cannot tolerate arbitrary use of () characters in the argument list. -" (Dan Nygren) silent! map d :cs find d =expand("") silent! map c :cs find c =expand("") silent! map t :cs find t =expand("") silent! map e :cs find e =expand("") - silent! map f :cs find f =expand("") - silent! map i :cs find i =expand("") -" Addition from Jason Duell's cscope settings (Dan Nygren) -" Split screen horizontally with CTRL underscore + silent! map f :cs find f =expand("") + silent! map i :cs find i =expand("") +" Split screen horizontally with CTRL underscore (CTRL-Shift-Dash) silent! map s :scs find s =expand("") silent! map g :scs find g =expand("") silent! map c :scs find c =expand("") silent! map t :scs find t =expand("") silent! map e :scs find e =expand("") silent! map f :scs find f =expand("") - silent! map i :scs find i ^=expand("")$ + silent! map i :scs find i =expand("") silent! map d :scs find d =expand("") " End Split screen horizontally +" Split screen vertically with CTRL underscore twice (CTRL-Shift-Dash twice) + silent! map s :vert scs find s =expand("") + silent! map g :vert scs find g =expand("") + silent! map c :vert scs find c =expand("") + silent! map t :vert scs find t =expand("") + silent! map e :vert scs find e =expand("") + silent! map f :vert scs find f =expand("") + silent! map i :vert scs find i =expand("") + silent! map d :vert scs find d =expand("") +" End Split screen vertically if has("menu") nmenu &Cscope.Find.Symbols \ :cs find s =expand("") @@ -149,11 +218,11 @@ function s:Cycle_macros_menus() nmenu &Cscope.Find.Egrepe \ :cs find e =expand("") nmenu &Cscope.Find.Filef - \ :cs find f =expand("") + \ :cs find f =expand("") nmenu &Cscope.Find.Includingi - \ :cs find i =expand("") -" nmenu &Cscope.Add :cs add -" nmenu &Cscope.Remove :cs kill + \ :cs find i =expand("") +" nmenu &Cscope.Add :cs add +" nmenu &Cscope.Remove :cs kill nmenu &Cscope.Reset :cs reset nmenu &Cscope.Show :cs show " Need to figure out how to do the add/remove. May end up writing @@ -179,7 +248,7 @@ endfunc " "== " Unload_csdb -" drop cscope connections. +" drop Cscope connections. function s:Unload_csdb() if exists("b:csdbpath") if cscope_connection(3, "out", b:csdbpath) @@ -194,7 +263,7 @@ endfunc " "== " Cycle_csdb -" cycle the loaded cscope db. +" cycle the loaded Cscope db. function s:Cycle_csdb() if exists("b:csdbpath") if cscope_connection(3, "out", b:csdbpath) @@ -215,12 +284,54 @@ function s:Cycle_csdb() let &csverb = save_csvb endif " - else " No cscope database, undo things. (someone rm-ed it or somesuch) + else " No Cscope database, undo things. (someone rm-ed it or ...?) call s:Unload_csdb() endif endfunc -" By default, cscope examines C (.c & .h), lex (.l), and yacc (.y) source files. +" If enabled, auto update your cscope/gtags database and reset the Cscope +" connection when a file is saved. +function s:Update_csdb() + if g:autocscope_auto_update != 1 + return + endif + + if exists("b:csdbpath") + if cscope_connection(3, g:autocscope_tagfile_name, b:csdbpath) + if g:autocscope_use_gtags == 1 + "exe "silent !cd " . b:csdbpath . " && global -u &" + exe "silent !cd " . b:csdbpath . " && global -u" +" Cscope only examines C (.c & .h), lex (.l), and yacc (.y) source files. +" else +" "exe "silent !cd " . b:csdbpath . " && cscope -Rbq &" +" exe "silent !cd " . b:csdbpath . " && cscope -Rbq" +" The cscope_db_gen script allows other source files to be examined by Cscope. + else + "exe "silent !cd " . b:csdbpath . " && cscope_db_gen &" + exe "silent !cd " . b:csdbpath . " && cscope_db_gen" + endif + + set nocsverb + exe "cs reset" + set csverb + endif + endif +endfunc + +" If you set this to 1, it will use gtags-cscope which is faster than cscope. +if !exists("g:autocscope_use_gtags") + let g:autocscope_use_gtags = 0 +endif + +if g:autocscope_use_gtags == 1 + let g:autocscope_tagfile_name = "GTAGS" + set cscopeprg=gtags-cscope +else + let g:autocscope_tagfile_name = "cscope.out" + set cscopeprg=cscope +endif + +" By default, Cscope examines C (.c & .h), lex (.l), and yacc (.y) source files. " Additions made for C++ source files (.cc, .cpp, .hpp). " Additions made for Java source files (.java). " auto toggle the menu @@ -229,16 +340,27 @@ augroup autoload_cscope au BufEnter *.[chly] call Cycle_csdb() | call Cycle_macros_menus() au BufEnter *.cc call Cycle_csdb() | call Cycle_macros_menus() au BufEnter *.[ch]pp call Cycle_csdb() | call Cycle_macros_menus() - au BufEnter *.java call Cycle_csdb() | call Cycle_macros_menus() + au BufEnter *.java call Cycle_csdb() | call Cycle_macros_menus() + au BufEnter *.py call Cycle_csdb() | call Cycle_macros_menus() + au BufEnter *.go call Cycle_csdb() | call Cycle_macros_menus() +" + au BufWritePost *.[chly] call Update_csdb() | call Cycle_macros_menus() + au BufWritePost *.cc call Update_csdb() | call Cycle_macros_menus() + au BufWritePost *.[ch]pp call Update_csdb() | call Cycle_macros_menus() + au BufWritePost *.java call Update_csdb() | call Cycle_macros_menus() + au BufWritePost *.py call Update_csdb() | call Cycle_macros_menus() + au BufWritePost *.go call Update_csdb() | call Cycle_macros_menus() +" au BufUnload *.[chly] call Unload_csdb() | call Cycle_macros_menus() au BufUnload *.cc call Unload_csdb() | call Cycle_macros_menus() - au BufUnload *.[ch]pp call Cycle_csdb() | call Cycle_macros_menus() - au BufUnload *.java call Cycle_csdb() | call Cycle_macros_menus() + au BufUnload *.[ch]pp call Unload_csdb() | call Cycle_macros_menus() + au BufUnload *.java call Unload_csdb() | call Cycle_macros_menus() + au BufUnload *.py call Unload_csdb() | call Cycle_macros_menus() + au BufUnload *.go call Unload_csdb() | call Cycle_macros_menus() augroup END let &cpo = s:save_cpo -" Addition from Jason Duell's cscope settings " """"""""""""" key map timeouts " " " " By default Vim will only wait 1 second for each keystroke in a mapping. @@ -251,7 +373,7 @@ let &cpo = s:save_cpo " " with your own personal favorite value (in milliseconds): " " " "set timeoutlen=4000 -set timeoutlen=2000 +set timeoutlen=3000 " " " " Either way, since mapping timeout settings by default also set the " " timeouts for multicharacter 'keys codes' (like ), you should also From db3f1e44eb184ceb93391e93b4442e51680ab6c4 Mon Sep 17 00:00:00 2001 From: nygren Date: Wed, 16 Feb 2022 13:14:24 -0800 Subject: [PATCH 3/7] Changed call to cscope_db_gen script to -q quick mode. --- cheatsheet.txt | 14 +++-- plugin/autoload_cscope.vim | 101 ++++++++++++++++++++++++------------- 2 files changed, 72 insertions(+), 43 deletions(-) diff --git a/cheatsheet.txt b/cheatsheet.txt index 7c67ef4..6843c92 100644 --- a/cheatsheet.txt +++ b/cheatsheet.txt @@ -11,16 +11,14 @@ " 'i' includes: find files that include the filename under cursor " 'd' called: find functions that function under cursor calls " -" Below are the maps: one set that just jumps to your search result, one -" that splits the existing vim window horizontally and displays your search -" result in the new window, and one that does the same thing except vertically. -" -" CTRL-\ (Control Backslash) and for the splits CTRL-_ (Control Underscore, -" i.e. CTRL-Shift-Dash) are the starting keys for these maps. +" The starting keys for the searches are: +" CTRL-\ (Control Backslash) which just jumps to your search result, +" CTRL-_ (Control Underscore, i.e. CTRL-Shift-Dash) splits the Vim window, +" CTRL-_CTRL-_ (Control Underscore twice) splits the Vim window vertically. " " To do the first type of search, hit 'CTRL-\', followed by one of the Cscope -" search types above (s,g,c,t,e,f,i,d). You can use CTRL-t to go back to where -" you were before the search. The second and third types of search use CTRL-_ +" search types above (s,g,c,t,e,f,i,d). Use CTRL-t to go back to where the +" searching began. The second and third types of search use CTRL-_ and then " and CTRL-_ twice respectively. The result of your Cscope search will be " displayed in the current window. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/plugin/autoload_cscope.vim b/plugin/autoload_cscope.vim index 022b83b..d185ad0 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/autoload_cscope.vim @@ -76,16 +76,14 @@ " 'i' includes: find files that include the filename under cursor " 'd' called: find functions that function under cursor calls " -" Below are the maps: one set that just jumps to your search result, one -" that splits the existing vim window horizontally and displays your search -" result in the new window, and one that does the same thing except vertically. -" -" CTRL-\ (Control Backslash) and for the splits CTRL-_ (Control Underscore, -" i.e. CTRL-Shift-Dash) are the starting keys for these maps. +" The starting keys for the searches are: +" CTRL-\ (Control Backslash) which just jumps to your search result, +" CTRL-_ (Control Underscore, i.e. CTRL-Shift-Dash) splits the Vim window, +" CTRL-_CTRL-_ (Control Underscore twice) splits the Vim window vertically. " " To do the first type of search, hit 'CTRL-\', followed by one of the Cscope -" search types above (s,g,c,t,e,f,i,d). You can use CTRL-t to go back to where -" you were before the search. The second and third types of search use CTRL-_ +" search types above (s,g,c,t,e,f,i,d). Use CTRL-t to go back to where the +" searching began. The second and third types of search use CTRL-_ and then " and CTRL-_ twice respectively. The result of your Cscope search will be " displayed in the current window. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -96,7 +94,17 @@ if exists("loaded_autoload_cscope") endif let loaded_autoload_cscope = 1 -" If set to 1, it will auto update your cscope/gtags database and reset the +" The default Cscope path component (cspc) value of "0" displays the entire +" path, which usually doesn't fit the screen and so gets be abbreviated to just +" the starting path (usually useless) and the ending path (most already known). +" The below construct sets cspc to a more reasonable value if cscp hasn't been +" changed from the default in the user's .vimrc file. +" +if &cspc == "0" + set cspc=4 +endif + +" If set to 1, auto update your cscope/gtags database and reset the " Cscope connection when a file is saved. if !exists("g:autocscope_auto_update") let g:autocscope_auto_update = 1 @@ -108,12 +116,18 @@ if !exists("g:autocscope_menus") let g:autocscope_menus = 1 endif +" If set to 1, use gtags-cscope which is faster than cscope. +if !exists("g:autocscope_use_gtags") + let g:autocscope_use_gtags = 0 +endif + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " ^^^^^^^^^^ Place code that may need modification above this point. ^^^^^^^^^^ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " Vim must have these enabled or this plugin is useless. -if( !has('cscope') || !has('modify_fname') ) +if( !has('cscope') || !has('modify_fname') ) finish endif @@ -195,16 +209,26 @@ function s:Cycle_macros_menus() silent! map d :scs find d =expand("") " End Split screen horizontally " Split screen vertically with CTRL underscore twice (CTRL-Shift-Dash twice) - silent! map s :vert scs find s =expand("") - silent! map g :vert scs find g =expand("") - silent! map c :vert scs find c =expand("") - silent! map t :vert scs find t =expand("") - silent! map e :vert scs find e =expand("") - silent! map f :vert scs find f =expand("") - silent! map i :vert scs find i =expand("") - silent! map d :vert scs find d =expand("") +" Line continuation. See :help line-continuation + silent! map s + \ :vert scs find s =expand("") + silent! map g + \ :vert scs find g =expand("") + silent! map c + \ :vert scs find c =expand("") + silent! map t + \ :vert scs find t =expand("") + silent! map e + \ :vert scs find e =expand("") + silent! map f + \ :vert scs find f =expand("") + silent! map i + \ :vert scs find i =expand("") + silent! map d + \ :vert scs find d =expand("") " End Split screen vertically if has("menu") +" Line continuation. See :help line-continuation nmenu &Cscope.Find.Symbols \ :cs find s =expand("") nmenu &Cscope.Find.Definitiong @@ -299,16 +323,21 @@ function s:Update_csdb() if exists("b:csdbpath") if cscope_connection(3, g:autocscope_tagfile_name, b:csdbpath) if g:autocscope_use_gtags == 1 - "exe "silent !cd " . b:csdbpath . " && global -u &" + "exe "silent !cd " . b:csdbpath . " && global -u" exe "silent !cd " . b:csdbpath . " && global -u" " Cscope only examines C (.c & .h), lex (.l), and yacc (.y) source files. " else -" "exe "silent !cd " . b:csdbpath . " && cscope -Rbq &" +" "exe "silent !cd " . b:csdbpath . " && cscope -Rbq" " exe "silent !cd " . b:csdbpath . " && cscope -Rbq" -" The cscope_db_gen script allows other source files to be examined by Cscope. +" +" The cscope_db_gen script allows source files other than the Cscope defaults +" to be examined by Cscope (C++ files etc.). When called with the -q "quick" +" flag, cscope_db_gen uses the existing cscope.files list of files. So if new +" files are created, cscope_db_gen without flags must be executed in the +" repository's base directory. else - "exe "silent !cd " . b:csdbpath . " && cscope_db_gen &" - exe "silent !cd " . b:csdbpath . " && cscope_db_gen" + "exe "silent !cd " . b:csdbpath . " && cscope_db_gen -q" + exe "silent !cd " . b:csdbpath . " && cscope_db_gen -q" endif set nocsverb @@ -318,11 +347,7 @@ function s:Update_csdb() endif endfunc -" If you set this to 1, it will use gtags-cscope which is faster than cscope. -if !exists("g:autocscope_use_gtags") - let g:autocscope_use_gtags = 0 -endif - +" If set to 1, use gtags-cscope which is faster than cscope. if g:autocscope_use_gtags == 1 let g:autocscope_tagfile_name = "GTAGS" set cscopeprg=gtags-cscope @@ -343,13 +368,19 @@ augroup autoload_cscope au BufEnter *.java call Cycle_csdb() | call Cycle_macros_menus() au BufEnter *.py call Cycle_csdb() | call Cycle_macros_menus() au BufEnter *.go call Cycle_csdb() | call Cycle_macros_menus() -" - au BufWritePost *.[chly] call Update_csdb() | call Cycle_macros_menus() - au BufWritePost *.cc call Update_csdb() | call Cycle_macros_menus() - au BufWritePost *.[ch]pp call Update_csdb() | call Cycle_macros_menus() - au BufWritePost *.java call Update_csdb() | call Cycle_macros_menus() - au BufWritePost *.py call Update_csdb() | call Cycle_macros_menus() - au BufWritePost *.go call Update_csdb() | call Cycle_macros_menus() +" Line continuation. See :help line-continuation + au BufWritePost *.[chly] call Update_csdb() | call + \ Cycle_macros_menus() + au BufWritePost *.cc call Update_csdb() | call + \ Cycle_macros_menus() + au BufWritePost *.[ch]pp call Update_csdb() | call + \ Cycle_macros_menus() + au BufWritePost *.java call Update_csdb() | call + \ Cycle_macros_menus() + au BufWritePost *.py call Update_csdb() | call + \ Cycle_macros_menus() + au BufWritePost *.go call Update_csdb() | call + \ Cycle_macros_menus() " au BufUnload *.[chly] call Unload_csdb() | call Cycle_macros_menus() au BufUnload *.cc call Unload_csdb() | call Cycle_macros_menus() From c6f72130244419900b86f3824ddb7c990d7df53e Mon Sep 17 00:00:00 2001 From: nygren Date: Tue, 5 Apr 2022 12:21:36 -0700 Subject: [PATCH 4/7] Changed window splits to use Ctrl-H and Ctrl-V --- README | 4 +- cheatsheet.txt | 32 +++++++-------- plugin/autoload_cscope.vim | 79 +++++++++++++++++++------------------- 3 files changed, 58 insertions(+), 57 deletions(-) diff --git a/README b/README index 9f2d03b..f28818e 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ This Vim plugin is based on prior work from a number of authors. See the -autoload_cscope.vim file header for details. +autoload_cscope.vim comment header block for details. This plugin will automatically load cscope.out databases (created separately) into Vim when you open a file. @@ -9,3 +9,5 @@ checking the parent directories until it finds the cscope.out file. Therefore you can start editing a file deep in a project directory, and it will find the correct Cscope database. Keystroke macros and a pull down menu are provided to invoke the Cscope functions. + +A cheatsheet is provided to assist in executing the keystroke macros. diff --git a/cheatsheet.txt b/cheatsheet.txt index 6843c92..6567e8c 100644 --- a/cheatsheet.txt +++ b/cheatsheet.txt @@ -1,24 +1,24 @@ """""""""""""" Jason Duell's Cscope/Vim Key Mappings Cheat Sheet """"""""""""""" -" (From http://cscope.sourceforge.net/cscope_maps.vim with light edits. ) +" (Based on http://cscope.sourceforge.net/cscope_maps.vim with light edits.) " The following maps all invoke one of the following Cscope search types: " -" 's' symbol: find all references to the token under cursor -" 'g' global: find global definition(s) of the token under cursor -" 'c' calls: find all calls to the function name under cursor -" 't' text: find all instances of the text under cursor -" 'e' egrep: egrep search for the word under cursor -" 'f' file: open the filename under cursor -" 'i' includes: find files that include the filename under cursor -" 'd' called: find functions that function under cursor calls +" 's' symbol Find all references to the token under cursor +" 'g' global Find global definition(s) of the token under cursor +" 'c' calls Find all calls to the function name under cursor +" 'd' called Find functions that function under cursor calls +" 't' text Find all instances of the text under cursor +" 'e' egrep Find egrep pattern for the word under cursor +" 'f' file Open the filename under cursor +" 'i' includes Find files that include the filename under cursor " " The starting keys for the searches are: -" CTRL-\ (Control Backslash) which just jumps to your search result, -" CTRL-_ (Control Underscore, i.e. CTRL-Shift-Dash) splits the Vim window, -" CTRL-_CTRL-_ (Control Underscore twice) splits the Vim window vertically. +" CTRL-\ (Control Backslash) jumps the whole Vim window to the search result, +" CTRL-H (Control H) splits the Vim window horizontally to display the result, +" CTRL-V (Control V) splits the Vim window vertically to display the result. +" CTRL-T (Control T) jumps back to where the search began. " " To do the first type of search, hit 'CTRL-\', followed by one of the Cscope -" search types above (s,g,c,t,e,f,i,d). Use CTRL-t to go back to where the -" searching began. The second and third types of search use CTRL-_ and then -" and CTRL-_ twice respectively. The result of your Cscope search will be -" displayed in the current window. +" search types above (s,g,c,d,t,e,f,i). Use CTRL-T to go back to where the +" searching began. The second and third types of search use CTRL-H or CTRL-V +" to split the window horizontally or vertically to display the search result. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/plugin/autoload_cscope.vim b/plugin/autoload_cscope.vim index d185ad0..6dc8112 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/autoload_cscope.vim @@ -64,28 +64,28 @@ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""" Jason Duell's Cscope/Vim Key Mappings Cheat Sheet """"""""""""""" -" (From http://cscope.sourceforge.net/cscope_maps.vim with light edits. ) +" (Based on http://cscope.sourceforge.net/cscope_maps.vim with light edits.) " The following maps all invoke one of the following Cscope search types: " -" 's' symbol: find all references to the token under cursor -" 'g' global: find global definition(s) of the token under cursor -" 'c' calls: find all calls to the function name under cursor -" 't' text: find all instances of the text under cursor -" 'e' egrep: egrep search for the word under cursor -" 'f' file: open the filename under cursor -" 'i' includes: find files that include the filename under cursor -" 'd' called: find functions that function under cursor calls +" 's' symbol Find all references to the token under cursor +" 'g' global Find global definition(s) of the token under cursor +" 'c' calls Find all calls to the function name under cursor +" 'd' called Find functions that function under cursor calls +" 't' text Find all instances of the text under cursor +" 'e' egrep Find egrep pattern for the word under cursor +" 'f' file Open the filename under cursor +" 'i' includes Find files that include the filename under cursor " " The starting keys for the searches are: -" CTRL-\ (Control Backslash) which just jumps to your search result, -" CTRL-_ (Control Underscore, i.e. CTRL-Shift-Dash) splits the Vim window, -" CTRL-_CTRL-_ (Control Underscore twice) splits the Vim window vertically. +" CTRL-\ (Control Backslash) jumps the whole Vim window to the search result, +" CTRL-H (Control H) splits the Vim window horizontally to display the result, +" CTRL-V (Control V) splits the Vim window vertically to display the result. +" CTRL-T (Control T) jumps back to where the search began. " " To do the first type of search, hit 'CTRL-\', followed by one of the Cscope -" search types above (s,g,c,t,e,f,i,d). Use CTRL-t to go back to where the -" searching began. The second and third types of search use CTRL-_ and then -" and CTRL-_ twice respectively. The result of your Cscope search will be -" displayed in the current window. +" search types above (s,g,c,d,t,e,f,i). Use CTRL-T to go back to where the +" searching began. The second and third types of search use CTRL-H or CTRL-V +" to split the window horizontally or vertically to display the search result. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " If this script is already loaded, skip loading the script again. @@ -121,7 +121,6 @@ if !exists("g:autocscope_use_gtags") let g:autocscope_use_gtags = 0 endif - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " ^^^^^^^^^^ Place code that may need modification above this point. ^^^^^^^^^^ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,40 +191,40 @@ function s:Cycle_macros_menus() " Update the cheat sheet if the mappings are changed. silent! map s :cs find s =expand("") silent! map g :cs find g =expand("") - silent! map d :cs find d =expand("") silent! map c :cs find c =expand("") + silent! map d :cs find d =expand("") silent! map t :cs find t =expand("") silent! map e :cs find e =expand("") silent! map f :cs find f =expand("") silent! map i :cs find i =expand("") -" Split screen horizontally with CTRL underscore (CTRL-Shift-Dash) - silent! map s :scs find s =expand("") - silent! map g :scs find g =expand("") - silent! map c :scs find c =expand("") - silent! map t :scs find t =expand("") - silent! map e :scs find e =expand("") - silent! map f :scs find f =expand("") - silent! map i :scs find i =expand("") - silent! map d :scs find d =expand("") +" Split screen horizontally with CTRL h + silent! map s :scs find s =expand("") + silent! map g :scs find g =expand("") + silent! map c :scs find c =expand("") + silent! map d :scs find d =expand("") + silent! map t :scs find t =expand("") + silent! map e :scs find e =expand("") + silent! map f :scs find f =expand("") + silent! map i :scs find i =expand("") " End Split screen horizontally -" Split screen vertically with CTRL underscore twice (CTRL-Shift-Dash twice) +" Split screen vertically with CTRL v " Line continuation. See :help line-continuation - silent! map s + silent! map s \ :vert scs find s =expand("") - silent! map g + silent! map g \ :vert scs find g =expand("") - silent! map c + silent! map c \ :vert scs find c =expand("") - silent! map t + silent! map d + \ :vert scs find d =expand("") + silent! map t \ :vert scs find t =expand("") - silent! map e + silent! map e \ :vert scs find e =expand("") - silent! map f + silent! map f \ :vert scs find f =expand("") - silent! map i + silent! map i \ :vert scs find i =expand("") - silent! map d - \ :vert scs find d =expand("") " End Split screen vertically if has("menu") " Line continuation. See :help line-continuation @@ -233,10 +232,10 @@ function s:Cycle_macros_menus() \ :cs find s =expand("") nmenu &Cscope.Find.Definitiong \ :cs find g =expand("") - nmenu &Cscope.Find.Calledd - \ :cs find d =expand("") nmenu &Cscope.Find.Callingc \ :cs find c =expand("") + nmenu &Cscope.Find.Calledd + \ :cs find d =expand("") nmenu &Cscope.Find.Assignmentt \ :cs find t =expand("") nmenu &Cscope.Find.Egrepe @@ -258,8 +257,8 @@ function s:Cycle_macros_menus() set nocst silent! unmap s silent! unmap g - silent! unmap d silent! unmap c + silent! unmap d silent! unmap t silent! unmap e silent! unmap f From 47db05e0868b8f413eb038bf58756d4e89c4e8ac Mon Sep 17 00:00:00 2001 From: nygren Date: Wed, 6 Apr 2022 16:49:06 -0700 Subject: [PATCH 5/7] Added ability to select between cscope_db_gen or cscope. --- README | 13 ++-- plugin/autoload_cscope.vim | 132 +++++++++++++++++++------------------ 2 files changed, 78 insertions(+), 67 deletions(-) diff --git a/README b/README index f28818e..1d3f449 100644 --- a/README +++ b/README @@ -1,13 +1,18 @@ This Vim plugin is based on prior work from a number of authors. See the autoload_cscope.vim comment header block for details. -This plugin will automatically load cscope.out databases (created separately) -into Vim when you open a file. +This plugin will automatically load a cscope.out database (created manually in +the base directory of a source code file tree) into Vim when you open a file. It performs a search starting at the directory that the edited file is in, checking the parent directories until it finds the cscope.out file. Therefore you can start editing a file deep in a project directory, and it will find the -correct Cscope database. Keystroke macros and a pull down menu are provided to -invoke the Cscope functions. +correct Cscope database. + +It will also automatically update the cscope database after file saves. If new +files are created, the cscope.out database must be recreated manually. + +Keystroke macros and a pull down menu are provided to invoke the Cscope +functions. A cheatsheet is provided to assist in executing the keystroke macros. diff --git a/plugin/autoload_cscope.vim b/plugin/autoload_cscope.vim index 6dc8112..0d19ddd 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/autoload_cscope.vim @@ -3,15 +3,16 @@ " " Based on revision: 0.5 of autoload_cscope.vim by Michael Conrad Tadpol Tilsra " https://www.vim.org/scripts/script.php?script_id=157 -" With additions from Jason Duell's cscope_macros.vim 2.0.0 +" https://github.com/vim-scripts/autoload_cscope.vim +" and based on Jason Duell's cscope_macros.vim 2.0.0 " https://www.vim.org/scripts/script.php?script_id=51 " http://cscope.sourceforge.net/cscope_maps.vim -" With additions from ckelau & ufengzh for .cpp suffix files -" With additions from Code-Monky & ckelau for .java suffix files -" With additions for .hpp suffix files by Dan Nygren -" With additions for Python and Go by xin3liang +" with additions from ckelau & ufengzh for .cpp suffix files +" with additions from Code-Monky & ckelau for .java suffix files +" with additions for .hpp suffix files by Dan Nygren +" with additions for Python and Go by xin3liang " See pull requests at https://github.com/vim-scripts/autoload_cscope.vim -" With additions for automatically updating cscope database after saves by Flynn +" with additions for automatically updating cscope database after saves by Flynn " https://vim.fandom.com/wiki/Script:157 " CC BY-SA license " @@ -41,7 +42,7 @@ " " DEVELOPED ON Linux " -" CALLS cscope, cscope_db_gen +" CALLS cscope, cscope_db_gen, global, gtags-cscope " " CALLED BY vim / gvim " @@ -56,7 +57,10 @@ " SECURE CODING (List methods used to prevent exploits against this code) " " WARNINGS 1) A Cscope database must exist in a parent directory. -" 2) Cscope's global function definition search does not work +" 2) If new files are created, create a new list of files +" (e.g. cscope.files) in the repository's base directory by +" running cscope_db_gen without flags or a similar command. +" 3) Cscope's global function definition search does not work " with '__attribute__((unused))' in function definitions because " Cscope cannot tolerate arbitrary use of () characters in the " argument list. @@ -104,23 +108,63 @@ if &cspc == "0" set cspc=4 endif -" If set to 1, auto update your cscope/gtags database and reset the -" Cscope connection when a file is saved. +" If set to 1, auto update your cscope/gtags database and reset the Cscope +" connection when a file is saved. +" The default is 1, update the cscope/gtags database and reset the connection. if !exists("g:autocscope_auto_update") let g:autocscope_auto_update = 1 endif -" If set to 1, the menu and macros will be loaded. Set value something other -" than 1 if they are not wanted. +" If set to 1, the menu and macros will be loaded. +" The default is 1, use menus. Set value to 0 if they are not wanted. if !exists("g:autocscope_menus") let g:autocscope_menus = 1 endif -" If set to 1, use gtags-cscope which is faster than cscope. +" If set to 1, use gtags-cscope which is faster than cscope / cscope_bd_gen. +" The default is 0, do not use gtags-cscope, use cscope / cscope_db_gen instead. if !exists("g:autocscope_use_gtags") let g:autocscope_use_gtags = 0 endif +" If set to 1, use the cscope database generator script "cscope_db_gen" which +" can examine more that Cscope's C (.c & .h), lex (.l), and yacc (.y) files. +" The default is 1, use cscope_db_gen. Set value to 0 if cscope is wanted. +if !exists("g:autocscope_use_cscope_db_gen") + let g:autocscope_use_cscope_db_gen = 1 +endif + +" """"""""""""" key map timeouts """"""""""""" +" " +" " By default Vim will only wait 1 second for each keystroke in a mapping. +" " You may find that too short with the above typemaps. If so, you should +" " either turn off mapping timeouts via 'notimeout'. +" " +" "set notimeout +" " +" " Or, you can keep timeouts, by uncommenting the timeoutlen line below, +" " with your own personal favorite value (in milliseconds): +" " +" "set timeoutlen=4000 +set timeoutlen=3000 +" " +" " Either way, since mapping timeout settings by default also set the +" " timeouts for multicharacter 'keys codes' (like ), you should also +" " set ttimeout and ttimeoutlen: otherwise, you will experience strange +" " delays as vim waits for a keystroke after you hit ESC (it will be +" " waiting to see if the ESC is actually part of a key code like ). +" " +" "set ttimeout +set ttimeout +" " +" " A tenth of a second works well for key code timeouts. If you +" " experience problems and have a slow terminal or network connection +" " set it higher. If you don't set ttimeoutlen, a sluggish value for +" " timeoutlent (default: 1000 = 1 second) is used. +" " +" "set ttimeoutlen=100 +set ttimeoutlen=100 + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " ^^^^^^^^^^ Place code that may need modification above this point. ^^^^^^^^^^ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -245,7 +289,7 @@ function s:Cycle_macros_menus() nmenu &Cscope.Find.Includingi \ :cs find i =expand("") " nmenu &Cscope.Add :cs add -" nmenu &Cscope.Remove :cs kill +" nmenu &Cscope.Remove :cs kill nmenu &Cscope.Reset :cs reset nmenu &Cscope.Show :cs show " Need to figure out how to do the add/remove. May end up writing @@ -318,35 +362,29 @@ function s:Update_csdb() if g:autocscope_auto_update != 1 return endif - if exists("b:csdbpath") if cscope_connection(3, g:autocscope_tagfile_name, b:csdbpath) if g:autocscope_use_gtags == 1 - "exe "silent !cd " . b:csdbpath . " && global -u" exe "silent !cd " . b:csdbpath . " && global -u" -" Cscope only examines C (.c & .h), lex (.l), and yacc (.y) source files. -" else -" "exe "silent !cd " . b:csdbpath . " && cscope -Rbq" -" exe "silent !cd " . b:csdbpath . " && cscope -Rbq" -" -" The cscope_db_gen script allows source files other than the Cscope defaults -" to be examined by Cscope (C++ files etc.). When called with the -q "quick" -" flag, cscope_db_gen uses the existing cscope.files list of files. So if new -" files are created, cscope_db_gen without flags must be executed in the -" repository's base directory. - else - "exe "silent !cd " . b:csdbpath . " && cscope_db_gen -q" + " The cscope_db_gen script allows source files other than the + " Cscope defaults to be examined by Cscope (C++ files etc.). When + " called with the -q "quick" flag, cscope_db_gen uses the existing + " cscope.files list of files. So if new files are created, + " cscope_db_gen without flags must be executed in the repository's + " base directory. + else if g:autocscope_use_cscope_db_gen = 1 exe "silent !cd " . b:csdbpath . " && cscope_db_gen -q" + " Cscope only examines C (.c & .h), lex (.l), and yacc (.y) files. + else + exe "silent !cd " . b:csdbpath . " && cscope -Rbq" endif - set nocsverb exe "cs reset" set csverb endif - endif + endif endfunc -" If set to 1, use gtags-cscope which is faster than cscope. if g:autocscope_use_gtags == 1 let g:autocscope_tagfile_name = "GTAGS" set cscopeprg=gtags-cscope @@ -390,35 +428,3 @@ augroup autoload_cscope augroup END let &cpo = s:save_cpo - -" """"""""""""" key map timeouts -" " -" " By default Vim will only wait 1 second for each keystroke in a mapping. -" " You may find that too short with the above typemaps. If so, you should -" " either turn off mapping timeouts via 'notimeout'. -" " -" "set notimeout -" " -" " Or, you can keep timeouts, by uncommenting the timeoutlen line below, -" " with your own personal favorite value (in milliseconds): -" " -" "set timeoutlen=4000 -set timeoutlen=3000 -" " -" " Either way, since mapping timeout settings by default also set the -" " timeouts for multicharacter 'keys codes' (like ), you should also -" " set ttimeout and ttimeoutlen: otherwise, you will experience strange -" " delays as vim waits for a keystroke after you hit ESC (it will be -" " waiting to see if the ESC is actually part of a key code like ). -" " -" "set ttimeout -set ttimeout -" " -" " personally, I find a tenth of a second to work well for key code -" " timeouts. If you experience problems and have a slow terminal or network -" " connection, set it higher. If you don't set ttimeoutlen, the value for -" " timeoutlent (default: 1000 = 1 second, which is sluggish) is used. -" " -" "set ttimeoutlen=100 -set ttimeoutlen=100 -" From 0d85c52af1d64c93ac7b06c043da3616505bc92f Mon Sep 17 00:00:00 2001 From: nygren Date: Mon, 11 Apr 2022 09:59:18 -0700 Subject: [PATCH 6/7] Fixed elseif statement typos. --- plugin/autoload_cscope.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/autoload_cscope.vim b/plugin/autoload_cscope.vim index 0d19ddd..9c2a5f1 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/autoload_cscope.vim @@ -372,7 +372,7 @@ function s:Update_csdb() " cscope.files list of files. So if new files are created, " cscope_db_gen without flags must be executed in the repository's " base directory. - else if g:autocscope_use_cscope_db_gen = 1 + elseif g:autocscope_use_cscope_db_gen == 1 exe "silent !cd " . b:csdbpath . " && cscope_db_gen -q" " Cscope only examines C (.c & .h), lex (.l), and yacc (.y) files. else From 2e25bb79109148057cee2f7a8f02238b940a0152 Mon Sep 17 00:00:00 2001 From: nygren Date: Tue, 28 Jun 2022 10:15:14 -0700 Subject: [PATCH 7/7] Name change to cscope_helper.vim --- LICENSE | 14 ++++++++++++++ README | 17 ++++++++++++----- .../{autoload_cscope.vim => cscope_helper.vim} | 4 ++-- 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 LICENSE rename plugin/{autoload_cscope.vim => cscope_helper.vim} (99%) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f2747f7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ +BSD 0-clause license, "Zero Clause BSD", SPDX: 0BSD + +Copyright (C) 2022 by Daniel C. Nygren + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README b/README index 1d3f449..3a5ee0d 100644 --- a/README +++ b/README @@ -1,5 +1,13 @@ This Vim plugin is based on prior work from a number of authors. See the -autoload_cscope.vim comment header block for details. +cscope_helper.vim comment header block for details. + +Save this file as ~/.vim/plugin/cscope_helper.vim so you can invoke vim/gvim in +subdirectories and still get cscope.out loaded. + +A prerequisite for use is that an initial Cscope database has been generated. +Cscope can be executed on the command line, or a script like cscope_db_gen can +be used to generate the database. See https://github.com/dnygren/cscope_db_gen +for an example of how to generate a Cscope database for C/C++. This plugin will automatically load a cscope.out database (created manually in the base directory of a source code file tree) into Vim when you open a file. @@ -7,10 +15,9 @@ the base directory of a source code file tree) into Vim when you open a file. It performs a search starting at the directory that the edited file is in, checking the parent directories until it finds the cscope.out file. Therefore you can start editing a file deep in a project directory, and it will find the -correct Cscope database. - -It will also automatically update the cscope database after file saves. If new -files are created, the cscope.out database must be recreated manually. +correct Cscope database. It will also automatically update the cscope database +after file saves. If new files are created, the cscope.out database must be +recreated manually. Keystroke macros and a pull down menu are provided to invoke the Cscope functions. diff --git a/plugin/autoload_cscope.vim b/plugin/cscope_helper.vim similarity index 99% rename from plugin/autoload_cscope.vim rename to plugin/cscope_helper.vim index 9c2a5f1..a4aed23 100644 --- a/plugin/autoload_cscope.vim +++ b/plugin/cscope_helper.vim @@ -1,5 +1,5 @@ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" autoload_cscope.vim: Vim global plugin for autoloading Cscope databases +" cscope_helper.vim: Vim global plugin for Cscope databases " " Based on revision: 0.5 of autoload_cscope.vim by Michael Conrad Tadpol Tilsra " https://www.vim.org/scripts/script.php?script_id=157 @@ -22,7 +22,7 @@ " Copyright (c) 2022 Dan Nygren. " BSD 0-clause license, "Zero Clause BSD", SPDX: 0BSD " -" Save this file as ~/.vim/plugin/autoload_cscope.vim so you can invoke +" Save this file as ~/.vim/plugin/cscope_helper.vim so you can invoke " vim/gvim in subdirectories and still get cscope.out loaded. It performs a " search starting at the directory that the edited file is in, checking the " parent directories until it finds the cscope.out file. Therefore you can