Skip to content

Commit 1642542

Browse files
committed
Indent: Implement indentation on standalone blocks
Disable is controlled through g:verilog_disable_indent_lst and its default was updated to also include `standalone` to mimic original behavior. Nonetheless, if this variable is defined in user's .vimrc then it will need to be updated to recover the previous behavior.
1 parent 898f60e commit 1642542

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

autoload/verilog_systemverilog.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,8 @@ function verilog_systemverilog#CompleteCommand(lead, command, cursor)
601601
\ 'method',
602602
\ 'preproc',
603603
\ 'conditional',
604-
\ 'eos'
604+
\ 'eos',
605+
\ 'standalone'
605606
\ ]
606607
for item in current_values
607608
call filter(valid_completions, 'v:val !=# item')

doc/verilog_systemverilog.txt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Example:
387387
*b:verilog_disable_indent_lst* *g:verilog_disable_indent_lst*
388388
b:verilog_disable_indent_lst~
389389
g:verilog_disable_indent_lst~
390-
Default: "eos"
390+
Default: "eos,standalone"
391391

392392
Disables indent for specific Verilog/SystemVerilog contexts.
393393
The following contexts are supported:
@@ -404,25 +404,26 @@ Default: "eos"
404404
- `preproc`
405405
- `conditional`
406406
- `eos`
407+
- `standalone`
407408

408-
Example:
409+
Examples:
409410

410411
>
411412
let g:verilog_disable_indent_lst = "module,class,interface"
412413
<
413414
Disabling indentation of `conditional` will change the following:
414415
>
415-
// Default indent
416-
assign a = cond ? b :
417-
c ;
418-
// Disabling 'conditional'
419-
assign a = cond ? b :
420-
c ;
416+
// Default indent
417+
assign a = cond ? b :
418+
c ;
419+
// Disabling 'conditional'
420+
assign a = cond ? b :
421+
c ;
421422
<
422423

423424
Disabling indentation of `eos` will affect how the closing parentheses of
424425
modules, functions, tasks, etc. are indented.
425-
By default:
426+
When enabled:
426427
>
427428
module mod(
428429
input wire a,
@@ -437,6 +438,23 @@ Example:
437438
);
438439
<
439440

441+
Disabling indentation of `standalone` will affect how standalone blocks,
442+
like begin..end or {..} are indented.
443+
When enabled:
444+
>
445+
if (expr)
446+
begin
447+
func();
448+
end
449+
<
450+
When disabled:
451+
>
452+
if (expr)
453+
begin
454+
func();
455+
end
456+
<
457+
440458
Note: The commands |:VerilogIndentAdd| and |:VerilogIndentRemove| are
441459
provided to allow an easier management of this variable.
442460

indent/verilog_systemverilog.vim

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,20 @@ function! s:GetContextIndent()
357357
call verilog_systemverilog#Verbose("'begin'..'end' pair.")
358358
return indent(l:lnum)
359359
elseif l:oneline_mode == 1 && l:line =~ s:vlog_block_decl && l:line !~ '\<begin\>.*\<end\>'
360+
if index(s:verilog_disable_indent, 'standalone') < 0
361+
let l:standalone = s:offset
362+
else
363+
let l:standalone = 0
364+
endif
360365
if s:curr_line =~ '^\s*\<begin\>'
361366
call verilog_systemverilog#Verbose("Standalone 'begin' after block declaration.")
362-
return indent(l:lnum)
367+
return indent(l:lnum) + l:standalone
363368
elseif s:curr_line =~ '^\s*{\s*$' && l:cbracket_level == 0
364369
call verilog_systemverilog#Verbose("Standalone '{' after block declaration.")
365-
return indent(l:lnum)
370+
return indent(l:lnum) + l:standalone
366371
elseif s:curr_line =~ '^\s*(\s*$' && l:bracket_level == 0
367372
call verilog_systemverilog#Verbose("Standalone '(' after block declaration.")
368-
return indent(l:lnum)
373+
return indent(l:lnum) + l:standalone
369374
else
370375
call verilog_systemverilog#Verbose("Indenting a single line block.")
371376
return indent(l:lnum) + s:offset + l:open_offset

plugin/verilog_systemverilog.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
" Global plugin settings
2-
let g:verilog_disable_indent_lst="eos"
2+
let g:verilog_disable_indent_lst="eos,standalone"
33

44
" Command definitions
55
command! -nargs=* VerilogErrorFormat call verilog_systemverilog#VerilogErrorFormat(<f-args>)

test/run_test.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ endfunction
5252
" Syntax indent test
5353
"-----------------------------------------------------------------------
5454
function! RunTestIndent()
55-
let g:verilog_disable_indent_lst = "module,eos"
55+
let g:verilog_disable_indent_lst = "module,eos,standalone"
5656
let test_result=0
5757

5858
" Open syntax indent test file

0 commit comments

Comments
 (0)