unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH 3/3] octave.el: Go to error in inferior-octave.
@ 2013-10-02 20:39 Rüdiger Sonderfeld
  2013-10-03  3:57 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Rüdiger Sonderfeld @ 2013-10-02 20:39 UTC (permalink / raw)
  To: emacs-devel; +Cc: Leo Liu

Some Octave error messages contain location information.
See (info "(octave) Errors").  This patch buttonizes the location
information and provides an easy way to jump to the source of the
problem.  It modifies the keymap to provide support for the buttons.

* lisp/progmodes/octave.el (inferior-octave-mode-map): Support
  buttons.
  (inferior-octave--mouse-2): New function.
   (inferior-octave--ret): New function.
  (inferior-octave-font-lock-keywords): Buttonize error messages with
  location.
  (inferior-octave-goto-error): New function.
---
 lisp/progmodes/octave.el | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index 4a17258..53fa09b 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -640,6 +640,8 @@ (defvar inferior-octave-mode-map
     (define-key map "\t" 'completion-at-point)
     (define-key map "\C-hd" 'octave-help)
     (define-key map "\C-ha" 'octave-lookfor)
+    (define-key map [mouse-2] 'inferior-octave--mouse-2)
+    (define-key map "\C-m" 'inferior-octave--ret)
     ;; Same as in `shell-mode'.
     (define-key map "\M-?" 'comint-dynamic-list-filename-completions)
     (define-key map "\C-c\C-l" 'inferior-octave-dynamic-list-input-ring)
@@ -648,6 +650,21 @@ (defvar inferior-octave-mode-map
     map)
   "Keymap used in Inferior Octave mode.")
 
+(defun inferior-octave--mouse-2 (event)
+  "Call `push-button' if EVENT is on a button else `comint-insert-input'."
+  (interactive "e")
+  (let ((pt (posn-point (event-end event))))
+    (if (button-at pt)
+        (push-button pt)
+      (comint-insert-input event))))
+
+(defun inferior-octave--ret ()
+  "Call `push-button' if `point' is on a button else `comint-send-input'."
+  (interactive)
+  (if (button-at (point))
+      (push-button)
+    (comint-send-input)))
+
 (defvar inferior-octave-mode-syntax-table
   (let ((table (make-syntax-table octave-mode-syntax-table)))
     table)
@@ -665,6 +682,15 @@ (defface inferior-octave-warning-face '((t :inherit warning))
 
 (defvar inferior-octave-font-lock-keywords
   '(("^\\(?:parse \\)?error:" . 'inferior-octave-error-face)
+    ("^error:[[:blank:]]*\\([^[:blank:]]+ at line.*\\)"
+     (1 '(face button
+               button (t)
+               action (lambda (b)
+                        (inferior-octave--goto-error
+                         (buffer-substring (button-start b)
+                                           (button-end b))))
+               help-echo "mouse-2 or C-m to go to error location"
+               follow-link t)))
     ("^warning:" . 'inferior-octave-warning-face))
   ;; Could certainly do more font locking in inferior Octave ...
   "Additional expressions to highlight in Inferior Octave mode.")
@@ -1793,5 +1819,20 @@ (defun octave-find-definition (fn)
             (find-file file)
             (octave-goto-function-definition fn)))))))
 
+(defun inferior-octave--goto-error (error-msg)
+  "Go to error described in ERROR-MSG."
+  (when (string-match "\\([^[:blank:]]+\\) at line\
+ \\([[:digit:]]\\)+, column \\([[:digit:]]\\)+" error-msg)
+    (let ((fn (match-string 1 error-msg))
+          (line (string-to-number (match-string 2 error-msg)))
+          (column (string-to-number (match-string 3 error-msg))))
+      ;; fn is either a file or function name.
+      (if (and (string-prefix-p "/" fn) (file-exists-p fn))
+          (find-file fn)
+        (octave-find-definition fn))
+      (goto-char (point-min))
+      (forward-line (1- line))
+      (forward-char column))))
+
 (provide 'octave)
 ;;; octave.el ends here
-- 
1.8.4




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

end of thread, other threads:[~2013-10-04 10:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-02 20:39 [PATCH 3/3] octave.el: Go to error in inferior-octave Rüdiger Sonderfeld
2013-10-03  3:57 ` Stefan Monnier
2013-10-03  4:07   ` Leo Liu
2013-10-03 13:39     ` Rüdiger Sonderfeld
2013-10-04 10:04       ` Leo Liu

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).