From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?R=FCdiger?= Sonderfeld Newsgroups: gmane.emacs.devel Subject: [PATCH 3/3] octave.el: Go to error in inferior-octave. Date: Wed, 02 Oct 2013 22:39:17 +0200 Message-ID: <1542085.GCVjMo2CM9@descartes> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: ger.gmane.org 1380747180 4807 80.91.229.3 (2 Oct 2013 20:53:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Oct 2013 20:53:00 +0000 (UTC) Cc: Leo Liu To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 02 22:53:02 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VRTPq-0008MM-7C for ged-emacs-devel@m.gmane.org; Wed, 02 Oct 2013 22:53:02 +0200 Original-Received: from localhost ([::1]:38284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRTPp-0008Qv-SJ for ged-emacs-devel@m.gmane.org; Wed, 02 Oct 2013 16:53:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRTCl-00061Z-Cm for emacs-devel@gnu.org; Wed, 02 Oct 2013 16:39:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VRTCc-0000Mm-KG for emacs-devel@gnu.org; Wed, 02 Oct 2013 16:39:31 -0400 Original-Received: from ptmx.org ([178.63.28.110]:59676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRTCc-0000Me-9u for emacs-devel@gnu.org; Wed, 02 Oct 2013 16:39:22 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by ptmx.org (Postfix) with ESMTP id B33962AC6B; Wed, 2 Oct 2013 22:39:21 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at ptmx.org Original-Received: from ptmx.org ([127.0.0.1]) by localhost (ptmx.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A2PtvzfNNtwZ; Wed, 2 Oct 2013 22:39:19 +0200 (CEST) Original-Received: from descartes.localnet (chello080108246092.7.14.vie.surfer.at [80.108.246.92]) by ptmx.org (Postfix) with ESMTPSA id 951752ABFC; Wed, 2 Oct 2013 22:39:19 +0200 (CEST) User-Agent: KMail/4.10.5 (Linux/3.8.0-30-generic; KDE/4.10.5; x86_64; ; ) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 178.63.28.110 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:163814 Archived-At: 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