completion marks buffer modified too soon
When using |completion-function|, Vim is marking the buffer as modified, as soon as the popup is triggered. When a plugin offers matches using 'completefunc' the user should be able to cancel by pressing C-E and this shouldn't leave the buffer as modified. Here is a sample function to show what I mean: function! TComplete(findstart, base) if a:findstart return 0 else return [a:base]+['test1', 'test2'] endif endfunction setl completefunc=TComplete Thinking about it, it might be that Vim automatically chooses the first item in the completion, but this provides no option to leave buffer as not modified when completion is cancelled without selecting an item. I even tried explicitly setting nomodified (though it is ugly), something like: inoremap C-XC-U C-XC-UC-R=ResetModified() function! ResetModified() setl nomodified return '' endfunction But Vim seems to ignore this, as the buffer is still modified at the end. -- Thanks, Hari __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: completion marks buffer modified too soon
Hari Krishna Dara wrote: When using |completion-function|, Vim is marking the buffer as modified, as soon as the popup is triggered. When a plugin offers matches using 'completefunc' the user should be able to cancel by pressing C-E and this shouldn't leave the buffer as modified. Here is a sample function to show what I mean: function! TComplete(findstart, base) if a:findstart return 0 else return [a:base]+['test1', 'test2'] endif endfunction setl completefunc=TComplete Thinking about it, it might be that Vim automatically chooses the first item in the completion, but this provides no option to leave buffer as not modified when completion is cancelled without selecting an item. I even tried explicitly setting nomodified (though it is ugly), something like: inoremap C-XC-U C-XC-UC-R=ResetModified() function! ResetModified() setl nomodified return '' endfunction But Vim seems to ignore this, as the buffer is still modified at the end. The completion itself is seen as a change. If you cancel completion it's like changing the text back to what it was. It's very difficult to do this otherwise. -- hundred-and-one symptoms of being an internet addict: 88. Every single time you press the 'Get mail' button...it does get new mail. /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\download, build and distribute -- http://www.A-A-P.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org///
Re: completion marks buffer modified too soon
On Sat, 21 Oct 2006 at 1:59pm, Bram Moolenaar wrote: Hari Krishna Dara wrote: When using |completion-function|, Vim is marking the buffer as modified, as soon as the popup is triggered. When a plugin offers matches using 'completefunc' the user should be able to cancel by pressing C-E and this shouldn't leave the buffer as modified. Here is a sample function to show what I mean: function! TComplete(findstart, base) if a:findstart return 0 else return [a:base]+['test1', 'test2'] endif endfunction setl completefunc=TComplete Thinking about it, it might be that Vim automatically chooses the first item in the completion, but this provides no option to leave buffer as not modified when completion is cancelled without selecting an item. I even tried explicitly setting nomodified (though it is ugly), something like: inoremap C-XC-U C-XC-UC-R=ResetModified() function! ResetModified() setl nomodified return '' endfunction But Vim seems to ignore this, as the buffer is still modified at the end. The completion itself is seen as a change. If you cancel completion it's like changing the text back to what it was. It's very difficult to do this otherwise. How about adding an option something like showonly in 'completeopt', that when set brings up the menu, but doesn't automatically choose the first item? However this should probably be better controlled at per buffer level. There were requests before for this same issue, e.g., someone was trying to map . to bring up omni-completion menu, but didn't want the first item to be automatically chosen (as it is the case in *all* the IDEs), and the workaround was to include the . also as part of completion (it solves the problem, but I think is ugly, as you need to type C-N or C-P twice to get to the real first item or last item in the matches). If there is a way for the |complete-function| to indicate this option, it will solve this problem. -- Thank you, Hari __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com