emacs-diffs
[Top][All Lists]
Advanced

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

master 63a38fd2921: Function to load GDB history


From: Eli Zaretskii
Subject: master 63a38fd2921: Function to load GDB history
Date: Thu, 21 Dec 2023 06:52:39 -0500 (EST)

branch: master
commit 63a38fd2921269b6fbacf8a8bbd31b91df8f31a1
Author: Manuel Giraud <manuel@ledu-giraud.fr>
Commit: Eli Zaretskii <eliz@gnu.org>

    Function to load GDB history
    
    * lisp/progmodes/gdb-mi.el (gud-gdb-load-history): New function to
    load GDB history, code factored out of 'gdb'.
    (gdb): Call it.  (Bug#67928)
---
 lisp/progmodes/gdb-mi.el | 66 +++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 7ae4bcea1e1..cbb165a6a0c 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -817,6 +817,39 @@ NOARG must be t when this macro is used outside `gud-def'."
 
 (defvar gdb-control-level 0)
 
+(defun gdb-load-history ()
+  (when (ring-empty-p comint-input-ring) ; cf shell-mode
+    (let ((hfile (expand-file-name (or (getenv "GDBHISTFILE")
+                                      (if (eq system-type 'ms-dos)
+                                          "_gdb_history"
+                                        ".gdb_history"))))
+         ;; gdb defaults to 256, but we'll default to comint-input-ring-size.
+         (hsize (getenv "HISTSIZE")))
+      (dolist (file (append '("~/.gdbinit")
+                           (unless (string-equal (expand-file-name ".")
+                                                  (expand-file-name "~"))
+                             '(".gdbinit"))))
+       (if (file-readable-p (setq file (expand-file-name file)))
+           (with-temp-buffer
+             (insert-file-contents file)
+             ;; TODO? check for "set history save\\(  *on\\)?" and do
+             ;; not use history otherwise?
+             (while (re-search-forward
+                     "^ *set history \\(filename\\|size\\)  *\\(.*\\)" nil t)
+               (cond ((string-equal (match-string 1) "filename")
+                      (setq hfile (expand-file-name
+                                   (match-string 2)
+                                   (file-name-directory file))))
+                     ((string-equal (match-string 1) "size")
+                      (setq hsize (match-string 2))))))))
+      (and (stringp hsize)
+          (integerp (setq hsize (string-to-number hsize)))
+          (> hsize 0)
+           (setq-local comint-input-ring-size hsize))
+      (if (stringp hfile)
+          (setq-local comint-input-ring-file-name hfile))
+      (comint-read-input-ring t))))
+
 ;;;###autoload
 (defun gdb (command-line)
   "Run gdb passing it COMMAND-LINE as arguments.
@@ -902,37 +935,8 @@ detailed description of this mode.
   (setq-local gud-minor-mode 'gdbmi)
   (setq-local gdb-control-level 0)
   (setq comint-input-sender 'gdb-send)
-  (when (ring-empty-p comint-input-ring) ; cf shell-mode
-    (let ((hfile (expand-file-name (or (getenv "GDBHISTFILE")
-                                      (if (eq system-type 'ms-dos)
-                                          "_gdb_history"
-                                        ".gdb_history"))))
-         ;; gdb defaults to 256, but we'll default to comint-input-ring-size.
-         (hsize (getenv "HISTSIZE")))
-      (dolist (file (append '("~/.gdbinit")
-                           (unless (string-equal (expand-file-name ".")
-                                                  (expand-file-name "~"))
-                             '(".gdbinit"))))
-       (if (file-readable-p (setq file (expand-file-name file)))
-           (with-temp-buffer
-             (insert-file-contents file)
-             ;; TODO? check for "set history save\\(  *on\\)?" and do
-             ;; not use history otherwise?
-             (while (re-search-forward
-                     "^ *set history \\(filename\\|size\\)  *\\(.*\\)" nil t)
-               (cond ((string-equal (match-string 1) "filename")
-                      (setq hfile (expand-file-name
-                                   (match-string 2)
-                                   (file-name-directory file))))
-                     ((string-equal (match-string 1) "size")
-                      (setq hsize (match-string 2))))))))
-      (and (stringp hsize)
-          (integerp (setq hsize (string-to-number hsize)))
-          (> hsize 0)
-           (setq-local comint-input-ring-size hsize))
-      (if (stringp hfile)
-          (setq-local comint-input-ring-file-name hfile))
-      (comint-read-input-ring t)))
+  (gdb-load-history)
+
   (gud-def gud-tbreak "tbreak %f:%l" "\C-t"
           "Set temporary breakpoint at current line." t)
   (gud-def gud-jump



reply via email to

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