Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed smart indent when pressing Enter inside {} #68

Open
wants to merge 20 commits into from

6 participants

@atsepkov

There do seem to be test cases for this, however, this functionality did not work for me in vim 7.3. I attached a fix.

@kana
Owner

Thank you. I'll review it later.
By the way, there are more than 700 patches to Vim 7.3. Please let me know more details of your Vim version.
And please exclude unrelated commits for the title of the pull request.

atsepkov Tweaked {"Enter"} logic to be bulletproof (will now work in cases when
there is more content on the line after the brackets)
2c1ce15
@atsepkov

I'll undo the mduem removal, that was only removed so my vundle could sync to the updated version. As far as vim version, it's the standard one from 'vim' apt-get package in Linux Mint 13:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May 4 2012 04:25:35)
Included patches: 1-429
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@

@dag

For me it works as long as I'm using smartinput's <CR> mappings. Except for <C-j>, this is not the case if I load the endwise plugin, regardless of load order: endwise just writes over any existing mappings, but smartinput does not. On the other hand if I load smartinput before supertab, and I don't load endwise, then smartinput breaks the supertab mappings for selecting a completion.

In short, Vim scripting is a mess. Perhaps a "framework" for hooking into things like "hit Enter in Insert mode" without breaking other plugins would be possible and desirable, that then all these addons would use [if installed; could probably fall back to normal mappings].

@atsepkov Are you using any plugin that maps Enter in Insert mode, besides smartinput? What does :imap <CR> say?

@faceleg

Can this be merged? @kana?

@faceleg

@kanaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

@rgrinberg

Senpaaaiiiiiiiiiiiiiii

@Shougo

@atsepkov You should remove tags file from this PR.

@atsepkov

Hey guys, sorry for being slow to respond, have a few other projects I've been working on. By tags, do you mean docs/tags? I think that was there with the original version I forked from, but I have no problem removing it. Also, just wanted to mention, I've made a number of changes in my own fork since the merge request, mainly revolving around better handling of block spacing and indentation and automatic semi-colon/comma addition/removal. That's something the community may or may not want (although judging by comments from other members it sounds like they do).

@Shougo

I think that was there with the original version I forked from, but I have no problem removing it.

Oh, OK.

@kana ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 19, 2013
  1. Tweaked {"Enter"} logic to be bulletproof (will now work in cases when

    atsepkov authored
    there is more content on the line after the brackets)
Commits on Aug 9, 2013
  1. @atsepkov
Commits on Aug 10, 2013
  1. @atsepkov
Commits on Aug 16, 2013
  1. @atsepkov

    Tweaks to make perl 'smarter'

    atsepkov authored
Commits on Aug 17, 2013
  1. @atsepkov
  2. @atsepkov

    Additional fixes for Perl

    atsepkov authored
Commits on Aug 19, 2013
  1. @atsepkov
Commits on Sep 3, 2013
  1. @atsepkov
  2. @atsepkov
Commits on Sep 12, 2013
  1. @atsepkov

    More auto-semicolon logic

    atsepkov authored
  2. @atsepkov
Commits on Dec 18, 2013
  1. Small tweak to perl semi-colon logic

    Alexander Tsepkov authored
Commits on Dec 25, 2013
  1. More syntax improvements for Perl

    Alexander Tsepkov authored
Commits on Dec 26, 2013
  1. @atsepkov
Commits on Jan 3, 2014
  1. @atsepkov

    Python blocks

    atsepkov authored
  2. @atsepkov

    RapydScript addition

    atsepkov authored
Commits on Jan 8, 2014
  1. @atsepkov
Commits on Apr 16, 2015
  1. @atsepkov

    added JS macro

    atsepkov authored
This page is out of date. Refresh to see the latest.
Showing with 115 additions and 11 deletions.
  1. +6 −0 .gitignore
  2. +73 −10 autoload/smartinput.vim
  3. +36 −0 doc/tags
  4. +0 −1  mduem
