all messages for Emacs-related lists mirrored at yhetil.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

* Re: [PATCH 3/3] octave.el: Go to error in inferior-octave.
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2013-10-03  3:57 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: Leo Liu, emacs-devel

> Some Octave error messages contain location information.

The way to do that is to use compilation-shell-minor-mode.
See how it's used in prolog.el, for example,


        Stefan



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

* Re: [PATCH 3/3] octave.el: Go to error in inferior-octave.
  2013-10-03  3:57 ` Stefan Monnier
@ 2013-10-03  4:07   ` Leo Liu
  2013-10-03 13:39     ` Rüdiger Sonderfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Leo Liu @ 2013-10-03  4:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Rüdiger Sonderfeld, emacs-devel@gnu.org

On 2013年10月3日, at 11:57, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> The way to do that is to use compilation-shell-minor-mode.
> See how it's used in prolog.el, for example,
> 
> 
>        Stefan

Agree I have that in my local copy and will commit ASAP. - Leo

Sent from my iPhone 4S


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

* Re: [PATCH 3/3] octave.el: Go to error in inferior-octave.
  2013-10-03  4:07   ` Leo Liu
@ 2013-10-03 13:39     ` Rüdiger Sonderfeld
  2013-10-04 10:04       ` Leo Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Rüdiger Sonderfeld @ 2013-10-03 13:39 UTC (permalink / raw)
  To: Leo Liu; +Cc: Stefan Monnier, emacs-devel@gnu.org

On Thursday 03 October 2013 12:07:55 Leo Liu wrote:
> On 2013年10月3日, at 11:57, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> > The way to do that is to use compilation-shell-minor-mode.
> > See how it's used in prolog.el, for example,
> > 
> >        Stefan
> 
> Agree I have that in my local copy and will commit ASAP. - Leo
> 
> Sent from my iPhone 4S


Oh, I was looking for something like `compilation-shell-minor-mode' yesterday 
but must have missed it.  This should probably make patches 1 and 3 obsolete.  
But I think patch 2 is still valid.  Comint is already having highlight for 
the prompt and adding our own highlight in octave.el is not necessary and just 
confusing.

Regards,
Rüdiger




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

* Re: [PATCH 3/3] octave.el: Go to error in inferior-octave.
  2013-10-03 13:39     ` Rüdiger Sonderfeld
@ 2013-10-04 10:04       ` Leo Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Leo Liu @ 2013-10-04 10:04 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: Stefan Monnier, emacs-devel@gnu.org

I have committed the patch to use `compilation-shell-minor-mode' please
give it a try. Thanks.

On 2013-10-03 21:39 +0800, Rüdiger Sonderfeld wrote:
> Oh, I was looking for something like `compilation-shell-minor-mode' yesterday 
> but must have missed it.  This should probably make patches 1 and 3 obsolete.  
> But I think patch 2 is still valid.  Comint is already having highlight for 
> the prompt and adding our own highlight in octave.el is not necessary and just 
> confusing.

The small prompt font-lock by inferior-octave shouldn't be a problem
because it will have effect only on prompts of past inputs. BTW, seems
stop working that way in trunk.

Leo



^ permalink raw reply	[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 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.