Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoformat only normal mode #136

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autoload/puppet/format.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"
" Simple format using puppet's l:indents and align hashrockets function
function! puppet#format#Format() abort
" only allow reformatting through the gq command
" (e.g. Vim is in normal mode)
if mode() !=# 'n'
" do not fall back to internal formatting
return 0
endif

let l:start_lnum = v:lnum
let l:end_lnum = v:lnum + v:count - 1
" Don't modify indentation or alignment if called by textwidth. We'll only
Expand Down
24 changes: 24 additions & 0 deletions test/format/textwidth.vader
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# First let's test that formatting without textwidth set doesn't do unexpected things

Given puppet (long line):
# Long comment 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
file { 'foo':
Expand All @@ -13,12 +15,18 @@ Expect puppet (nothing changed):
ensure => present,
}

-------------------------------------------------------------------------------
# Now let's check that the plugin does the right thing when textwidth is set.
#
# All of the tests below this point expect to have 'textwidth' set during the test.
Before (set textwidth):
set textwidth=76

After (unset textwidth):
set textwidth=0

-------------------------------------------------------------------------------
# note: using the same fixture as before
Do (format all text with textwidth set):
gqG

Expand All @@ -30,3 +38,19 @@ Expect puppet (comment is wrapped into more lines):
ensure => present,
}

-------------------------------------------------------------------------------
Given puppet (long line before editing):
file { 'foo':
ensure => present,
source => ['puppet:///modules/very_long_module_name_that_will_not_stop'],
}

Do (type in some more on long line):
jjA mode

Expect puppet (formatting did not change line):
file { 'foo':
ensure => present,
source => ['puppet:///modules/very_long_module_name_that_will_not_stop'], mode
}

Loading