From 44fd88410c72432fd3e74e0af00e7ec617fc8fe9 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Wed, 20 Dec 2023 12:08:30 +0100 Subject: [PATCH] Load GDB history into gud-gdb * lisp/progmodes/gud.el (gud-gdb-load-history): New function to load GDB history into 'comint-input-ring'. (gud-gdb): Call it. * lisp/progmodes/gdb-mi.el (gdb): Call it. --- lisp/progmodes/gdb-mi.el | 33 ++------------------------------- lisp/progmodes/gud.el | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 7ae4bcea1e1..c14f2e2ba65 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el @@ -902,37 +902,8 @@ gdb (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))) + (gud-gdb-load-history) + (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set temporary breakpoint at current line." t) (gud-def gud-jump diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index 0f0bb73ae77..1fc0f1f5b6a 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -803,6 +803,39 @@ gud-gdb-completion-function ;; If in gdb mode, gdb-mi is loaded. (declare-function gdb-restore-windows "gdb-mi" ()) +(defun gud-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)))) + ;; The old gdb command (text command mode). The new one is in gdb-mi.el. ;;;###autoload (defun gud-gdb (command-line) @@ -832,6 +865,7 @@ gud-gdb (gud-common-init command-line nil 'gud-gdb-marker-filter) (setq-local gud-minor-mode 'gdb) + (gud-gdb-load-history) (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.") (gud-def gud-tbreak "tbreak %f:%l" "\C-t" -- 2.43.0