emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for broken `insert-kbd-macro'.


From: Luc Teirlinck
Subject: Patch for broken `insert-kbd-macro'.
Date: Sat, 27 Nov 2004 21:34:37 -0600 (CST)

The minibuffer completion for `insert-kbd-macro' is broken, because it
assumes that keyboard macros are always strings or vectors, which is
no longer true.  As a result `insert-kbd-macro' _always_ claims that
there are no completions, whenever the keyboard macro is given by a
lambda expression, as is true for nearly all newly defined keyboard
macros.  The patch below fixes this.

If you look at a lambda expression corresponding to a keyboard macro,
as inserted by `insert-kbd-macro' (once you  take care of the
completion problem):

(fset 'a1
   (lambda (&optional arg) "Keyboard macro." (interactive "p")
   (kmacro-exec-ring-item (quote ([97 98 99 return] 0 "%d")) arg)))

then I do not want to rely on the docstring "Keyboard macro.", because
even a user unfamiliar with Elisp may realize that he can provide an
individualized docstring by straightforwardly hand editing that string
in his .emacs and might actually do so.  So the patch below relies on
the `kmacro-exec-ring-item' instead.  Maybe some functions that are
not keyboard macros may have, by some incredible coincidence,
`kmacro-exec-ring-item' in the same position.  But the only negative
from such a very improbable occurrence would be that the user _might_
have to type a few extra characters to get a unique completion.
(Remember, all we are talking about is minibuffer completion.)

I could install the patch below, if desired.

===File ~/macros.el-diff====================================
*** macros.el   06 Nov 2004 09:06:27 -0600      1.43
--- macros.el   27 Nov 2004 21:18:57 -0600      
***************
*** 63,76 ****
  
  To save a kbd macro, visit a file of Lisp code such as your `~/.emacs',
  use this command, and then save the file."
!   (interactive (list (intern (completing-read "Insert kbd macro (name): " 
!                                             obarray 
!                                             (lambda (elt)
!                                               (and (fboundp elt)
!                                                    (or (stringp 
(symbol-function elt))
!                                                        (vectorp 
(symbol-function elt)))))
!                                             t))
!                    current-prefix-arg))
    (let (definition)
      (if (string= (symbol-name macroname) "")
        (progn
--- 63,86 ----
  
  To save a kbd macro, visit a file of Lisp code such as your `~/.emacs',
  use this command, and then save the file."
!   (interactive
!    (list
!     (intern
!      (completing-read "Insert kbd macro (name): " 
!                     obarray 
!                     (lambda (elt)
!                       (and (fboundp elt)
!                            (let ((macr (symbol-function elt)))
!                              (or (stringp macr)
!                                  (vectorp macr)
!                                  ;; the call to `safe-length' is to
!                                  ;; avoid errors of the type
!                                  ;; (nth 4 '(1 . 2))
!                                  (and (>= (safe-length macr) 5)
!                                       (eq (car (nth 4 macr))
!                                           'kmacro-exec-ring-item))))))
!                     t))
!     current-prefix-arg))
    (let (definition)
      (if (string= (symbol-name macroname) "")
        (progn
============================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]