all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* GUD octave support
@ 2007-11-18  5:42 Daniel Elliott
  2007-11-18 10:42 ` Nick Roberts
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Elliott @ 2007-11-18  5:42 UTC (permalink / raw)
  To: emacs-devel

Hello,

This is my first crack at adding octave support in GUD.  It still
needs to have some of the features from the octave-inf mode included
if possible within the GUD framework.

It is a little rough, but appears to be stable and robust.

original is the version supplied debian (etch, i beleive)

*** original.el 2007-11-17 22:50:35.000000000 -0600
--- gud.el      2007-11-17 22:34:58.000000000 -0600
*************** gud, see `gud-mode'."
*** 2332,2337 ****
--- 2332,2462 ----
  ;; End of debugger-specific information
  ;;

+ ;; ======================================================================
+ ;; octave debugger functions
+
+ (defvar gud-octavedb-command-name "octave")
+
+ ;;; History of argument lists passed to octavedb
+ (defvar gud-octavedb-history nil)
+
+ (defun gud-octavedb-massage-args (file args)
+   ;; just use the default arguments from octave-inf
+   '("-i" "--no-line-editing" "-q" "--traditional"))
+
+ (setq gud-octavedb-marker-regexp
+       "keyboard: stopped in\s\\(.*\\)\sat line \\([0-9]+\\)")
+
+ (defun gud-octavedb-marker-filter (string)
+
+   (setq gud-marker-acc (concat gud-marker-acc string))
+   (let ((output ""))
+
+
+     ;; Process all the complete markers in this chunk.
+     (while (string-match gud-octavedb-marker-regexp gud-marker-acc)
+       (setq
+
+        ;; Extract the frame position from the marker.
+        gud-last-frame
+        (cons (match-string 1 gud-marker-acc)
+            (string-to-number (match-string 2 gud-marker-acc)))
+
+        ;; Append any text before the marker to the output we're going
+        ;; to return - we don't include the marker in this text.
+        output (concat output
+                     (substring gud-marker-acc 0 (match-beginning 0)))
+        ;; Set the accumulator to the remaining text.
+        gud-marker-acc (substring gud-marker-acc (match-end 0))))
+
+     ;; Does the remaining text look like it might end with the
+     ;; beginning of another marker?  If it does, then keep it in
+     ;; gud-marker-acc until we receive the rest of it.  Since we
+     ;; know the full marker regexp above failed, it's pretty simple to
+     ;; test for marker starts.
+
+     ;; DLE: i doubt this is applicable to octave's debug mode
+     (if (string-match "\032.*\\'" gud-marker-acc)
+       (progn
+         ;; Everything before the potential marker start can be output.
+         (setq output (concat output (substring gud-marker-acc
+                                                0 (match-beginning 0))))
+
+         ;; Everything after, we save, to combine with later input.
+         (setq gud-marker-acc
+               (substring gud-marker-acc (match-beginning 0))))
+
+       (setq output (concat output gud-marker-acc)
+           gud-marker-acc ""))
+
+     output))
+
+ (defvar octavedb-path '())
+ (defvar octavedb-init-file-locations '(~/.octaverc))
+
+ (defun octavedb-paths-from-init (init-file)
+   (switch-to-buffer (find-file init-file))
+   (keep-lines "addpath")
+   (goto-char (point-min))
+   (while (re-search-forward "addpath(\"\\(.*?\\)\".*" (point-max) nil)
+     (setq octavedb-path (cons (match-string 1) octavedb-path)))
+   ;; kill file without saving
+
+   )
+
+
+ (defun octavedb-find-file (full-paths)
+   (if (or (not full-paths) (file-regular-p (car full-paths)))
+       (car full-paths)
+     (octavedb-find-file (cdr full-paths)))
+   )
+
+ (defun gud-octavedb-find-file (f)
+   (when (not octavedb-path)
+     (setq octavedb-path (octavedb-paths-from-init "~/.octaverc")))
+   (if (file-regular-p f)
+       (set-buffer (find-file-noselect f))
+     (let* ((found-file (octavedb-find-file (mapcar (lambda (x)
(concat x "/" f)) octavedb-path))))
+       (if found-file
+         (set-buffer (find-file-noselect found-file))
+       ;; DLE: ask the user for the path
+       ;; DLE: add the path to our path list
+       (set-buffer (find-file-noselect f)))))
+   )
+
+
+
+
+ ;;;###autoload
+ (defun octavedb (command-line)
+   "Run octavedb starting with FILE
+ The directory containing FILE becomes the initial working directory
+ and source-file directory for your debugger."
+   ;;   (interactive
+   ;;    (list (read-from-minibuffer "Run which octave: "
+   ;;                         (if (consp gud-octavedb-history)
+   ;;                             (car gud-octavedb-history)
+   ;;                           gud-octavedb-command-name)
+   ;;                         nil nil
+   ;;                         '(gud-octavedb-history . 1))))
+   (setq command-line gud-octavedb-command-name)
+
+   (gud-common-init command-line 'gud-octavedb-massage-args
+                  'gud-octavedb-marker-filter 'gud-octavedb-find-file)
+
+   ;; DLE: try to add temporary break point
+   (gud-def gud-break  "dbstop(\"%f\",%l)"  "\C-b" "Set breakpoint at
current line.")
+   (gud-def gud-remove "dbclear(\"%f\",%l)"  "\C-d" "Remove
breakpoint at current line")
+   (gud-def gud-step   "dbstep"      "\C-s" "Step one source line
with display.")
+   (gud-def gud-next   "dbnext"      "\C-n" "Step one line (skip functions).")
+   (gud-def gud-cont   "dbcont"         "\C-r" "Continue with display.")
+
+   (setq comint-prompt-regexp "debug>\\|>>")
+   (setq paragraph-start comint-prompt-regexp)
+   (run-hooks 'octavedb-mode-hook)
+   )

  ;; When we send a command to the debugger via gud-call, it's annoying
  ;; to see the command and the new prompt inserted into the debugger's

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

* Re: GUD octave support
  2007-11-18  5:42 GUD octave support Daniel Elliott
@ 2007-11-18 10:42 ` Nick Roberts
  2007-11-18 11:04   ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Roberts @ 2007-11-18 10:42 UTC (permalink / raw)
  To: Daniel Elliott; +Cc: Kurt Hornik, emacs-devel


 > This is my first crack at adding octave support in GUD.  It still
 > needs to have some of the features from the octave-inf mode included
 > if possible within the GUD framework.
 > 
 > It is a little rough, but appears to be stable and robust.
 > 
 > original is the version supplied debian (etch, i beleive)

I think Debian Etch uses Emacs 21.3 and gud.el has changed significantly
since then.  Your patch looks good but you will need to checkout Emacs from
the CVS repository (http://savannah.gnu.org/projects/emacs/) to submit
improvements.

 > + (defvar gud-octavedb-command-name "octave")

Use defcustom here:

(defcustom gud-octavedb-command-name
  "octave -i --no-line-editing -q --traditional"
  "Default command to execute an Octave script under debugger."
  :type 'string
  :group 'gud
  :version "22.2")

 > + ;;; History of argument lists passed to octavedb
 > + (defvar gud-octavedb-history nil)

Do you need massage-args, or can they just be included in the command-name as
above?

 > + (defun gud-octavedb-massage-args (file args)
 > +   ;; just use the default arguments from octave-inf
 > +   '("-i" "--no-line-editing" "-q" "--traditional"))
 > +
 > + (setq gud-octavedb-marker-regexp
 > +       "keyboard: stopped in\s\\(.*\\)\sat line \\([0-9]+\\)")

Use defvar here:

(defvar gud-octavedb-marker-regexp
      "keyboard: stopped in\s\\(.*\\)\sat line \\([0-9]+\\)")

 > + (defun gud-octavedb-marker-filter (string)
 > +
 > +   (setq gud-marker-acc (concat gud-marker-acc string))
 > +   (let ((output ""))
 > +
 > +
 > +     ;; Process all the complete markers in this chunk.
 > +     (while (string-match gud-octavedb-marker-regexp gud-marker-acc)
 > +       (setq
 > +
 > +        ;; Extract the frame position from the marker.
 > +        gud-last-frame
 > +        (cons (match-string 1 gud-marker-acc)
 > +            (string-to-number (match-string 2 gud-marker-acc)))
 > +
 > +        ;; Append any text before the marker to the output we're going
 > +        ;; to return - we don't include the marker in this text.
 > +        output (concat output
 > +                     (substring gud-marker-acc 0 (match-beginning 0)))
 > +        ;; Set the accumulator to the remaining text.
 > +        gud-marker-acc (substring gud-marker-acc (match-end 0))))
 > +
 > +     ;; Does the remaining text look like it might end with the
 > +     ;; beginning of another marker?  If it does, then keep it in
 > +     ;; gud-marker-acc until we receive the rest of it.  Since we
 > +     ;; know the full marker regexp above failed, it's pretty simple to
 > +     ;; test for marker starts.
 > +
 > +     ;; DLE: i doubt this is applicable to octave's debug mode

You don't need to match "\032.*\\'" but there may be a problem if
gud-octavedb-marker-regexp is split between chunks of output though.
Let's ignore that for now.

 > +     (if (string-match "\032.*\\'" gud-marker-acc)
 > +       (progn
 > +         ;; Everything before the potential marker start can be output.
 > +         (setq output (concat output (substring gud-marker-acc
 > +                                                0 (match-beginning 0))))
 > +
 > +         ;; Everything after, we save, to combine with later input.
 > +         (setq gud-marker-acc
 > +               (substring gud-marker-acc (match-beginning 0))))
 > +
 > +       (setq output (concat output gud-marker-acc)
 > +           gud-marker-acc ""))
 > +
 > +     output))

Just

     (setq output (concat output gud-marker-acc)
           gud-marker-acc ""))

     output))

should do.

 > + (defvar octavedb-path '())
 > + (defvar octavedb-init-file-locations '(~/.octaverc))

If it's a list, call it one.  Also this is presumably customisable.

(defcustom octavedb-init-file-list '(~/.octaverc)
   "List of...")

 > + (defun octavedb-paths-from-init (init-file)
 > +   (switch-to-buffer (find-file init-file))
 > +   (keep-lines "addpath")
 > +   (goto-char (point-min))
 > +   (while (re-search-forward "addpath(\"\\(.*?\\)\".*" (point-max) nil)
 > +     (setq octavedb-path (cons (match-string 1) octavedb-path)))


This looks a bit flakey.  Does Octave use an environment variable for the
path too?

 > +   ;; kill file without saving
 > +

A left over comment?

 > +   )
 > +

Please put this brace on the same line as the previous one and leave just one
space between functions.

 > +
 > + (defun octavedb-find-file (full-paths)
 > +   (if (or (not full-paths) (file-regular-p (car full-paths)))
 > +       (car full-paths)
 > +     (octavedb-find-file (cdr full-paths)))

Ditto (brace).

 > +   )
 > +
 > + (defun gud-octavedb-find-file (f)
 > +   (when (not octavedb-path)
 > +     (setq octavedb-path (octavedb-paths-from-init "~/.octaverc")))
 > +   (if (file-regular-p f)
 > +       (set-buffer (find-file-noselect f))
 > +     (let* ((found-file (octavedb-find-file (mapcar (lambda (x)
 > (concat x "/" f)) octavedb-path))))
 > +       (if found-file
 > +         (set-buffer (find-file-noselect found-file))
 > +       ;; DLE: ask the user for the path
 > +       ;; DLE: add the path to our path list
 > +       (set-buffer (find-file-noselect f)))))

Ditto.

 > +   )
 > +
 > +
 > +
 > +
 > + ;;;###autoload
 > + (defun octavedb (command-line)
 > +   "Run octavedb starting with FILE
 > + The directory containing FILE becomes the initial working directory
 > + and source-file directory for your debugger."
 > +   ;;   (interactive
 > +   ;;    (list (read-from-minibuffer "Run which octave: "
 > +   ;;                         (if (consp gud-octavedb-history)
 > +   ;;                             (car gud-octavedb-history)
 > +   ;;                           gud-octavedb-command-name)
 > +   ;;                         nil nil
 > +   ;;                         '(gud-octavedb-history . 1))))

This should presumably be uncommented.  Why not just:

  (interactive (list (gud-query-cmdline 'octavedb)))

 > +   (setq command-line gud-octavedb-command-name)
 > +
 > +   (gud-common-init command-line 'gud-octavedb-massage-args
 > +                  'gud-octavedb-marker-filter 'gud-octavedb-find-file)

If massage-args aren't needed:

  (gud-common-init command-line nil 'gud-octavedb-marker-filter
                   'gud-octavedb-find-file)

 > +   ;; DLE: try to add temporary break point
 > +   (gud-def gud-break  "dbstop(\"%f\",%l)"  "\C-b" "Set breakpoint at
 > current line.")
 > +   (gud-def gud-remove "dbclear(\"%f\",%l)"  "\C-d" "Remove
 > breakpoint at current line")
 > +   (gud-def gud-step   "dbstep"      "\C-s" "Step one source line
 > with display.")
 > +   (gud-def gud-next   "dbnext"      "\C-n" "Step one line (skip functions).")
 > +   (gud-def gud-cont   "dbcont"         "\C-r" "Continue with display.")
 > +
 > +   (setq comint-prompt-regexp "debug>\\|>>")
 > +   (setq paragraph-start comint-prompt-regexp)
 > +   (run-hooks 'octavedb-mode-hook)
 > +   )

When I tried M-x octavedb and gave it a script as an argument:

Run octavedb (like this): octave -i --no-line-editing -q --traditional example.m

it just ran the script.  How does octavedb allow the user to stop and step
through lines?

I think this should be included in Emacs 22 when all issues have been
addressed.  Thanks for your contribution.


-- 
Nick                                           http://www.inet.net.nz/~nickrob

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

* Re: GUD octave support
  2007-11-18 10:42 ` Nick Roberts
@ 2007-11-18 11:04   ` Andreas Schwab
  2007-11-18 19:48     ` Nick Roberts
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2007-11-18 11:04 UTC (permalink / raw)
  To: Nick Roberts; +Cc: Daniel Elliott, emacs-devel, Kurt Hornik

Nick Roberts <nickrob@snap.net.nz> writes:

>  > + (defvar octavedb-path '())
>  > + (defvar octavedb-init-file-locations '(~/.octaverc))
>
> If it's a list, call it one.  Also this is presumably customisable.
>
> (defcustom octavedb-init-file-list '(~/.octaverc)
>    "List of...")

The variable appears to be unused, and I don't see how a list of symbols
would be a useful value here anyway.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: GUD octave support
  2007-11-18 11:04   ` Andreas Schwab
@ 2007-11-18 19:48     ` Nick Roberts
  2007-11-18 20:16       ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Roberts @ 2007-11-18 19:48 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Daniel Elliott, emacs-devel, Kurt Hornik

 > > If it's a list, call it one.  Also this is presumably customisable.
 > >
 > > (defcustom octavedb-init-file-list '(~/.octaverc)
 > >    "List of...")
 > 
 > The variable appears to be unused, and I don't see how a list of symbols
 > would be a useful value here anyway.

Presumably it should be used in gud-octavedb-find-file.  Octave must
store this information internally.  Perhaps the best thing to do would
be to contact the author of Octave and ask him if he's willing to add
a "--fullname" option like GDB has, so that instead of the db* commands
outputting something like:

keyboard: stopped in example.m at line 4

they output something like:

^Z^Z/home/nickrob/octave/example.m:4

-- 
Nick                                           http://www.inet.net.nz/~nickrob

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

* Re: GUD octave support
  2007-11-18 19:48     ` Nick Roberts
@ 2007-11-18 20:16       ` Tom Tromey
  2007-11-18 23:18         ` Nick Roberts
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2007-11-18 20:16 UTC (permalink / raw)
  To: Nick Roberts; +Cc: Andreas Schwab, emacs-devel, Kurt Hornik, Daniel Elliott

>>>>> "Nick" == Nick Roberts <nickrob@snap.net.nz> writes:

Nick> Perhaps the best thing to do would
Nick> be to contact the author of Octave and ask him if he's willing to add
Nick> a "--fullname" option like GDB has

This reminds me of a different problem I've seen with gud and gdb.

GCC has several files that have the same base name.  If I use C-x SPC
to set a breakpoint in one of these, sometimes the breakpoint will
wind up in the wrong file.

I think this could be fixed by changing the gud-break binding in
gud-gdb from "break %f:%l" to "break %d%f:%l".

Tom

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

* Re: GUD octave support
  2007-11-18 20:16       ` Tom Tromey
@ 2007-11-18 23:18         ` Nick Roberts
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Roberts @ 2007-11-18 23:18 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Andreas Schwab, emacs-devel

 > This reminds me of a different problem I've seen with gud and gdb.
 > 
 > GCC has several files that have the same base name.  If I use C-x SPC
 > to set a breakpoint in one of these, sometimes the breakpoint will
 > wind up in the wrong file.

If you run GDB from the command line, does it DTRT? (I don't think it does)

 > I think this could be fixed by changing the gud-break binding in
 > gud-gdb from "break %f:%l" to "break %d%f:%l".

I see that M-x dbx does this, and perhaps gud-tbreak, gud-remove and
gud-tbreak should be changed too, but I think GDB needs to be fixed first.

I guess another solution is for GCC not to use files with the same name, which
can presumably lead to confusion elsewhere too.

-- 
Nick                                           http://www.inet.net.nz/~nickrob

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

end of thread, other threads:[~2007-11-18 23:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-18  5:42 GUD octave support Daniel Elliott
2007-11-18 10:42 ` Nick Roberts
2007-11-18 11:04   ` Andreas Schwab
2007-11-18 19:48     ` Nick Roberts
2007-11-18 20:16       ` Tom Tromey
2007-11-18 23:18         ` Nick Roberts

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.