From d2d1851b5d3b7583e7a7db2f8b3db2d33c753f5c Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Wed, 23 May 2001 18:41:33 +0000
Subject: [PATCH] (gud-gdb-run-command-fetch-lines): Use forward-line rather
 than beginning-of-line to avoid problems with fields.
 (gud-perldb-massage-args): Use unless and push. (gud-chdir-before-run): New
 var. (gud-common-init): Use it.

---
 lisp/ChangeLog | 15 +++++++++++----
 lisp/gud.el    | 19 ++++++++++++-------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 12d5ebd4474..067a9e820c0 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,12 +1,19 @@
+2001-05-23  Stefan Monnier  <monnier@cs.yale.edu>
+
+	* gud.el (gud-gdb-run-command-fetch-lines): Use forward-line
+	rather than beginning-of-line to avoid problems with fields.
+	(gud-perldb-massage-args): Use unless and push.
+	(gud-chdir-before-run): New var.
+	(gud-common-init): Use it.
+
 2001-05-24  Andrew Choi  <akochoi@i-cable.com>
 
 	* international/titdic-cnv.el (quail-cxterm-package-ext-info):
 	delete entries for chinese-ctlau and chinese-ctlaub.
-	(quail-misc-package-ext-info): add entries for chinese-ctlau and
+	(quail-misc-package-ext-info): Add entries for chinese-ctlau and
 	chinese-ctlaub.
-	(ctlau-converter): New function.
-	(ctlau-gb-converter): New function.
-	(ctlau-b5-converter): New function.
+	(ctlau-converter, ctlau-gb-converter, ctlau-b5-converter):
+	New functions.
 
 2001-05-22  Gerd Moellmann  <gerd@gnu.org>
 
diff --git a/lisp/gud.el b/lisp/gud.el
index 0161e854854..9119a2b9497 100644
--- a/lisp/gud.el
+++ b/lisp/gud.el
@@ -580,7 +580,7 @@ BUFFER is the GUD buffer in which to run the command."
     (set-buffer buffer)
     (if (save-excursion
 	  (goto-char (point-max))
-	  (beginning-of-line)
+	  (forward-line 0)
 	  (not (looking-at comint-prompt-regexp)))
 	nil
       ;; Much of this copied from GDB complete, but I'm grabbing the stack
@@ -1201,7 +1201,7 @@ directories if your program contains sources from more than one directory."
 	(setq seen-e t))
       (funcall shift))
 
-    (when (not seen-e)
+    (unless seen-e
       (if (or (not args)
 	      (string-match "^-" (car args)))
 	  (error "Can't use stdin as the script to debug."))
@@ -1212,9 +1212,9 @@ directories if your program contains sources from more than one directory."
     ;; as -e macs.
     (if (and args (equal "--" (car args)))
 	(funcall shift)
-      (and seen-e (setq new-args (cons "--" new-args))))
+      (and seen-e (push "--" new-args)))
 
-    (setq new-args (cons "-emacs" new-args))
+    (push "-emacs" new-args)
     (while args
       (funcall shift))
 
@@ -2021,12 +2021,17 @@ comint mode, which see."
 ;; in the selected window.
 ;;;###autoload (add-hook 'same-window-regexps "\\*gud-.*\\*\\(\\|<[0-9]+>\\)")
 
+(defcustom gud-chdir-before-run t
+  "Non-nil if GUD should `cd' to the debugged executable."
+  :group 'gud
+  :type 'boolean)
+
 ;; Perform initializations common to all debuggers.
 ;; The first arg is the specified command line,
 ;; which starts with the program to debug.
 ;; The other three args specify the values to use
 ;; for local variables in the debugger buffer.
-(defun gud-common-init (command-line massage-args marker-filter find-file)
+(defun gud-common-init (command-line massage-args marker-filter &optional find-file)
   (let* ((words (split-string command-line))
 	 (program (car words))
 	 ;; Extract the file name from WORDS
@@ -2054,6 +2059,7 @@ comint mode, which see."
     (pop-to-buffer (concat "*gud" filepart "*"))
     ;; Set default-directory to the file's directory.
     (and file-word
+	 gud-chdir-before-run
 	 ;; Don't set default-directory if no directory was specified.
 	 ;; In that case, either the file is found in the current directory,
 	 ;; in which case this setq is a no-op,
@@ -2075,8 +2081,7 @@ comint mode, which see."
   (gud-mode)
   (make-local-variable 'gud-marker-filter)
   (setq gud-marker-filter marker-filter)
-  (make-local-variable 'gud-find-file)
-  (setq gud-find-file find-file)
+  (if find-file (set (make-local-variable 'gud-find-file) find-file))
 
   (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
   (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
-- 
2.39.5