2017-07-29 15:01:57 +00:00
|
|
|
;;; kmacro.el --- enhanced keyboard macros -*- lexical-binding: t -*-
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2021-01-01 09:13:56 +00:00
|
|
|
;; Copyright (C) 2002-2021 Free Software Foundation, Inc.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
;; Author: Kim F. Storm <storm@cua.dk>
|
2002-06-28 22:45:16 +00:00
|
|
|
;; Keywords: keyboard convenience
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2002-06-28 22:37:18 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2006-11-26 11:50:51 +00:00
|
|
|
;; The kmacro package provides the user interface to emacs' basic
|
|
|
|
;; keyboard macro functionality. With kmacro, two function keys are
|
|
|
|
;; dedicated to keyboard macros, by default F3 and F4.
|
|
|
|
|
|
|
|
;; Note: The traditional bindings C-x (, C-x ), and C-x e are still
|
|
|
|
;; supported, but for some users these bindings are too hard to type
|
|
|
|
;; to be really useful for doing small repeated tasks.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
;; To start defining a keyboard macro, use F3. To end the macro,
|
|
|
|
;; use F4, and to call the macro also use F4. This makes it very
|
2002-06-28 22:37:18 +00:00
|
|
|
;; easy to repeat a macro immediately after defining it.
|
|
|
|
;;
|
2002-08-29 13:06:26 +00:00
|
|
|
;; You can call the macro repeatedly by pressing F4 multiple times, or
|
2002-06-28 22:37:18 +00:00
|
|
|
;; you can give a numeric prefix argument specifying the number of
|
|
|
|
;; times to repeat the macro. Macro execution automatically
|
|
|
|
;; terminates when point reaches the end of the buffer or if an error
|
2008-06-27 02:14:52 +00:00
|
|
|
;; is signaled by ringing the bell.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
;; When you define a macro with F3/F4, it is automatically added to
|
|
|
|
;; the head of the "keyboard macro ring", and F4 actually executes the
|
2002-08-19 23:05:29 +00:00
|
|
|
;; first element of the macro ring.
|
|
|
|
;;
|
|
|
|
;; Note: an empty macro is never added to the macro ring.
|
|
|
|
;;
|
2002-08-29 13:06:26 +00:00
|
|
|
;; You can execute the second element on the macro ring with C-u F4 or
|
2002-08-19 23:05:29 +00:00
|
|
|
;; C-x C-k C-l, you can use C-x C-k C-p and C-x C-k C-n to cycle
|
|
|
|
;; through the macro ring, and you can swap the first and second
|
|
|
|
;; elements with C-x C-k C-t. To delete the first element in the
|
|
|
|
;; macro ring, use C-x C-k C-d.
|
|
|
|
;;
|
|
|
|
;; You can also use C-x C-k C-s to start a macro, and C-x C-k C-k to
|
|
|
|
;; end it; then use C-k to execute it immediately, or C-x C-k C-k to
|
|
|
|
;; execute it later.
|
|
|
|
;;
|
|
|
|
;; In general, immediately after using C-x C-k followed by one of C-k,
|
|
|
|
;; C-l, C-p, or C-n, you can further cycle the macro ring using C-p or
|
|
|
|
;; C-n, execute the first or second macro using C-k or C-l, delete
|
|
|
|
;; the head macro with C-d, or edit the current macro with C-e without
|
|
|
|
;; repeating the C-x C-k prefix.
|
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
;; If you enter F3 while defining the macro, the numeric value of
|
2002-06-28 22:37:18 +00:00
|
|
|
;; `kmacro-counter' is inserted using the `kmacro-counter-format', and
|
|
|
|
;; `kmacro-counter' is incremented by 1 (or the numeric prefix value
|
2002-08-29 13:06:26 +00:00
|
|
|
;; of F3).
|
2002-06-28 22:37:18 +00:00
|
|
|
;;
|
|
|
|
;; The initial value of `kmacro-counter' is 0, or the numeric prefix
|
2002-08-29 13:06:26 +00:00
|
|
|
;; value given to F3 when starting the macro.
|
2002-06-28 22:37:18 +00:00
|
|
|
;;
|
2002-08-29 13:06:26 +00:00
|
|
|
;; Now, each time you call the macro using F4, the current
|
2002-06-28 22:37:18 +00:00
|
|
|
;; value of `kmacro-counter' is inserted and incremented, making it
|
|
|
|
;; easy to insert incremental numbers in the buffer.
|
|
|
|
;;
|
|
|
|
;; Example:
|
|
|
|
;;
|
2002-08-29 13:06:26 +00:00
|
|
|
;; The following sequence: M-5 F3 x M-2 F3 y F4 F4 F4 F4
|
2002-06-28 22:37:18 +00:00
|
|
|
;; inserts the following string: x5yx7yx9yx11y
|
|
|
|
|
2002-06-29 20:43:59 +00:00
|
|
|
;; A macro can also be called using a mouse click, default S-mouse-3.
|
2002-06-28 22:37:18 +00:00
|
|
|
;; This calls the macro at the point where you click the mouse.
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
;; You can edit the last macro using C-x C-k C-e.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
;; You can append to the last macro using C-u F3.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
;; You can set the macro counter using C-x C-k C-c, add to it using C-x C-k C-a,
|
|
|
|
;; and you can set the macro counter format with C-x C-k C-f.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
;; The following key bindings are performed:
|
2003-02-04 12:29:42 +00:00
|
|
|
;;
|
2002-06-28 22:37:18 +00:00
|
|
|
;; Normal While defining macro
|
|
|
|
;; --------------------------- ------------------------------
|
2002-08-29 13:06:26 +00:00
|
|
|
;; f3 Define macro Insert current counter value
|
2002-06-28 22:37:18 +00:00
|
|
|
;; Prefix arg specifies initial and increase counter by prefix
|
|
|
|
;; counter value (default 0) (default increment: 1)
|
|
|
|
;;
|
2002-08-29 13:06:26 +00:00
|
|
|
;; C-u f3 APPENDs to last macro
|
2003-02-04 12:29:42 +00:00
|
|
|
;;
|
|
|
|
;; f4 Call last macro End macro
|
2002-06-28 22:37:18 +00:00
|
|
|
;; Prefix arg specifies number
|
|
|
|
;; of times to execute macro.
|
|
|
|
;;
|
2002-08-29 13:06:26 +00:00
|
|
|
;; C-u f4 Swap last and head of macro ring.
|
2003-02-04 12:29:42 +00:00
|
|
|
;;
|
2002-06-28 22:37:18 +00:00
|
|
|
;; S-mouse-3 Set point at click and End macro and execute macro at
|
|
|
|
;; execute last macro. click.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2002-06-29 20:43:59 +00:00
|
|
|
;; Customization:
|
2017-10-25 16:31:40 +00:00
|
|
|
(require 'replace)
|
2019-06-12 16:21:35 +00:00
|
|
|
(require 'cl-lib)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
(defgroup kmacro nil
|
|
|
|
"Simplified keyboard macro user interface."
|
|
|
|
:group 'keyboard
|
|
|
|
:group 'convenience
|
2005-02-09 15:50:47 +00:00
|
|
|
:version "22.1"
|
2002-06-28 22:37:18 +00:00
|
|
|
:link '(emacs-commentary-link :tag "Commentary" "kmacro.el")
|
|
|
|
:link '(emacs-library-link :tag "Lisp File" "kmacro.el"))
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
(defcustom kmacro-call-mouse-event 'S-mouse-3
|
|
|
|
"The mouse event used by kmacro to call a macro.
|
|
|
|
Set to nil if no mouse binding is desired."
|
2017-11-24 16:32:14 +00:00
|
|
|
:type 'symbol)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
(defcustom kmacro-ring-max 8
|
|
|
|
"Maximum number of keyboard macros to save in macro ring."
|
2017-11-24 16:32:14 +00:00
|
|
|
:type 'integer)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(defcustom kmacro-execute-before-append t
|
|
|
|
"Controls whether appending to a macro starts by executing the macro.
|
|
|
|
If non-nil, using a single \\[universal-argument] prefix executes the macro
|
|
|
|
before appending, while more than one \\[universal-argument] prefix does not
|
|
|
|
execute the macro.
|
|
|
|
Otherwise, a single \\[universal-argument] prefix does not execute the
|
|
|
|
macro, while more than one \\[universal-argument] prefix causes the
|
|
|
|
macro to be executed before appending to it."
|
2017-11-24 16:32:14 +00:00
|
|
|
:type 'boolean)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(defcustom kmacro-repeat-no-prefix t
|
|
|
|
"Allow repeating certain macro commands without entering the C-x C-k prefix."
|
2017-11-24 16:32:14 +00:00
|
|
|
:type 'boolean)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(defcustom kmacro-call-repeat-key t
|
|
|
|
"Allow repeating macro call using last key or a specific key."
|
|
|
|
:type '(choice (const :tag "Disabled" nil)
|
|
|
|
(const :tag "Last key" t)
|
|
|
|
(character :tag "Character" :value ?e)
|
2017-11-24 16:32:14 +00:00
|
|
|
(symbol :tag "Key symbol" :value RET)))
|
2002-08-29 13:06:26 +00:00
|
|
|
|
|
|
|
(defcustom kmacro-call-repeat-with-arg nil
|
|
|
|
"Repeat macro call with original arg when non-nil; repeat once if nil."
|
2017-11-24 16:32:14 +00:00
|
|
|
:type 'boolean)
|
2002-08-29 13:06:26 +00:00
|
|
|
|
2002-09-08 20:38:04 +00:00
|
|
|
(defcustom kmacro-step-edit-mini-window-height 0.75
|
|
|
|
"Override `max-mini-window-height' when step edit keyboard macro."
|
2017-11-24 16:32:14 +00:00
|
|
|
:type 'number)
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
;; Keymap
|
|
|
|
|
|
|
|
(defvar kmacro-keymap
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2003-08-17 22:04:44 +00:00
|
|
|
;; Start, end, execute macros
|
2021-05-18 02:16:42 +00:00
|
|
|
(define-key map "s" #'kmacro-start-macro)
|
|
|
|
(define-key map "\C-s" #'kmacro-start-macro)
|
|
|
|
(define-key map "\C-k" #'kmacro-end-or-call-macro-repeat)
|
|
|
|
(define-key map "r" #'apply-macro-to-region-lines)
|
|
|
|
(define-key map "q" #'kbd-macro-query) ;; Like C-x q
|
|
|
|
(define-key map "Q" #'kdb-macro-redisplay)
|
2003-08-17 22:04:44 +00:00
|
|
|
|
|
|
|
;; macro ring
|
2021-05-18 02:16:42 +00:00
|
|
|
(define-key map "\C-n" #'kmacro-cycle-ring-next)
|
|
|
|
(define-key map "\C-p" #'kmacro-cycle-ring-previous)
|
|
|
|
(define-key map "\C-v" #'kmacro-view-macro-repeat)
|
|
|
|
(define-key map "\C-d" #'kmacro-delete-ring-head)
|
|
|
|
(define-key map "\C-t" #'kmacro-swap-ring)
|
|
|
|
(define-key map "\C-l" #'kmacro-call-ring-2nd-repeat)
|
2003-08-17 22:04:44 +00:00
|
|
|
|
|
|
|
;; macro counter
|
2021-05-18 02:16:42 +00:00
|
|
|
(define-key map "\C-f" #'kmacro-set-format)
|
|
|
|
(define-key map "\C-c" #'kmacro-set-counter)
|
|
|
|
(define-key map "\C-i" #'kmacro-insert-counter)
|
|
|
|
(define-key map "\C-a" #'kmacro-add-counter)
|
2003-08-17 22:04:44 +00:00
|
|
|
|
|
|
|
;; macro editing
|
2021-05-18 02:16:42 +00:00
|
|
|
(define-key map "\C-e" #'kmacro-edit-macro-repeat)
|
|
|
|
(define-key map "\r" #'kmacro-edit-macro)
|
|
|
|
(define-key map "e" #'edit-kbd-macro)
|
|
|
|
(define-key map "l" #'kmacro-edit-lossage)
|
|
|
|
(define-key map " " #'kmacro-step-edit-macro)
|
2003-08-17 22:04:44 +00:00
|
|
|
|
|
|
|
;; naming and binding
|
2021-05-18 02:16:42 +00:00
|
|
|
(define-key map "b" #'kmacro-bind-to-key)
|
|
|
|
(define-key map "n" #'kmacro-name-last-macro)
|
|
|
|
(define-key map "x" #'kmacro-to-register)
|
2002-08-19 23:05:29 +00:00
|
|
|
map)
|
|
|
|
"Keymap for keyboard macro commands.")
|
|
|
|
(defalias 'kmacro-keymap kmacro-keymap)
|
|
|
|
|
|
|
|
;;; Provide some binding for startup:
|
2021-05-18 02:16:42 +00:00
|
|
|
;;;###autoload (global-set-key "\C-x(" #'kmacro-start-macro)
|
|
|
|
;;;###autoload (global-set-key "\C-x)" #'kmacro-end-macro)
|
|
|
|
;;;###autoload (global-set-key "\C-xe" #'kmacro-end-and-call-macro)
|
|
|
|
;;;###autoload (global-set-key [f3] #'kmacro-start-macro-or-insert-counter)
|
|
|
|
;;;###autoload (global-set-key [f4] #'kmacro-end-or-call-macro)
|
|
|
|
;;;###autoload (global-set-key "\C-x\C-k" #'kmacro-keymap)
|
2002-08-19 23:05:29 +00:00
|
|
|
;;;###autoload (autoload 'kmacro-keymap "kmacro" "Keymap for keyboard macro commands." t 'keymap)
|
|
|
|
|
|
|
|
(if kmacro-call-mouse-event
|
2021-05-18 02:16:42 +00:00
|
|
|
(global-set-key (vector kmacro-call-mouse-event) #'kmacro-end-call-mouse))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
2004-11-01 23:06:32 +00:00
|
|
|
;;; Called from keyboard-quit
|
|
|
|
|
|
|
|
(defun kmacro-keyboard-quit ()
|
|
|
|
(or (not defining-kbd-macro)
|
|
|
|
(eq defining-kbd-macro 'append)
|
|
|
|
(kmacro-ring-empty-p)
|
|
|
|
(kmacro-pop-ring)))
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
;;; Keyboard macro counter
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
(defvar kmacro-counter 0
|
2018-05-11 09:11:14 +00:00
|
|
|
"Current keyboard macro counter.
|
|
|
|
|
|
|
|
This is normally initialized to zero when the macro is defined,
|
|
|
|
and incremented each time the value of the counter is inserted
|
|
|
|
into a buffer. See `kmacro-start-macro-or-insert-counter' for
|
|
|
|
more details.")
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2004-12-02 00:17:54 +00:00
|
|
|
(defvar kmacro-default-counter-format "%d")
|
|
|
|
|
2002-06-28 22:37:18 +00:00
|
|
|
(defvar kmacro-counter-format "%d"
|
2018-05-11 09:11:14 +00:00
|
|
|
"Current keyboard macro counter format.
|
|
|
|
|
|
|
|
Can be set directly via `kmacro-set-format', which see.")
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
(defvar kmacro-counter-format-start kmacro-counter-format
|
|
|
|
"Macro format at start of macro execution.")
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
(defvar kmacro-counter-value-start kmacro-counter
|
|
|
|
"Macro counter at start of macro execution.")
|
|
|
|
|
2003-08-17 22:04:44 +00:00
|
|
|
(defvar kmacro-last-counter 0
|
|
|
|
"Last counter inserted by key macro.")
|
|
|
|
|
|
|
|
(defvar kmacro-initial-counter-value nil
|
|
|
|
"Initial counter value for the next keyboard macro to be defined.")
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
(defun kmacro-insert-counter (arg)
|
2018-05-11 09:11:14 +00:00
|
|
|
"Insert current value of `kmacro-counter', then increment it by ARG.
|
2008-11-22 03:19:06 +00:00
|
|
|
Interactively, ARG defaults to 1. With \\[universal-argument], insert
|
2019-02-01 15:34:23 +00:00
|
|
|
the previous value of `kmacro-counter', and do not increment the
|
|
|
|
current value.
|
|
|
|
The previous value of the counter is the one it had before
|
|
|
|
the last increment."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive "P")
|
2004-10-11 22:13:20 +00:00
|
|
|
(if kmacro-initial-counter-value
|
|
|
|
(setq kmacro-counter kmacro-initial-counter-value
|
|
|
|
kmacro-initial-counter-value nil))
|
2017-11-24 16:32:14 +00:00
|
|
|
(if (consp arg)
|
2002-08-19 23:05:29 +00:00
|
|
|
(insert (format kmacro-counter-format kmacro-last-counter))
|
|
|
|
(insert (format kmacro-counter-format kmacro-counter))
|
|
|
|
(kmacro-add-counter (prefix-numeric-value arg))))
|
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-set-format (format)
|
2018-05-11 09:11:14 +00:00
|
|
|
"Set the format of `kmacro-counter' to FORMAT."
|
2004-12-02 00:17:54 +00:00
|
|
|
(interactive "sMacro Counter Format: ")
|
2002-08-19 23:05:29 +00:00
|
|
|
(setq kmacro-counter-format
|
|
|
|
(if (equal format "") "%d" format))
|
|
|
|
;; redefine initial macro counter if we are not executing a macro.
|
|
|
|
(if (not (or defining-kbd-macro executing-kbd-macro))
|
2004-12-02 00:17:54 +00:00
|
|
|
(setq kmacro-default-counter-format kmacro-counter-format)))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-display-counter (&optional value)
|
|
|
|
"Display current counter value."
|
|
|
|
(unless value (setq value kmacro-counter))
|
2017-11-24 16:32:14 +00:00
|
|
|
(message "New macro counter value: %s (%d)"
|
|
|
|
(format kmacro-counter-format value) value))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(defun kmacro-set-counter (arg)
|
2018-05-11 09:11:14 +00:00
|
|
|
"Set the value of `kmacro-counter' to ARG, or prompt for value if no argument.
|
2020-12-19 16:14:33 +00:00
|
|
|
With \\[universal-argument] prefix, reset counter to its value prior to this iteration of the
|
|
|
|
macro."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive "NMacro counter value: ")
|
2004-10-11 22:13:20 +00:00
|
|
|
(if (not (or defining-kbd-macro executing-kbd-macro))
|
|
|
|
(kmacro-display-counter (setq kmacro-initial-counter-value arg))
|
|
|
|
(setq kmacro-last-counter kmacro-counter
|
|
|
|
kmacro-counter (if (and current-prefix-arg (listp current-prefix-arg))
|
|
|
|
kmacro-counter-value-start
|
|
|
|
arg))
|
|
|
|
(unless executing-kbd-macro
|
|
|
|
(kmacro-display-counter))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-add-counter (arg)
|
2018-05-11 09:11:14 +00:00
|
|
|
"Add the value of numeric prefix arg (prompt if missing) to `kmacro-counter'.
|
2002-08-19 23:05:29 +00:00
|
|
|
With \\[universal-argument], restore previous counter value."
|
|
|
|
(interactive "NAdd to macro counter: ")
|
2004-10-11 22:13:20 +00:00
|
|
|
(if kmacro-initial-counter-value
|
|
|
|
(setq kmacro-counter kmacro-initial-counter-value
|
|
|
|
kmacro-initial-counter-value nil))
|
2002-08-19 23:05:29 +00:00
|
|
|
(let ((last kmacro-last-counter))
|
|
|
|
(setq kmacro-last-counter kmacro-counter
|
|
|
|
kmacro-counter (if (and current-prefix-arg (listp current-prefix-arg))
|
|
|
|
last
|
|
|
|
kmacro-counter (+ kmacro-counter arg))))
|
|
|
|
(unless executing-kbd-macro
|
|
|
|
(kmacro-display-counter)))
|
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-loop-setup-function ()
|
|
|
|
"Function called prior to each iteration of macro."
|
|
|
|
;; Restore macro counter format to initial format, so it is ok to change
|
|
|
|
;; counter format in the macro without restoring it.
|
|
|
|
(setq kmacro-counter-format kmacro-counter-format-start)
|
|
|
|
;; Save initial counter value so we can restore it with C-u kmacro-set-counter.
|
|
|
|
(setq kmacro-counter-value-start kmacro-counter)
|
|
|
|
;; Return non-nil to continue execution.
|
|
|
|
t)
|
|
|
|
|
|
|
|
|
|
|
|
;;; Keyboard macro ring
|
|
|
|
|
|
|
|
(defvar kmacro-ring nil
|
|
|
|
"The keyboard macro ring.
|
|
|
|
Each element is a list (MACRO COUNTER FORMAT). Actually, the head of
|
|
|
|
the macro ring (when defining or executing) is not stored in the ring;
|
|
|
|
instead it is available in the variables `last-kbd-macro', `kmacro-counter',
|
|
|
|
and `kmacro-counter-format'.")
|
|
|
|
|
2003-08-17 22:04:44 +00:00
|
|
|
;; Remember what we are currently looking at with kmacro-view-macro.
|
|
|
|
|
|
|
|
(defvar kmacro-view-last-item nil)
|
|
|
|
(defvar kmacro-view-item-no 0)
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(defun kmacro-ring-head ()
|
|
|
|
"Return pseudo head element in macro ring."
|
|
|
|
(and last-kbd-macro
|
|
|
|
(list last-kbd-macro kmacro-counter kmacro-counter-format-start)))
|
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-push-ring (&optional elt)
|
|
|
|
"Push ELT or current macro onto `kmacro-ring'."
|
|
|
|
(when (setq elt (or elt (kmacro-ring-head)))
|
2006-05-07 20:49:16 +00:00
|
|
|
(let ((history-delete-duplicates nil))
|
|
|
|
(add-to-history 'kmacro-ring elt kmacro-ring-max))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-split-ring-element (elt)
|
|
|
|
(setq last-kbd-macro (car elt)
|
|
|
|
kmacro-counter (nth 1 elt)
|
|
|
|
kmacro-counter-format-start (nth 2 elt)))
|
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-pop-ring1 (&optional raw)
|
|
|
|
"Pop head element off macro ring (no check).
|
|
|
|
Non-nil arg RAW means just return raw first element."
|
|
|
|
(prog1 (car kmacro-ring)
|
|
|
|
(unless raw
|
|
|
|
(kmacro-split-ring-element (car kmacro-ring)))
|
|
|
|
(setq kmacro-ring (cdr kmacro-ring))))
|
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-pop-ring (&optional raw)
|
|
|
|
"Pop head element off macro ring.
|
|
|
|
Non-nil arg RAW means just return raw first element."
|
|
|
|
(unless (kmacro-ring-empty-p)
|
|
|
|
(kmacro-pop-ring1 raw)))
|
2003-02-04 12:29:42 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(defun kmacro-ring-empty-p (&optional none)
|
|
|
|
"Tell user and return t if `last-kbd-macro' is nil or `kmacro-ring' is empty.
|
|
|
|
Check only `last-kbd-macro' if optional arg NONE is non-nil."
|
|
|
|
(while (and (null last-kbd-macro) kmacro-ring)
|
|
|
|
(kmacro-pop-ring1))
|
|
|
|
(cond
|
|
|
|
((null last-kbd-macro)
|
|
|
|
(message "No keyboard macro defined.")
|
|
|
|
t)
|
|
|
|
((and (null none) (null kmacro-ring))
|
|
|
|
(message "Only one keyboard macro defined.")
|
|
|
|
t)
|
|
|
|
(t nil)))
|
|
|
|
|
|
|
|
|
2003-08-17 22:04:44 +00:00
|
|
|
(defun kmacro-display (macro &optional trunc descr empty)
|
|
|
|
"Display a keyboard MACRO.
|
|
|
|
Optional arg TRUNC non-nil specifies to limit width of macro to 60 chars.
|
|
|
|
Optional arg DESCR is descriptive text for macro; default is \"Macro:\".
|
|
|
|
Optional arg EMPTY is message to print if no macros are defined."
|
2002-08-19 23:05:29 +00:00
|
|
|
(if macro
|
|
|
|
(let* ((x 60)
|
|
|
|
(m (format-kbd-macro macro))
|
|
|
|
(l (length m))
|
2004-12-02 00:17:54 +00:00
|
|
|
(z (and trunc (> l x))))
|
|
|
|
(message "%s%s: %s%s" (or descr "Macro")
|
|
|
|
(if (= kmacro-counter 0) ""
|
|
|
|
(format " [%s]"
|
|
|
|
(format kmacro-counter-format-start kmacro-counter)))
|
|
|
|
(if z (substring m 0 (1- x)) m) (if z "..." "")))
|
2007-12-08 01:02:29 +00:00
|
|
|
(message "%s" (or empty "No keyboard macros defined"))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(defun kmacro-repeat-on-last-key (keys)
|
2006-08-25 20:30:17 +00:00
|
|
|
"Process kmacro commands keys immediately after cycling the ring."
|
2002-08-29 13:06:26 +00:00
|
|
|
(setq keys (vconcat keys))
|
|
|
|
(let ((n (1- (length keys)))
|
|
|
|
cmd done repeat)
|
|
|
|
(while (and last-kbd-macro
|
|
|
|
(not done)
|
|
|
|
(aset keys n (read-event))
|
|
|
|
(setq cmd (key-binding keys t))
|
|
|
|
(setq repeat (get cmd 'kmacro-repeat)))
|
|
|
|
(clear-this-command-keys t)
|
|
|
|
(cond
|
|
|
|
((eq repeat 'ring)
|
|
|
|
(if kmacro-ring
|
|
|
|
(let ((kmacro-repeat-no-prefix nil))
|
|
|
|
(funcall cmd nil))
|
|
|
|
(kmacro-display last-kbd-macro t)))
|
|
|
|
((eq repeat 'head)
|
|
|
|
(let ((kmacro-repeat-no-prefix nil))
|
|
|
|
(funcall cmd nil)))
|
|
|
|
((eq repeat 'stop)
|
|
|
|
(funcall cmd nil)
|
|
|
|
(setq done t)))
|
|
|
|
(setq last-input-event nil)))
|
|
|
|
(when last-input-event
|
|
|
|
(clear-this-command-keys t)
|
2015-07-25 16:54:42 +00:00
|
|
|
(push last-input-event unread-command-events)))
|
2002-08-29 13:06:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-get-repeat-prefix ()
|
|
|
|
(let (keys)
|
|
|
|
(and kmacro-repeat-no-prefix
|
|
|
|
(setq keys (this-single-command-keys))
|
|
|
|
(> (length keys) 1)
|
|
|
|
keys)))
|
|
|
|
|
|
|
|
|
2008-08-05 22:58:38 +00:00
|
|
|
;;;###autoload
|
2003-08-17 22:04:44 +00:00
|
|
|
(defun kmacro-exec-ring-item (item arg)
|
2014-02-08 12:34:52 +00:00
|
|
|
"Execute item ITEM from the macro ring.
|
2014-02-12 19:40:35 +00:00
|
|
|
ARG is the number of times to execute the item."
|
2003-08-17 22:04:44 +00:00
|
|
|
;; Use counter and format specific to the macro on the ring!
|
|
|
|
(let ((kmacro-counter (nth 1 item))
|
|
|
|
(kmacro-counter-format-start (nth 2 item)))
|
|
|
|
(execute-kbd-macro (car item) arg #'kmacro-loop-setup-function)
|
|
|
|
(setcar (cdr item) kmacro-counter)))
|
|
|
|
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
(defun kmacro-call-ring-2nd (arg)
|
2007-01-14 03:22:45 +00:00
|
|
|
"Execute second keyboard macro in macro ring."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive "P")
|
|
|
|
(unless (kmacro-ring-empty-p)
|
2003-08-17 22:04:44 +00:00
|
|
|
(kmacro-exec-ring-item (car kmacro-ring) arg)))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(defun kmacro-call-ring-2nd-repeat (arg)
|
2007-01-14 03:22:45 +00:00
|
|
|
"Execute second keyboard macro in macro ring.
|
2003-08-17 22:04:44 +00:00
|
|
|
This is like `kmacro-call-ring-2nd', but allows repeating macro commands
|
|
|
|
without repeating the prefix."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive "P")
|
2002-08-29 13:06:26 +00:00
|
|
|
(let ((keys (kmacro-get-repeat-prefix)))
|
|
|
|
(kmacro-call-ring-2nd arg)
|
|
|
|
(if (and kmacro-ring keys)
|
|
|
|
(kmacro-repeat-on-last-key keys))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(put 'kmacro-call-ring-2nd-repeat 'kmacro-repeat 'head)
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
(defun kmacro-view-ring-2nd ()
|
2021-05-30 06:10:15 +00:00
|
|
|
"Display the second macro in the keyboard macro ring."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive)
|
|
|
|
(unless (kmacro-ring-empty-p)
|
2016-04-29 13:23:38 +00:00
|
|
|
(kmacro-display (car (car kmacro-ring)) nil "2nd macro")))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
2011-04-19 13:44:55 +00:00
|
|
|
(defun kmacro-cycle-ring-next (&optional _arg)
|
2002-08-19 23:05:29 +00:00
|
|
|
"Move to next keyboard macro in keyboard macro ring.
|
2014-02-10 06:51:32 +00:00
|
|
|
Displays the selected macro in the echo area.
|
|
|
|
The ARG parameter is unused."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive)
|
|
|
|
(unless (kmacro-ring-empty-p)
|
|
|
|
(kmacro-push-ring)
|
2002-08-29 13:06:26 +00:00
|
|
|
(let* ((keys (kmacro-get-repeat-prefix))
|
|
|
|
(len (length kmacro-ring))
|
2002-08-19 23:05:29 +00:00
|
|
|
(tail (nthcdr (- len 2) kmacro-ring))
|
|
|
|
(elt (car (cdr tail))))
|
|
|
|
(setcdr tail nil)
|
2002-08-29 13:06:26 +00:00
|
|
|
(kmacro-split-ring-element elt)
|
|
|
|
(kmacro-display last-kbd-macro t)
|
|
|
|
(if keys
|
|
|
|
(kmacro-repeat-on-last-key keys)))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(put 'kmacro-cycle-ring-next 'kmacro-repeat 'ring)
|
|
|
|
|
|
|
|
|
2011-04-19 13:44:55 +00:00
|
|
|
(defun kmacro-cycle-ring-previous (&optional _arg)
|
2002-08-19 23:05:29 +00:00
|
|
|
"Move to previous keyboard macro in keyboard macro ring.
|
2014-02-10 06:51:32 +00:00
|
|
|
Displays the selected macro in the echo area.
|
|
|
|
The ARG parameter is unused."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive)
|
|
|
|
(unless (kmacro-ring-empty-p)
|
2002-08-29 13:06:26 +00:00
|
|
|
(let ((keys (kmacro-get-repeat-prefix))
|
|
|
|
(cur (kmacro-ring-head)))
|
2002-08-19 23:05:29 +00:00
|
|
|
(kmacro-pop-ring1)
|
|
|
|
(if kmacro-ring
|
|
|
|
(nconc kmacro-ring (list cur))
|
2002-08-29 13:06:26 +00:00
|
|
|
(setq kmacro-ring (list cur)))
|
|
|
|
(kmacro-display last-kbd-macro t)
|
|
|
|
(if keys
|
|
|
|
(kmacro-repeat-on-last-key keys)))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(put 'kmacro-cycle-ring-previous 'kmacro-repeat 'ring)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
(defun kmacro-swap-ring ()
|
|
|
|
"Swap first two elements on keyboard macro ring."
|
|
|
|
(interactive)
|
|
|
|
(unless (kmacro-ring-empty-p)
|
|
|
|
(let ((cur (kmacro-ring-head)))
|
|
|
|
(kmacro-pop-ring1)
|
|
|
|
(kmacro-push-ring cur))
|
|
|
|
(kmacro-display last-kbd-macro t)))
|
|
|
|
|
|
|
|
|
2011-04-19 13:44:55 +00:00
|
|
|
(defun kmacro-delete-ring-head (&optional _arg)
|
2014-02-10 06:51:32 +00:00
|
|
|
"Delete current macro from keyboard macro ring.
|
|
|
|
The ARG parameter is unused."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive)
|
|
|
|
(unless (kmacro-ring-empty-p t)
|
|
|
|
(if (null kmacro-ring)
|
|
|
|
(setq last-kbd-macro nil)
|
|
|
|
(kmacro-pop-ring))
|
|
|
|
(kmacro-display last-kbd-macro t nil "Keyboard macro ring is now empty.")))
|
|
|
|
|
|
|
|
(put 'kmacro-delete-ring-head 'kmacro-repeat 'head)
|
|
|
|
|
|
|
|
;;; Traditional bindings:
|
|
|
|
|
2003-02-04 12:29:42 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
;;;###autoload
|
2002-06-28 22:37:18 +00:00
|
|
|
(defun kmacro-start-macro (arg)
|
2002-08-19 23:05:29 +00:00
|
|
|
"Record subsequent keyboard input, defining a keyboard macro.
|
|
|
|
The commands are recorded even as they are executed.
|
2002-08-27 15:06:13 +00:00
|
|
|
Use \\[kmacro-end-macro] to finish recording and make the macro available.
|
2002-09-13 07:18:27 +00:00
|
|
|
Use \\[kmacro-end-and-call-macro] to execute the macro.
|
2004-09-09 20:48:12 +00:00
|
|
|
|
|
|
|
Non-nil arg (prefix arg) means append to last macro defined.
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
With \\[universal-argument] prefix, append to last keyboard macro
|
|
|
|
defined. Depending on `kmacro-execute-before-append', this may begin
|
|
|
|
by re-executing the last macro as if you typed it again.
|
|
|
|
|
|
|
|
Otherwise, it sets `kmacro-counter' to ARG or 0 if missing before
|
|
|
|
defining the macro.
|
|
|
|
|
|
|
|
Use \\[kmacro-insert-counter] to insert (and increment) the macro counter.
|
|
|
|
The counter value can be set or modified via \\[kmacro-set-counter] and \\[kmacro-add-counter].
|
2004-09-09 20:48:12 +00:00
|
|
|
The format of the counter can be modified via \\[kmacro-set-format].
|
|
|
|
|
2017-07-22 08:24:05 +00:00
|
|
|
Use \\[kmacro-name-last-macro] to give it a name that will remain valid even
|
|
|
|
after another macro is defined.
|
2004-09-09 20:48:12 +00:00
|
|
|
Use \\[kmacro-bind-to-key] to bind it to a key sequence."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive "P")
|
|
|
|
(if (or defining-kbd-macro executing-kbd-macro)
|
|
|
|
(message "Already defining keyboard macro.")
|
|
|
|
(let ((append (and arg (listp arg))))
|
|
|
|
(unless append
|
|
|
|
(if last-kbd-macro
|
2006-05-05 23:37:37 +00:00
|
|
|
(kmacro-push-ring
|
|
|
|
(list last-kbd-macro kmacro-counter kmacro-counter-format-start)))
|
2003-08-17 22:04:44 +00:00
|
|
|
(setq kmacro-counter (or (if arg (prefix-numeric-value arg))
|
|
|
|
kmacro-initial-counter-value
|
|
|
|
0)
|
|
|
|
kmacro-initial-counter-value nil
|
2002-08-19 23:05:29 +00:00
|
|
|
kmacro-counter-value-start kmacro-counter
|
|
|
|
kmacro-last-counter kmacro-counter
|
2004-12-02 00:17:54 +00:00
|
|
|
kmacro-counter-format kmacro-default-counter-format
|
|
|
|
kmacro-counter-format-start kmacro-default-counter-format))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2003-02-04 12:29:42 +00:00
|
|
|
(start-kbd-macro append
|
2002-08-19 23:05:29 +00:00
|
|
|
(and append
|
|
|
|
(if kmacro-execute-before-append
|
|
|
|
(> (car arg) 4)
|
2004-11-01 23:06:32 +00:00
|
|
|
(= (car arg) 4))))
|
|
|
|
(if (and defining-kbd-macro append)
|
|
|
|
(setq defining-kbd-macro 'append)))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun kmacro-end-macro (arg)
|
|
|
|
"Finish defining a keyboard macro.
|
|
|
|
The definition was started by \\[kmacro-start-macro].
|
|
|
|
The macro is now available for use via \\[kmacro-call-macro],
|
2004-09-09 20:48:12 +00:00
|
|
|
or it can be given a name with \\[kmacro-name-last-macro] and then invoked
|
2002-08-19 23:05:29 +00:00
|
|
|
under that name.
|
|
|
|
|
|
|
|
With numeric arg, repeat macro now that many times,
|
|
|
|
counting the definition just completed as the first repetition.
|
|
|
|
An argument of zero means repeat until error."
|
|
|
|
(interactive "P")
|
2005-03-30 10:25:10 +00:00
|
|
|
;; Isearch may push the kmacro-end-macro key sequence onto the macro.
|
|
|
|
;; Just ignore it when executing the macro.
|
|
|
|
(unless executing-kbd-macro
|
|
|
|
(end-kbd-macro arg #'kmacro-loop-setup-function)
|
|
|
|
(when (and last-kbd-macro (= (length last-kbd-macro) 0))
|
2007-07-18 08:46:42 +00:00
|
|
|
(setq last-kbd-macro nil)
|
2005-03-30 10:25:10 +00:00
|
|
|
(message "Ignore empty macro")
|
2007-07-18 08:46:42 +00:00
|
|
|
;; Don't call `kmacro-ring-empty-p' to avoid its messages.
|
|
|
|
(while (and (null last-kbd-macro) kmacro-ring)
|
|
|
|
(kmacro-pop-ring1)))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2013-03-30 13:49:00 +00:00
|
|
|
(defun kmacro-call-macro (arg &optional no-repeat end-macro macro)
|
|
|
|
"Call the keyboard MACRO that you defined with \\[kmacro-start-macro].
|
2002-08-19 23:05:29 +00:00
|
|
|
A prefix argument serves as a repeat count. Zero means repeat until error.
|
2013-03-30 13:49:00 +00:00
|
|
|
MACRO defaults to `last-kbd-macro'.
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
When you call the macro, you can call the macro again by repeating
|
|
|
|
just the last key in the key sequence that you used to call this
|
|
|
|
command. See `kmacro-call-repeat-key' and `kmacro-call-repeat-with-arg'
|
2005-06-10 14:04:52 +00:00
|
|
|
for details on how to adjust or disable this behavior.
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2017-07-22 08:24:05 +00:00
|
|
|
To give a macro a name so you can call it even after defining others,
|
|
|
|
use \\[kmacro-name-last-macro]."
|
2002-08-29 13:06:26 +00:00
|
|
|
(interactive "p")
|
2012-05-05 02:50:20 +00:00
|
|
|
(let ((repeat-key (and (or (and (null no-repeat)
|
|
|
|
(> (length (this-single-command-keys)) 1))
|
|
|
|
;; Used when we're in the process of repeating.
|
|
|
|
(eq no-repeat 'repeating))
|
2013-04-05 08:38:06 +00:00
|
|
|
last-input-event)))
|
2002-08-29 13:06:26 +00:00
|
|
|
(if end-macro
|
2013-04-05 08:38:06 +00:00
|
|
|
(kmacro-end-macro arg) ; modifies last-kbd-macro
|
|
|
|
(let ((last-kbd-macro (or macro last-kbd-macro)))
|
|
|
|
(call-last-kbd-macro arg #'kmacro-loop-setup-function)))
|
2002-09-10 01:23:22 +00:00
|
|
|
(when (consp arg)
|
|
|
|
(setq arg (car arg)))
|
2002-08-29 13:06:26 +00:00
|
|
|
(when (and (or (null arg) (> arg 0))
|
|
|
|
(setq repeat-key
|
2002-09-10 01:23:22 +00:00
|
|
|
(if (eq kmacro-call-repeat-key t)
|
|
|
|
repeat-key
|
|
|
|
kmacro-call-repeat-key)))
|
2012-07-06 21:34:49 +00:00
|
|
|
;; Issue a hint to the user, if the echo area isn't in use.
|
|
|
|
(unless (current-message)
|
|
|
|
(message "(Type %s to repeat macro%s)"
|
|
|
|
(format-kbd-macro (vector repeat-key) nil)
|
|
|
|
(if (and kmacro-call-repeat-with-arg
|
|
|
|
arg (> arg 1))
|
|
|
|
(format " %d times" arg) "")))
|
2013-12-23 03:59:10 +00:00
|
|
|
;; Can't use the `keep-pred' arg because this overlay keymap
|
|
|
|
;; needs to be removed during the next run of the kmacro
|
|
|
|
;; (i.e. we must add and remove this map at each repetition).
|
|
|
|
(set-transient-map
|
2012-05-05 02:50:20 +00:00
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (vector repeat-key)
|
2021-05-18 02:16:42 +00:00
|
|
|
(let ((ra (and kmacro-call-repeat-with-arg arg))
|
|
|
|
(m (if end-macro
|
|
|
|
last-kbd-macro
|
|
|
|
(or macro last-kbd-macro))))
|
|
|
|
(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(kmacro-call-macro ra 'repeating nil m))))
|
2012-05-05 02:50:20 +00:00
|
|
|
map)))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Combined function key bindings:
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun kmacro-start-macro-or-insert-counter (arg)
|
2002-08-29 13:06:26 +00:00
|
|
|
"Record subsequent keyboard input, defining a keyboard macro.
|
|
|
|
The commands are recorded even as they are executed.
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2018-05-11 09:11:14 +00:00
|
|
|
Initializes the macro's `kmacro-counter' to ARG (or 0 if no prefix arg)
|
|
|
|
before defining the macro.
|
2002-08-29 13:06:26 +00:00
|
|
|
|
|
|
|
With \\[universal-argument], appends to current keyboard macro (keeping
|
|
|
|
the current value of `kmacro-counter').
|
|
|
|
|
2018-05-11 09:11:14 +00:00
|
|
|
When used during defining/executing a macro, inserts the current value
|
|
|
|
of `kmacro-counter' and increments the counter value by ARG (or by 1 if no
|
2019-02-01 15:34:23 +00:00
|
|
|
prefix argument). With just \\[universal-argument], inserts the previous
|
|
|
|
value of `kmacro-counter', and does not modify the counter; this is
|
|
|
|
different from incrementing the counter by zero. (The previous value
|
|
|
|
of the counter is the one it had before the last increment.)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2018-05-11 09:11:14 +00:00
|
|
|
The macro counter can be set directly via \\[kmacro-set-counter] and \\[kmacro-add-counter].
|
|
|
|
The format of the inserted value of the counter can be controlled
|
|
|
|
via \\[kmacro-set-format]."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive "P")
|
2002-06-28 22:37:18 +00:00
|
|
|
(if (or defining-kbd-macro executing-kbd-macro)
|
2002-08-19 23:05:29 +00:00
|
|
|
(kmacro-insert-counter arg)
|
|
|
|
(kmacro-start-macro arg)))
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
2002-08-29 13:06:26 +00:00
|
|
|
(defun kmacro-end-or-call-macro (arg &optional no-repeat)
|
2002-06-28 22:37:18 +00:00
|
|
|
"End kbd macro if currently being defined; else call last kbd macro.
|
2002-06-29 20:43:59 +00:00
|
|
|
With numeric prefix ARG, repeat macro that many times.
|
2002-08-19 23:05:29 +00:00
|
|
|
With \\[universal-argument], call second macro in macro ring."
|
|
|
|
(interactive "P")
|
2003-02-04 12:29:42 +00:00
|
|
|
(cond
|
2002-06-28 22:37:18 +00:00
|
|
|
(defining-kbd-macro
|
2002-08-29 13:06:26 +00:00
|
|
|
(if kmacro-call-repeat-key
|
|
|
|
(kmacro-call-macro arg no-repeat t)
|
|
|
|
(kmacro-end-macro arg)))
|
2003-08-17 22:04:44 +00:00
|
|
|
((and (eq this-command 'kmacro-view-macro) ;; We are in repeat mode!
|
|
|
|
kmacro-view-last-item)
|
|
|
|
(kmacro-exec-ring-item (car kmacro-view-last-item) arg))
|
2002-08-19 23:05:29 +00:00
|
|
|
((and arg (listp arg))
|
|
|
|
(kmacro-call-ring-2nd 1))
|
2002-06-28 22:37:18 +00:00
|
|
|
(t
|
2002-08-29 13:06:26 +00:00
|
|
|
(kmacro-call-macro arg no-repeat))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(defun kmacro-end-or-call-macro-repeat (arg)
|
|
|
|
"As `kmacro-end-or-call-macro' but allows repeat without repeating prefix."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive "P")
|
2002-08-29 13:06:26 +00:00
|
|
|
(let ((keys (kmacro-get-repeat-prefix)))
|
|
|
|
(kmacro-end-or-call-macro arg t)
|
|
|
|
(if keys
|
|
|
|
(kmacro-repeat-on-last-key keys))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(put 'kmacro-end-or-call-macro-repeat 'kmacro-repeat 'head)
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
|
2002-09-08 20:38:04 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun kmacro-end-and-call-macro (arg &optional no-repeat)
|
|
|
|
"Call last keyboard macro, ending it first if currently being defined.
|
2003-04-03 23:01:45 +00:00
|
|
|
With numeric prefix ARG, repeat macro that many times.
|
|
|
|
Zero argument means repeat until there is an error.
|
|
|
|
|
2017-07-22 08:24:05 +00:00
|
|
|
To give a macro a name, so you can call it even after defining other
|
|
|
|
macros, use \\[kmacro-name-last-macro]."
|
2002-09-08 20:38:04 +00:00
|
|
|
(interactive "P")
|
|
|
|
(if defining-kbd-macro
|
|
|
|
(kmacro-end-macro nil))
|
|
|
|
(kmacro-call-macro arg no-repeat))
|
|
|
|
|
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
;;;###autoload
|
2002-06-28 22:37:18 +00:00
|
|
|
(defun kmacro-end-call-mouse (event)
|
|
|
|
"Move point to the position clicked with the mouse and call last kbd macro.
|
|
|
|
If kbd macro currently being defined end it before activating it."
|
|
|
|
(interactive "e")
|
|
|
|
(when defining-kbd-macro
|
2017-12-18 18:08:59 +00:00
|
|
|
(end-kbd-macro)
|
|
|
|
(when (and last-kbd-macro (= (length last-kbd-macro) 0))
|
|
|
|
(setq last-kbd-macro nil)
|
|
|
|
(message "Ignore empty macro")
|
|
|
|
;; Don't call `kmacro-ring-empty-p' to avoid its messages.
|
|
|
|
(while (and (null last-kbd-macro) kmacro-ring)
|
|
|
|
(kmacro-pop-ring1))))
|
2002-06-28 22:37:18 +00:00
|
|
|
(mouse-set-point event)
|
2002-08-29 13:06:26 +00:00
|
|
|
(kmacro-call-macro nil t))
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
;;; Misc. commands
|
|
|
|
|
2003-08-17 22:04:44 +00:00
|
|
|
;; An idea for macro bindings:
|
|
|
|
;; Create a separate keymap installed as a minor-mode keymap (e.g. in
|
|
|
|
;; the emulation-mode-map-alists) in which macro bindings are made
|
|
|
|
;; independent of any other bindings. When first binding is made,
|
2011-12-04 08:02:42 +00:00
|
|
|
;; the keymap is created, installed, and enabled. Key seq. C-x C-k +
|
2003-08-17 22:04:44 +00:00
|
|
|
;; can then be used to toggle the use of this keymap on and off.
|
|
|
|
;; This means that it would be safe(r) to bind ordinary keys like
|
|
|
|
;; letters and digits, provided that we inhibit the keymap while
|
|
|
|
;; executing the macro later on (but that's controversial...)
|
|
|
|
|
2019-05-05 17:24:15 +00:00
|
|
|
;;;###autoload
|
2021-05-19 15:19:10 +00:00
|
|
|
(defun kmacro-lambda-form (mac &optional counter format)
|
2004-09-30 13:27:45 +00:00
|
|
|
"Create lambda form for macro bound to symbol or key."
|
2021-05-19 15:19:10 +00:00
|
|
|
;; Apparently, there are two different ways this is called:
|
|
|
|
;; either `counter' and `format' are both provided and `mac' is a vector,
|
|
|
|
;; or only `mac' is provided, as a list (MAC COUNTER FORMAT).
|
|
|
|
;; The first is used from `insert-kbd-macro' and `edmacro-finish-edit',
|
|
|
|
;; while the second is used from within this file.
|
|
|
|
(let ((mac (if counter (list mac counter format) mac)))
|
|
|
|
;; FIXME: This should be a "funcallable struct"!
|
|
|
|
(lambda (&optional arg)
|
|
|
|
"Keyboard macro."
|
|
|
|
;; We put an "unused prompt" as a special marker so
|
|
|
|
;; `kmacro-extract-lambda' can see it's "one of us".
|
|
|
|
(interactive "pkmacro")
|
|
|
|
(if (eq arg 'kmacro--extract-lambda)
|
|
|
|
(cons 'kmacro--extract-lambda mac)
|
|
|
|
(kmacro-exec-ring-item mac arg)))))
|
2004-09-30 13:27:45 +00:00
|
|
|
|
|
|
|
(defun kmacro-extract-lambda (mac)
|
|
|
|
"Extract kmacro from a kmacro lambda form."
|
2021-05-18 14:37:57 +00:00
|
|
|
(let ((mac (cond
|
|
|
|
((eq (car-safe mac) 'lambda)
|
|
|
|
(let ((e (assoc 'kmacro-exec-ring-item mac)))
|
|
|
|
(car-safe (cdr-safe (car-safe (cdr-safe e))))))
|
|
|
|
((and (functionp mac)
|
|
|
|
(equal (interactive-form mac) '(interactive "pkmacro")))
|
|
|
|
(let ((r (funcall mac 'kmacro--extract-lambda)))
|
|
|
|
(and (eq (car-safe r) 'kmacro--extract-lambda) (cdr r)))))))
|
|
|
|
(and (consp mac)
|
|
|
|
(= (length mac) 3)
|
|
|
|
(arrayp (car mac))
|
|
|
|
mac)))
|
2004-09-30 13:27:45 +00:00
|
|
|
|
2017-11-24 16:32:14 +00:00
|
|
|
(defalias 'kmacro-p #'kmacro-extract-lambda
|
|
|
|
"Return non-nil if MAC is a kmacro keyboard macro.")
|
|
|
|
|
2011-04-19 13:44:55 +00:00
|
|
|
(defun kmacro-bind-to-key (_arg)
|
2003-08-17 22:04:44 +00:00
|
|
|
"When not defining or executing a macro, offer to bind last macro to a key.
|
|
|
|
The key sequences [C-x C-k 0] through [C-x C-k 9] and [C-x C-k A]
|
|
|
|
through [C-x C-k Z] are reserved for user bindings, and to bind to
|
|
|
|
one of these sequences, just enter the digit or letter, rather than
|
|
|
|
the whole sequence.
|
|
|
|
|
|
|
|
You can bind to any valid key sequence, but if you try to bind to
|
|
|
|
a key with an existing command binding, you will be asked for
|
|
|
|
confirmation whether to replace that binding. Note that the
|
|
|
|
binding is made in the `global-map' keymap, so the macro binding
|
2014-02-10 06:51:32 +00:00
|
|
|
may be shaded by a local key binding.
|
|
|
|
The ARG parameter is unused."
|
2002-06-28 22:37:18 +00:00
|
|
|
(interactive "p")
|
|
|
|
(if (or defining-kbd-macro executing-kbd-macro)
|
2002-08-19 23:05:29 +00:00
|
|
|
(if defining-kbd-macro
|
|
|
|
(message "Cannot save macro while defining it."))
|
|
|
|
(unless last-kbd-macro
|
|
|
|
(error "No keyboard macro defined"))
|
2003-08-17 22:04:44 +00:00
|
|
|
(let ((key-seq (read-key-sequence "Bind last macro to key: "))
|
|
|
|
ok cmd)
|
|
|
|
(when (= (length key-seq) 1)
|
|
|
|
(let ((ch (aref key-seq 0)))
|
2007-07-15 18:45:59 +00:00
|
|
|
(if (and (integerp ch)
|
|
|
|
(or (and (>= ch ?0) (<= ch ?9))
|
|
|
|
(and (>= ch ?A) (<= ch ?Z))))
|
2003-08-17 22:04:44 +00:00
|
|
|
(setq key-seq (concat "\C-x\C-k" key-seq)
|
|
|
|
ok t))))
|
2018-03-30 00:41:11 +00:00
|
|
|
(when (and (not (equal key-seq "\^G"))
|
2003-08-17 22:04:44 +00:00
|
|
|
(or ok
|
|
|
|
(not (setq cmd (key-binding key-seq)))
|
|
|
|
(stringp cmd)
|
|
|
|
(vectorp cmd)
|
|
|
|
(yes-or-no-p (format "%s runs command %S. Bind anyway? "
|
|
|
|
(format-kbd-macro key-seq)
|
|
|
|
cmd))))
|
2004-09-09 20:48:12 +00:00
|
|
|
(define-key global-map key-seq
|
2004-09-30 13:27:45 +00:00
|
|
|
(kmacro-lambda-form (kmacro-ring-head)))
|
2003-08-17 22:04:44 +00:00
|
|
|
(message "Keyboard macro bound to %s" (format-kbd-macro key-seq))))))
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2017-11-24 16:32:14 +00:00
|
|
|
(defun kmacro-keyboard-macro-p (symbol)
|
|
|
|
"Return non-nil if SYMBOL is the name of some sort of keyboard macro."
|
|
|
|
(let ((f (symbol-function symbol)))
|
|
|
|
(when f
|
|
|
|
(or (stringp f)
|
|
|
|
(vectorp f)
|
|
|
|
(kmacro-p f)))))
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2004-09-09 20:48:12 +00:00
|
|
|
(defun kmacro-name-last-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
|
|
|
|
(error "No keyboard macro defined"))
|
|
|
|
(and (fboundp symbol)
|
2017-11-24 16:32:14 +00:00
|
|
|
(not (kmacro-keyboard-macro-p symbol))
|
2004-09-09 20:48:12 +00:00
|
|
|
(error "Function %s is already defined and not a keyboard macro"
|
|
|
|
symbol))
|
|
|
|
(if (string-equal symbol "")
|
|
|
|
(error "No command name given"))
|
2017-11-24 16:32:14 +00:00
|
|
|
;; FIXME: Use plain old `last-kbd-macro' for kmacros where it doesn't
|
|
|
|
;; make a difference?
|
2004-09-30 13:27:45 +00:00
|
|
|
(fset symbol (kmacro-lambda-form (kmacro-ring-head)))
|
2017-11-24 16:32:14 +00:00
|
|
|
;; This used to be used to detect when a symbol corresponds to a kmacro.
|
|
|
|
;; Nowadays it's unused because we used `kmacro-p' instead to see if the
|
|
|
|
;; symbol's function definition matches that of a kmacro, which is more
|
|
|
|
;; reliable.
|
2004-09-09 20:48:12 +00:00
|
|
|
(put symbol 'kmacro t))
|
|
|
|
|
|
|
|
|
2019-06-12 16:21:35 +00:00
|
|
|
(cl-defstruct (kmacro-register
|
|
|
|
(:constructor nil)
|
|
|
|
(:constructor kmacro-make-register (macro)))
|
|
|
|
macro)
|
|
|
|
|
|
|
|
(cl-defmethod register-val-jump-to ((data kmacro-register) _arg)
|
|
|
|
(kmacro-call-macro current-prefix-arg nil nil (kmacro-register-macro data)))
|
|
|
|
|
|
|
|
(cl-defmethod register-val-describe ((data kmacro-register) _verbose)
|
|
|
|
(princ (format "a keyboard macro:\n %s"
|
|
|
|
(format-kbd-macro (kmacro-register-macro data)))))
|
|
|
|
|
|
|
|
(cl-defmethod register-val-insert ((data kmacro-register))
|
|
|
|
(insert (format-kbd-macro (kmacro-register-macro data))))
|
2013-03-29 14:53:27 +00:00
|
|
|
|
|
|
|
(defun kmacro-to-register (r)
|
2014-02-03 00:40:49 +00:00
|
|
|
"Store the last keyboard macro in register R.
|
|
|
|
|
|
|
|
Interactively, reads the register using `register-read-with-preview'."
|
2013-03-29 14:53:27 +00:00
|
|
|
(interactive
|
|
|
|
(progn
|
|
|
|
(or last-kbd-macro (error "No keyboard macro defined"))
|
2014-02-03 00:40:49 +00:00
|
|
|
(list (register-read-with-preview "Save to register: "))))
|
2019-06-12 16:21:35 +00:00
|
|
|
(set-register r (kmacro-make-register last-kbd-macro)))
|
2013-03-29 14:53:27 +00:00
|
|
|
|
|
|
|
|
2011-04-19 13:44:55 +00:00
|
|
|
(defun kmacro-view-macro (&optional _arg)
|
2003-08-17 22:04:44 +00:00
|
|
|
"Display the last keyboard macro.
|
2014-02-10 06:51:32 +00:00
|
|
|
If repeated, it shows previous elements in the macro ring.
|
|
|
|
The ARG parameter is unused."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive)
|
2003-08-17 22:04:44 +00:00
|
|
|
(cond
|
|
|
|
((or (kmacro-ring-empty-p)
|
|
|
|
(not (eq last-command 'kmacro-view-macro)))
|
|
|
|
(setq kmacro-view-last-item nil))
|
|
|
|
((null kmacro-view-last-item)
|
|
|
|
(setq kmacro-view-last-item kmacro-ring
|
|
|
|
kmacro-view-item-no 2))
|
|
|
|
((consp kmacro-view-last-item)
|
|
|
|
(setq kmacro-view-last-item (cdr kmacro-view-last-item)
|
|
|
|
kmacro-view-item-no (1+ kmacro-view-item-no)))
|
|
|
|
(t
|
|
|
|
(setq kmacro-view-last-item nil)))
|
|
|
|
(setq this-command 'kmacro-view-macro
|
|
|
|
last-command this-command) ;; in case we repeat
|
|
|
|
(kmacro-display (if kmacro-view-last-item
|
|
|
|
(car (car kmacro-view-last-item))
|
|
|
|
last-kbd-macro)
|
|
|
|
nil
|
|
|
|
(if kmacro-view-last-item
|
|
|
|
(concat (cond ((= kmacro-view-item-no 2) "2nd")
|
2020-09-21 11:29:10 +00:00
|
|
|
((= kmacro-view-item-no 3) "3rd")
|
2003-08-17 22:04:44 +00:00
|
|
|
(t (format "%dth" kmacro-view-item-no)))
|
|
|
|
" previous macro")
|
|
|
|
"Last macro")))
|
2002-06-28 22:37:18 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(defun kmacro-view-macro-repeat (&optional arg)
|
2003-08-17 22:04:44 +00:00
|
|
|
"Display the last keyboard macro.
|
|
|
|
If repeated, it shows previous elements in the macro ring.
|
|
|
|
To execute the displayed macro ring item without changing the macro ring,
|
|
|
|
just enter C-k.
|
|
|
|
This is like `kmacro-view-macro', but allows repeating macro commands
|
|
|
|
without repeating the prefix."
|
2002-06-28 22:37:18 +00:00
|
|
|
(interactive)
|
2002-08-29 13:06:26 +00:00
|
|
|
(let ((keys (kmacro-get-repeat-prefix)))
|
|
|
|
(kmacro-view-macro arg)
|
|
|
|
(if (and last-kbd-macro keys)
|
|
|
|
(kmacro-repeat-on-last-key keys))))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2003-08-17 22:04:44 +00:00
|
|
|
(put 'kmacro-view-macro-repeat 'kmacro-repeat 'ring)
|
2002-08-19 23:05:29 +00:00
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
|
|
|
|
(defun kmacro-edit-macro-repeat (&optional arg)
|
2002-08-19 23:05:29 +00:00
|
|
|
"Edit last keyboard macro."
|
|
|
|
(interactive "P")
|
|
|
|
(edit-kbd-macro "\r" arg))
|
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(put 'kmacro-edit-macro-repeat 'kmacro-repeat 'stop)
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
2002-08-29 13:06:26 +00:00
|
|
|
(defun kmacro-edit-macro (&optional arg)
|
2002-08-19 23:05:29 +00:00
|
|
|
"As edit last keyboard macro, but without kmacro-repeat property."
|
|
|
|
(interactive "P")
|
2002-08-29 13:06:26 +00:00
|
|
|
(edit-kbd-macro "\r" arg))
|
2002-08-19 23:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-edit-lossage ()
|
2008-10-11 18:43:38 +00:00
|
|
|
"Edit most recent 300 keystrokes as a keyboard macro."
|
2002-08-19 23:05:29 +00:00
|
|
|
(interactive)
|
|
|
|
(kmacro-push-ring)
|
2021-05-05 12:59:49 +00:00
|
|
|
(edit-kbd-macro (car (where-is-internal 'view-lossage))))
|
2002-06-28 22:37:18 +00:00
|
|
|
|
|
|
|
|
2002-09-08 20:38:04 +00:00
|
|
|
;;; Single-step editing of keyboard macros
|
|
|
|
|
2017-10-16 16:36:06 +00:00
|
|
|
(defvar kmacro-step-edit-active nil) ;; step-editing active
|
2002-09-08 20:38:04 +00:00
|
|
|
(defvar kmacro-step-edit-new-macro) ;; storage for new macro
|
|
|
|
(defvar kmacro-step-edit-inserting) ;; inserting into macro
|
|
|
|
(defvar kmacro-step-edit-appending) ;; append to end of macro
|
|
|
|
(defvar kmacro-step-edit-replace) ;; replace orig macro when done
|
|
|
|
(defvar kmacro-step-edit-key-index) ;; index of current key
|
|
|
|
(defvar kmacro-step-edit-action) ;; automatic action on next pre-command hook
|
|
|
|
(defvar kmacro-step-edit-help) ;; kmacro step edit help enabled
|
|
|
|
(defvar kmacro-step-edit-num-input-keys) ;; to ignore duplicate pre-command hook
|
|
|
|
|
Move keymap initialization into declaration.
* lisp/textmodes/enriched.el (enriched-mode-map):
* lisp/textmodes/bib-mode.el (bib-mode-map):
* lisp/term/lk201.el (lk201-function-map):
* lisp/tar-mode.el (tar-mode-map):
* lisp/replace.el (occur-mode-map):
* lisp/progmodes/idlwave.el (idlwave-rinfo-mouse-map, idlwave-rinfo-map):
* lisp/progmodes/idlw-help.el (idlwave-help-mode-map):
* lisp/progmodes/gdb-mi.el (gdb-memory-format-menu, gdb-memory-unit-menu):
* lisp/play/solitaire.el (solitaire-mode-map):
* lisp/play/snake.el (snake-mode-map, snake-null-map):
* lisp/play/pong.el (pong-mode-map):
* lisp/play/handwrite.el (menu-bar-handwrite-map):
* lisp/play/gametree.el (gametree-mode-map):
* lisp/net/rcirc.el (rcirc-mode-map, rcirc-browse-url-map
(rcirc-multiline-minor-mode-map, rcirc-track-minor-mode-map):
* lisp/net/newst-plainview.el (newsticker-menu, newsticker-mode-map)
(newsticker--url-keymap):
* lisp/net/net-utils.el (nslookup-mode-map, ftp-mode-map):
* lisp/menu-bar.el (menu-bar-file-menu, menu-bar-i-search-menu)
(menu-bar-search-menu, menu-bar-replace-menu, menu-bar-goto-menu)
(menu-bar-edit-menu, menu-bar-custom-menu)
(menu-bar-showhide-fringe-ind-menu, menu-bar-showhide-fringe-menu)
(menu-bar-showhide-scroll-bar-menu, menu-bar-showhide-menu)
(menu-bar-line-wrapping-menu, menu-bar-options-menu)
(menu-bar-games-menu, menu-bar-encryption-decryption-menu)
(menu-bar-tools-menu, menu-bar-describe-menu)
(menu-bar-search-documentation-menu, menu-bar-manuals-menu)
(menu-bar-help-menu):
* lisp/mail/rmailsum.el (rmail-summary-mode-map):
* lisp/kmacro.el (kmacro-step-edit-map):
* lisp/ibuffer.el (ibuffer-mode-groups-popup, ibuffer-mode-map)
(ibuffer-mode-operate-map):
* lisp/hi-lock.el (hi-lock-menu, hi-lock-map):
* lisp/emulation/vip.el (vip-mode-map):
* lisp/emacs-lisp/re-builder.el (reb-lisp-mode-map):
* lisp/bookmark.el (bookmark-bmenu-mode-map):
* lisp/help-mode.el (help-mode-map):
* lisp/erc/erc-list.el (erc-list-menu-mode-map):
* lisp/org/org-remember.el (org-remember-mode-map):
* lisp/org/org-src.el (org-src-mode-map): Move initialization into declaration.
2011-02-10 16:56:00 +00:00
|
|
|
(defvar kmacro-step-edit-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
;; query-replace-map answers include: `act', `skip', `act-and-show',
|
|
|
|
;; `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
|
|
|
|
;; `automatic', `backup', `exit-prefix', and `help'.")
|
|
|
|
;; Also: `quit', `edit-replacement'
|
|
|
|
|
|
|
|
(set-keymap-parent map query-replace-map)
|
|
|
|
|
|
|
|
(define-key map "\t" 'act-repeat)
|
|
|
|
(define-key map [tab] 'act-repeat)
|
|
|
|
(define-key map "\C-k" 'skip-rest)
|
|
|
|
(define-key map "c" 'automatic)
|
|
|
|
(define-key map "f" 'skip-keep)
|
|
|
|
(define-key map "q" 'quit)
|
|
|
|
(define-key map "d" 'skip)
|
|
|
|
(define-key map "\C-d" 'skip)
|
|
|
|
(define-key map "i" 'insert)
|
|
|
|
(define-key map "I" 'insert-1)
|
|
|
|
(define-key map "r" 'replace)
|
|
|
|
(define-key map "R" 'replace-1)
|
|
|
|
(define-key map "a" 'append)
|
|
|
|
(define-key map "A" 'append-end)
|
|
|
|
map)
|
2002-09-08 20:38:04 +00:00
|
|
|
"Keymap that defines the responses to questions in `kmacro-step-edit-macro'.
|
|
|
|
This keymap is an extension to the `query-replace-map', allowing the
|
2002-09-10 22:08:45 +00:00
|
|
|
following additional answers: `insert', `insert-1', `replace', `replace-1',
|
|
|
|
`append', `append-end', `act-repeat', `skip-end', `skip-keep'.")
|
2002-09-08 20:38:04 +00:00
|
|
|
|
|
|
|
(defun kmacro-step-edit-prompt (macro index)
|
|
|
|
;; Show step-edit prompt
|
|
|
|
(let ((keys (and (not kmacro-step-edit-appending)
|
2005-05-02 10:33:33 +00:00
|
|
|
index (substring macro index executing-kbd-macro-index)))
|
2002-09-08 20:38:04 +00:00
|
|
|
(future (and (not kmacro-step-edit-appending)
|
2005-05-02 10:33:33 +00:00
|
|
|
(substring macro executing-kbd-macro-index)))
|
2002-09-08 20:38:04 +00:00
|
|
|
(message-log-max nil)
|
|
|
|
(curmsg (current-message)))
|
|
|
|
|
|
|
|
;; TODO: Scroll macro if max-mini-window-height is too small.
|
2004-09-12 21:39:40 +00:00
|
|
|
(message "%s"
|
|
|
|
(concat
|
2002-09-08 20:38:04 +00:00
|
|
|
(format "Macro: %s%s%s%s%s\n"
|
|
|
|
(format-kbd-macro kmacro-step-edit-new-macro 1)
|
|
|
|
(if (and kmacro-step-edit-new-macro (> (length kmacro-step-edit-new-macro) 0)) " " "")
|
2003-02-04 12:29:42 +00:00
|
|
|
(propertize (if keys (format-kbd-macro keys)
|
2002-09-08 20:38:04 +00:00
|
|
|
(if kmacro-step-edit-appending "<APPEND>" "<INSERT>")) 'face 'region)
|
|
|
|
(if future " " "")
|
|
|
|
(if future (format-kbd-macro future) ""))
|
|
|
|
(cond
|
|
|
|
((minibufferp)
|
|
|
|
(format "%s\n%s\n"
|
|
|
|
(propertize "\
|
|
|
|
minibuffer " 'face 'header-line)
|
|
|
|
(buffer-substring (point-min) (point-max))))
|
|
|
|
(curmsg
|
|
|
|
(format "%s\n%s\n"
|
|
|
|
(propertize "\
|
|
|
|
echo area " 'face 'header-line)
|
|
|
|
curmsg))
|
|
|
|
(t ""))
|
|
|
|
(if keys
|
2003-02-04 12:29:42 +00:00
|
|
|
(format "%s\n%s%s %S [yn iIaArR C-k kq!] "
|
2002-09-08 20:38:04 +00:00
|
|
|
(propertize "\
|
|
|
|
--------------Step Edit Keyboard Macro [?: help]---------------" 'face 'mode-line)
|
|
|
|
(if kmacro-step-edit-help "\
|
|
|
|
Step: y/SPC: execute next, d/n/DEL: skip next, f: skip but keep
|
|
|
|
TAB: execute while same, ?: toggle help
|
2002-09-10 22:19:39 +00:00
|
|
|
Edit: i: insert, r: replace, a: append, A: append at end,
|
|
|
|
I/R: insert/replace with one sequence,
|
2002-09-08 20:38:04 +00:00
|
|
|
End: !/c: execute rest, C-k: skip rest and save, q/C-g: quit
|
|
|
|
----------------------------------------------------------------
|
|
|
|
" "")
|
|
|
|
(propertize "Next command:" 'face 'bold)
|
|
|
|
this-command)
|
2003-02-04 12:29:42 +00:00
|
|
|
(propertize
|
2002-09-08 20:38:04 +00:00
|
|
|
(format "Type key sequence%s to insert and execute%s: "
|
|
|
|
(if (numberp kmacro-step-edit-inserting) "" "s")
|
2002-09-10 22:08:45 +00:00
|
|
|
(if (numberp kmacro-step-edit-inserting) "" " (end with C-j)"))
|
2002-09-08 20:38:04 +00:00
|
|
|
'face 'bold))))))
|
|
|
|
|
|
|
|
(defun kmacro-step-edit-query ()
|
|
|
|
;; Pre-command hook function for step-edit in "command" mode
|
|
|
|
(let ((resize-mini-windows t)
|
|
|
|
(max-mini-window-height kmacro-step-edit-mini-window-height)
|
|
|
|
act restore-index next-index)
|
|
|
|
|
|
|
|
;; Handle commands which reads additional input using read-char.
|
|
|
|
(cond
|
|
|
|
((and (eq this-command 'quoted-insert)
|
|
|
|
(not (eq kmacro-step-edit-action t)))
|
|
|
|
;; Find the actual end of this key sequence.
|
|
|
|
;; Must be able to backtrack in case we actually execute it.
|
2005-05-02 10:33:33 +00:00
|
|
|
(setq restore-index executing-kbd-macro-index)
|
2002-09-08 20:38:04 +00:00
|
|
|
(let (unread-command-events)
|
|
|
|
(quoted-insert 0)
|
|
|
|
(when unread-command-events
|
2005-05-02 10:33:33 +00:00
|
|
|
(setq executing-kbd-macro-index (- executing-kbd-macro-index (length unread-command-events))
|
|
|
|
next-index executing-kbd-macro-index)))))
|
2002-09-08 20:38:04 +00:00
|
|
|
|
2011-11-17 09:09:20 +00:00
|
|
|
;; Query the user; stop macro execution temporarily.
|
2002-09-08 20:38:04 +00:00
|
|
|
(let ((macro executing-kbd-macro)
|
|
|
|
(executing-kbd-macro nil)
|
|
|
|
(defining-kbd-macro nil))
|
|
|
|
|
|
|
|
;; Any action requested by previous command
|
|
|
|
(cond
|
|
|
|
((eq kmacro-step-edit-action t) ;; Reentry for actual command @ end of prefix arg.
|
|
|
|
(cond
|
|
|
|
((eq this-command 'quoted-insert)
|
|
|
|
(clear-this-command-keys) ;; recent-keys actually
|
|
|
|
(let (unread-command-events)
|
|
|
|
(quoted-insert (prefix-numeric-value current-prefix-arg))
|
2003-02-04 12:29:42 +00:00
|
|
|
(setq kmacro-step-edit-new-macro
|
2002-09-08 20:38:04 +00:00
|
|
|
(vconcat kmacro-step-edit-new-macro (recent-keys)))
|
|
|
|
(when unread-command-events
|
|
|
|
(setq kmacro-step-edit-new-macro
|
|
|
|
(substring kmacro-step-edit-new-macro 0 (- (length unread-command-events)))
|
2005-05-02 10:33:33 +00:00
|
|
|
executing-kbd-macro-index (- executing-kbd-macro-index (length unread-command-events)))))
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq current-prefix-arg nil
|
|
|
|
prefix-arg nil)
|
|
|
|
(setq act 'ignore))
|
|
|
|
(t
|
|
|
|
(setq act 'act)))
|
|
|
|
(setq kmacro-step-edit-action nil))
|
|
|
|
((eq this-command kmacro-step-edit-action) ;; TAB -> activate while same command
|
|
|
|
(setq act 'act))
|
|
|
|
(t
|
|
|
|
(setq kmacro-step-edit-action nil)))
|
|
|
|
|
|
|
|
;; Handle prefix arg, or query user
|
|
|
|
(cond
|
|
|
|
(act act) ;; set above
|
|
|
|
(t
|
Generalize the prefix-command machinery of C-u
* lisp/simple.el (prefix-command-echo-keystrokes-functions)
(prefix-command-preserve-state-hook): New hooks.
(internal-echo-keystrokes-prefix): New function.
(prefix-command--needs-update, prefix-command--last-echo): New vars.
(prefix-command-update, prefix-command-preserve): New functions.
(reset-this-command-lengths): New compatibility definition.
(universal-argument--mode): Call prefix-command-update.
(universal-argument, universal-argument-more, negative-argument)
(digit-argument): Call prefix-command-preserve-state.
* src/keyboard.c: Call internal-echo-keystrokes-prefix to build
the "prefix argument" to echo.
(this_command_key_count_reset, before_command_key_count)
(before_command_echo_length): Delete variables.
(echo_add_key): Always add a space.
(echo_char): Remove.
(echo_dash): Don't give up when this_command_key_count is 0, since that
is now the case after a prefix command.
(echo_update): New function, extracted from echo_now.
(echo_now): Use it.
(add_command_key, read_char, record_menu_key): Remove old disabled code.
(command_loop_1): Don't refrain from pushing an undo boundary when
prefix-arg is set. Remove other prefix-arg special case, now handled
directly in the prefix commands instead. But call echo_now if there's
a prefix state to echo.
(read_char, record_menu_key): Use echo_update instead of echo_char.
(read_key_sequence): Use echo_now rather than echo_dash/echo_char.
(Freset_this_command_lengths): Delete function.
(syms_of_keyboard): Define Qinternal_echo_keystrokes_prefix.
(syms_of_keyboard): Don't defsubr Sreset_this_command_lengths.
* lisp/simple.el: Use those new hooks for C-u.
(universal-argument--description): New function.
(prefix-command-echo-keystrokes-functions): Use it.
(universal-argument--preserve): New function.
(prefix-command-preserve-state-hook): Use it.
(command-execute): Call prefix-command-update if needed.
* lisp/kmacro.el (kmacro-step-edit-prefix-commands)
(kmacro-step-edit-prefix-index): Delete variables.
(kmacro-step-edit-query, kmacro-step-edit-insert): Remove ad-hoc
support for prefix arg commands.
(kmacro-step-edit-macro): Don't bind kmacro-step-edit-prefix-index.
* lisp/emulation/cua-base.el (cua--prefix-override-replay)
(cua--shift-control-prefix): Use prefix-command-preserve-state.
Remove now unused arg `arg'.
(cua--prefix-override-handler, cua--prefix-repeat-handler)
(cua--shift-control-c-prefix, cua--shift-control-x-prefix):
Update accordingly.
(cua--prefix-override-timeout): Don't call reset-this-command-lengths
any more.
(cua--keep-active, cua-exchange-point-and-mark): Don't set mark-active
if the mark is not set.
2015-09-02 01:14:18 +00:00
|
|
|
(kmacro-step-edit-prompt macro kmacro-step-edit-key-index)
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq act (lookup-key kmacro-step-edit-map
|
|
|
|
(vector (with-current-buffer (current-buffer) (read-event))))))))
|
|
|
|
|
|
|
|
;; Resume macro execution and perform the action
|
|
|
|
(cond
|
|
|
|
((cond
|
|
|
|
((eq act 'act)
|
|
|
|
t)
|
|
|
|
((eq act 'act-repeat)
|
|
|
|
(setq kmacro-step-edit-action this-command)
|
|
|
|
t)
|
|
|
|
((eq act 'quit)
|
|
|
|
(setq kmacro-step-edit-replace nil)
|
|
|
|
(setq kmacro-step-edit-active 'ignore)
|
|
|
|
nil)
|
|
|
|
((eq act 'skip)
|
|
|
|
nil)
|
|
|
|
((eq act 'skip-keep)
|
|
|
|
(setq this-command 'ignore)
|
|
|
|
t)
|
|
|
|
((eq act 'skip-rest)
|
|
|
|
(setq kmacro-step-edit-active 'ignore)
|
|
|
|
nil)
|
2002-09-20 20:38:18 +00:00
|
|
|
((memq act '(automatic exit))
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq kmacro-step-edit-active nil)
|
|
|
|
(setq act t)
|
|
|
|
t)
|
|
|
|
((member act '(insert-1 insert))
|
Generalize the prefix-command machinery of C-u
* lisp/simple.el (prefix-command-echo-keystrokes-functions)
(prefix-command-preserve-state-hook): New hooks.
(internal-echo-keystrokes-prefix): New function.
(prefix-command--needs-update, prefix-command--last-echo): New vars.
(prefix-command-update, prefix-command-preserve): New functions.
(reset-this-command-lengths): New compatibility definition.
(universal-argument--mode): Call prefix-command-update.
(universal-argument, universal-argument-more, negative-argument)
(digit-argument): Call prefix-command-preserve-state.
* src/keyboard.c: Call internal-echo-keystrokes-prefix to build
the "prefix argument" to echo.
(this_command_key_count_reset, before_command_key_count)
(before_command_echo_length): Delete variables.
(echo_add_key): Always add a space.
(echo_char): Remove.
(echo_dash): Don't give up when this_command_key_count is 0, since that
is now the case after a prefix command.
(echo_update): New function, extracted from echo_now.
(echo_now): Use it.
(add_command_key, read_char, record_menu_key): Remove old disabled code.
(command_loop_1): Don't refrain from pushing an undo boundary when
prefix-arg is set. Remove other prefix-arg special case, now handled
directly in the prefix commands instead. But call echo_now if there's
a prefix state to echo.
(read_char, record_menu_key): Use echo_update instead of echo_char.
(read_key_sequence): Use echo_now rather than echo_dash/echo_char.
(Freset_this_command_lengths): Delete function.
(syms_of_keyboard): Define Qinternal_echo_keystrokes_prefix.
(syms_of_keyboard): Don't defsubr Sreset_this_command_lengths.
* lisp/simple.el: Use those new hooks for C-u.
(universal-argument--description): New function.
(prefix-command-echo-keystrokes-functions): Use it.
(universal-argument--preserve): New function.
(prefix-command-preserve-state-hook): Use it.
(command-execute): Call prefix-command-update if needed.
* lisp/kmacro.el (kmacro-step-edit-prefix-commands)
(kmacro-step-edit-prefix-index): Delete variables.
(kmacro-step-edit-query, kmacro-step-edit-insert): Remove ad-hoc
support for prefix arg commands.
(kmacro-step-edit-macro): Don't bind kmacro-step-edit-prefix-index.
* lisp/emulation/cua-base.el (cua--prefix-override-replay)
(cua--shift-control-prefix): Use prefix-command-preserve-state.
Remove now unused arg `arg'.
(cua--prefix-override-handler, cua--prefix-repeat-handler)
(cua--shift-control-c-prefix, cua--shift-control-x-prefix):
Update accordingly.
(cua--prefix-override-timeout): Don't call reset-this-command-lengths
any more.
(cua--keep-active, cua-exchange-point-and-mark): Don't set mark-active
if the mark is not set.
2015-09-02 01:14:18 +00:00
|
|
|
(setq executing-kbd-macro-index kmacro-step-edit-key-index)
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq kmacro-step-edit-inserting (if (eq act 'insert-1) 1 t))
|
|
|
|
nil)
|
|
|
|
((member act '(replace-1 replace))
|
|
|
|
(setq kmacro-step-edit-inserting (if (eq act 'replace-1) 1 t))
|
2005-05-02 10:33:33 +00:00
|
|
|
(if (= executing-kbd-macro-index (length executing-kbd-macro))
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
|
|
|
|
kmacro-step-edit-appending t))
|
|
|
|
nil)
|
2002-09-10 22:08:45 +00:00
|
|
|
((eq act 'append)
|
|
|
|
(setq kmacro-step-edit-inserting t)
|
2005-05-02 10:33:33 +00:00
|
|
|
(if (= executing-kbd-macro-index (length executing-kbd-macro))
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
|
|
|
|
kmacro-step-edit-appending t))
|
|
|
|
t)
|
2002-09-10 22:08:45 +00:00
|
|
|
((eq act 'append-end)
|
2005-05-02 10:33:33 +00:00
|
|
|
(if (= executing-kbd-macro-index (length executing-kbd-macro))
|
2002-09-10 22:08:45 +00:00
|
|
|
(setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
|
|
|
|
kmacro-step-edit-inserting t
|
|
|
|
kmacro-step-edit-appending t)
|
|
|
|
(setq kmacro-step-edit-active 'append-end))
|
|
|
|
(setq act t)
|
|
|
|
t)
|
2002-09-08 20:38:04 +00:00
|
|
|
((eq act 'help)
|
Generalize the prefix-command machinery of C-u
* lisp/simple.el (prefix-command-echo-keystrokes-functions)
(prefix-command-preserve-state-hook): New hooks.
(internal-echo-keystrokes-prefix): New function.
(prefix-command--needs-update, prefix-command--last-echo): New vars.
(prefix-command-update, prefix-command-preserve): New functions.
(reset-this-command-lengths): New compatibility definition.
(universal-argument--mode): Call prefix-command-update.
(universal-argument, universal-argument-more, negative-argument)
(digit-argument): Call prefix-command-preserve-state.
* src/keyboard.c: Call internal-echo-keystrokes-prefix to build
the "prefix argument" to echo.
(this_command_key_count_reset, before_command_key_count)
(before_command_echo_length): Delete variables.
(echo_add_key): Always add a space.
(echo_char): Remove.
(echo_dash): Don't give up when this_command_key_count is 0, since that
is now the case after a prefix command.
(echo_update): New function, extracted from echo_now.
(echo_now): Use it.
(add_command_key, read_char, record_menu_key): Remove old disabled code.
(command_loop_1): Don't refrain from pushing an undo boundary when
prefix-arg is set. Remove other prefix-arg special case, now handled
directly in the prefix commands instead. But call echo_now if there's
a prefix state to echo.
(read_char, record_menu_key): Use echo_update instead of echo_char.
(read_key_sequence): Use echo_now rather than echo_dash/echo_char.
(Freset_this_command_lengths): Delete function.
(syms_of_keyboard): Define Qinternal_echo_keystrokes_prefix.
(syms_of_keyboard): Don't defsubr Sreset_this_command_lengths.
* lisp/simple.el: Use those new hooks for C-u.
(universal-argument--description): New function.
(prefix-command-echo-keystrokes-functions): Use it.
(universal-argument--preserve): New function.
(prefix-command-preserve-state-hook): Use it.
(command-execute): Call prefix-command-update if needed.
* lisp/kmacro.el (kmacro-step-edit-prefix-commands)
(kmacro-step-edit-prefix-index): Delete variables.
(kmacro-step-edit-query, kmacro-step-edit-insert): Remove ad-hoc
support for prefix arg commands.
(kmacro-step-edit-macro): Don't bind kmacro-step-edit-prefix-index.
* lisp/emulation/cua-base.el (cua--prefix-override-replay)
(cua--shift-control-prefix): Use prefix-command-preserve-state.
Remove now unused arg `arg'.
(cua--prefix-override-handler, cua--prefix-repeat-handler)
(cua--shift-control-c-prefix, cua--shift-control-x-prefix):
Update accordingly.
(cua--prefix-override-timeout): Don't call reset-this-command-lengths
any more.
(cua--keep-active, cua-exchange-point-and-mark): Don't set mark-active
if the mark is not set.
2015-09-02 01:14:18 +00:00
|
|
|
(setq executing-kbd-macro-index kmacro-step-edit-key-index)
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq kmacro-step-edit-help (not kmacro-step-edit-help))
|
|
|
|
nil)
|
|
|
|
(t ;; Ignore unknown responses
|
Generalize the prefix-command machinery of C-u
* lisp/simple.el (prefix-command-echo-keystrokes-functions)
(prefix-command-preserve-state-hook): New hooks.
(internal-echo-keystrokes-prefix): New function.
(prefix-command--needs-update, prefix-command--last-echo): New vars.
(prefix-command-update, prefix-command-preserve): New functions.
(reset-this-command-lengths): New compatibility definition.
(universal-argument--mode): Call prefix-command-update.
(universal-argument, universal-argument-more, negative-argument)
(digit-argument): Call prefix-command-preserve-state.
* src/keyboard.c: Call internal-echo-keystrokes-prefix to build
the "prefix argument" to echo.
(this_command_key_count_reset, before_command_key_count)
(before_command_echo_length): Delete variables.
(echo_add_key): Always add a space.
(echo_char): Remove.
(echo_dash): Don't give up when this_command_key_count is 0, since that
is now the case after a prefix command.
(echo_update): New function, extracted from echo_now.
(echo_now): Use it.
(add_command_key, read_char, record_menu_key): Remove old disabled code.
(command_loop_1): Don't refrain from pushing an undo boundary when
prefix-arg is set. Remove other prefix-arg special case, now handled
directly in the prefix commands instead. But call echo_now if there's
a prefix state to echo.
(read_char, record_menu_key): Use echo_update instead of echo_char.
(read_key_sequence): Use echo_now rather than echo_dash/echo_char.
(Freset_this_command_lengths): Delete function.
(syms_of_keyboard): Define Qinternal_echo_keystrokes_prefix.
(syms_of_keyboard): Don't defsubr Sreset_this_command_lengths.
* lisp/simple.el: Use those new hooks for C-u.
(universal-argument--description): New function.
(prefix-command-echo-keystrokes-functions): Use it.
(universal-argument--preserve): New function.
(prefix-command-preserve-state-hook): Use it.
(command-execute): Call prefix-command-update if needed.
* lisp/kmacro.el (kmacro-step-edit-prefix-commands)
(kmacro-step-edit-prefix-index): Delete variables.
(kmacro-step-edit-query, kmacro-step-edit-insert): Remove ad-hoc
support for prefix arg commands.
(kmacro-step-edit-macro): Don't bind kmacro-step-edit-prefix-index.
* lisp/emulation/cua-base.el (cua--prefix-override-replay)
(cua--shift-control-prefix): Use prefix-command-preserve-state.
Remove now unused arg `arg'.
(cua--prefix-override-handler, cua--prefix-repeat-handler)
(cua--shift-control-c-prefix, cua--shift-control-x-prefix):
Update accordingly.
(cua--prefix-override-timeout): Don't call reset-this-command-lengths
any more.
(cua--keep-active, cua-exchange-point-and-mark): Don't set mark-active
if the mark is not set.
2015-09-02 01:14:18 +00:00
|
|
|
(setq executing-kbd-macro-index kmacro-step-edit-key-index)
|
2002-09-08 20:38:04 +00:00
|
|
|
nil))
|
Generalize the prefix-command machinery of C-u
* lisp/simple.el (prefix-command-echo-keystrokes-functions)
(prefix-command-preserve-state-hook): New hooks.
(internal-echo-keystrokes-prefix): New function.
(prefix-command--needs-update, prefix-command--last-echo): New vars.
(prefix-command-update, prefix-command-preserve): New functions.
(reset-this-command-lengths): New compatibility definition.
(universal-argument--mode): Call prefix-command-update.
(universal-argument, universal-argument-more, negative-argument)
(digit-argument): Call prefix-command-preserve-state.
* src/keyboard.c: Call internal-echo-keystrokes-prefix to build
the "prefix argument" to echo.
(this_command_key_count_reset, before_command_key_count)
(before_command_echo_length): Delete variables.
(echo_add_key): Always add a space.
(echo_char): Remove.
(echo_dash): Don't give up when this_command_key_count is 0, since that
is now the case after a prefix command.
(echo_update): New function, extracted from echo_now.
(echo_now): Use it.
(add_command_key, read_char, record_menu_key): Remove old disabled code.
(command_loop_1): Don't refrain from pushing an undo boundary when
prefix-arg is set. Remove other prefix-arg special case, now handled
directly in the prefix commands instead. But call echo_now if there's
a prefix state to echo.
(read_char, record_menu_key): Use echo_update instead of echo_char.
(read_key_sequence): Use echo_now rather than echo_dash/echo_char.
(Freset_this_command_lengths): Delete function.
(syms_of_keyboard): Define Qinternal_echo_keystrokes_prefix.
(syms_of_keyboard): Don't defsubr Sreset_this_command_lengths.
* lisp/simple.el: Use those new hooks for C-u.
(universal-argument--description): New function.
(prefix-command-echo-keystrokes-functions): Use it.
(universal-argument--preserve): New function.
(prefix-command-preserve-state-hook): Use it.
(command-execute): Call prefix-command-update if needed.
* lisp/kmacro.el (kmacro-step-edit-prefix-commands)
(kmacro-step-edit-prefix-index): Delete variables.
(kmacro-step-edit-query, kmacro-step-edit-insert): Remove ad-hoc
support for prefix arg commands.
(kmacro-step-edit-macro): Don't bind kmacro-step-edit-prefix-index.
* lisp/emulation/cua-base.el (cua--prefix-override-replay)
(cua--shift-control-prefix): Use prefix-command-preserve-state.
Remove now unused arg `arg'.
(cua--prefix-override-handler, cua--prefix-repeat-handler)
(cua--shift-control-c-prefix, cua--shift-control-x-prefix):
Update accordingly.
(cua--prefix-override-timeout): Don't call reset-this-command-lengths
any more.
(cua--keep-active, cua-exchange-point-and-mark): Don't set mark-active
if the mark is not set.
2015-09-02 01:14:18 +00:00
|
|
|
(if (> executing-kbd-macro-index kmacro-step-edit-key-index)
|
2002-09-08 20:38:04 +00:00
|
|
|
(setq kmacro-step-edit-new-macro
|
|
|
|
(vconcat kmacro-step-edit-new-macro
|
2003-02-04 12:29:42 +00:00
|
|
|
(substring executing-kbd-macro
|
Generalize the prefix-command machinery of C-u
* lisp/simple.el (prefix-command-echo-keystrokes-functions)
(prefix-command-preserve-state-hook): New hooks.
(internal-echo-keystrokes-prefix): New function.
(prefix-command--needs-update, prefix-command--last-echo): New vars.
(prefix-command-update, prefix-command-preserve): New functions.
(reset-this-command-lengths): New compatibility definition.
(universal-argument--mode): Call prefix-command-update.
(universal-argument, universal-argument-more, negative-argument)
(digit-argument): Call prefix-command-preserve-state.
* src/keyboard.c: Call internal-echo-keystrokes-prefix to build
the "prefix argument" to echo.
(this_command_key_count_reset, before_command_key_count)
(before_command_echo_length): Delete variables.
(echo_add_key): Always add a space.
(echo_char): Remove.
(echo_dash): Don't give up when this_command_key_count is 0, since that
is now the case after a prefix command.
(echo_update): New function, extracted from echo_now.
(echo_now): Use it.
(add_command_key, read_char, record_menu_key): Remove old disabled code.
(command_loop_1): Don't refrain from pushing an undo boundary when
prefix-arg is set. Remove other prefix-arg special case, now handled
directly in the prefix commands instead. But call echo_now if there's
a prefix state to echo.
(read_char, record_menu_key): Use echo_update instead of echo_char.
(read_key_sequence): Use echo_now rather than echo_dash/echo_char.
(Freset_this_command_lengths): Delete function.
(syms_of_keyboard): Define Qinternal_echo_keystrokes_prefix.
(syms_of_keyboard): Don't defsubr Sreset_this_command_lengths.
* lisp/simple.el: Use those new hooks for C-u.
(universal-argument--description): New function.
(prefix-command-echo-keystrokes-functions): Use it.
(universal-argument--preserve): New function.
(prefix-command-preserve-state-hook): Use it.
(command-execute): Call prefix-command-update if needed.
* lisp/kmacro.el (kmacro-step-edit-prefix-commands)
(kmacro-step-edit-prefix-index): Delete variables.
(kmacro-step-edit-query, kmacro-step-edit-insert): Remove ad-hoc
support for prefix arg commands.
(kmacro-step-edit-macro): Don't bind kmacro-step-edit-prefix-index.
* lisp/emulation/cua-base.el (cua--prefix-override-replay)
(cua--shift-control-prefix): Use prefix-command-preserve-state.
Remove now unused arg `arg'.
(cua--prefix-override-handler, cua--prefix-repeat-handler)
(cua--shift-control-c-prefix, cua--shift-control-x-prefix):
Update accordingly.
(cua--prefix-override-timeout): Don't call reset-this-command-lengths
any more.
(cua--keep-active, cua-exchange-point-and-mark): Don't set mark-active
if the mark is not set.
2015-09-02 01:14:18 +00:00
|
|
|
kmacro-step-edit-key-index
|
|
|
|
(if (eq act t) nil
|
|
|
|
executing-kbd-macro-index)))))
|
2002-09-08 20:38:04 +00:00
|
|
|
(if restore-index
|
2005-05-02 10:33:33 +00:00
|
|
|
(setq executing-kbd-macro-index restore-index)))
|
2002-09-08 20:38:04 +00:00
|
|
|
(t
|
|
|
|
(setq this-command 'ignore)))
|
|
|
|
(setq kmacro-step-edit-key-index next-index)))
|
|
|
|
|
|
|
|
(defun kmacro-step-edit-insert ()
|
|
|
|
;; Pre-command hook function for step-edit in "insert" mode
|
|
|
|
(let ((resize-mini-windows t)
|
|
|
|
(max-mini-window-height kmacro-step-edit-mini-window-height)
|
|
|
|
(macro executing-kbd-macro)
|
|
|
|
(executing-kbd-macro nil)
|
|
|
|
(defining-kbd-macro nil)
|
|
|
|
cmd keys next-index)
|
Generalize the prefix-command machinery of C-u
* lisp/simple.el (prefix-command-echo-keystrokes-functions)
(prefix-command-preserve-state-hook): New hooks.
(internal-echo-keystrokes-prefix): New function.
(prefix-command--needs-update, prefix-command--last-echo): New vars.
(prefix-command-update, prefix-command-preserve): New functions.
(reset-this-command-lengths): New compatibility definition.
(universal-argument--mode): Call prefix-command-update.
(universal-argument, universal-argument-more, negative-argument)
(digit-argument): Call prefix-command-preserve-state.
* src/keyboard.c: Call internal-echo-keystrokes-prefix to build
the "prefix argument" to echo.
(this_command_key_count_reset, before_command_key_count)
(before_command_echo_length): Delete variables.
(echo_add_key): Always add a space.
(echo_char): Remove.
(echo_dash): Don't give up when this_command_key_count is 0, since that
is now the case after a prefix command.
(echo_update): New function, extracted from echo_now.
(echo_now): Use it.
(add_command_key, read_char, record_menu_key): Remove old disabled code.
(command_loop_1): Don't refrain from pushing an undo boundary when
prefix-arg is set. Remove other prefix-arg special case, now handled
directly in the prefix commands instead. But call echo_now if there's
a prefix state to echo.
(read_char, record_menu_key): Use echo_update instead of echo_char.
(read_key_sequence): Use echo_now rather than echo_dash/echo_char.
(Freset_this_command_lengths): Delete function.
(syms_of_keyboard): Define Qinternal_echo_keystrokes_prefix.
(syms_of_keyboard): Don't defsubr Sreset_this_command_lengths.
* lisp/simple.el: Use those new hooks for C-u.
(universal-argument--description): New function.
(prefix-command-echo-keystrokes-functions): Use it.
(universal-argument--preserve): New function.
(prefix-command-preserve-state-hook): Use it.
(command-execute): Call prefix-command-update if needed.
* lisp/kmacro.el (kmacro-step-edit-prefix-commands)
(kmacro-step-edit-prefix-index): Delete variables.
(kmacro-step-edit-query, kmacro-step-edit-insert): Remove ad-hoc
support for prefix arg commands.
(kmacro-step-edit-macro): Don't bind kmacro-step-edit-prefix-index.
* lisp/emulation/cua-base.el (cua--prefix-override-replay)
(cua--shift-control-prefix): Use prefix-command-preserve-state.
Remove now unused arg `arg'.
(cua--prefix-override-handler, cua--prefix-repeat-handler)
(cua--shift-control-c-prefix, cua--shift-control-x-prefix):
Update accordingly.
(cua--prefix-override-timeout): Don't call reset-this-command-lengths
any more.
(cua--keep-active, cua-exchange-point-and-mark): Don't set mark-active
if the mark is not set.
2015-09-02 01:14:18 +00:00
|
|
|
(setq executing-kbd-macro-index kmacro-step-edit-key-index)
|
2002-09-08 20:38:04 +00:00
|
|
|
(kmacro-step-edit-prompt macro nil)
|
|
|
|
;; Now, we have read a key sequence from the macro, but we don't want
|
|
|
|
;; to execute it yet. So push it back and read another sequence.
|
|
|
|
(setq keys (read-key-sequence nil nil nil nil t))
|
|
|
|
(setq cmd (key-binding keys t nil))
|
|
|
|
(if (cond
|
|
|
|
((null cmd)
|
|
|
|
t)
|
|
|
|
((eq cmd 'quoted-insert)
|
|
|
|
(clear-this-command-keys) ;; recent-keys actually
|
|
|
|
(quoted-insert (prefix-numeric-value current-prefix-arg))
|
|
|
|
(setq current-prefix-arg nil
|
|
|
|
prefix-arg nil)
|
|
|
|
(setq keys (vconcat keys (recent-keys)))
|
|
|
|
(when (numberp kmacro-step-edit-inserting)
|
|
|
|
(setq kmacro-step-edit-inserting nil)
|
|
|
|
(when unread-command-events
|
|
|
|
(setq keys (substring keys 0 (- (length unread-command-events)))
|
2005-05-02 10:33:33 +00:00
|
|
|
executing-kbd-macro-index (- executing-kbd-macro-index (length unread-command-events))
|
|
|
|
next-index executing-kbd-macro-index
|
2002-09-08 20:38:04 +00:00
|
|
|
unread-command-events nil)))
|
|
|
|
(setq cmd 'ignore)
|
|
|
|
nil)
|
|
|
|
((numberp kmacro-step-edit-inserting)
|
|
|
|
(setq kmacro-step-edit-inserting nil)
|
|
|
|
nil)
|
|
|
|
((equal keys "\C-j")
|
|
|
|
(setq kmacro-step-edit-inserting nil)
|
|
|
|
(setq kmacro-step-edit-action nil)
|
|
|
|
(setq next-index kmacro-step-edit-key-index)
|
|
|
|
t)
|
|
|
|
(t nil))
|
|
|
|
(setq this-command 'ignore)
|
|
|
|
(setq this-command cmd)
|
|
|
|
(if (memq this-command '(self-insert-command digit-argument))
|
2009-01-09 04:44:15 +00:00
|
|
|
(setq last-command-event (aref keys (1- (length keys)))))
|
2002-09-08 20:38:04 +00:00
|
|
|
(if keys
|
|
|
|
(setq kmacro-step-edit-new-macro (vconcat kmacro-step-edit-new-macro keys))))
|
|
|
|
(setq kmacro-step-edit-key-index next-index)))
|
|
|
|
|
|
|
|
(defun kmacro-step-edit-pre-command ()
|
2017-11-24 16:32:14 +00:00
|
|
|
(remove-hook 'post-command-hook #'kmacro-step-edit-post-command)
|
2002-09-08 20:38:04 +00:00
|
|
|
(when kmacro-step-edit-active
|
|
|
|
(cond
|
|
|
|
((eq kmacro-step-edit-active 'ignore)
|
|
|
|
(setq this-command 'ignore))
|
2002-09-10 22:08:45 +00:00
|
|
|
((eq kmacro-step-edit-active 'append-end)
|
2005-05-02 10:33:33 +00:00
|
|
|
(if (= executing-kbd-macro-index (length executing-kbd-macro))
|
2002-09-10 22:08:45 +00:00
|
|
|
(setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
|
|
|
|
kmacro-step-edit-inserting t
|
|
|
|
kmacro-step-edit-appending t
|
|
|
|
kmacro-step-edit-active t)))
|
2002-09-08 20:38:04 +00:00
|
|
|
((/= kmacro-step-edit-num-input-keys num-input-keys)
|
|
|
|
(if kmacro-step-edit-inserting
|
|
|
|
(kmacro-step-edit-insert)
|
|
|
|
(kmacro-step-edit-query))
|
|
|
|
(setq kmacro-step-edit-num-input-keys num-input-keys)
|
|
|
|
(if (and kmacro-step-edit-appending (not kmacro-step-edit-inserting))
|
|
|
|
(setq kmacro-step-edit-appending nil
|
|
|
|
kmacro-step-edit-active 'ignore)))))
|
|
|
|
(when (eq kmacro-step-edit-active t)
|
2017-11-24 16:32:14 +00:00
|
|
|
(add-hook 'post-command-hook #'kmacro-step-edit-post-command t)))
|
2002-09-08 20:38:04 +00:00
|
|
|
|
|
|
|
(defun kmacro-step-edit-minibuf-setup ()
|
2017-11-24 16:32:14 +00:00
|
|
|
(remove-hook 'pre-command-hook #'kmacro-step-edit-pre-command t)
|
2002-09-08 20:38:04 +00:00
|
|
|
(when kmacro-step-edit-active
|
2017-11-24 16:32:14 +00:00
|
|
|
(add-hook 'pre-command-hook #'kmacro-step-edit-pre-command nil t)))
|
2002-09-08 20:38:04 +00:00
|
|
|
|
|
|
|
(defun kmacro-step-edit-post-command ()
|
2017-11-24 16:32:14 +00:00
|
|
|
(remove-hook 'pre-command-hook #'kmacro-step-edit-pre-command)
|
2002-09-08 20:38:04 +00:00
|
|
|
(when kmacro-step-edit-active
|
2017-11-24 16:32:14 +00:00
|
|
|
(add-hook 'pre-command-hook #'kmacro-step-edit-pre-command nil nil)
|
2002-09-08 20:38:04 +00:00
|
|
|
(if kmacro-step-edit-key-index
|
2005-05-02 10:33:33 +00:00
|
|
|
(setq executing-kbd-macro-index kmacro-step-edit-key-index)
|
|
|
|
(setq kmacro-step-edit-key-index executing-kbd-macro-index))))
|
2002-09-08 20:38:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun kmacro-step-edit-macro ()
|
|
|
|
"Step edit and execute last keyboard macro.
|
|
|
|
|
2020-12-19 16:14:33 +00:00
|
|
|
To customize possible responses, change the \"bindings\" in
|
|
|
|
`kmacro-step-edit-map'."
|
2002-09-08 20:38:04 +00:00
|
|
|
(interactive)
|
|
|
|
(let ((kmacro-step-edit-active t)
|
|
|
|
(kmacro-step-edit-new-macro "")
|
|
|
|
(kmacro-step-edit-inserting nil)
|
|
|
|
(kmacro-step-edit-appending nil)
|
|
|
|
(kmacro-step-edit-replace t)
|
|
|
|
(kmacro-step-edit-key-index 0)
|
|
|
|
(kmacro-step-edit-action nil)
|
|
|
|
(kmacro-step-edit-help nil)
|
|
|
|
(kmacro-step-edit-num-input-keys num-input-keys)
|
|
|
|
(pre-command-hook pre-command-hook)
|
|
|
|
(post-command-hook post-command-hook)
|
|
|
|
(minibuffer-setup-hook minibuffer-setup-hook))
|
2017-11-24 16:32:14 +00:00
|
|
|
(add-hook 'pre-command-hook #'kmacro-step-edit-pre-command nil)
|
|
|
|
(add-hook 'post-command-hook #'kmacro-step-edit-post-command t)
|
|
|
|
(add-hook 'minibuffer-setup-hook #'kmacro-step-edit-minibuf-setup t)
|
2002-09-08 20:38:04 +00:00
|
|
|
(call-last-kbd-macro nil nil)
|
2002-09-20 20:38:18 +00:00
|
|
|
(when (and kmacro-step-edit-replace
|
|
|
|
kmacro-step-edit-new-macro
|
|
|
|
(not (equal last-kbd-macro kmacro-step-edit-new-macro)))
|
|
|
|
(kmacro-push-ring)
|
|
|
|
(setq last-kbd-macro kmacro-step-edit-new-macro))))
|
2002-09-08 20:38:04 +00:00
|
|
|
|
2021-01-29 07:01:12 +00:00
|
|
|
(defun kdb-macro-redisplay ()
|
|
|
|
"Force redisplay during kbd macro execution."
|
|
|
|
(interactive)
|
|
|
|
(or executing-kbd-macro
|
|
|
|
defining-kbd-macro
|
|
|
|
(user-error "Not defining or executing kbd macro"))
|
|
|
|
(when executing-kbd-macro
|
|
|
|
(let ((executing-kbd-macro nil))
|
|
|
|
(redisplay))))
|
|
|
|
|
2002-06-29 20:43:59 +00:00
|
|
|
(provide 'kmacro)
|
2003-09-01 15:45:59 +00:00
|
|
|
|
2002-06-29 20:43:59 +00:00
|
|
|
;;; kmacro.el ends here
|