The dot Command not able to repeat text inserted by "Auto-complete"

Frank Fischer frank.fischer at mathematik.tu-chemnitz.de
Tue Aug 16 11:59:24 CEST 2011


Am Montag, 15. August 2011 schrieb Frank Fischer:
> Am Mon, 15 Aug 2011 14:54:44 -0400
>
> schrieb York Zhao <gtdplatform at gmail.com>:
> > Hi,
> >
> > I've been having this problem for a while and it is now my biggest
> > complain to Evil because other than Evil itself, "auto-complete" is
> > the next thing I can't be living without.
>
> In fact, the change based repeation system (in contrast to the
> key-stroke based one, I described both in another mail and it will
> hopefully find its way in the docs) is designed exactly for these
> cases and I'm quite confident that this is indeed not a big problem.
> I just haven't activated it yet, but I'm going to have a look at it
> in the next days.

In turned out to be a little bit more difficult than a thought. 
Activating the change-based repeation for auto-complete worked well 
except in one case: when the completion is done near the end of the 
buffer. The reason is that in this case auto-complete adds a few 
newlines to the end of the buffer in order to show its popup-menu 
(those newlines are removed when the popup closes). The problem is that 
these insertions/deletions are, well, buffer-changes and therefore 
confused the recording. Even worse, the popup menu is triggered by a 
timer and not by a command, therefore there is no command active when 
the first buffer changes appear and this confuses the system even more. 

Luckily, Evil had already had the ability to execute arbitrary functions 
to realize a repeation, there just was no way to specify such a 
function for a command. I added this functionality in d15b75a5. The 
following code should equip auto-complete with working repeation. I'm 
going to cleanup the repeation code, especially the definition of 
user-defined repeation functions, a little bit, so don't assume this as 
a stable example but feel free to test and tell us about problems.


(evil-set-command-properties 'ac-complete :repeat 'evil-ac-repeat)
(evil-set-command-properties 'ac-expand :repeat 'evil-ac-repeat)
(evil-set-command-properties 'ac-next :repeat 'ignore)
(evil-set-command-properties 'ac-previous :repeat 'ignore)

(defvar evil-ac-prefix-len nil
  "The length of the prefix of the current item to be completed.")

(defun evil-ac-repeat (flag)
  "Record the changes for auto-completion."
  (if (eq flag 'pre)
      (setq evil-ac-prefix-len (length ac-prefix))
    ;; Add change to remove the prefix
    (evil-repeat-record-change 
     (list (- evil-ac-prefix-len) "" evil-ac-prefix-len))
    ;; Add change to insert the full completed text
    (evil-repeat-record-change 
     (list (- evil-ac-prefix-len)
	   (buffer-substring-no-properties (- evil-repeat-pos
					      evil-ac-prefix-len)
					   (point))
	   0))
    ;; Finish repeation
    (evil-repeat-record-change)))


Hope it works,
Frank



More information about the implementations-list mailing list