summaryrefslogtreecommitdiff
path: root/lisp/macros.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2017-11-24 11:32:14 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2017-11-24 11:32:14 -0500
commit4f779ff8e6445d9b46a87f494396ccb5f72b0350 (patch)
tree4007a6a4b32718cc73a07adea8a80868ae239bd9 /lisp/macros.el
parentb407c521f24b07b76eee0cd06d471e629cef18e8 (diff)
downloademacs-4f779ff8e6445d9b46a87f494396ccb5f72b0350.tar.gz
* lisp/macros.el (insert-kbd-macro): Recognize kmacros reliably
* lisp/macros.el (name-last-kbd-macro): Make it an alias of kmacro-name-last-macro. (insert-kbd-macro): Use kmacro-keyboard-macro-p so it also works for kmacros that fail to have a `kmacro' property. (see https://emacs.stackexchange.com/questions/37065, for an example). * lisp/kmacro.el: Remove redundant :group args. (kmacro-insert-counter): Simplify. (kmacro-extract-lambda): Use car/cdr-safe. (kmacro-p, kmacro-keyboard-macro-p): New functions. (kmacro-name-last-macro): Use them.
Diffstat (limited to 'lisp/macros.el')
-rw-r--r--lisp/macros.el30
1 files changed, 8 insertions, 22 deletions
diff --git a/lisp/macros.el b/lisp/macros.el
index 34e81f693f5..5583c02f68b 100644
--- a/lisp/macros.el
+++ b/lisp/macros.el
@@ -1,4 +1,4 @@
-;;; macros.el --- non-primitive commands for keyboard macros
+;;; macros.el --- non-primitive commands for keyboard macros -*- lexical-binding:t -*-
;; Copyright (C) 1985-1987, 1992, 1994-1995, 2001-2017 Free Software
;; Foundation, Inc.
@@ -31,23 +31,10 @@
;;; Code:
+(require 'kmacro)
+
;;;###autoload
-(defun name-last-kbd-macro (symbol)
- "Assign a name to the last keyboard macro defined.
-Argument SYMBOL is the name to define.
-The symbol's function definition becomes the keyboard macro string.
-Such a \"function\" cannot be called from Lisp, but it is a valid editor command."
- (interactive "SName for last kbd macro: ")
- (or last-kbd-macro
- (user-error "No keyboard macro defined"))
- (and (fboundp symbol)
- (not (stringp (symbol-function symbol)))
- (not (vectorp (symbol-function symbol)))
- (user-error "Function %s is already defined and not a keyboard macro"
- symbol))
- (if (string-equal symbol "")
- (user-error "No command name given"))
- (fset symbol last-kbd-macro))
+(defalias 'name-last-kbd-macro #'kmacro-name-last-macro)
;;;###autoload
(defun insert-kbd-macro (macroname &optional keys)
@@ -66,11 +53,7 @@ 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))
- (get elt 'kmacro))))
+ #'kmacro-keyboard-macro-p
t))
current-prefix-arg))
(let (definition)
@@ -137,6 +120,9 @@ use this command, and then save the file."
(prin1 char (current-buffer))
(princ (prin1-char char) (current-buffer))))
(insert ?\]))
+ ;; FIXME: For kmacros, we shouldn't write the (lambda ...)
+ ;; gunk but instead we should write something more abstract like
+ ;; (kmacro-create [<keys>] 0 "%d").
(prin1 definition (current-buffer))))
(insert ")\n")
(if keys