emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] octave.el: Go to error in inferior-octave.


From: Rüdiger Sonderfeld
Subject: [PATCH 3/3] octave.el: Go to error in inferior-octave.
Date: Wed, 02 Oct 2013 22:39:17 +0200
User-agent: KMail/4.10.5 (Linux/3.8.0-30-generic; KDE/4.10.5; x86_64; ; )

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]