all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* gdb <-> .gdbinit
@ 2003-08-01  3:21 Masatake YAMATO
  2003-07-31 17:43 ` Nick Roberts
  2003-08-02  4:46 ` Richard Stallman
  0 siblings, 2 replies; 3+ messages in thread
From: Masatake YAMATO @ 2003-08-01  3:21 UTC (permalink / raw)


You may want to open/select .gdbinit from gdb(buffer created by M-x gdb) quickly.
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 
C-cC-v.

2003-08-01  Masatake YAMATO  <jet@gyve.org>

	* progmodes/gud.el (gdb-script-select-associated-gud-buffer): New function.
	(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 
	gdb-script-mode-map.
	

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 user."
+  (interactive)
+  (if (and gdb-script-associated-gud-buffer (buffer-live-p gdb-script-associated-gud-buffer))
+      (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))))))
+    
+
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("/\\.gdbinit" . gdb-script-mode))
 
@@ -2971,7 +3004,9 @@
 	 (font-lock-syntactic-keywords
 	  . gdb-script-font-lock-syntactic-keywords)
 	 (font-lock-syntactic-face-function
-	  . 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" 'gdb-script-select-associated-gud-buffer))
 
 (provide 'gud)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-08-02  4:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-01  3:21 gdb <-> .gdbinit Masatake YAMATO
2003-07-31 17:43 ` Nick Roberts
2003-08-02  4:46 ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.