├── .github └── FUNDING.yml ├── .gitignore ├── .projections.json ├── .travis.yml ├── LICENSE ├── README.md ├── addon-info.json ├── doc └── debugstring.txt ├── ftplugin ├── Dockerfile.vim ├── arduino.vim ├── c.vim ├── cmake.vim ├── common │ └── sh_like.vim ├── cpp.vim ├── cs.vim ├── fish.vim ├── fortran.vim ├── go.vim ├── haskell.vim ├── java.vim ├── javascript.vim ├── lua.vim ├── make.vim ├── php.vim ├── python.vim ├── r.vim ├── ruby.vim ├── rust.vim ├── sh.vim ├── typescript.vim ├── vim.vim └── zsh.vim ├── misc ├── add_logo_to_help ├── build_doc ├── control-flow.gif ├── expression.gif ├── find-segfault.gif └── logo.txt ├── plugin └── debugstring.vim └── test ├── basic.vader ├── env_setup.vader ├── ft ├── a.Dockerfile ├── a.arduino ├── a.c ├── a.cmake ├── a.cpp ├── a.cs ├── a.fortran ├── a.go ├── a.haskell ├── a.java ├── a.javascript ├── a.lua ├── a.make ├── a.python ├── a.r ├── a.ruby ├── a.rust ├── a.sh ├── a.typescript ├── a.vim └── a.zsh ├── run-tests.sh ├── text_setup.vader └── vimrc /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [bergercookie] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | b.* 3 | /vader.vim 4 | /vim-repeat 5 | -------------------------------------------------------------------------------- /.projections.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugin/*.vim": {"type": "pl"}, 3 | "autoload/*.vim": {"type": "au"}, 4 | "ftplugin/*.vim": {"type": "ft"}, 5 | "doc/*.txt": {"type": "doc"}, 6 | "README.md": {"type": "md"} 7 | } 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: vim 2 | 3 | before_script: | 4 | git clone https://github.com/junegunn/vader.vim.git 5 | git clone https://github.com/tpope/vim-repeat.git 6 | 7 | script: 8 | ./test/run-tests.sh 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | VIM LICENSE 2 | 3 | I) There are no restrictions on distributing unmodified copies of Vim except that they must include this license text. You can also distribute unmodified parts of Vim, likewise unrestricted except that they must include this license text. You are also allowed to include executables that you made from the unmodified Vim sources, plus your own usage examples and Vim scripts. 4 | 5 | II) It is allowed to distribute a modified (or extended) version of Vim, including executables and/or source code, when the following four conditions are met: 6 | 7 | 1) This license text must be included unmodified. 8 | 9 | 2) The modified Vim must be distributed in one of the following five ways: 10 | 11 | a) If you make changes to Vim yourself, you must clearly describe in the distribution how to contact you. When the maintainer asks you (in any way) for a copy of the modified Vim you distributed, you must make your changes, including source code, available to the maintainer without fee. The maintainer reserves the right to include your changes in the official version of Vim. What the maintainer will do with your changes and under what license they will be distributed is negotiable. If there has been no negotiation then this license, or a later version, also applies to your changes. The current maintainer is Bram Moolenaar . If this changes it will be announced in appropriate places (most likely vim.sf.net, www.vim.org and/or comp.editors). When it is completely impossible to contact the maintainer, the obligation to send him your changes ceases. Once the maintainer has confirmed that he has received your changes they will not have to be sent again. 12 | 13 | b) If you have received a modified Vim that was distributed as mentioned under a) you are allowed to further distribute it unmodified, as mentioned at I). If you make additional changes the text under a) applies to those changes. 14 | 15 | c) Provide all the changes, including source code, with every copy of the modified Vim you distribute. This may be done in the form of a context diff. You can choose what license to use for new code you add. The changes and their license must not restrict others from making their own changes to the official version of Vim. 16 | 17 | d) When you have a modified Vim which includes changes as mentioned under c), you can distribute it without the source code for the changes if the following three conditions are met: 18 | - The license that applies to the changes permits you to distribute the changes to the Vim maintainer without fee or restriction, and permits the Vim maintainer to include the changes in the official version of Vim without fee or restriction. 19 | - You keep the changes for at least three years after last distributing the corresponding modified Vim. When the maintainer or someone who you distributed the modified Vim to asks you (in any way) for the changes within this period, you must make them available to him. 20 | - You clearly describe in the distribution how to contact you. This contact information must remain valid for at least three years after last distributing the corresponding modified Vim, or as long as possible. 21 | 22 | e) When the GNU General Public License (GPL) applies to the changes, you can distribute the modified Vim under the GNU GPL version 2 or any later version. 23 | 24 | 3) A message must be added, at least in the output of the ":version" command and in the intro screen, such that the user of the modified Vim is able to see that it was modified. When distributing as mentioned under 2)e) adding the message is only required for as far as this does not conflict with the license used for the changes. 25 | 26 | 4) The contact information as required under 2)a) and 2)d) must not be removed or changed, except that the person himself can make corrections. 27 | 28 | III) If you distribute a modified version of Vim, you are encouraged to use the Vim license for your changes and make them available to the maintainer, including the source code. The preferred way to do this is by e-mail or by uploading the files to a server and e-mailing the URL. If the number of changes is small (e.g., a modified Makefile) e-mailing a context diff will do. The e-mail address to be used is 29 | 30 | IV) It is not allowed to remove this license from the distribution of the Vim sources, parts of it or from a modified version. You may use this license for previous Vim releases instead of the license that they came with, at your option. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-debugstring 2 | 3 |

4 | 5 | 6 |

7 | 8 | ``` 9 | _ _ _ _ 10 | | | | | | | (_) 11 | __| | ___| |__ _ _ __ _ ___| |_ _ __ _ _ __ __ _ 12 | / _` |/ _ \ '_ \| | | |/ _` / __| __| '__| | '_ \ / _` | 13 | | (_| | __/ |_) | |_| | (_| \__ \ |_| | | | | | | (_| | 14 | \__,_|\___|_.__/ \__,_|\__, |___/\__|_| |_|_| |_|\__, | 15 | __/ | __/ | 16 | |___/ |___/ 17 | 18 | ``` 19 | 20 | ## Purpose 21 | 22 | `debugstring` aims to automate standard debugging operations (e.g., segfaults). 23 | It does that by facilitating the ubiquitous 24 | [printf()-debugging](https://everything2.com/title/printf%28%29%20debugging) 25 | i.e., scatter logging statements around the various code snippets that you want 26 | to test. 27 | 28 | 29 | ## Demos 30 | 31 | [Presentation at Vim-London](https://www.youtube.com/watch?v=cJIoH5r2zSk) 32 | 33 | ### Finding a segfault 34 | 35 | ![demo_gif](misc/find-segfault.gif) 36 | 37 | ### Control flow 38 | 39 | ![demo_gif2](misc/control-flow.gif) 40 | 41 | ### Expression evaluation 42 | 43 | ![demo_gif3](misc/expression.gif) 44 | 45 | ## Features 46 | 47 | - The form and syntax of the logging statements target the language at hand 48 | (e.g., use `printf()` in C/C++ but `puts()` in Ruby) 49 | - Support for debugging variable expressions e.g., the values of variables or 50 | arbitrary expressions at certain parts of your code 51 | - Support for : Place your cursor over the variable you want to print and 52 | press `DS`. It will create a debugging string for that variable 53 | - Support for [vim-repeat](https://github.com/tpope/vim-repeat). No 54 | need for repeat the same mapping, or rewrite the lengthy expression that you 55 | want to monitor, just use the `.` character 56 | 57 | 58 | Currently the following languages are supported. First column corresponds to the 59 | standard debugging string while the second to the case of debugging for a 60 | specific variable. 61 | 62 | Lang | Debug String | Debug Variable 63 | --- | --- | --- 64 | Arduino | :heavy_check_mark: | :heavy_check_mark: 65 | Awk | :x: | :x: 66 | C | :heavy_check_mark: | :heavy_check_mark: 67 | C# | :heavy_check_mark: | :heavy_check_mark: 68 | C++ | :heavy_check_mark: | :heavy_check_mark: 69 | CMake | :heavy_check_mark: | :heavy_check_mark: 70 | D | :x: | :x: 71 | Dockerfile | :heavy_check_mark: | :heavy_check_mark: 72 | Fish-Shell | :heavy_check_mark: | :heavy_check_mark: 73 | Fortran | :heavy_check_mark: | :heavy_check_mark: 74 | Go | :heavy_check_mark: | :heavy_check_mark: 75 | Haskell | :heavy_check_mark: | :heavy_check_mark: 76 | Java | :heavy_check_mark: | :heavy_check_mark: 77 | Javascript | :heavy_check_mark: | :heavy_check_mark: 78 | Julia | :x: | :x: 79 | Lua | :heavy_check_mark: | :heavy_check_mark: 80 | Makefile | :heavy_check_mark: | :heavy_check_mark: 81 | Matlab | :x: | :x: 82 | PHP | :heavy_check_mark: | :heavy_check_mark: 83 | Perl | :x: | :x: 84 | Python | :heavy_check_mark: | :heavy_check_mark: 85 | R | :heavy_check_mark: | :heavy_check_mark: 86 | Ruby | :heavy_check_mark: | :heavy_check_mark: 87 | Rust | :heavy_check_mark: | :heavy_check_mark: 88 | Scala | :x: | :x: 89 | Shell | :heavy_check_mark: | :heavy_check_mark: 90 | Swift | :x: | :x: 91 | Typescript | :heavy_check_mark: | :heavy_check_mark: 92 | Vim | :heavy_check_mark: | :heavy_check_mark: 93 | Visual Basic | :x: | :x: 94 | Zsh | :heavy_check_mark: | :heavy_check_mark: 95 | 96 | For a more detailed description of `debugstring` check 97 | [doc/debugstring.txt](https://github.com/bergercookie/vim-debugstring/blob/master/doc/debugstring.txt) 98 | 99 | ## Usage 100 | 101 | Use the mappings of your choice to place unique logging directives during 102 | debugging times. 103 | 104 | ```vim 105 | nnoremap DumpDebugString 106 | nnoremap DumpDebugStringExpr 107 | nnoremap DumpDebugStringCexpr 108 | ``` 109 | 110 | Default mappings are: `ds`, `dS`, `DS` respectively. 111 | 112 | An example of using it in a C++ file is given below: 113 | 114 | ```c++ 115 | // Debug String 116 | std::cout << "[a.c:4] DEBUGGING STRING ==> " << 0 << std::endl; 117 | 118 | // Debug Variable 119 | std::cout << "[a.c:4] a_variable: " << a_variable << std::endl; 120 | ``` 121 | 122 | ### Remarks - Debugging 123 | 124 | * Make sure that `filetype plugin` is enabled. A line like `filetype plugin on` in 125 | your `.vimrc` should do the job. 126 | 127 | 128 | ## Installation 129 | 130 | | Plugin manager | How to install | 131 | | :------------- | :------------- | 132 | | [Dein][1] | `call dein#add('bergercookie/vim-debugstring')` | 133 | | [minpac][2] | `call minpac#add('bergercookie/vim-debugstring')` | 134 | | [Pathogen][3] | `git clone https://github.com/bergercookie/vim-debugstring.git ~/.vim/bundle/vim-debugstring` | 135 | | [Plug][4] | `Plug 'bergercookie/vim-debugstring'` | 136 | | [Vundle][5] | `Plugin 'bergercookie/vim-debugstring'` | 137 | | manual | copy all of the files into your `.vim` directory (or `~/.config/nvim` if you're using neovim)| 138 | 139 | [1]: https://github.com/Shougo/dein.vim 140 | [2]: https://github.com/k-takata/minpac 141 | [3]: https://github.com/tpope/vim-pathogen 142 | [4]: https://github.com/junegunn/vim-plug 143 | [5]: https://github.com/VundleVim/Vundle.vim 144 | 145 | ### Dependencies 146 | 147 | `debugstring` depends on the following vim plugins: 148 | 149 | - vim-repeat [OPTIONAL] 150 | 151 | ## Contributing 152 | 153 | In case you want to contribute on a certain feature/fix, don't hesitate to 154 | discuss about it in the Github issues or to implement it and make a PR. 155 | 156 | ## License 157 | 158 | Current plugin is distributed under the same terms as Vim itself. See the 159 | [LICENSE](https://github.com/bergercookie/vim-debugstring/blob/master/LICENSE) 160 | file 161 | 162 | ## Self Promotion 163 | 164 | In case you like the plugin, you might as well [star it on 165 | Github](https://github.com/bergercookie/vim-debugstring) or [rate it on 166 | vim.org](https://vim8.org/scripts/script.php?script_id=5634) Also feel 167 | free to check my [other 168 | plugins](https://github.com/bergercookie?tab=repositories) 169 | 170 | ## Notes on Development 171 | 172 | This mostly comprises a list of stuff I want to keep track of when developing 173 | this or other vim plugins 174 | 175 | * Use [vimdoc](https://github.com/google/vimdoc) to generate documentation from 176 | the `vim` docstring (instead of manually updating the .txt file). See the 177 | misc/build_doc for more on how this is done. 178 | * Use [vader](https://github.com/junegunn/vader.vim) for unittesting. Use 179 | `test/run-tests.sh` to run them: 180 | 181 | ``` 182 | vim -Nu test/vimrc 183 | :set rtp+=vader.vim/plugin 184 | :set rtp+=vim-repeat/autoload 185 | 186 | :Vader test/* 187 | ``` 188 | ## TODO 189 | 190 | - [ ] Method to delete all the debugging strings in current buffer / all "touched" buffers - see far.vim 191 | - [x] Method to print name and contents of a variable 192 | - ~[ ]Make the counter buffer-specific~ Nope, we already have the filename & 193 | line for file-specific text 194 | - [ ] Escape double single quotes vimscript variable printing 195 | - [x] Append to current line if that is empty 196 | - [x] Support repeat.vim 197 | - [x] Use an assertion module - vader 198 | - [x] Use vader.vim for TDD 199 | - [x] Extend vader support for rest of languages 200 | - [x] Use travis for CI 201 | - [x] Bug with changing the filename of the current file 202 | - [x] Make vim-repeat dependency optional 203 | - [x] Turn supported languages into a table - what do we support in which 204 | language 205 | - [x] Make vim-repeat dependency optional 206 | -------------------------------------------------------------------------------- /addon-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "debugstring", 3 | "version" : "0.1", 4 | "author" : "Nikos Koukis ", 5 | "maintainer" : "Nikos Koukis ", 6 | "repository" : {"type": "git", "url": "git://github.com/bergercookie/vim-debugstring.git"}, 7 | "dependencies" : {}, 8 | "description" : "Debug, printf()-style, at the speed of light" 9 | } 10 | -------------------------------------------------------------------------------- /doc/debugstring.txt: -------------------------------------------------------------------------------- 1 | *debugstring.txt* Debug, printf()-style, at the speed of light 2 | Nikos Koukis *debugstring* 3 | 4 | ============================================================================== 5 | CONTENTS *debugstring-contents* 6 | 1. Introduction..........................................|debugstring-intro| 7 | 2. Configuration........................................|debugstring-config| 8 | 3. Commands...........................................|debugstring-commands| 9 | 4. Functions.........................................|debugstring-functions| 10 | 5. About.................................................|debugstring-about| 11 | 12 | ============================================================================== 13 | INTRODUCTION *debugstring-intro* 14 | _ _ _ _ ~ 15 | | | | | | | (_) ~ 16 | __| | ___| |__ _ _ __ _ ___| |_ _ __ _ _ __ __ _ ~ 17 | / _` |/ _ \ '_ \| | | |/ _` / __| __| '__| | '_ \ / _` | ~ 18 | | (_| | __/ |_) | |_| | (_| \__ \ |_| | | | | | | (_| | ~ 19 | \__,_|\___|_.__/ \__,_|\__, |___/\__|_| |_|_| |_|\__, | ~ 20 | __/ | __/ | ~ 21 | |___/ |___/ ~ 22 | 23 | 24 | 25 | debugstring aims to automate standard debugging operations (e.g., segfaults). 26 | It does that by facilitating the ubiquitous printf()-debugging i.e., scatter 27 | logging statements around the various code snippets that you want to test. 28 | 29 | The form and syntax of the logging statements target the language at hand 30 | (e.g., use printf() in C/C++ but puts() in Ruby) 31 | 32 | vim-debugstring should be compatible with Vim >= 7.4.313 33 | 34 | 35 | ============================================================================== 36 | CONFIGURATION *debugstring-config* 37 | 38 | To add a logging statement either use the default normal mode mapping 39 | (|g:default_dump_debug_map|) or define your own: 40 | 41 | * nmap DumpDebugStringVar 42 | 43 | * nmap DumpDebugStringExpr 44 | 45 | 46 | ============================================================================== 47 | COMMANDS *debugstring-commands* 48 | 49 | :ResetDebugCounter *:ResetDebugCounter* 50 | Reset the debugging counter 51 | 52 | 53 | ============================================================================== 54 | FUNCTIONS *debugstring-functions* 55 | 56 | 57 | Each debug* method supports one (or a family of) programming languages. This 58 | way it takes care of the different logging directives + different syntaxes. 59 | 60 | If you want to extend debugstring for language not yet suppoprted you just 61 | have to implement a corresponding s:debug* method and also add a line for that 62 | language in the |g:debugstring_mappings| group 63 | 64 | 65 | ============================================================================== 66 | ABOUT *debugstring-about* 67 | 68 | 69 | Original version of this package is written by Nikos Koukis - bergercookie 70 | 71 | https://github.com/bergercookie 72 | 73 | * Thanks to Steve Losh for writing the excellent book "Learn Vimscript the 74 | Hard Way". If that helped you as much as it helped me seriously consider 75 | buying either the e-book or paperback version of it. 76 | 77 | http://learnvimscriptthehardway.stevelosh.com/ 78 | 79 | * Thanks to tpope for providing so much quality vimscript code to work with 80 | and get constant inspiration from while writing this 81 | 82 | https://github.com/tpope/ 83 | 84 | 85 | 86 | vim:tw=78:ts=8:ft=help:norl: 87 | -------------------------------------------------------------------------------- /ftplugin/Dockerfile.vim: -------------------------------------------------------------------------------- 1 | let g:path = fnamemodify(resolve(expand(':p')), ':h') 2 | 3 | function! s:DebugStringFun(desc, ...) 4 | execute 'source ' . g:path . '/common/sh_like.vim' 5 | let b:res = "" 6 | if len(a:000) ==# 0 7 | let b:res = DebugStringFunShellBase(a:desc) 8 | else 9 | let b:res = DebugStringFunShellBase(a:desc, a:1) 10 | endif 11 | return "RUN " . b:res 12 | endfunc 13 | 14 | command! -buffer -nargs=0 AddDebugString 15 | \ put=s:DebugStringFun(g:DebugstringPrefixStr() . g:debugStringCounter) 16 | command! -buffer -nargs=1 AddDebugStringExpr 17 | \ put=s:DebugStringFun( . ': ', ) 18 | 19 | -------------------------------------------------------------------------------- /ftplugin/arduino.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFun() 2 | let l:debug_str = 'Serial.println("' . g:DebugstringPrefixStr() . g:debugStringCounter . '")' 3 | return l:debug_str 4 | endfunc 5 | 6 | function! s:DebugStringFunExpr(expr) 7 | let l:debug_str = 'Serial.print("' . a:expr . ': ' . '")' . '; ' . 'Serial.println(' . a:expr . ')' 8 | return l:debug_str 9 | endfunc 10 | 11 | command! -buffer -nargs=0 AddDebugString put=s:DebugStringFun() 12 | command! -buffer -nargs=1 AddDebugStringExpr put=s:DebugStringFunExpr() 13 | 14 | 15 | -------------------------------------------------------------------------------- /ftplugin/c.vim: -------------------------------------------------------------------------------- 1 | if exists('g:debugstring_loaded_cpp_vim') 2 | finish 3 | endif 4 | 5 | function! s:DebugStringFunBase(desc, var) 6 | let l:debug_str = "printf(\"" . a:desc . "%d\\n\", " . a:var . ");" 7 | return l:debug_str 8 | endfunc 9 | 10 | command! -buffer -nargs=0 AddDebugString 11 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 12 | command! -buffer -nargs=1 AddDebugStringExpr 13 | \ put=s:DebugStringFunBase( . ': ', ) 14 | -------------------------------------------------------------------------------- /ftplugin/cmake.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFun() 2 | let l:debug_str = 'message(STATUS "' . g:DebugstringPrefixStr() . g:debugStringCounter . '")' 3 | return l:debug_str 4 | endfunc 5 | 6 | function! s:DebugStringFunExpr(expr) 7 | let l:debug_str = 'message(STATUS ' . '"' 8 | \ . a:expr . ': ' 9 | \ . '${' . a:expr . '}' 10 | \ . '")' 11 | return l:debug_str 12 | endfunc 13 | 14 | command! -buffer -nargs=0 AddDebugString put=s:DebugStringFun() 15 | command! -buffer -nargs=1 AddDebugStringExpr put=s:DebugStringFunExpr() 16 | 17 | -------------------------------------------------------------------------------- /ftplugin/common/sh_like.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_sh_like') 2 | finish 3 | endif 4 | let g:loaded_sh_like = 1 5 | 6 | function! DebugStringFunShellBase(desc, ...) 7 | let l:debug_str = 'echo "' . a:desc 8 | if len(a:000) ==# 1 9 | let l:debug_str .= ' ${' . a:1 . '}' 10 | endif 11 | 12 | let l:debug_str .= '"' 13 | return l:debug_str 14 | endfunc 15 | -------------------------------------------------------------------------------- /ftplugin/cpp.vim: -------------------------------------------------------------------------------- 1 | let g:debugstring_loaded_cpp_vim = 1 2 | 3 | function! s:DebugStringFunBase(desc, var) 4 | " Escape quotes in description 5 | let l:desc = a:desc 6 | if stridx('"', l:desc) 7 | let l:desc = substitute(l:desc, '"', '\\"', "g") 8 | endif 9 | 10 | let l:debug_str = 'std::cout << "' . l:desc 11 | \ . '" << ' 12 | \ . a:var 13 | \ . ' << ' 14 | \ . 'std::endl;' 15 | 16 | return l:debug_str 17 | endfunc 18 | 19 | command! -buffer -nargs=0 AddDebugString 20 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 21 | command! -buffer -nargs=1 AddDebugStringExpr 22 | \ put=s:DebugStringFunBase( . ': ', ) 23 | -------------------------------------------------------------------------------- /ftplugin/cs.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = 'System.Console.WriteLine($"' 3 | \ . a:desc 4 | \ . '{' . a:var . '}' 5 | \ . '");' 6 | return l:debug_str 7 | endfunc 8 | 9 | command! -buffer -nargs=0 AddDebugString 10 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 11 | command! -buffer -nargs=1 AddDebugStringExpr 12 | \ put=s:DebugStringFunBase( . ': ', ) 13 | -------------------------------------------------------------------------------- /ftplugin/fish.vim: -------------------------------------------------------------------------------- 1 | let g:path = fnamemodify(resolve(expand(':p')), ':h') 2 | 3 | function! s:DebugStringFun(desc, ...) 4 | let l:debug_str = 'echo "' . a:desc 5 | if len(a:000) ==# 1 6 | let l:debug_str .= ' $' . a:1 7 | endif 8 | let l:debug_str .= '"' 9 | return l:debug_str 10 | endfunc 11 | 12 | command! -buffer -nargs=0 AddDebugString 13 | \ put=s:DebugStringFun(g:DebugstringPrefixStr() . g:debugStringCounter) 14 | command! -buffer -nargs=1 AddDebugStringExpr 15 | \ put=s:DebugStringFun( . ': ', ) 16 | -------------------------------------------------------------------------------- /ftplugin/fortran.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = 'PRINT *,"' . a:desc . '", ' . a:var 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | 11 | -------------------------------------------------------------------------------- /ftplugin/go.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = "fmt.Printf(\"" . a:desc . "%+v\\n\", " . a:var . ")" 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | -------------------------------------------------------------------------------- /ftplugin/haskell.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = "putStrLn \"" . a:desc . "\" ++ " . a:var 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | -------------------------------------------------------------------------------- /ftplugin/java.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = 'System.out.println("' . a:desc . '" + ' . a:var . ');' 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | -------------------------------------------------------------------------------- /ftplugin/javascript.vim: -------------------------------------------------------------------------------- 1 | " Contents should be identical for javascript, typescript - not creating 2 | " symlinks to make it compatible for potential Windows users. 3 | function! s:DebugStringFun() 4 | let l:debug_str = 'console.log("' . g:DebugstringPrefixStr() . g:debugStringCounter . '");' 5 | :return l:debug_str 6 | endfunc 7 | 8 | function! s:DebugVarFun(desc, var) 9 | let l:debug_str = 'console.log(`' . a:desc . '`, ' . a:var . ')' 10 | return l:debug_str 11 | endfunc 12 | 13 | 14 | command! -buffer -nargs=0 AddDebugString put=s:DebugStringFun() 15 | command! -buffer -nargs=1 AddDebugStringExpr 16 | \ put=s:DebugVarFun( . ': ', ) 17 | -------------------------------------------------------------------------------- /ftplugin/lua.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = 'print("' . a:desc . '" .. tostring(' . a:var . '))' 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | -------------------------------------------------------------------------------- /ftplugin/make.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFun() 2 | let l:debug_str = '@echo "' . g:DebugstringPrefixStr() . g:debugStringCounter . '"' 3 | return l:debug_str 4 | endfunc 5 | 6 | function! s:DebugStringFunExpr(expr) 7 | let l:debug_str = '@echo ' . '"' 8 | \ . a:expr . ': ' 9 | \ . '$(' . a:expr . ')' 10 | \ . '"' 11 | return l:debug_str 12 | endfunc 13 | 14 | command! -buffer -nargs=0 AddDebugString put=s:DebugStringFun() 15 | command! -buffer -nargs=1 AddDebugStringExpr put=s:DebugStringFunExpr() 16 | 17 | 18 | -------------------------------------------------------------------------------- /ftplugin/php.vim: -------------------------------------------------------------------------------- 1 | let g:path = fnamemodify(resolve(expand(':p')), ':h') 2 | 3 | function! s:DebugStringFun(desc, ...) 4 | let l:debug_str = 'echo "' . a:desc 5 | if len(a:000) ==# 1 6 | let l:debug_str .= ' $' . a:1 7 | endif 8 | 9 | let l:debug_str .= '\n";' 10 | return l:debug_str 11 | endfunc 12 | 13 | command! -buffer -nargs=0 AddDebugString 14 | \ put=s:DebugStringFun(g:DebugstringPrefixStr() . g:debugStringCounter) 15 | command! -buffer -nargs=1 AddDebugStringExpr 16 | \ put=s:DebugStringFun( . ': ', ) 17 | -------------------------------------------------------------------------------- /ftplugin/python.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | " Escape quotes in description 3 | let l:desc = a:desc 4 | if stridx('"', l:desc) 5 | let l:desc = substitute(l:desc, '"', '\\"', "g") 6 | endif 7 | 8 | let l:debug_str = 'print("' . l:desc . '", ' . a:var . ')' 9 | return l:debug_str 10 | endfunc 11 | 12 | command! -buffer -nargs=0 AddDebugString 13 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 14 | command! -buffer -nargs=1 AddDebugStringExpr 15 | \ put=s:DebugStringFunBase( . ': ', ) 16 | -------------------------------------------------------------------------------- /ftplugin/r.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = 'message(sprintf("' . a:desc . '%s\n", ' . a:var . '))' 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | -------------------------------------------------------------------------------- /ftplugin/ruby.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFun() 2 | let l:debug_str = "puts \"" . g:DebugstringPrefixStr() . g:debugStringCounter . "\"" 3 | return l:debug_str 4 | endfunc 5 | 6 | function! s:DebugStringFunExpr(expr) 7 | let l:debug_str = 'puts "' 8 | \ . a:expr . ': ' 9 | \ . '#{' . a:expr . '}' 10 | \ . '"' 11 | return l:debug_str 12 | endfunc 13 | 14 | 15 | command! -buffer -nargs=0 AddDebugString put=s:DebugStringFun() 16 | command! -buffer -nargs=1 AddDebugStringExpr put=s:DebugStringFunExpr() 17 | -------------------------------------------------------------------------------- /ftplugin/rust.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = 'println!("' . a:desc . '{:#?}", ' . a:var . ');' 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | -------------------------------------------------------------------------------- /ftplugin/sh.vim: -------------------------------------------------------------------------------- 1 | " Contents should be identical for zsh, sh - not creating symlinks to make it 2 | " compatible for potential Windows users. 3 | let g:path = fnamemodify(resolve(expand(':p')), ':h') 4 | 5 | function! s:DebugStringFun(desc, ...) 6 | execute 'source ' . g:path . '/common/sh_like.vim' 7 | if len(a:000) ==# 0 8 | return DebugStringFunShellBase(a:desc) 9 | else 10 | return DebugStringFunShellBase(a:desc, a:1) 11 | endif 12 | endfunc 13 | 14 | command! -buffer -nargs=0 AddDebugString 15 | \ put=s:DebugStringFun(g:DebugstringPrefixStr() . g:debugStringCounter) 16 | command! -buffer -nargs=1 AddDebugStringExpr 17 | \ put=s:DebugStringFun( . ': ', ) 18 | -------------------------------------------------------------------------------- /ftplugin/typescript.vim: -------------------------------------------------------------------------------- 1 | " Contents should be identical for javascript, typescript - not creating 2 | " symlinks to make it compatible for potential Windows users. 3 | function! s:DebugStringFun() 4 | let l:debug_str = 'console.log("' . g:DebugstringPrefixStr() . g:debugStringCounter . '");' 5 | :return l:debug_str 6 | endfunc 7 | 8 | function! s:DebugVarFun(desc, var) 9 | let l:debug_str = 'console.log(`' . a:desc . '`, ' . a:var . ')' 10 | return l:debug_str 11 | endfunc 12 | 13 | 14 | command! -buffer -nargs=0 AddDebugString put=s:DebugStringFun() 15 | command! -buffer -nargs=1 AddDebugStringExpr 16 | \ put=s:DebugVarFun( . ': ', ) 17 | -------------------------------------------------------------------------------- /ftplugin/vim.vim: -------------------------------------------------------------------------------- 1 | function! s:DebugStringFunBase(desc, var) 2 | let l:debug_str = "echom '" . a:desc . "' . string(" . a:var . ")" 3 | return l:debug_str 4 | endfunc 5 | 6 | command! -buffer -nargs=0 AddDebugString 7 | \ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter) 8 | command! -buffer -nargs=1 AddDebugStringExpr 9 | \ put=s:DebugStringFunBase( . ': ', ) 10 | -------------------------------------------------------------------------------- /ftplugin/zsh.vim: -------------------------------------------------------------------------------- 1 | " Contents should be identical for zsh, sh - not creating symlinks to make it 2 | " compatible for potential Windows users. 3 | let g:path = fnamemodify(resolve(expand(':p')), ':h') 4 | 5 | function! s:DebugStringFun(desc, ...) 6 | execute 'source ' . g:path . '/common/sh_like.vim' 7 | if len(a:000) ==# 0 8 | return DebugStringFunShellBase(a:desc) 9 | else 10 | return DebugStringFunShellBase(a:desc, a:1) 11 | endif 12 | endfunc 13 | 14 | command! -buffer -nargs=0 AddDebugString 15 | \ put=s:DebugStringFun(g:DebugstringPrefixStr() . g:debugStringCounter) 16 | command! -buffer -nargs=1 AddDebugStringExpr 17 | \ put=s:DebugStringFun( . ': ', ) 18 | -------------------------------------------------------------------------------- /misc/add_logo_to_help: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | logo_file="`dirname ${BASH_SOURCE[0]}`/logo.txt" 6 | help_file="`dirname ${logo_file}`/../doc/debugstring.txt" 7 | 8 | line_num=`grep -n "INTRODUCTION" "${help_file}" | cut -d':' -f1` 9 | 10 | if [[ -z "${line_num}" ]]; then 11 | echo "Intro section was not found. Exiting..." 12 | exit 1 13 | fi 14 | 15 | # add the logo to the help page 16 | f="`mktemp`" 17 | head -n "${line_num}" "${help_file}" > "${f}" 18 | cat "${logo_file}" >> "${f}" 19 | tail -n +`echo "${line_num}"+1 | bc` "${help_file}" >> "${f}" 20 | 21 | cat "${f}" > "${help_file}" 22 | rm "${f}" 23 | 24 | 25 | -------------------------------------------------------------------------------- /misc/build_doc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ROOT=$(dirname $(readlink -f $0))/.. 4 | 5 | ( 6 | cd $ROOT 7 | vimdoc . 8 | ./misc/add_logo_to_help 9 | ) 10 | 11 | 12 | -------------------------------------------------------------------------------- /misc/control-flow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bergercookie/vim-debugstring/5fad4c0fa5d93db9cbb62e87c847e7bebcd7716f/misc/control-flow.gif -------------------------------------------------------------------------------- /misc/expression.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bergercookie/vim-debugstring/5fad4c0fa5d93db9cbb62e87c847e7bebcd7716f/misc/expression.gif -------------------------------------------------------------------------------- /misc/find-segfault.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bergercookie/vim-debugstring/5fad4c0fa5d93db9cbb62e87c847e7bebcd7716f/misc/find-segfault.gif -------------------------------------------------------------------------------- /misc/logo.txt: -------------------------------------------------------------------------------- 1 | _ _ _ _ ~ 2 | | | | | | | (_) ~ 3 | __| | ___| |__ _ _ __ _ ___| |_ _ __ _ _ __ __ _ ~ 4 | / _` |/ _ \ '_ \| | | |/ _` / __| __| '__| | '_ \ / _` | ~ 5 | | (_| | __/ |_) | |_| | (_| \__ \ |_| | | | | | | (_| | ~ 6 | \__,_|\___|_.__/ \__,_|\__, |___/\__|_| |_|_| |_|\__, | ~ 7 | __/ | __/ | ~ 8 | |___/ |___/ ~ 9 | -------------------------------------------------------------------------------- /plugin/debugstring.vim: -------------------------------------------------------------------------------- 1 | " debugstring.vim - Debug, printf()-style, at the speed of light 2 | " Maintainer: Nikos Koukis 3 | " Version: 0.1 4 | 5 | 6 | "" 7 | " @section Introduction, intro 8 | " 9 | " 10 | " @plugin(name) aims to automate standard debugging operations (e.g., 11 | " segfaults). It does that by facilitating the ubiquitous printf()-debugging 12 | " i.e., scatter logging statements around the various code snippets that you 13 | " want to test. 14 | " 15 | " The form and syntax of the logging statements target the language at hand 16 | " (e.g., use printf() in C/C++ but puts() in Ruby) 17 | " 18 | " vim-debugstring should be compatible with Vim >= 7.4.313 19 | " 20 | 21 | "" 22 | " @section Configuration, config 23 | " To add a logging statement either use the default normal mode mapping 24 | " (@setting(default_dump_debug_map)) or define your own: 25 | " 26 | " * nmap DumpDebugStringVar 27 | " 28 | " * nmap DumpDebugStringExpr 29 | 30 | "" 31 | " @section Functions 32 | " 33 | " Each debug* method supports one (or a family of) programming languages. This 34 | " way it takes care of the different logging directives + different syntaxes. 35 | " 36 | " If you want to extend @plugin(name) for language not yet suppoprted you just 37 | " have to implement a corresponding s:debug* method and also add a line for that 38 | " language in the @setting(debugstring_mappings) group 39 | " 40 | 41 | 42 | "" 43 | " @section About 44 | " 45 | " Original version of this package is written by Nikos Koukis - bergercookie 46 | " 47 | " https://github.com/bergercookie 48 | " 49 | " * Thanks to Steve Losh for writing the excellent book "Learn Vimscript the 50 | " Hard Way". If that helped you as much as it helped me seriously consider 51 | " buying either the e-book or paperback version of it. 52 | " 53 | " http://learnvimscriptthehardway.stevelosh.com/ 54 | " 55 | " * Thanks to tpope for providing so much quality vimscript code to work with 56 | " and get constant inspiration from while writing this 57 | " 58 | " https://github.com/tpope/ 59 | " 60 | 61 | " Introductory moves {{{ 62 | if exists('g:loaded_debugstring') || &compatible 63 | finish 64 | endif 65 | let g:loaded_debugstring = 1 66 | 67 | let s:save_cpo = &cpoptions 68 | set cpoptions&vim 69 | " }}} 70 | " 71 | 72 | "" 73 | " Available modes - to be used with the debugFunctionWrapper method 74 | "@setting debugging_modes 75 | " 76 | " 77 | let s:modes = { 78 | \ 'std_debug': 0, 79 | \ 'var_debug': 1, 80 | \ 'var_debug_cexpr': 2, 81 | \} 82 | 83 | 84 | let g:debugStringCounter = 0 85 | let g:debugStringCounterStep = 1 86 | 87 | "" 88 | " By default debugging lines should be of the form 89 | " 90 | function! g:DebugstringPrefixStr() 91 | let l:debug_str = '[' . fnamemodify(bufname('%'), ':t') . ':' 92 | if getline('.') =~# '^$' " Empty line 93 | let l:debug_str .= line('.') 94 | else 95 | let l:debug_str .= string(str2nr(line('.')) + 1) 96 | endif 97 | let l:debug_str .= '] DEBUGGING STRING ==> ' 98 | 99 | return l:debug_str 100 | endfunc 101 | 102 | " Supplementary functions {{{ 103 | "" 104 | " Reset the debugging counter. 105 | " 106 | function! s:resetDebugCounter() 107 | let g:debugStringCounter = 0 108 | endfunc 109 | 110 | " }}} 111 | 112 | "" 113 | " Reset the debugging counter 114 | " 115 | command -nargs=0 ResetDebugCounter :call resetDebugCounter() 116 | 117 | "" 118 | " Increment the debugging counter 119 | " This is called automaticall every time a debug* method is used 120 | " 121 | function! s:incrDebugCounter() 122 | let g:debugStringCounter += g:debugStringCounterStep 123 | endfunc 124 | 125 | if !hasmapto('DumpDebugStringVar') 126 | ""@setting default_dump_debug_map 127 | " 128 | nmap ds DumpDebugStringVar 129 | endif 130 | if !hasmapto('DumpDebugStringExpr') 131 | ""@setting default_dump_debug_map 132 | " 133 | nmap dS DumpDebugStringExpr 134 | endif 135 | if !hasmapto('DumpDebugStringCexpr') 136 | ""@setting default_dump_debug_map 137 | " 138 | nmap DS DumpDebugStringCexpr 139 | endif 140 | 141 | "" 142 | " Wrapper around the low-level debug* methods. 143 | " It also takes care of incrementing the g:debugCounter 144 | " 145 | " {mode} refers to the type of debugging that is to be done. See 146 | " @setting(debugging_modes) for the available modes 147 | " 148 | " If an additional argument is provided it will be used as the expression - This 149 | " additional argument implies that the debugging mode is 'var_debug' 150 | " 151 | " 152 | function! s:debugFunctionWrapper(mode, ...) 153 | let l:prev_pos = getpos('.') 154 | 155 | let l:append_at_same_line = 0 156 | if getline('.') =~# '^$' " Empty line 157 | let l:append_at_same_line = 1 158 | endif 159 | 160 | if a:mode ==# s:modes['std_debug'] 161 | if !exists(':AddDebugString') 162 | echoerr "Command AddDebugString isn't implemented for filetype \"" . &filetype . "\"" 163 | return 0 164 | endif 165 | 166 | AddDebugString 167 | 168 | if &runtimepath =~# 'vim-repeat' 169 | call repeat#set("\DumpDebugStringVar") 170 | endif 171 | 172 | elseif a:mode ==# s:modes['var_debug'] || a:mode ==# s:modes['var_debug_cexpr'] 173 | if !exists(':AddDebugStringExpr') 174 | echoerr "Command AddDebugStringExpr isn't implemented for filetype \"" . &filetype . "\"" 175 | return 0 176 | endif 177 | if a:mode ==# s:modes['var_debug_cexpr'] 178 | let l:expr = expand("") 179 | else 180 | let l:expr = '' 181 | if len(a:000) ==# 0 182 | " TODO enable autocompletion 183 | let l:expr = input('Input Expression: ') 184 | else 185 | let l:expr = a:1 186 | endif 187 | endif 188 | if empty(l:expr) 189 | return 190 | endif 191 | 192 | AddDebugStringExpr(l:expr) 193 | 194 | " Make way for repeat.vim 195 | if &runtimepath =~# 'vim-repeat' 196 | execute 'nnoremap DumpDebugStringSpecExpr :call debugFunctionWrapper(1, "' . l:expr . '")' 197 | call repeat#set("\DumpDebugStringSpecExpr") 198 | endif 199 | else 200 | echoerr 's:debugFunctionWrapper - Unknown mode: ' a:mode 201 | return 0 202 | endif 203 | 204 | " correct indentation level 205 | if indent(line('.') - 1) !=# 0 206 | normal! k0vwhyjP 207 | endif 208 | normal! == 209 | 210 | call s:incrDebugCounter() " increase the counter 211 | 212 | let l:new_pos = l:prev_pos 213 | if l:append_at_same_line 214 | " move them to previous line 215 | normal! kJ 216 | else 217 | let l:new_pos[1] += 1 " go directly to the next line 218 | endif 219 | call setpos('.', l:new_pos) 220 | endfunc 221 | 222 | "" 223 | " For debugging, execute a command using execute: 224 | " :execute "normal \DumpDebugStringVar" 225 | " 226 | nnoremap DumpDebugStringVar :call debugFunctionWrapper(0) 227 | nnoremap DumpDebugStringExpr :call debugFunctionWrapper(1) 228 | nnoremap DumpDebugStringCexpr :call debugFunctionWrapper(2) 229 | 230 | let &cpoptions = s:save_cpo 231 | unlet s:save_cpo 232 | 233 | " vim shiftwidth=4 234 | -------------------------------------------------------------------------------- /test/basic.vader: -------------------------------------------------------------------------------- 1 | Include: env_setup.vader 2 | Include: text_setup.vader 3 | 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | "" 7 | " Tests include the following 8 | " - Add Debugging string when I am in a line that has text + make sure the 9 | " counter advances 10 | " - Add Debugging string when I am on an empty line 11 | " - Add a variable debugging string when I am in a line that has text 12 | After (): 13 | " Log(&filetype) 14 | execute l1_text - 1 15 | AssertEqual getline('.'), "And each in your season", "Current line contents don't match" 16 | :normal ,ds 17 | :normal . 18 | execute l1_notext 19 | AssertEqual getline('.'), '', "Current line is not empty" 20 | :normal ,ds 21 | execute l1_text_var - 1 22 | execute ":normal ,dSa**2 + b**2\" 23 | 24 | execute l1_text 25 | AssertEqual getline('.'), FormatStrForExpectedLine(GetFileForLang(&filetype, 1), l1_text, 0) 26 | execute l2_text 27 | AssertEqual getline('.'), FormatStrForExpectedLine(GetFileForLang(&filetype, 1), l2_text, 1) 28 | execute l1_notext 29 | AssertEqual getline('.'), FormatStrForExpectedLine(GetFileForLang(&filetype, 1), l1_notext, 2) 30 | execute l1_text_var 31 | AssertEqual getline('.'), FormatStrForExpectedLine(GetFileForLang(&filetype, 2), l1_text_var, -1) 32 | 33 | ================================================================================ 34 | 35 | "" 36 | " Test cases - one for each supported language 37 | Execute (C): 38 | :set filetype=c 39 | Execute (C++): 40 | :set filetype=cpp 41 | Execute (C#): 42 | :set filetype=cs 43 | Execute (CMake): 44 | :set filetype=cmake 45 | Execute (Haskell): 46 | :set filetype=haskell 47 | Execute (Java): 48 | :set filetype=java 49 | Execute (Javascript): 50 | :set filetype=javascript 51 | Execute (Typescript): 52 | :set filetype=typescript 53 | Execute (Python): 54 | :set filetype=python 55 | Execute (R): 56 | :set filetype=r 57 | " For some reason putting this block after `Python` or `Ruby` makes this test 58 | " crash... no sensible explanation, should be a Vader bug. 59 | Execute (Rust): 60 | :set filetype=rust 61 | Execute (Ruby): 62 | :set filetype=ruby 63 | Execute (Shell): 64 | :set filetype=sh 65 | Execute (Zsh): 66 | :set filetype=zsh 67 | Execute (Vim): 68 | :set filetype=vim 69 | Execute (Fortran): 70 | :set filetype=fortran 71 | Execute (Go): 72 | :set filetype=go 73 | Execute (Arduino): 74 | :set filetype=arduino 75 | Execute (Makefile): 76 | :set filetype=make 77 | Execute (Dockerfile): 78 | :set filetype=Dockerfile 79 | Execute (Lua): 80 | :set filetype=lua 81 | 82 | ================================================================================ 83 | 84 | # vim: ft=vader 85 | -------------------------------------------------------------------------------- /test/env_setup.vader: -------------------------------------------------------------------------------- 1 | Before (setup): 2 | ResetDebugCounter 3 | 4 | let l1_text = 4 5 | let l2_text = 5 6 | let l1_notext = 10 7 | let l1_text_var = 11 8 | -------------------------------------------------------------------------------- /test/ft/a.Dockerfile: -------------------------------------------------------------------------------- 1 | RUN echo "[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$" 2 | RUN echo "a**2 + b**2: ${a**2 + b**2}" 3 | 4 | -------------------------------------------------------------------------------- /test/ft/a.arduino: -------------------------------------------------------------------------------- 1 | Serial.println("[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$") 2 | Serial.print("a**2 + b**2: "); Serial.println(a**2 + b**2) 3 | -------------------------------------------------------------------------------- /test/ft/a.c: -------------------------------------------------------------------------------- 1 | printf("[[Vader-workbench]:$1$] DEBUGGING STRING ==> %d\n", $2$); 2 | printf("a**2 + b**2: %d\n", a**2 + b**2); 3 | 4 | -------------------------------------------------------------------------------- /test/ft/a.cmake: -------------------------------------------------------------------------------- 1 | message(STATUS "[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$") 2 | message(STATUS "a**2 + b**2: ${a**2 + b**2}") 3 | -------------------------------------------------------------------------------- /test/ft/a.cpp: -------------------------------------------------------------------------------- 1 | std::cout << "[[Vader-workbench]:$1$] DEBUGGING STRING ==> " << $2$ << std::endl; 2 | std::cout << "a**2 + b**2: " << a**2 + b**2 << std::endl; 3 | -------------------------------------------------------------------------------- /test/ft/a.cs: -------------------------------------------------------------------------------- 1 | System.Console.WriteLine($"[[Vader-workbench]:$1$] DEBUGGING STRING ==> {$2$}"); 2 | System.Console.WriteLine($"a**2 + b**2: {a**2 + b**2}"); 3 | -------------------------------------------------------------------------------- /test/ft/a.fortran: -------------------------------------------------------------------------------- 1 | PRINT *,"[[Vader-workbench]:$1$] DEBUGGING STRING ==> ", $2$ 2 | PRINT *,"a**2 + b**2: ", a**2 + b**2 3 | -------------------------------------------------------------------------------- /test/ft/a.go: -------------------------------------------------------------------------------- 1 | fmt.Printf("[[Vader-workbench]:$1$] DEBUGGING STRING ==> %+v\n", $2$) 2 | fmt.Printf("a**2 + b**2: %+v\n", a**2 + b**2) 3 | -------------------------------------------------------------------------------- /test/ft/a.haskell: -------------------------------------------------------------------------------- 1 | putStrLn "[[Vader-workbench]:$1$] DEBUGGING STRING ==> " ++ $2$ 2 | putStrLn "a**2 + b**2: " ++ a**2 + b**2 3 | -------------------------------------------------------------------------------- /test/ft/a.java: -------------------------------------------------------------------------------- 1 | System.out.println("[[Vader-workbench]:$1$] DEBUGGING STRING ==> " + $2$); 2 | System.out.println("a**2 + b**2: " + a**2 + b**2); 3 | -------------------------------------------------------------------------------- /test/ft/a.javascript: -------------------------------------------------------------------------------- 1 | console.log("[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$"); 2 | console.log(`a**2 + b**2: `, a**2 + b**2) 3 | -------------------------------------------------------------------------------- /test/ft/a.lua: -------------------------------------------------------------------------------- 1 | print("[[Vader-workbench]:$1$] DEBUGGING STRING ==> " .. tostring($2$)) 2 | print("a**2 + b**2: " .. tostring(a**2 + b**2)) 3 | -------------------------------------------------------------------------------- /test/ft/a.make: -------------------------------------------------------------------------------- 1 | @echo "[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$" 2 | @echo "a**2 + b**2: $(a**2 + b**2)" 3 | -------------------------------------------------------------------------------- /test/ft/a.python: -------------------------------------------------------------------------------- 1 | print("[[Vader-workbench]:$1$] DEBUGGING STRING ==> ", $2$) 2 | print("a**2 + b**2: ", a**2 + b**2) 3 | -------------------------------------------------------------------------------- /test/ft/a.r: -------------------------------------------------------------------------------- 1 | message(sprintf("[[Vader-workbench]:$1$] DEBUGGING STRING ==> %s\n", $2$)) 2 | message(sprintf("a**2 + b**2: %s\n", a**2 + b**2)) 3 | -------------------------------------------------------------------------------- /test/ft/a.ruby: -------------------------------------------------------------------------------- 1 | puts "[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$" 2 | puts "a**2 + b**2: #{a**2 + b**2}" 3 | -------------------------------------------------------------------------------- /test/ft/a.rust: -------------------------------------------------------------------------------- 1 | println!("[[Vader-workbench]:$1$] DEBUGGING STRING ==> {:#?}", $2$); 2 | println!("a**2 + b**2: {:#?}", a**2 + b**2); 3 | -------------------------------------------------------------------------------- /test/ft/a.sh: -------------------------------------------------------------------------------- 1 | echo "[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$" 2 | echo "a**2 + b**2: ${a**2 + b**2}" 3 | -------------------------------------------------------------------------------- /test/ft/a.typescript: -------------------------------------------------------------------------------- 1 | console.log("[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$"); 2 | console.log(`a**2 + b**2: `, a**2 + b**2) 3 | -------------------------------------------------------------------------------- /test/ft/a.vim: -------------------------------------------------------------------------------- 1 | echom '[[Vader-workbench]:$1$] DEBUGGING STRING ==> ' . string($2$) 2 | echom 'a**2 + b**2: ' . string(a**2 + b**2) 3 | -------------------------------------------------------------------------------- /test/ft/a.zsh: -------------------------------------------------------------------------------- 1 | echo "[[Vader-workbench]:$1$] DEBUGGING STRING ==> $2$" 2 | echo "a**2 + b**2: ${a**2 + b**2}" 3 | -------------------------------------------------------------------------------- /test/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | oldpwd=$PWD 4 | cd $(dirname $(readlink -f $0))/.. 5 | 6 | # make sure dependencies are set up 7 | test -d vader.vim || git clone https://github.com/junegunn/vader.vim.git 8 | test -d vim-repeat || git clone https://github.com/tpope/vim-repeat.git 9 | test -d vader.vim || exit 1 10 | test -d vim-repeat || exit 1 11 | 12 | command vim -Nu test/vimrc -c 'Vader! test/*' 13 | ret=$? 14 | cd $oldpwd 15 | 16 | exit $ret 17 | -------------------------------------------------------------------------------- /test/text_setup.vader: -------------------------------------------------------------------------------- 1 | Given (stars-javert): 2 | You know your place in the sky 3 | You hold your course and your aim 4 | And each in your season 5 | Returns and returns 6 | And is always the same 7 | And if you fall as Lucifer fell 8 | You fall in flame! 9 | 10 | Source: https://www.youtube.com/watch?v=lXsJ3Q5Z7cM 11 | 12 | -------------------------------------------------------------------------------- /test/vimrc: -------------------------------------------------------------------------------- 1 | filetype off 2 | let g:mapleader = "," 3 | 4 | nmap ds DumpDebugStringVar 5 | nmap dS DumpDebugStringExpr 6 | 7 | set runtimepath+=. 8 | set runtimepath+=vader.vim 9 | set runtimepath+=vim-repeat 10 | set runtimepath+=after 11 | 12 | filetype plugin indent on 13 | syntax enable 14 | set nomore 15 | set noswapfile 16 | set viminfo= 17 | 18 | 19 | fun! GetFileForLang(lang_name,line) 20 | let l:path = fnamemodify(resolve(expand('%:p')), ':h') 21 | let l:filename = l:path . '/test/ft/' . 'a.' . a:lang_name 22 | return readfile(l:filename,'',a:line)[a:line-1] 23 | endfun 24 | 25 | "" 26 | " Format the given str based on the expected line and the expected given 27 | " counter. Function searches for the $N$ identifiers in the string and replaces 28 | " them with the line and counter respectively. 29 | " 30 | " Returns the modified string. 31 | " 32 | fun! FormatStrForExpectedLine(str, line, cnt) 33 | let l:strTmp = substitute(a:str, '\$1\$', a:line, "") 34 | let l:res = substitute(l:strTmp, '\$2\$', a:cnt, "") 35 | return l:res 36 | endfun 37 | --------------------------------------------------------------------------------