Raimondi / delimitMate

Vim plugin, provides insert mode auto-completion for quotes, parens, brackets, etc.
http://www.vim.org/scripts/script.php?script_id=2754
1.98k stars 117 forks source link

Support bracket expansion according to Python PEP8 #190

Closed sebdah closed 9 years ago

sebdah commented 10 years ago

I would like to be able to <CR> expand according to the following pattern in order to write PEP8 compliant code.

Typing this:

 my_function(|<CR>

to get:

my_function(
    |)

rather than:

my_function(
    |
)

Thanks for an awesome plugin!

Raimondi commented 9 years ago

It looks like you need to use let delimitMate_expand_cr = 0 or au FileType python let b:delimitMate_expand_cr = 0, because the behaviour you describe is the one with <CR> expansion off.

Raimondi commented 9 years ago

Please reopen the issue if needed.

sebdah commented 9 years ago

Thanks for the reply. Unfortunately this does not work. Setting let delimitMate_expand_cr = 0 gets the following behaviour:

my_function(|<CR>)

Results in:

my_function(
|)

While expected would be:

my_function(
    |)
Raimondi commented 9 years ago

For me that results in :

my_function(
        |)

open an empty buffer and :set ft=pyton then paste the output of :DelimitMateTest here.

There is also a basic_vimrc in the repo, copy it and put the the basic setup needed to reproduce your problem there, if you can do it.

sebdah commented 9 years ago

Thanks for the advice. I didn't have time today to change the vimrc, but here's the output from the test:

delimitMate Report
==================

* Options: ( ) default, (g) global, (b) buffer

( ) delimitMate_apostrophes = ''
(g) delimitMate_autoclose = 1
(g) delimitMate_balance_matchpairs = 1
( ) delimitMate_eol_marker = ''
( ) delimitMate_excluded_ft = ''
( ) delimitMate_excluded_regions = 'Comment'
(b) delimitMate_expand_cr = 0
(g) delimitMate_expand_space = 1
( ) delimitMate_jump_expansion = 0
( ) delimitMate_matchpairs = '(:),{:},[:]'
(b) delimitMate_nesting_quotes = ['"', '''']
( ) delimitMate_quotes = '" '' `'
(g) delimitMate_smart_matchpairs = 1
(g) delimitMate_smart_quotes = 1
--------------------

* Mappings:

i  )            @<Plug>delimitMate)
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  }            @<Plug>delimitMate}
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  ]            @<Plug>delimitMate]
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  (            @<Plug>delimitMate(
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  {            @<Plug>delimitMate{
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  [            @<Plug>delimitMate[
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  "            @<Plug>delimitMate"
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  '            @<Plug>delimitMate'
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  `            @<Plug>delimitMate`
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  <BS>         @<Plug>delimitMateBS
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  <S-BS>       @<Plug>delimitMateS-BS
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  <S-Tab>       <Plug>SuperTabBackward
    Last set from ~/git/sebdah/vim-ide/vim/bundle/supertab/plugin/supertab.vim
No mapping found
i  <C-G>g       @<Plug>delimitMateJumpMany
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
i  <Space>      @<Plug>delimitMateSpace
    Last set from ~/git/sebdah/vim-ide/vim/bundle/delimitMate/plugin/delimitMate.vim
--------------------

* Showcase:

Open: (|)
Delete: |
Exit: ()|
Space: ( | )
Delete space: (|)

Open: {|}
Delete: |
Exit: {}|
Space: { | }
Delete space: {|}

Open: [|]
Delete: |
Exit: []|
Space: [ | ]
Delete space: [|]

Open: "|"
Delete: |
Exit: ""|
Space: " |"
Delete space: "|"

Open: '|'
Delete: |
Exit: ''|
Space: ' |'
Delete space: '|'

Open: `|`
Delete: |
Exit: ``|
Space: ` |`
Delete space: `|`

--- Options ---
  autoindent          colorcolumn=+1    nofoldenable          hidden              modified            shiftround          suffixesadd=.py     ttyfast
  autoread            comments=b:#,fb:-   foldlevel=1         history=1000        mouse=a             shiftwidth=4      noswapfile            ttymouse=xterm2
  background=dark     completeopt=menu    foldmethod=indent   incsearch           relativenumber      showcmd             syntax=python       visualbell
  backspace=2         cursorline          foldnestmax=10      keywordprg=pydoc    ruler               showtabline=2       tabstop=4           wildmenu
  backupcopy=yes      expandtab           formatoptions=cq    laststatus=2        scroll=21           smartcase           textwidth=80      nowrap
  clipboard=unnamed   filetype=python     helplang=en         list                scrolloff=3         softtabstop=4       title
  cinkeys=0{,0},0),:,!^F,o,O,e
  commentstring=# %s
  define=^s*\(def\|class\)
  directory=~/tmp,/var/tmp,/tmp
  fileencodings=ucs-bom,utf-8,default,latin1
  include=^\s*\(from\|import\)
  includeexpr=substitute(v:fname,'\.','/','g')
  indentexpr=pymode#indent#get_indent(v:lnum)
  indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
  listchars=tab:▸ ,trail:▫
  omnifunc=pythoncomplete#Complete
  runtimepath=~/.vim,~/.vim/bundle/vim-ps1,~/.vim/bundle/delimitMate,~/.vim/bundle/neocomplcache.vim,~/.vim/bundle/vim-gitgutter,~/.vim/bundle/plexer.vim,~/.vim/bundle/vim-colors-solarized,~/.vim/bundle/vim-airline,~/.vim/bundle/scss-syntax.vim,~/.vim/bundle/tomorrow-theme/vim,~/.vim/bundle/vim-jade,~/.vim/bundle/vim-json,~/.vim/bundle/supertab,~/.vim/bundle/gitv,~/.vim/bundle/vim-numbertoggle,~/.vim/bundle/vim-virtualenv,~/.vim/bundle/vim-coffee-script,~/.vim/bundle/ctrlp.vim,~/.vim/bundle/python-mode,~/.vim/bundle/apiblueprint.vim,~/.vim/bundle/tagbar,~/.vim/bundle/emmet-vim,~/.vim/bundle/vim-jinja,~/.vim/bundle/vim-javascript,~/.vim/bundle/nerdcommenter,~/.vim/bundle/nerdtree,~/.vim/bundle/syntastic,~/.vim/bundle/vim-fugitive,~/.vim/bundle/vim-repeat,~/.vim/bundle/vim-surround,~/.vim/bundle/vim-vividchalk,~/.vim/bundle/SearchComplete,~/.vim/bundle/dbext.vim,~/.vim/bundle/vim-stylus,~/.vim/bundle/command-t,/usr/local/share/vim/vimfiles,/usr/local/share/vim/vim74,/usr/local/share/vim/vimfiles/after,~/.vim/after,~/.vim/bu
  statusline=%!airline#statusline(1)
  tabline=%!airline#extensions#tabline#get()
  wildignore=*/log/*,*/node_modules/*,*/target/*,*/tmp/*,*.rbc,*.pyc,*.swp,*.bak
  wildmode=longest,list,full
filetype detection:ON  plugin:ON  indent:ON

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug  8 2014 08:19:30)
MacOS X (unix) version
Included patches: 1-335
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +cmdline_info    +emacs_tags      -hangul_input    +menu            +mouse_xterm     -python3         +syntax          +virtualedit     -xsmp
+arabic          +comments        +eval            +iconv           +mksession       +multi_byte      +quickfix        +tag_binary      +visual          -xterm_clipboard
+autocmd         +conceal         +ex_extra        +insert_expand   +modify_fname    +multi_lang      +reltime         +tag_old_static  +visualextra     -xterm_save
-balloon_eval    +cryptv          +extra_search    +jumplist        +mouse           -mzscheme        +rightleft       -tag_any_white   +viminfo         -xpm
-browse          +cscope          +farsi           +keymap          -mouseshape      +netbeans_intg   +ruby            -tcl             +vreplace        
++builtin_terms  +cursorbind      +file_in_path    +langmap         +mouse_dec       +path_extra      +scrollbind      +terminfo        +wildignore      
+byte_offset     +cursorshape     +find_in_path    +libcall         -mouse_gpm       -perl            +signs           +termresponse    +wildmenu        
+cindent         +dialog_con      +float           +linebreak       -mouse_jsbterm   +persistent_undo +smartindent     +textobjects     +windows         
-clientserver    +diff            +folding         +lispindent      +mouse_netterm   +postscript      -sniff           +title           +writebackup     
+clipboard       +digraphs        -footer          +listcmds        +mouse_sgr       +printer         +startuptime     -toolbar         -X11             
+cmdline_compl   -dnd             +fork()          +localmap        -mouse_sysmouse  +profile         +statusline      +user_commands   -xfontset        
+cmdline_hist    -ebcdic          -gettext         -lua             +mouse_urxvt     +python          -sun_workshop    +vertsplit       -xim             
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -F/usr/local/Frameworks -DMACOS_X_UNIX  -Os -w -pipe -march=native -mmacosx-version-min=10.9 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: /usr/bin/clang   -L. -fstack-protector -L/Users/sebastian/.rvm/usr/lib -L/Users/sebastian/.rvm/usr/lib  -L/usr/local/lib -F/usr/local/Frameworks -Wl,-headerpad_max_install_names -o vim        -lm  -lncurses -liconv -framework Cocoa    -framework Python   -lruby-static -lobjc -L/Users/sebastian/.rvm/rubies/ruby-2.0.0-p0/lib   
--------------------

(comment updated since I accidentally did this without having the au FileType python let b:delimitMate_expand_cr = 0 setting in my vimrc)

Raimondi commented 9 years ago

I see you are not using the built-in indent plugin, maybe that has something to do with it. BTW, modify basic_vimrc and run vim with vim -N -u basic_vimrc foo.py

Raimondi commented 9 years ago

Please, reopen the issue if you still have troubles.