]> git.eshelyaron.com Git - emacs.git/commitdiff
Add "forward history" support for some debuggers
authorPaul Nelson <ultrono@gmail.com>
Mon, 21 Apr 2025 20:14:53 +0000 (22:14 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 26 Apr 2025 17:37:01 +0000 (19:37 +0200)
* lisp/progmodes/gud.el (gud-query-cmdline): Add an optional
default-list parameter to allow passing a list of "forward
history" suggestions to the minibuffer.
(perldb, pdb, guiler): Use buffer file name to suggest a default
debugging command via "forward history".

* doc/emacs/building.texi (Starting GUD): Document the new
feature.

(Bug#77989)

(cherry picked from commit f808f637f57eb0fe87fdc2ea7c2a1fd9e2f9d912)

doc/emacs/building.texi
lisp/progmodes/gud.el

index 2e02422739c345a2ff0e59e294331bbd8881f604..da7275e24fa534e8f09cee83d797e744133b97fc 100644 (file)
@@ -674,6 +674,9 @@ Run the SDB debugger.
 using the minibuffer.  The minibuffer's initial contents contain the
 standard executable name and options for the debugger, and sometimes
 also a guess for the name of the executable file you want to debug.
+For @code{pdb}, @code{perldb}, and @code{guiler}, if the current buffer
+visits a file, pressing @kbd{M-n} (@code{next-history-element})
+in the prompt suggests a full command line including that file name.
 Shell wildcards and variables are not allowed in this command line.
 Emacs assumes that the first command argument which does not start
 with a @samp{-} is the executable file name.
index 552b5576190ac2f5420b347f3777986d36f8a2b1..bc273da3f70bd3fdc254345c6ff97ccc1a991847 100644 (file)
@@ -756,7 +756,11 @@ The option \"--fullname\" must be included in this value."
   :parent minibuffer-local-map
   "C-i" #'comint-dynamic-complete-filename)
 
-(defun gud-query-cmdline (minor-mode &optional init)
+(defun gud-query-cmdline (minor-mode &optional init default-list)
+  "Prompt for a command to run the debugger.
+MINOR-MODE is the name of the debugger to run.  INIT is the initial
+command, before any history is available.  DEFAULT-LIST is a list of
+default commands, accessible via \\[next-history-element]."
   (let* ((hist-sym (gud-symbol 'history nil minor-mode))
         (cmd-name (gud-val 'command-name minor-mode)))
     (unless (boundp hist-sym) (set hist-sym nil))
@@ -779,7 +783,8 @@ The option \"--fullname\" must be included in this value."
                               (setq file f)))
                             file)))))
      gud-minibuffer-local-map nil
-     hist-sym)))
+     hist-sym
+     default-list)))
 
 (defvar gdb-first-prompt t)
 
@@ -1670,8 +1675,13 @@ Noninteractively, COMMAND-LINE should be on the form
 The directory containing the perl program becomes the initial
 working directory and source-file directory for your debugger."
   (interactive
-   (list (gud-query-cmdline 'perldb
-                           (concat (or (buffer-file-name) "-E 0") " "))))
+   (list
+    (gud-query-cmdline
+     'perldb
+     (concat (or (buffer-file-name) "-E 0") " ")
+     (when-let* ((file (buffer-file-name)))
+       (list (concat gud-perldb-command-name " "
+                     (shell-quote-argument file) " "))))))
 
   (gud-common-init command-line 'gud-perldb-massage-args
                   'gud-perldb-marker-filter)
@@ -1801,7 +1811,11 @@ If called interactively, the command line will be prompted for.
 The directory containing this file becomes the initial working
 directory and source-file directory for your debugger."
   (interactive
-   (list (gud-query-cmdline 'pdb)))
+   (list (gud-query-cmdline
+          'pdb nil
+          (when-let* ((file (buffer-file-name)))
+            (list (concat gud-pdb-command-name " "
+                          (shell-quote-argument file)))))))
 
   (gud-common-init command-line nil 'gud-pdb-marker-filter)
   (setq-local gud-minor-mode 'pdb)
@@ -1888,7 +1902,12 @@ This should be an executable on your path, or an absolute file name."
 The directory containing FILE becomes the initial working directory
 and source-file directory for your debugger."
   (interactive
-   (list (gud-query-cmdline 'guiler)))
+   (list
+    (gud-query-cmdline
+     'guiler nil
+     (when-let* ((file (buffer-file-name)))
+       (list (concat gud-guiler-command-name " "
+                     (shell-quote-argument file)))))))
 
   (gud-common-init command-line nil 'gud-guiler-marker-filter)
   (setq-local gud-minor-mode 'guiler)