View
6 .gitignore
@@ -0,0 +1,6 @@
+# use glob syntax
+
+*~
+*.swp
+*.tmp
+*.orig
View
83 autoload/smartinput.vim
@@ -73,27 +73,75 @@ function! smartinput#define_default_rules() "{{{2
endfunction
call urules.add('()', [
\ {'at': '\%#', 'char': '(', 'input': '()<Left>'},
- \ {'at': '\%#\_s*)', 'char': ')', 'input': '<C-r>=smartinput#_leave_block('')'')<Enter><Right>'},
\ {'at': '(\%#)', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '()\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '(', 'input': '('},
- \ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter><Enter><Up><Esc>"_S'},
+ \ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter><Esc>"_O'},
+ \ {'at': '(\n\t*\%#\n\t*)', 'char': '<BS>', 'input': '<Esc>dd:left<CR>i<BS>'},
+ \ {'at': '\%#\s*)', 'char': ')', 'input': '<C-r>=smartinput#_leave_block('')'')<Enter><Right>'},
\ ])
+ "\ {'at': '\%#\_s*)', 'char': ')', 'input': '<C-r>=smartinput#_leave_block('')'')<Enter><Right>'},
+ "\ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter><Enter><BS><Up><Esc>"_A'},
call urules.add('[]', [
\ {'at': '\%#', 'char': '[', 'input': '[]<Left>'},
- \ {'at': '\%#\_s*\]', 'char': ']', 'input': '<C-r>=smartinput#_leave_block('']'')<Enter><Right>'},
\ {'at': '\[\%#\]', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '\[\]\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '[', 'input': '['},
+ \ {'at': '\[\%#\]', 'char': '<Enter>', 'input': '<Enter><Esc>"_O'},
+ \ {'at': '\[\n\t*\%#\n\t*\]', 'char': '<BS>', 'input': '<Esc>dd:left<CR>i<BS>'},
+ \ {'at': '\%#\s*\]', 'char': ']', 'input': '<C-r>=smartinput#_leave_block('']'')<Enter><Right>'},
\ ])
+ "\ {'at': '\%#\_s*\]', 'char': ']', 'input': '<C-r>=smartinput#_leave_block('']'')<Enter><Right>'},
call urules.add('{}', [
\ {'at': '\%#', 'char': '{', 'input': '{}<Left>'},
- \ {'at': '\%#\_s*}', 'char': '}', 'input': '<C-r>=smartinput#_leave_block(''}'')<Enter><Right>'},
\ {'at': '{\%#}', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '{}\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '{', 'input': '{'},
- \ {'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter><Enter><Up><Esc>"_S'},
+ \ {'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter><Esc>"_O'},
+ \ {'at': '{\n\t*\%#\n\t*}', 'char': '<BS>', 'input': '<Esc>dd:left<CR>i<BS>'},
+ \ {'at': '\%#\s*}', 'char': '}', 'input': '<C-r>=smartinput#_leave_block(''}'')<Enter><Right>'},
\ ])
+ call urules.add('Common blocks', [
+ \ {'at': '=[^>][^)]*{\%#}', 'char': '<Space>', 'input': '<Space><Space><Left>'},
+ \ {'at': '=[^>][^)]*(\%#)', 'char': '<Space>', 'input': '<Space><Space><Left>'},
+ \ {'at': '=[^>][^)]*\[\%#\]', 'char': '<Space>', 'input': '<Space><Space><Left>'},
+ \ {'at': '=[^>][^)]*{\s\%#\s}', 'char': '<BS>', 'input': '<BS><Del>'},
+ \ {'at': '=[^>][^)]*(\s\%#\s)', 'char': '<BS>', 'input': '<BS><Del>'},
+ \ {'at': '=[^>][^)]*\[\s\%#\s\]', 'char': '<BS>', 'input': '<BS><Del>'},
+ \ ])
+ call urules.add('C blocks', [
+ \ {'at': '=[^>][^)]*{\%#}$', 'char': '<Enter>', 'input': '<Enter><End>;<Esc>"_O'},
+ \ {'at': '=[^>][^)]*(\%#)$', 'char': '<Enter>', 'input': '<Enter><End>;<Esc>"_O'},
+ \ {'at': '=[^>][^)]*\[\%#\]$', 'char': '<Enter>', 'input': '<Enter><End>;<Esc>"_O'},
+ \ {'at': '^\_s*return .*{\%#}$', 'char': '<Enter>', 'input': '<Enter><End>;<Esc>"_O'},
+ \ {'at': '(.*{\%#})$', 'char': '<Enter>', 'input': '<Enter><End>;<Esc>"_O'},
+ \ {'at': '^\s*[A-Za-z_][A-Za-z0-9_.]*\%#$', 'char': '(', 'input': '();<Left><Left>'},
+ \ {'at': '\%#[,;]', 'char': ';', 'input': '<Del>;'},
+ \ {'at': '\%#[,;]', 'char': ',', 'input': '<Del>,'},
+ \ {'at': '=\%#$', 'char': '<Space>', 'input': '<Space>;<Left>'},
+ \ {'at': '^\s*return\%#$', 'char': '<Space>', 'input': '<Space>;<Left>'},
+ \ ])
+ call urules.add('JS macro', [
+ \ {'at': '^\_s*\%#', 'char': '#', 'input': '// '},
+ \ ])
+" \ {'at': '(.*{\%#})', 'char': '<Enter>', 'input': '<Enter><Enter><BS><End><Up><Esc>"_A'},
+" \ {'at': '(.*{\%#})$', 'char': '<Enter>', 'input': '<Enter><Enter><BS><End>;<Up><Esc>"_A'},
+ call urules.add('Perl blocks', [
+ \ {'at': '=>.*{\%#}$', 'char': '<Enter>', 'input': '<Enter><End>,<Esc>"_O'},
+ \ {'at': '=>.*(\%#)$', 'char': '<Enter>', 'input': '<Enter><End>,<Esc>"_O'},
+ \ {'at': '=>.*\[\%#\]$', 'char': '<Enter>', 'input': '<Enter><End>,<Esc>"_O'},
+ \ {'at': '=>\%#$', 'char': '<Space>', 'input': '<Space>,<Left>'},
+ \ ])
+ call urules.add('Python blocks', [
+ \ {'at': '^\s*def\%#$', 'char': '<Space>', 'input': '<Space>:<Left>'},
+ \ {'at': '\%#:$', 'char': ':', 'input': '<Right>'},
+ \ ])
+ call urules.add('RapydScript blocks', [
+ \ {'at': '[^A-Za-z0-9_]def\%#$', 'char': '(', 'input': '():<Left><Left>'},
+ \ {'at': '[^A-Za-z0-9_]def\%#.\+$', 'char': '(', 'input': '(): <Left><Left><Left>'},
+ \ ])
+ "\ {'at': '\%#\_s*}', 'char': '}', 'input': '<C-r>=smartinput#_leave_block(''}'')<Enter><Right>'},
+ "\ {'at': '(.*{\%#})', 'char': '<Enter>', 'input': '<Enter><Enter><BS><Up><Esc>"_A'},
call urules.add('''''', [
\ {'at': '\%#', 'char': '''', 'input': '''''<Left>'},
\ {'at': '\%#''\ze', 'char': '''', 'input': '<Right>'},
@@ -161,6 +209,7 @@ function! smartinput#define_default_rules() "{{{2
\ {'at': '^\s*\%#', 'char': '"', 'input': '"'},
\ ])
"}}}
+" autocmd FileType perl call smartinput#perl_define_default_rules(urules)
" ft_urule_sets_table... "{{{
let ft_urule_sets_table = {
@@ -175,6 +224,7 @@ function! smartinput#define_default_rules() "{{{2
\ urules.table['``'],
\ urules.table['```'],
\ urules.table['English'],
+ \ urules.table['Common blocks'],
\ ],
\ 'clojure': [
\ urules.table['Lisp quote'],
@@ -182,14 +232,27 @@ function! smartinput#define_default_rules() "{{{2
\ 'csh': [
\ urules.table[''''' as strong quote'],
\ ],
+ \ 'javascript': [
+ \ urules.table[''''' as strong quote'],
+ \ urules.table['C blocks'],
+ \ urules.table['JS macro'],
+ \ ],
\ 'lisp': [
\ urules.table['Lisp quote'],
\ ],
\ 'perl': [
\ urules.table[''''' as strong quote'],
+ \ urules.table['C blocks'],
+ \ urules.table['Perl blocks'],
\ ],
\ 'python': [
+ \ urules.table['Python blocks'],
+ \ urules.table['Python string'],
+ \ ],
+ \ 'rapydscript': [
+ \ urules.table['Python blocks'],
\ urules.table['Python string'],
+ \ urules.table['RapydScript blocks'],
\ ],
\ 'ruby': [
\ urules.table[''''' as strong quote'],
@@ -219,9 +282,9 @@ function! smartinput#define_default_rules() "{{{2
endfor
endfor
- let overlaied_urules = {}
- let overlaied_urules.pairs = [] " [(URule, [FileType])]
- function! overlaied_urules.add(urule, ft)
+ let overlaid_urules = {}
+ let overlaid_urules.pairs = [] " [(URule, [FileType])]
+ function! overlaid_urules.add(urule, ft)
for [urule, fts] in self.pairs
if urule is a:urule
call add(fts, a:ft)
@@ -233,11 +296,11 @@ function! smartinput#define_default_rules() "{{{2
for ft in filter(keys(ft_urule_sets_table), 'v:val != "*"')
for urule_set in ft_urule_sets_table[ft]
for urule in urule_set
- call overlaied_urules.add(urule, ft)
+ call overlaid_urules.add(urule, ft)
endfor
endfor
endfor
- for [urule, fts] in overlaied_urules.pairs
+ for [urule, fts] in overlaid_urules.pairs
let completed_urule = copy(urule)
let completed_urule.filetype = fts
call smartinput#define_rule(completed_urule)
View
36 doc/tags
@@ -0,0 +1,36 @@
+g:smartinput_no_default_key_mappings smartinput.txt /*g:smartinput_no_default_key_mappings*
+smartinput smartinput.txt /*smartinput*
+smartinput#clear_rules() smartinput.txt /*smartinput#clear_rules()*
+smartinput#define_default_rules() smartinput.txt /*smartinput#define_default_rules()*
+smartinput#define_rule() smartinput.txt /*smartinput#define_rule()*
+smartinput#map_to_trigger() smartinput.txt /*smartinput#map_to_trigger()*
+smartinput#map_trigger_keys() smartinput.txt /*smartinput#map_trigger_keys()*
+smartinput-backspace-requirement smartinput.txt /*smartinput-backspace-requirement*
+smartinput-bugs smartinput.txt /*smartinput-bugs*
+smartinput-changelog smartinput.txt /*smartinput-changelog*
+smartinput-changelog-0.0.0 smartinput.txt /*smartinput-changelog-0.0.0*
+smartinput-changelog-0.0.1 smartinput.txt /*smartinput-changelog-0.0.1*
+smartinput-changelog-0.0.2 smartinput.txt /*smartinput-changelog-0.0.2*
+smartinput-changelog-0.0.3 smartinput.txt /*smartinput-changelog-0.0.3*
+smartinput-changelog-0.0.4 smartinput.txt /*smartinput-changelog-0.0.4*
+smartinput-changelog-0.0.5 smartinput.txt /*smartinput-changelog-0.0.5*
+smartinput-check-syntax-highlighting smartinput.txt /*smartinput-check-syntax-highlighting*
+smartinput-contents smartinput.txt /*smartinput-contents*
+smartinput-customization smartinput.txt /*smartinput-customization*
+smartinput-customization-a smartinput.txt /*smartinput-customization-a*
+smartinput-customization-b smartinput.txt /*smartinput-customization-b*
+smartinput-customization-c smartinput.txt /*smartinput-customization-c*
+smartinput-customization-d smartinput.txt /*smartinput-customization-d*
+smartinput-default-rules smartinput.txt /*smartinput-default-rules*
+smartinput-disable-completion-temporarily smartinput.txt /*smartinput-disable-completion-temporarily*
+smartinput-functions smartinput.txt /*smartinput-functions*
+smartinput-interface smartinput.txt /*smartinput-interface*
+smartinput-introduction smartinput.txt /*smartinput-introduction*
+smartinput-key-mappings smartinput.txt /*smartinput-key-mappings*
+smartinput-rule-conventions smartinput.txt /*smartinput-rule-conventions*
+smartinput-rule-definition smartinput.txt /*smartinput-rule-definition*
+smartinput-rule-priorities smartinput.txt /*smartinput-rule-priorities*
+smartinput-rule-selection-algorithm smartinput.txt /*smartinput-rule-selection-algorithm*
+smartinput-rules smartinput.txt /*smartinput-rules*
+smartinput-special-keys smartinput.txt /*smartinput-special-keys*
+smartinput.txt smartinput.txt /*smartinput.txt*
1  mduem
@@ -1 +0,0 @@
-Subproject commit 3ec335aeba147e3c9171cad5e5fb990d4365afa6
Something went wrong with that request. Please try again.