From d12a32b225c364aa75708c766370e8f27a08995a Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Mon, 19 Jul 2021 23:41:01 -0700 Subject: [PATCH 1/2] Ensure that gud commands for M-x gdb are handled by repeat-mode * lisp/progmodes/gud.el (gud-gdb-repeat-map): Rename from gud-repeat-map, and populate at the top-level. (gud-set-repeat-map-property): Introduce this helper function for setting the repeat-map property. (gud-gdb): Use the gud-set-repeat-map-property function to assign the repeat-map property. * lisp/progmodes/gdb-mi.el (gdb): Use the gud-set-repeat-map-property function to assign the repeat-map property. Because different debugging tools may not support all of the gud-foo functions, we reassign the repeat-map property within the respective commands, as opposed to the top level of the files, to ensure that the repeat-map property is reassigned each time to a symbol corresponding to the active debugging tool. * lisp/repeat.el (repeat-post-hook): Allow the repeat-map property to be an evaluated keymap. --- lisp/progmodes/gdb-mi.el | 2 ++ lisp/progmodes/gud.el | 33 +++++++++++++++++++++------------ lisp/repeat.el | 3 ++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 57c99abec6..ad579eb89f 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el @@ -996,6 +996,8 @@ gdb (define-key gud-minor-mode-map [left-margin C-mouse-3] 'gdb-mouse-jump) + (gud-set-repeat-map-property gud-gdb-repeat-map) + (setq-local gud-gdb-completion-function 'gud-gdbmi-completions) (add-hook 'completion-at-point-functions #'gud-gdb-completion-at-point diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index 740a6e2581..3ffae7f2e0 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -320,10 +320,28 @@ gud-tool-bar-map (tool-bar-local-item-from-menu (car x) (cdr x) map gud-minor-mode-map)))) -(defvar gud-repeat-map (make-sparse-keymap) - "Keymap to repeat gud stepping instructions `C-x C-a C-n n n'. +(defvar gud-gdb-repeat-map + (let ((map (make-sparse-keymap))) + (pcase-dolist (`(,key . ,cmd) '(("n" . gud-next) + ("s" . gud-step) + ("i" . gud-stepi) + ("c" . gud-cont) + ("l" . gud-refresh) + ("f" . gud-finish) + ("<" . gud-up) + (">" . gud-down))) + (define-key map key cmd)) + map) + "Keymap to repeat `gud-gdb' stepping instructions `C-x C-a C-n n n'. Used in `repeat-mode'.") +(defun gud-set-repeat-map-property (keymap) + "Set the `repeat-map' property of each command in KEYMAP to KEYMAP." + (map-keymap-internal (lambda (_ cmd) + (put cmd 'repeat-map keymap)) + keymap)) + + (defun gud-file-name (f) "Transform a relative file name to an absolute file name. Uses `gud--directories' to find the source files." @@ -814,16 +832,7 @@ gud-gdb (gud-def gud-until "until %l" "\C-u" "Continue to current line.") (gud-def gud-run "run" nil "Run the program.") - (dolist (cmd '(("n" . gud-next) - ("s" . gud-step) - ("i" . gud-stepi) - ("c" . gud-cont) - ("l" . gud-refresh) - ("f" . gud-finish) - ("<" . gud-up) - (">" . gud-down))) - (define-key gud-repeat-map (car cmd) (cdr cmd)) - (put (cdr cmd) 'repeat-map 'gud-repeat-map)) + (gud-set-repeat-map-property gud-gdb-repeat-map) (add-hook 'completion-at-point-functions #'gud-gdb-completion-at-point nil 'local) diff --git a/lisp/repeat.el b/lisp/repeat.el index cec3cb643a..aa2c3a0779 100644 --- a/lisp/repeat.el +++ b/lisp/repeat.el @@ -410,7 +410,8 @@ repeat-post-hook (and (symbolp real-this-command) (get real-this-command 'repeat-map))))) (when rep-map - (when (boundp rep-map) + (when (and (boundp rep-map) + (not (keymapp rep-map))) (setq rep-map (symbol-value rep-map))) (let ((map (copy-keymap rep-map))) -- 2.32.0