]> code.delx.au - gnu-emacs/blobdiff - lisp/gud.el
(gud-jdb-build-source-files-list): Fix typo.
[gnu-emacs] / lisp / gud.el
index 036515176aea32df57b8ae8488a4502c1f3519f1..1e869565cb415db0c2d55c53c291682518365f0d 100644 (file)
@@ -1184,27 +1184,48 @@ directories if your program contains sources from more than one directory."
 ;;; History of argument lists passed to perldb.
 (defvar gud-perldb-history nil)
 
+;; Convert a command line as would be typed normally to run a script
+;; into one that invokes an Emacs-enabled debugging session.
+;; "-d" in inserted as the first switch, and "-emacs" is inserted where
+;; it will be $ARGV[0] (see perl5db.pl).
 (defun gud-perldb-massage-args (file args)
-  (let (new-args)
+  (let* ((new-args '("-d"))
+        (seen-e nil)
+        (shift (lambda ()
+                 (setq new-args (cons (car args) new-args))
+                 (setq args (cdr args)))))
 
+    ;; Pass all switches and -e scripts through.
     (while (and args
-               (string-match "^-[^-]" (car args)))
-      (setq new-args (cons (car args) new-args))
-      (setq args (cdr args)))
-
-    (if args
-       (progn
-         (setq new-args (cons (car args) new-args))
-         (setq args (cdr args)))
-      (setq new-args (cons "--" new-args)))
+               (string-match "^-" (car args))
+               (not (equal "-" (car args)))
+               (not (equal "--" (car args))))
+      (when (equal "-e" (car args))
+       ;; -e goes with the next arg, so shift one extra.
+       (or (funcall shift)
+           ;; -e as the last arg is an error in Perl.
+           (error "No code specified for -e."))
+       (setq seen-e t))
+      (funcall shift))
+
+    (when (not seen-e)
+      (if (or (not args)
+             (string-match "^-" (car args)))
+         (error "Can't use stdin as the script to debug."))
+      ;; This is the program name.
+      (funcall shift))
+
+    ;; If -e specified, make sure there is a -- so -emacs is not taken
+    ;; as -e macs.
+    (if (and args (equal "--" (car args)))
+       (funcall shift)
+      (and seen-e (setq new-args (cons "--" new-args))))
 
     (setq new-args (cons "-emacs" new-args))
-
     (while args
-      (setq new-args (cons (car args) new-args))
-      (setq args (cdr args)))
+      (funcall shift))
 
-    (cons "-d" (nreverse new-args))))
+    (nreverse new-args)))
 
 ;; There's no guarantee that Emacs will hand the filter the entire
 ;; marker at once; it could be broken up across several strings.  We
@@ -1540,7 +1561,9 @@ The file names should be absolute, or relative to the current directory.")
 ;; which to search for files with extension EXTN.  Normally EXTN is
 ;; given as the regular expression "\\.java$" .
 (defun gud-jdb-build-source-files-list (path extn)
-  (apply 'nconc (mapcar (lambda (d) (directory-files d t extn nil)) path)))
+  (apply 'nconc (mapcar (lambda (d)
+                         (when (file-directory-p d)
+                           (directory-files d t extn nil)) path))))
 
 ;; Move point past whitespace.
 (defun gud-jdb-skip-whitespace ()
@@ -1740,7 +1763,7 @@ The file names should be absolute, or relative to the current directory.")
 ;; holding their definitions.  SOURCES holds a list of all the source
 ;; files to examine.
 (defun gud-jdb-build-class-source-alist (sources)
-  (setq gud-jdb-analysis-buffer (get-buffer-create "*gud-jdb-scratch*"))
+  (setq gud-jdb-analysis-buffer (get-buffer-create " *gud-jdb-scratch*"))
   (prog1
       (apply
        'nconc
@@ -2305,18 +2328,17 @@ Obeying it means displaying in another window the specified file and line."
          (setq subst (if insource
                          (save-excursion
                            (beginning-of-line)
-                           (save-restriction (widen)
-                                             (1+ (count-lines 1 (point)))))
+                           (save-restriction
+                             (widen)
+                             (int-to-string (1+ (count-lines 1 (point))))))
                        (cdr frame))))
         ((eq key ?e)
          (setq subst (gud-find-c-expr)))
         ((eq key ?a)
          (setq subst (gud-read-address)))
         ((eq key ?p)
-         (setq subst (if arg (int-to-string arg) ""))))
-       (setq result (concat result
-                            (substring str (match-beginning 1) (match-end 1))
-                            subst)))
+         (setq subst (if arg (int-to-string arg)))))
+       (setq result (concat result (match-string 1 str) subst)))
       (setq str (substring str (match-end 2))))
     ;; There might be text left in STR when the loop ends.
     (concat result str)))