[Top][All Lists]

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

gdb <-> .gdbinit

From: Masatake YAMATO
Subject: gdb <-> .gdbinit
Date: Fri, 01 Aug 2003 12:21:59 +0900 (JST)

You may want to open/select .gdbinit from gdb(buffer created by M-x gdb) 
After editing .gdbinit you may also want to select gdb buffer quickly.
With following patch, you can move between .gdbinit buffer and gdb quickly with 

2003-08-01  Masatake YAMATO  <address@hidden>

        * progmodes/gud.el (gdb-script-select-associated-gud-buffer): New 
        (gud-gdb-find-script): New function.
        (gdb): bind "\C-c\C-v" to gud-gdb-find-script in local key map.
        (gdb-script-associated-gud-buffer): New variable.
        (gdb-script-mode): make gdb-script-associated-gud-buffer buffer local.
        bind "\C-c\C-v" to gdb-script-select-associated-gud-buffer in 

cvs diff: warning: unrecognized response `access control disabled, clients can 
connect from any host' from cvs server
Warning: Remote host denied X11 forwarding.
Index: lisp/progmodes/gud.el
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/gud.el,v
retrieving revision 1.4
diff -u -r1.4 gud.el
--- lisp/progmodes/gud.el       28 Jul 2003 06:27:09 -0000      1.4
+++ lisp/progmodes/gud.el       31 Jul 2003 09:19:53 -0000
@@ -486,6 +486,7 @@
   (gud-def gud-run    "run"         nil    "Run the program.")
   (local-set-key "\C-i" 'gud-gdb-complete-command)
+  (local-set-key "\C-c\C-v" 'gud-gdb-find-script)
   (setq comint-prompt-regexp "^(.*gdb[+]?) *")
   (setq paragraph-start comint-prompt-regexp)
   (run-hooks 'gdb-mode-hook)
@@ -2883,6 +2884,9 @@
 ;;; GDB script mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defvar gdb-script-associated-gud-buffer nil 
+  "Gud buffer selected before gdb script buffer is selected.
+Used in `gdb-script-select-associated-gud-buffer' and `gud-gdb-find-script'.")
 (defvar gdb-script-mode-syntax-table
   (let ((st (make-syntax-table)))
@@ -2954,6 +2958,35 @@
          (save-excursion (indent-line-to indent))
        (indent-line-to indent)))))
+(defun gud-gdb-find-script (homedir)
+  "Open .gdbinit file.
+With a prefix argument HOMEDIR, .gdbinit under the home directory is open.
+Without a prefix argument, .gdbinit under the current directory is open."
+  (interactive "P")
+  (setq gdb-script-associated-gud-buffer (let ((buffer (current-buffer)))
+                                          (if homedir
+                                              (find-file "~/.gdbinit")
+                                            (find-file "./.gdbinit"))
+                                          buffer)))
+(defun gdb-script-select-associated-gud-buffer ()
+  "Select gud buffer selected before gdb script buffer is selected.
+Buffer specified by`gdb-script-associated-gud-buffer' is selected.
+`gdb-script-associated-gud-buffer' is set by `gud-gdb-find-script'.
+If `gdb-script-associated-gud-buffer' is nil, gdb is launched after asking 
+  (interactive)
+  (if (and gdb-script-associated-gud-buffer (buffer-live-p 
+      (switch-to-buffer gdb-script-associated-gud-buffer)
+    (when (y-or-n-p "No associated gud buffer for this buffer. Run gdb? ")
+      (let ((script-buffer (current-buffer))
+           gud-buffer)
+       (call-interactively 'gdb)
+       (setq gud-buffer (current-buffer))
+       (save-excursion
+         (set-buffer script-buffer)
+         (setq gdb-script-associated-gud-buffer gud-buffer))))))
 (add-to-list 'auto-mode-alist '("/\\.gdbinit" . gdb-script-mode))
@@ -2971,7 +3004,9 @@
          . gdb-script-font-lock-syntactic-keywords)
-         . gdb-script-font-lock-syntactic-face))))
+         . gdb-script-font-lock-syntactic-face)))
+  (make-local-variable 'gdb-script-associated-gud-buffer)
+  (define-key gdb-script-mode-map "\C-c\C-v" 
 (provide 'gud)

reply via email to

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