From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Nick Roberts Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] find-file-noselect-1 Date: Mon, 14 Feb 2005 09:49:57 +1300 Message-ID: <16911.48501.927221.675952@farnswood.snap.net.nz> References: <16907.50624.707323.36975@farnswood.snap.net.nz> <16908.7466.270296.502380@farnswood.snap.net.nz> <16908.8338.858602.199031@farnswood.snap.net.nz> <16909.56012.478599.348349@farnswood.snap.net.nz> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1108329272 18906 80.91.229.2 (13 Feb 2005 21:14:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 13 Feb 2005 21:14:32 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 13 22:14:31 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D0R4T-00013v-Rl for ged-emacs-devel@m.gmane.org; Sun, 13 Feb 2005 22:14:26 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D0REu-0007pI-LM for ged-emacs-devel@m.gmane.org; Sun, 13 Feb 2005 16:25:12 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1D0REE-0007kC-90 for emacs-devel@gnu.org; Sun, 13 Feb 2005 16:24:30 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1D0RE6-0007fv-E6 for emacs-devel@gnu.org; Sun, 13 Feb 2005 16:24:23 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D0RE6-0007fs-AX for emacs-devel@gnu.org; Sun, 13 Feb 2005 16:24:22 -0500 Original-Received: from [202.37.101.8] (helo=viper.snap.net.nz) by monty-python.gnu.org with esmtp (Exim 4.34) id 1D0Qip-0007jl-A4; Sun, 13 Feb 2005 15:52:04 -0500 Original-Received: from farnswood.snap.net.nz (p202-tnt1.snap.net.nz [202.124.110.202]) by viper.snap.net.nz (Postfix) with ESMTP id 65A2339A6F5; Mon, 14 Feb 2005 09:51:57 +1300 (NZDT) Original-Received: by farnswood.snap.net.nz (Postfix, from userid 501) id 97DA362FBE; Sun, 13 Feb 2005 20:49:58 +0000 (GMT) Original-To: rms@gnu.org In-Reply-To: X-Mailer: VM 7.19 under Emacs 22.0.50.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: main.gmane.org gmane.emacs.devel:33354 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:33354 > I don't think that gud-comint-buffer should be set > to nil because that would prevent the GDB session from recovering. > > Perhaps you should add a new variable, which you can set if you catch > an error, to disable this hook from really doing anything once it has > had an error. I have added a variable called gdb-find-file-unhook. It gets re-initialised at the start of every gdb session because the user might conceivably use different versions of gdb. The most likely cause of an error that I can see is gdb giving unexpected output eg GDB developers are internationalising the CLI output (Note: MI output should not change, however). > > Why call find-file-noselect there? If this is meant to operate on > > the file that was just visited, it already has a buffer, and it is > > the current buffer when gdb-find-file-hook runs. Why not just use > > that buffer? > > That might have been true but I'm now using this function to address > Kim's point about enabling gud-minor-mode for existing buffers. > > It sounds like you are in all cases trying to find an existing buffer. > So instead of using find-file-noselect, you could use > find-buffer-visiting. I've not used find-buffer-visiting but I have followed Stefan's advice about using the buffer instead of the filename. The patch is attached below. It includes a few small unrelated changes now. Probably the best test is for it to get some use. Shall I install it? Nick *** /home/nick/emacs/lisp/progmodes/gdb-ui.el.~1.47.~ 2005-02-10 08:22:54.000000000 +1300 --- /home/nick/emacs/lisp/progmodes/gdb-ui.el 2005-02-14 09:31:05.000000000 +1300 *************** *** 79,84 **** --- 79,86 ---- (defvar gdb-overlay-arrow-position nil) (defvar gdb-server-prefix nil) (defvar gdb-flush-pending-output nil) + (defvar gdb-location-list nil "List of directories for source files.") + (defvar gdb-find-file-unhook nil) (defvar gdb-buffer-type nil "One of the symbols bound in `gdb-buffer-rules'.") *************** *** 191,196 **** --- 193,227 ---- :group 'gud :version "22.1") + (defun gdb-set-gud-minor-mode (buffer) + "Set gud-minor-mode from find-file if appropriate." + (goto-char (point-min)) + (unless (search-forward "No source file named " nil t) + (condition-case nil + (gdb-enqueue-input + (list (concat gdb-server-prefix "info source\n") + `(lambda () (gdb-set-gud-minor-mode-1 ,buffer)))) + (error (setq gdb-find-file-unhook t))))) + + (defun gdb-set-gud-minor-mode-1 (buffer) + (goto-char (point-min)) + (if (and (search-forward "Located in " nil t) + (looking-at "\\S-*") + (string-equal (buffer-file-name buffer) + (match-string 0))) + (with-current-buffer buffer + (set (make-local-variable 'gud-minor-mode) 'gdba) + (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)))) + + (defun gdb-set-gud-minor-mode-existing-buffers () + (dolist (buffer (buffer-list)) + (let ((file (buffer-file-name buffer))) + (if file + (progn + (gdb-enqueue-input + (list (concat "list " (file-name-nondirectory file) ":1\n") + `(lambda () (gdb-set-gud-minor-mode ,buffer))))))))) + (defun gdb-ann3 () (setq gdb-debug-log nil) (set (make-local-variable 'gud-minor-mode) 'gdba) *************** *** 249,254 **** --- 280,286 ---- (setq gdb-server-prefix "server ") (setq gdb-flush-pending-output nil) (setq gdb-location-list nil) + (setq gdb-find-file-unhook nil) ;; (setq gdb-buffer-type 'gdba) ;; *************** *** 263,268 **** --- 295,301 ---- (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program (gdb-enqueue-input (list "server info source\n" 'gdb-source-info)) ;; + (gdb-set-gud-minor-mode-existing-buffers) (run-hooks 'gdba-mode-hook)) (defcustom gdb-use-colon-colon-notation nil *************** *** 1048,1055 **** ;; buffer specific functions gdb-info-breakpoints-custom) - (defvar gdb-location-list nil "List of directories for source files.") - (defconst breakpoint-xpm-data "/* XPM */ static char *magick[] = { --- 1081,1086 ---- *************** *** 1159,1171 **** (setq file (cdr (assoc bptno gdb-location-list)))) (unless (string-equal file "File not found") (if file ! (with-current-buffer ! (find-file-noselect file) ! (save-current-buffer ! (set (make-local-variable 'gud-minor-mode) 'gdba) ! (set (make-local-variable 'tool-bar-map) ! gud-tool-bar-map)) ;; only want one breakpoint icon at each location (save-excursion (goto-line (string-to-number line)) --- 1190,1200 ---- (setq file (cdr (assoc bptno gdb-location-list)))) (unless (string-equal file "File not found") (if file ! (with-current-buffer (find-file-noselect file) ! (set (make-local-variable 'gud-minor-mode) 'gdba) ! (set (make-local-variable 'tool-bar-map) ! gud-tool-bar-map) ;; only want one breakpoint icon at each location (save-excursion (goto-line (string-to-number line)) *************** *** 2054,2068 **** "Find the source file where the program starts and displays it with related buffers." (goto-char (point-min)) ! (if (search-forward "Located in " nil t) ! (if (looking-at "\\S-*") ! (setq gdb-main-file (match-string 0)))) (if gdb-many-windows (gdb-setup-windows) (gdb-get-create-buffer 'gdb-breakpoints-buffer) ! (if gdb-show-main ! (let ((pop-up-windows t)) ! (display-buffer (gud-find-file gdb-main-file)))))) (defun gdb-get-location (bptno line flag) "Find the directory containing the relevant source file. --- 2083,2097 ---- "Find the source file where the program starts and displays it with related buffers." (goto-char (point-min)) ! (if (and (search-forward "Located in " nil t) ! (looking-at "\\S-*")) ! (setq gdb-main-file (match-string 0))) (if gdb-many-windows (gdb-setup-windows) (gdb-get-create-buffer 'gdb-breakpoints-buffer) ! (if gdb-show-main ! (let ((pop-up-windows t)) ! (display-buffer (gud-find-file gdb-main-file)))))) (defun gdb-get-location (bptno line flag) "Find the directory containing the relevant source file. *************** *** 2085,2090 **** --- 2114,2135 ---- (goto-line (string-to-number line)) (gdb-put-breakpoint-icon (eq flag ?y) bptno)))) + (add-hook 'find-file-hook 'gdb-find-file-hook) + + (defun gdb-find-file-hook () + (if (and (not gdb-find-file-unhook) + ;; in case gud or gdb-ui is just loaded + gud-comint-buffer + (buffer-name gud-comint-buffer) + (with-current-buffer gud-comint-buffer + (eq gud-minor-mode 'gdba))) + (condition-case nil + (gdb-enqueue-input + (list (concat "list " (file-name-nondirectory buffer-file-name) + ":1\n") + `(lambda () (gdb-set-gud-minor-mode ,(current-buffer))))) + (error nil)))) + ;;from put-image (defun gdb-put-string (putstring pos &optional dprop) "Put string PUTSTRING in front of POS in the current buffer.