From: "Rüdiger Sonderfeld" <ruediger@c-plusplus.de>
To: emacs-devel@gnu.org
Cc: Leo Liu <sdl.web@gmail.com>
Subject: [PATCH 3/3] octave.el: Go to error in inferior-octave.
Date: Wed, 02 Oct 2013 22:39:17 +0200 [thread overview]
Message-ID: <1542085.GCVjMo2CM9@descartes> (raw)
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
next reply other threads:[~2013-10-02 20:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-02 20:39 Rüdiger Sonderfeld [this message]
2013-10-03 3:57 ` [PATCH 3/3] octave.el: Go to error in inferior-octave Stefan Monnier
2013-10-03 4:07 ` Leo Liu
2013-10-03 13:39 ` Rüdiger Sonderfeld
2013-10-04 10:04 ` Leo Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1542085.GCVjMo2CM9@descartes \
--to=ruediger@c-plusplus.de \
--cc=emacs-devel@gnu.org \
--cc=sdl.web@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).