Skip to content

Commit 3ac0c7b

Browse files
jdsutherlandbergercookie
authored andcommitted
Add using cexpr with debug variable
1 parent 30012f2 commit 3ac0c7b

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ debugging times.
100100
```vim
101101
nnoremap <your-key-combination> <Plug>DumpDebugString
102102
nnoremap <a-second-key-combination> <Plug>DumpDebugStringExpr
103+
nnoremap <a-third-key-combination> <Plug>DumpDebugStringCexpr
103104
```
104105

105-
Default mappings are: `<Leader>ds`, `<Leader>dS` respectively.
106+
Default mappings are: `<Leader>ds`, `<Leader>dS`, `<Leader>DS` respectively.
106107

107108
An example of using it in a C++ file is given below:
108109

plugin/debugstring.vim

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ set cpoptions&vim
7777
let s:modes = {
7878
\ 'std_debug': 0,
7979
\ 'var_debug': 1,
80+
\ 'var_debug_cexpr': 2,
8081
\}
8182

8283

@@ -131,6 +132,11 @@ if !hasmapto('<Plug>DumpDebugStringExpr')
131132
"
132133
nmap <unique> <Leader>dS <Plug>DumpDebugStringExpr
133134
endif
135+
if !hasmapto('<Plug>DumpDebugStringCexpr')
136+
""@setting default_dump_debug_map
137+
"
138+
nmap <unique> <Leader>DS <Plug>DumpDebugStringCexpr
139+
endif
134140

135141
""
136142
" Set this to false if you want to print just the logging statement without any
@@ -171,20 +177,23 @@ function! s:debugFunctionWrapper(mode, ...)
171177
call repeat#set("\<Plug>DumpDebugStringVar<CR>")
172178
endif
173179

174-
elseif a:mode ==# s:modes['var_debug']
180+
elseif a:mode ==# s:modes['var_debug'] || a:mode ==# s:modes['var_debug_cexpr']
175181
if !exists(':AddDebugStringExpr')
176182
echoerr "Command AddDebugStringExpr isn't implemented for filetype \"" . &filetype . "\""
177183
return 0
178184
endif
179-
let l:expr = ''
180-
if len(a:000) ==# 0
181-
let l:expr = input('Input Expression: ')
185+
if a:mode ==# s:modes['var_debug_cexpr']
186+
let l:expr = expand("<cexpr>")
182187
else
183-
let l:expr = a:1
184-
endif
185-
186-
if empty(l:expr)
187-
return
188+
let l:expr = ''
189+
if len(a:000) ==# 0
190+
let l:expr = input('Input Expression: ')
191+
else
192+
let l:expr = a:1
193+
endif
194+
if empty(l:expr)
195+
return
196+
endif
188197
endif
189198

190199
AddDebugStringExpr(l:expr)
@@ -223,6 +232,7 @@ endfunc
223232
"
224233
nnoremap <silent> <Plug>DumpDebugStringVar :<C-U>call <SID>debugFunctionWrapper(0)<CR>
225234
nnoremap <silent> <Plug>DumpDebugStringExpr :<C-U>call <SID>debugFunctionWrapper(1)<CR>
235+
nnoremap <silent> <Plug>DumpDebugStringCexpr :<C-U>call <SID>debugFunctionWrapper(2)<CR>
226236
227237
let &cpoptions = s:save_cpo
228238
unlet s:save_cpo

0 commit comments

Comments
 (0)