From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexander Shukaev Newsgroups: gmane.emacs.help Subject: Re: `define-key' in `defadvice' takes effect only after second invocation Date: Wed, 2 Sep 2015 22:45:58 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1441227147 15965 80.91.229.3 (2 Sep 2015 20:52:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Sep 2015 20:52:27 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 02 22:52:22 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZXF14-0003cF-0H for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Sep 2015 22:52:22 +0200 Original-Received: from localhost ([::1]:41426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXF13-0000iE-Ry for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Sep 2015 16:52:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXF0r-0000i1-PE for help-gnu-emacs@gnu.org; Wed, 02 Sep 2015 16:52:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXF0q-0006Uw-RO for help-gnu-emacs@gnu.org; Wed, 02 Sep 2015 16:52:09 -0400 Original-Received: from mail-lb0-x233.google.com ([2a00:1450:4010:c04::233]:34711) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXF0q-0006Ul-Jm for help-gnu-emacs@gnu.org; Wed, 02 Sep 2015 16:52:08 -0400 Original-Received: by lbbmp1 with SMTP id mp1so13472275lbb.1 for ; Wed, 02 Sep 2015 13:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=aRWJ44NmaHPi2zLELm6VFd9oDffeRJK+Hx8LuTTmIf4=; b=TI0r3iA9p6kDOaY01swoj+5EGitTdDxYP8TPAmrHFXWNkAuu6QXS0MlGYzBDbQKbVh Na7p/Kzsh7JjhvE3uao3Df8JlpZg86RoDf8UpeKIuf2lte9zhKMoYwYy6sVxtKF2XZbJ dmJPxzrb4h3HcptlQ+7g/yLloo1X0zGRGPDEmUBU8xD7CT24LMbKNob6ZR/1DZOKjob6 bPHfBToEPDJpoQ/2okEuCuQNb6Wmchs5clk53kiyl7MQ7S0exnyA5zW4cbfx/2yUOvj3 3kKVsP8rxRpq3jnNbHJOxxlprFZzKSjxtZy5iHgCiXeSBMmMJGbKoMpKbbLMRm/oyrjY 7FFQ== X-Received: by 10.112.12.102 with SMTP id x6mr18010621lbb.80.1441226758066; Wed, 02 Sep 2015 13:45:58 -0700 (PDT) Original-Received: by 10.112.34.10 with HTTP; Wed, 2 Sep 2015 13:45:58 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::233 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106992 Archived-At: > (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.