Modify repeat keys?

Frank Fischer frank.fischer at mathematik.tu-chemnitz.de
Thu Aug 11 14:42:28 CEST 2011


On Thu, Aug 11, 2011 at 12:40:20PM +0200, Michael Markert wrote:
> On 11 Aug 2011, Frank Fischer wrote:
> 
> > On Thu, Aug 11, 2011 at 01:56:05AM +0200, Michael Markert wrote:
> > You found a point where the evil already has an answer ;)
> 
> I hoped for this :)
> 
> > The following code should work (I removed the lambda-trick because you
> > need 'evil-define-command' so this is easier).
> 
> Thanks, it works great! But is there a way to produce a parameterized
> command like my function did? Short of extra variables/constants or a
> lexical-let on binding?

Currently the command-properties are stored in an alist that requires
the key to be a symbol (the function name), therefore a command with a
property like :repeat must be bound to a symbol, i.e., must be an
ordinary function and not a lambda expression. The only idea I have is
to use a macro:

(defmacro cofi/define-maybe-exit (entry-char exit-char)
  (let ((name (intern (concat "cofi/maybe-exit-"
			      (char-to-string entry-char)
			      (char-to-string exit-char)))))
    `(progn
       (define-key evil-insert-state-map (char-to-string ,entry-char) #',name)

       (evil-define-command ,name ()
	 :repeat change
	 (interactive)
	 (let ((modified (buffer-modified-p)))
	   (insert ,entry-char)
	   (let ((evt (read-event (format "Insert %c to exit insert state" ,exit-char)
				  nil 0.5)))
	     (cond
	      ((null evt) (message ""))
	      ((and (integerp evt) (char-equal evt ,exit-char))
	       (delete-char -1)
	       (set-buffer-modified-p modified)
	       (push 'escape unread-command-events))
	      (t (setq unread-command-events (append unread-command-events
						     (list evt)))))))))))

and then (cofi/define-maybe-exit ?j ?k). Alternatively one would have
to modify the functions `evil-put-property' and `evil-get-property' so
they can handle lambda-expressions as well.

Frank



More information about the implementations-list mailing list