Restore cursor position on insert-mode

This commit is contained in:
mattn
2013-09-09 21:19:38 +09:00
parent a5313498d7
commit 5d90a2c83d
8 changed files with 30 additions and 15 deletions
+3 -1
View File
@@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" emmet.vim " emmet.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 25-Aug-2013. " Last Change: 09-Sep-2013.
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
@@ -636,9 +636,11 @@ function! emmet#moveNextPrev(flag)
endfunction endfunction
function! emmet#imageSize() function! emmet#imageSize()
let orgpos = emmet#util#getcurpos()
let type = emmet#getFileType() let type = emmet#getFileType()
let rtype = emmet#lang#exists(type) ? type : 'html' let rtype = emmet#lang#exists(type) ? type : 'html'
call emmet#lang#{rtype}#imageSize() call emmet#lang#{rtype}#imageSize()
silent! call setpos('.', orgpos)
return '' return ''
endfunction endfunction
+1 -1
View File
@@ -194,7 +194,7 @@ function! emmet#lang#css#balanceTag(flag) range
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
endif endif
let block = emmet#util#getVisualBlock() let block = emmet#util#getVisualBlock()
if !emmet#util#regionIsValid(block) if !emmet#util#regionIsValid(block)
+1 -1
View File
@@ -178,7 +178,7 @@ function! emmet#lang#haml#balanceTag(flag) range
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
endif endif
let n = curpos[1] let n = curpos[1]
let ml = len(matchstr(getline(n), '^\s*')) let ml = len(matchstr(getline(n), '^\s*'))
+6 -6
View File
@@ -516,8 +516,8 @@ function! emmet#lang#html#parseTag(tag)
endfunction endfunction
function! emmet#lang#html#toggleComment() function! emmet#lang#html#toggleComment()
let orgpos = getpos('.') let orgpos = emmet#util#getcurpos()
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
let mx = '<\%#[^>]*>' let mx = '<\%#[^>]*>'
while 1 while 1
let block = emmet#util#searchRegion('<!--', '-->') let block = emmet#util#searchRegion('<!--', '-->')
@@ -535,7 +535,7 @@ function! emmet#lang#html#toggleComment()
if pos1[0] == 0 && pos1[1] == 0 if pos1[0] == 0 && pos1[1] == 0
return return
endif endif
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
continue continue
endif endif
let pos1 = block[0] let pos1 = block[0]
@@ -586,7 +586,7 @@ function! emmet#lang#html#balanceTag(flag) range
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
endif endif
let settings = emmet#getSettings() let settings = emmet#getSettings()
@@ -658,7 +658,7 @@ function! emmet#lang#html#moveNextPrev(flag)
endfunction endfunction
function! emmet#lang#html#splitJoinTag() function! emmet#lang#html#splitJoinTag()
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
while 1 while 1
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>' let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
let pos1 = searchpos(mx, 'bcnW') let pos1 = searchpos(mx, 'bcnW')
@@ -698,7 +698,7 @@ function! emmet#lang#html#splitJoinTag()
endfunction endfunction
function! emmet#lang#html#removeTag() function! emmet#lang#html#removeTag()
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
while 1 while 1
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>' let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
let pos1 = searchpos(mx, 'bcnW') let pos1 = searchpos(mx, 'bcnW')
+1 -1
View File
@@ -79,7 +79,7 @@ function! emmet#lang#sass#balanceTag(flag) range
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
endif endif
let n = curpos[1] let n = curpos[1]
let ml = len(matchstr(getline(n), '^\s*')) let ml = len(matchstr(getline(n), '^\s*'))
+2 -2
View File
@@ -81,7 +81,7 @@ function! emmet#lang#scss#balanceTag(flag) range
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
call setpos('.', curpos) call setpos('.', curpos)
else else
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
endif endif
if a:flag < 0 if a:flag < 0
let ret = searchpair('}', '', '.\zs{') let ret = searchpair('}', '', '.\zs{')
@@ -89,7 +89,7 @@ function! emmet#lang#scss#balanceTag(flag) range
let ret = searchpair('{', '', '}', 'bW') let ret = searchpair('{', '', '}', 'bW')
endif endif
if ret > 0 if ret > 0
let pos1 = getpos('.')[1:2] let pos1 = emmet#util#getcurpos()[1:2]
if a:flag < 0 if a:flag < 0
let pos2 = searchpairpos('{', '', '}') let pos2 = searchpairpos('{', '', '}')
else else
+1 -1
View File
@@ -156,7 +156,7 @@ function! emmet#lang#slim#balanceTag(flag) range
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = getpos('.') let curpos = emmet#util#getcurpos()
endif endif
let n = curpos[1] let n = curpos[1]
let ml = len(matchstr(getline(n), '^\s*')) let ml = len(matchstr(getline(n), '^\s*'))
+15 -2
View File
@@ -93,7 +93,7 @@ endfunction
" this function return 0 or 1 " this function return 0 or 1
function! emmet#util#cursorInRegion(region) function! emmet#util#cursorInRegion(region)
if !emmet#util#regionIsValid(a:region) | return 0 | endif if !emmet#util#regionIsValid(a:region) | return 0 | endif
let cur = getpos('.')[1:2] let cur = emmet#util#getcurpos()[1:2]
return emmet#util#pointInRegion(cur, a:region) return emmet#util#pointInRegion(cur, a:region)
endfunction endfunction
@@ -107,7 +107,12 @@ endfunction
" search_region : make region from pattern which is composing start/end " search_region : make region from pattern which is composing start/end
" this function return array of position " this function return array of position
function! emmet#util#searchRegion(start, end) function! emmet#util#searchRegion(start, end)
return [searchpairpos(a:start, '', a:end, 'bcnW'), searchpairpos(a:start, '\%#', a:end, 'nW')] let b = searchpairpos(a:start, '', a:end, 'bcnW')
if b == [0, 0]
return [searchpairpos(a:start, '', a:end, 'bnW'), searchpairpos(a:start, '\%#', a:end, 'ncW')]
else
return [b, searchpairpos(a:start, '', a:end. '', 'nW')]
endif
endfunction endfunction
" get_content : get content in region " get_content : get content in region
@@ -311,3 +316,11 @@ function! emmet#util#cache(name, ...)
endif endif
call writefile(split(content, "\n"), file) call writefile(split(content, "\n"), file)
endfunction endfunction
function! emmet#util#getcurpos()
let pos = getpos('.')
if mode(0) == 'i' && pos[2] > 0
let pos[2] -=1
endif
return pos
endfunction