From fda741250bda7dc2e93378ab548ad95c7d02af86 Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Sat, 8 Jun 2013 21:35:55 +0800 Subject: [PATCH] * progmodes/octave.el (octave-add-log-current-defun): New function. (octave-mode): Set add-log-current-defun-function. (octave-goto-function-definition): Do not move point if not found. (octave-find-definition): Enhance to try subfunctions first. --- lisp/ChangeLog | 7 +++++ lisp/progmodes/octave.el | 68 ++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4e02c72d984..18ea431a7df 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-06-08 Leo Liu + + * progmodes/octave.el (octave-add-log-current-defun): New function. + (octave-mode): Set add-log-current-defun-function. + (octave-goto-function-definition): Do not move point if not found. + (octave-find-definition): Enhance to try subfunctions first. + 2013-06-08 Glenn Morris * emacs-lisp/bytecomp.el (byte-compile-char-before) diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index 5281af60b5d..aaf723f8a8b 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -564,6 +564,8 @@ definitions can also be stored in files and used in batch mode." (setq-local imenu-generic-expression octave-mode-imenu-generic-expression) (setq-local imenu-case-fold-search nil) + (setq-local add-log-current-defun-function #'octave-add-log-current-defun) + (add-hook 'completion-at-point-functions 'octave-completion-at-point nil t) (add-hook 'before-save-hook 'octave-sync-function-file-names nil t) (setq-local beginning-of-defun-function 'octave-beginning-of-defun) @@ -977,15 +979,16 @@ directory and makes this the current buffer's default directory." (defun octave-goto-function-definition (fn) "Go to the function definition of FN in current buffer." - (goto-char (point-min)) (let ((search (lambda (re sub) - (let (done) - (while (and (not done) (re-search-forward re nil t)) + (let ((orig (point)) found) + (goto-char (point-min)) + (while (and (not found) (re-search-forward re nil t)) (when (and (equal (match-string sub) fn) (not (nth 8 (syntax-ppss)))) - (setq done t))) - (or done (goto-char (point-min))))))) + (setq found t))) + (unless found (goto-char orig)) + found)))) (pcase (file-name-extension (buffer-file-name)) (`"cc" (funcall search "\\_ str \n _ \n "endfunction" > \n) - + ;;; Communication with the inferior Octave process (defun octave-kill-process () "Kill inferior Octave process and its buffer." @@ -1703,26 +1714,29 @@ If the environment variable OCTAVE_SRCDIR is set, it is searched first." Functions implemented in C++ can be found if `octave-source-directories' is set correctly." (interactive (list (octave-completing-read))) - (inferior-octave-send-list-and-digest - ;; help NAME is more verbose - (list (format "\ + (require 'etags) + (let ((orig (point))) + (if (octave-goto-function-definition fn) + (ring-insert find-tag-marker-ring (copy-marker orig)) + (inferior-octave-send-list-and-digest + ;; help NAME is more verbose + (list (format "\ if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n" - fn fn fn))) - (let (line file) - ;; Skip garbage lines such as - ;; warning: fmincg.m: possible Matlab-style .... - (while (and (not file) (consp inferior-octave-output-list)) - (setq line (pop inferior-octave-output-list)) - (when (string-match "from the file \\(.*\\)$" line) - (setq file (match-string 1 line)))) - (if (not file) - (user-error "%s" (or line (format "`%s' not found" fn))) - (require 'etags) - (ring-insert find-tag-marker-ring (point-marker)) - (setq file (funcall octave-find-definition-filename-function file)) - (when file - (find-file file) - (octave-goto-function-definition fn))))) + fn fn fn))) + (let (line file) + ;; Skip garbage lines such as + ;; warning: fmincg.m: possible Matlab-style .... + (while (and (not file) (consp inferior-octave-output-list)) + (setq line (pop inferior-octave-output-list)) + (when (string-match "from the file \\(.*\\)$" line) + (setq file (match-string 1 line)))) + (if (not file) + (user-error "%s" (or line (format "`%s' not found" fn))) + (ring-insert find-tag-marker-ring (point-marker)) + (setq file (funcall octave-find-definition-filename-function file)) + (when file + (find-file file) + (octave-goto-function-definition fn))))))) (provide 'octave) -- 2.39.2