Skip to content

Commit 03823c3

Browse files
committed
Add support for repeat.vim
1 parent 0718b16 commit 03823c3

2 files changed

Lines changed: 50 additions & 14 deletions

File tree

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# vim-debugstring
22

3-
[![Project status][badge-status]][vimscripts]
4-
[![Current release][badge-release]][releases]
5-
[![Open issues][badge-issues]][issues]
63

74
```
85
_ _ _ _
@@ -42,6 +39,12 @@ Currently the following languages are supported:
4239
- Shell
4340
- Vim
4441

42+
### Features
43+
44+
45+
- Support for [vim-repeat](https://github.com/tpope/vim-repeat). No
46+
need for repeat the same mapping, or rewrite the lengthy expression that you
47+
want to monitor, just use the `.` character
4548

4649
For a more detailed outline of `debugstring` check
4750
[doc/debugstring.txt](https://github.com/bergercookie/vim-debugstring/blob/master/doc/debugstring.txt)
@@ -65,6 +68,12 @@ Default mapping is: `<Leader>ds`
6568

6669
## Installation
6770

71+
### Dependencies
72+
73+
debugstring depends on the following vim plugins:
74+
75+
- vim-repeat
76+
6877
### Using a runtimepath/package manager
6978

7079
I would personally recommend using [Pathogen](https://github.com/tpope/vim-pathogen/) for
@@ -74,10 +83,9 @@ please raise an
7483
[issue](https://github.com/bergercookie/vim-debugstring/issues) on Github)
7584

7685
```bash
86+
git clone https://github.com/tpope/vim-repeat ~/.vim/bundle/vim-repeat
7787
git clone https://github.com/bergercookie/vim-debustring.git ~/.vim/bundle/vim-debugstring
7888

79-
# If you're using submodules to handle your vim-dotfiles:
80-
cd $BUNDLE; git submodule add https://github.com/bergercookie/vim-debustring.git
8189
```
8290

8391
### Manual installation
@@ -111,7 +119,7 @@ vim.org](https://vim.sourceforge.io/scripts/script.php?script_id=5634)
111119
- [ ] Make the counter buffer-specific
112120
- [ ] Escape double single quotes vimscript variable printing
113121
- [ ] Append to current line if that is empty
114-
- [ ] Support repeat.vim
115-
122+
- [x] Support repeat.vim
123+
- [ ] Use an assertion module
116124

117125

plugin/debugstring.vim

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ let s:save_cpo = &cpoptions
6464
set cpoptions&vim
6565
" }}}
6666
"
67+
68+
""
69+
" Available modes - to be used with the debugFunctionWrapper method
70+
"@setting debugging_modes
71+
"
72+
"
6773
let s:modes = {
6874
\ 'std_debug': 0,
6975
\ 'var_debug': 1,
@@ -75,10 +81,14 @@ let g:debugStringCounterStep = 1
7581

7682
" By default debugging lines should be of the form <directive_to_print> " <prefix_string><debug_number>
7783
function! g:DebugstringPrefixStr()
78-
let l:debug_str =
79-
\ '[' . fnamemodify(bufname('%'), ':t') .
80-
\ ':' . getcurpos()[1] .
81-
\ '] DEBUGGING STRING ==> '
84+
let l:debug_str = '[' . fnamemodify(bufname('%'), ':t') . ':'
85+
if getline('.') =~# "^$" " Empty line
86+
let l:debug_str .= getcurpos()[1]
87+
else
88+
let l:debug_str .= string(str2nr(getcurpos()[1]) + 1)
89+
endif
90+
let l:debug_str .= '] DEBUGGING STRING ==> '
91+
8292
return l:debug_str
8393
endfunc
8494

@@ -122,7 +132,14 @@ let g:debugstringAlwaysIncludeHeader = 0 " Include Header in place?
122132
" Wrapper around the low-level debug* methods.
123133
" It also takes care of incrementing the g:debugCounter
124134
"
125-
function! s:debugFunctionWrapper(mode)
135+
" {mode} refers to the type of debugging that is to be done. See
136+
" @setting(debugging_modes) for the available modes
137+
"
138+
" If an additional argument is provided it will be used as the expression - This
139+
" additional argument implies that the debugging mode is 'var_debug'
140+
"
141+
"
142+
function! s:debugFunctionWrapper(mode, ...)
126143
let l:prev_pos = getcurpos()
127144

128145
let l:append_at_same_line = 0
@@ -137,21 +154,32 @@ function! s:debugFunctionWrapper(mode)
137154
endif
138155

139156
AddDebugString
157+
call repeat#set("\<Plug>DumpDebugString")
140158

141159
elseif a:mode ==# s:modes['var_debug']
142160
if !exists(':AddDebugStringExpr')
143161
echoerr "Command AddDebugStringExpr isn't implemented for filetype \"" . &filetype . "\""
144162
return 0
145163
endif
146-
let l:expr = input("Input Expression: ")
164+
let l:expr = ""
165+
if len(a:000) ==# 0
166+
let l:expr = input("Input Expression: ")
167+
else
168+
let l:expr = a:1
169+
endif
170+
147171
AddDebugStringExpr(l:expr)
172+
173+
" Make way for repeat.vim
174+
execute 'nnoremap <silent> <Plug>DumpDebugStringSpecExpr :<C-U> :call <SID>debugFunctionWrapper(1, "' . l:expr . '")<CR>'
175+
call repeat#set("\<Plug>DumpDebugStringSpecExpr")
148176
else
149177
echoerr 's:debugFunctionWrapper - Unknown mode: ' a:mode
150178
return 0
151179
endif
152180

153181
" correct indentation level
154-
" normal ==
182+
normal ==
155183

156184
call s:incrDebugCounter() " increase the counter
157185

0 commit comments

Comments
 (0)