Skip to content

Commit 69afca8

Browse files
committed
Add expression support for C/C++
1 parent 71c0e22 commit 69afca8

5 files changed

Lines changed: 27 additions & 40 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ std::cout << "[a.c:4] a_variable: " << a_variable << std::endl;
5151

5252
Lang | Debug String | Debug Variable
5353
--- | --- | ---
54-
C | :heavy_check_mark: | :x:
55-
C++ | :heavy_check_mark: | :x:
54+
C | :heavy_check_mark: | :heavy_check_mark:
55+
C++ | :heavy_check_mark: | :heavy_check_mark:
5656
CMake | :heavy_check_mark: | :heavy_check_mark:
5757
Fortran | :heavy_check_mark: | :x:
5858
Haskell | :heavy_check_mark: | :heavy_check_mark:
@@ -152,6 +152,6 @@ vim.org](https://vim.sourceforge.io/scripts/script.php?script_id=5634)
152152
- [ ] Use travis for CI
153153
- [x] Bug with changing the filename of the current file
154154
- [x] Make vim-repeat dependency optional
155-
- [ ] Turn supported languages into a table - what do we support in which
156-
language?
155+
- [x] Turn supported languages into a table - what do we support in which
156+
language
157157
- [x] Make vim-repeat dependency optional

ftplugin/c.vim

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ if exists('g:debugstring_loaded_cpp_vim')
22
finish
33
endif
44

5-
let g:path = fnamemodify(resolve(expand('<sfile>:p')), ':h')
6-
execute 'source ' . g:path . '/common/c_like.vim'
5+
function! s:DebugStringFunBase(desc, var)
6+
let l:debug_str = "printf(\"" . a:desc . "%d\\n\", " . a:var . ");"
77

8-
function! s:DebugStringFun()
9-
return DebugStringFunC()
8+
if g:debugstringAlwaysIncludeHeader
9+
let l:incStr = '#include <stdio.h>; '
10+
let l:debug_str = l:incStr . l:debug_str
11+
endif
12+
13+
return l:debug_str
1014
endfunc
1115

12-
command! -buffer -nargs=0 AddDebugString put=s:DebugStringFun()
16+
command! -buffer -nargs=0 AddDebugString
17+
\ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter)
18+
command! -buffer -nargs=1 AddDebugStringExpr
19+
\ put=s:DebugStringFunBase(<args> . ': ', <args>)

ftplugin/common/c_like.vim

Lines changed: 0 additions & 16 deletions
This file was deleted.

ftplugin/cpp.vim

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
let g:debugstring_loaded_cpp_vim = 1
22

3-
let g:path = fnamemodify(resolve(expand('<sfile>:p')), ':h')
4-
execute 'source ' . g:path . '/common/c_like.vim'
5-
6-
function! s:DebugStringFun()
7-
return DebugStringFunC()
8-
endfunc
9-
10-
function! s:DebugStringFunExpr(expr)
11-
let l:debug_str = 'std::cout << "' . g:DebugstringPrefixStr()
12-
\ . a:expr . '"' . ' << '
13-
\ . a:expr
3+
function! s:DebugStringFunBase(desc, var)
4+
let l:debug_str = 'std::cout << "' . a:desc
5+
\ . '" << '
6+
\ . a:var
147
\ . ' << '
158
\ . 'std::endl;'
169

@@ -22,6 +15,7 @@ function! s:DebugStringFunExpr(expr)
2215
return l:debug_str
2316
endfunc
2417

25-
command! -buffer -nargs=0 AddDebugString :put=s:DebugStringFun()
26-
command! -buffer -nargs=1 AddDebugStringExpr :put=s:DebugStringFunExpr(<args>)
27-
18+
command! -buffer -nargs=0 AddDebugString
19+
\ put=s:DebugStringFunBase(g:DebugstringPrefixStr(), g:debugStringCounter)
20+
command! -buffer -nargs=1 AddDebugStringExpr
21+
\ put=s:DebugStringFunBase(<args> . ': ', <args>)

plugin/debugstring.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66

7+
" TODO: Rewrite these instructions
78
""
89
" @section Introduction, intro
910
"
@@ -80,7 +81,8 @@ let s:modes = {
8081
let g:debugStringCounter = 0
8182
let g:debugStringCounterStep = 1
8283

83-
" By default debugging lines should be of the form <directive_to_print> " <prefix_string><debug_number>
84+
" By default debugging lines should be of the form
85+
" <directive_to_print> <prefix_string><debug_number>
8486
function! g:DebugstringPrefixStr()
8587
let l:debug_str = '[' . fnamemodify(bufname('%'), ':t') . ':'
8688
if getline('.') =~# '^$' " Empty line

0 commit comments

Comments
 (0)