From: Alexander Shukaev <haroogan@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: `define-key' in `defadvice' takes effect only after second invocation
Date: Wed, 2 Sep 2015 22:45:58 +0200 [thread overview]
Message-ID: <CAKu-7Wz7tGM-A4+3gKPpt=fvZB3tOtKwagW4Enfsd_GJ_mPcaQ@mail.gmail.com> (raw)
In-Reply-To: <CAKu-7WycOu0k7zmGtw_FiXe_EWc=yXuhpo6Zq++P4eASpfD0xQ@mail.gmail.com>
> (require 'devil-common)
> (require 'devil-core)
> (require 'devil-states)
> ;;
> (defgroup devil-repeat-motion
> nil
> "Devil repeat motion."
> :group 'devil
> :prefix 'devil-repeat-motion)
> ;;
> (defcustom devil-repeat-motion-key
> (kbd "SPC")
> "Key used to repeat (last) motion."
> :group 'devil-repeat-motion
> :type 'key-sequence)
> ;;
> (defcustom devil-repeat-motion-key-reverse
> (kbd "S-SPC")
> "Key used to repeat (last) motion in reverse direction."
> :group 'devil-repeat-motion
> :type 'key-sequence)
> ;;
> ;;;###autoload
> (defun devil-repeat-motion
> (key-or-command
> key-or-command-next
> key-or-command-previous
> &optional keymap)
> "\
> Make KEY-OR-COMMAND repeatable."
> (setq keymap (or keymap evil-motion-state-map))
> (let ((command (devil-key-command key-or-command keymap))
> (command-next (devil-key-command key-or-command-next keymap))
> (command-previous (devil-key-command key-or-command-previous keymap)))
> (eval
> `(defadvice ,command
> (before
> ,(intern (format "devil-repeat-motion--%s" (symbol-name command)))
> activate)
> ,(format "\
> Make `%s' repeatable.
> Repeatable with `%s'.
> Repeatable with `%s' in reverse direction."
> command
> command-next
> command-previous)
> (unless (eq last-command #',command)
> (evil-define-key 'motion devil-repeat-motion-mode-map
> ,devil-repeat-motion-key #',command-next
> ,devil-repeat-motion-key-reverse #',command-previous))))
> (list command
> command-next
> command-previous)))
> ;;
> ;;;###autoload
> (defmacro devil-repeat-motions
> (&rest ...)
> "Apply `devil-repeat-motion' to each three consecutive arguments.
> Return list of results where each element is the return value of the
> corresponding `devil-repeat-motion' application."
> (declare (debug t)
> (indent defun))
> (let (body)
> (while ...
> (push `(devil-repeat-motion ,(pop ...) ,(pop ...) ,(pop ...)) body))
> (setq body (nreverse body))
> `(list ,@body)))
> ;;
> ;;;###autoload
> (define-minor-mode devil-repeat-motion-mode
> "\
> Devil repeat motion mode."
> :global t
> :group 'devil-repeat-motion
> :keymap (make-sparse-keymap)
> :lighter " DRM")
> ;;
> (provide 'devil-repeat-motion)
Right, I found the problem. Indeed, Evil needs the commit of key
bindings with `evil-normalize-keymaps'. Hence, had to add the
following:
(define-minor-mode devil-repeat-motion-mode
"\
Devil repeat motion mode."
:global t
:group 'devil-repeat-motion
:keymap (make-sparse-keymap)
:lighter " DRM"
(evil-normalize-keymaps)) ;; <<<
and
(unless (eq last-command #',command)
(evil-define-key 'motion devil-repeat-motion-mode-map
,devil-repeat-motion-key #',command-next
,devil-repeat-motion-key-reverse #',command-previous)
(evil-normalize-keymaps)))) ;; <<<
Works as expected now. Sorry, for the noise.
prev parent reply other threads:[~2015-09-02 20:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-02 20:06 `define-key' in `defadvice' takes effect only after second invocation Alexander Shukaev
2015-09-02 20:45 ` Alexander Shukaev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKu-7Wz7tGM-A4+3gKPpt=fvZB3tOtKwagW4Enfsd_GJ_mPcaQ@mail.gmail.com' \
--to=haroogan@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.