aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu2013-06-08 21:35:55 +0800
committerLeo Liu2013-06-08 21:35:55 +0800
commitfda741250bda7dc2e93378ab548ad95c7d02af86 (patch)
tree18705ee91481b423c64de41609354bb2364fc329
parent5de0e0116411d36673ee3eeeb1d207f25c0d4b95 (diff)
downloademacs-fda741250bda7dc2e93378ab548ad95c7d02af86.tar.gz
emacs-fda741250bda7dc2e93378ab548ad95c7d02af86.zip
* 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.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/progmodes/octave.el68
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 @@
12013-06-08 Leo Liu <sdl.web@gmail.com>
2
3 * progmodes/octave.el (octave-add-log-current-defun): New function.
4 (octave-mode): Set add-log-current-defun-function.
5 (octave-goto-function-definition): Do not move point if not found.
6 (octave-find-definition): Enhance to try subfunctions first.
7
12013-06-08 Glenn Morris <rgm@gnu.org> 82013-06-08 Glenn Morris <rgm@gnu.org>
2 9
3 * emacs-lisp/bytecomp.el (byte-compile-char-before) 10 * 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."
564 (setq-local imenu-generic-expression octave-mode-imenu-generic-expression) 564 (setq-local imenu-generic-expression octave-mode-imenu-generic-expression)
565 (setq-local imenu-case-fold-search nil) 565 (setq-local imenu-case-fold-search nil)
566 566
567 (setq-local add-log-current-defun-function #'octave-add-log-current-defun)
568
567 (add-hook 'completion-at-point-functions 'octave-completion-at-point nil t) 569 (add-hook 'completion-at-point-functions 'octave-completion-at-point nil t)
568 (add-hook 'before-save-hook 'octave-sync-function-file-names nil t) 570 (add-hook 'before-save-hook 'octave-sync-function-file-names nil t)
569 (setq-local beginning-of-defun-function 'octave-beginning-of-defun) 571 (setq-local beginning-of-defun-function 'octave-beginning-of-defun)
@@ -977,15 +979,16 @@ directory and makes this the current buffer's default directory."
977 979
978(defun octave-goto-function-definition (fn) 980(defun octave-goto-function-definition (fn)
979 "Go to the function definition of FN in current buffer." 981 "Go to the function definition of FN in current buffer."
980 (goto-char (point-min))
981 (let ((search 982 (let ((search
982 (lambda (re sub) 983 (lambda (re sub)
983 (let (done) 984 (let ((orig (point)) found)
984 (while (and (not done) (re-search-forward re nil t)) 985 (goto-char (point-min))
986 (while (and (not found) (re-search-forward re nil t))
985 (when (and (equal (match-string sub) fn) 987 (when (and (equal (match-string sub) fn)
986 (not (nth 8 (syntax-ppss)))) 988 (not (nth 8 (syntax-ppss))))
987 (setq done t))) 989 (setq found t)))
988 (or done (goto-char (point-min))))))) 990 (unless found (goto-char orig))
991 found))))
989 (pcase (file-name-extension (buffer-file-name)) 992 (pcase (file-name-extension (buffer-file-name))
990 (`"cc" (funcall search 993 (`"cc" (funcall search
991 "\\_<DEFUN\\(?:_DLD\\)?\\s-*(\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)" 1)) 994 "\\_<DEFUN\\(?:_DLD\\)?\\s-*(\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)" 1))
@@ -1347,8 +1350,6 @@ The block marked is the one that contains point or follows point."
1347 (forward-line 1)))) 1350 (forward-line 1))))
1348 t))) 1351 t)))
1349 1352
1350;;; Completions
1351
1352(defun octave-completion-at-point () 1353(defun octave-completion-at-point ()
1353 "Find the text to complete and the corresponding table." 1354 "Find the text to complete and the corresponding table."
1354 (let* ((beg (save-excursion (skip-syntax-backward "w_") (point))) 1355 (let* ((beg (save-excursion (skip-syntax-backward "w_") (point)))
@@ -1365,6 +1366,16 @@ The block marked is the one that contains point or follows point."
1365 1366
1366(define-obsolete-function-alias 'octave-complete-symbol 1367(define-obsolete-function-alias 'octave-complete-symbol
1367 'completion-at-point "24.1") 1368 'completion-at-point "24.1")
1369
1370(defun octave-add-log-current-defun ()
1371 "A function for `add-log-current-defun-function' (which see)."
1372 (save-excursion
1373 (end-of-line)
1374 (and (beginning-of-defun)
1375 (re-search-forward octave-function-header-regexp
1376 (line-end-position) t)
1377 (match-string 3))))
1378
1368 1379
1369;;; Electric characters && friends 1380;;; Electric characters && friends
1370(define-skeleton octave-insert-defun 1381(define-skeleton octave-insert-defun
@@ -1389,7 +1400,7 @@ entered without parens)."
1389 "function " > str \n 1400 "function " > str \n
1390 _ \n 1401 _ \n
1391 "endfunction" > \n) 1402 "endfunction" > \n)
1392 1403
1393;;; Communication with the inferior Octave process 1404;;; Communication with the inferior Octave process
1394(defun octave-kill-process () 1405(defun octave-kill-process ()
1395 "Kill inferior Octave process and its buffer." 1406 "Kill inferior Octave process and its buffer."
@@ -1703,26 +1714,29 @@ If the environment variable OCTAVE_SRCDIR is set, it is searched first."
1703Functions implemented in C++ can be found if 1714Functions implemented in C++ can be found if
1704`octave-source-directories' is set correctly." 1715`octave-source-directories' is set correctly."
1705 (interactive (list (octave-completing-read))) 1716 (interactive (list (octave-completing-read)))
1706 (inferior-octave-send-list-and-digest 1717 (require 'etags)
1707 ;; help NAME is more verbose 1718 (let ((orig (point)))
1708 (list (format "\ 1719 (if (octave-goto-function-definition fn)
1720 (ring-insert find-tag-marker-ring (copy-marker orig))
1721 (inferior-octave-send-list-and-digest
1722 ;; help NAME is more verbose
1723 (list (format "\
1709if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n" 1724if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n"
1710 fn fn fn))) 1725 fn fn fn)))
1711 (let (line file) 1726 (let (line file)
1712 ;; Skip garbage lines such as 1727 ;; Skip garbage lines such as
1713 ;; warning: fmincg.m: possible Matlab-style .... 1728 ;; warning: fmincg.m: possible Matlab-style ....
1714 (while (and (not file) (consp inferior-octave-output-list)) 1729 (while (and (not file) (consp inferior-octave-output-list))
1715 (setq line (pop inferior-octave-output-list)) 1730 (setq line (pop inferior-octave-output-list))
1716 (when (string-match "from the file \\(.*\\)$" line) 1731 (when (string-match "from the file \\(.*\\)$" line)
1717 (setq file (match-string 1 line)))) 1732 (setq file (match-string 1 line))))
1718 (if (not file) 1733 (if (not file)
1719 (user-error "%s" (or line (format "`%s' not found" fn))) 1734 (user-error "%s" (or line (format "`%s' not found" fn)))
1720 (require 'etags) 1735 (ring-insert find-tag-marker-ring (point-marker))
1721 (ring-insert find-tag-marker-ring (point-marker)) 1736 (setq file (funcall octave-find-definition-filename-function file))
1722 (setq file (funcall octave-find-definition-filename-function file)) 1737 (when file
1723 (when file 1738 (find-file file)
1724 (find-file file) 1739 (octave-goto-function-definition fn)))))))
1725 (octave-goto-function-definition fn)))))
1726 1740
1727 1741
1728(provide 'octave) 1742(provide 'octave)