]> git.eshelyaron.com Git - emacs.git/commitdiff
* progmodes/octave.el (octave-goto-function-definition): Improve
authorLeo Liu <sdl.web@gmail.com>
Wed, 15 May 2013 08:17:22 +0000 (16:17 +0800)
committerLeo Liu <sdl.web@gmail.com>
Wed, 15 May 2013 08:17:22 +0000 (16:17 +0800)
and fix callers.

lisp/ChangeLog
lisp/progmodes/octave.el

index 6c5de802fd50254090f4c2062d58abafc6185fad..ffcd36f4af12a7d8114a6e42c33e0abd7051c42f 100644 (file)
@@ -1,3 +1,8 @@
+2013-05-15  Leo Liu  <sdl.web@gmail.com>
+
+       * progmodes/octave.el (octave-goto-function-definition): Improve
+       and fix callers.
+
 2013-05-15  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * emacs-lisp/cl-extra.el (cl-getf): Return the proper value in
index 2fd2aadfc99e732c29a5a41b103c8731a4ce3fac..49c9c30d313ef76e33f620192b02779f09bce3ca 100644 (file)
@@ -928,13 +928,21 @@ directory and makes this the current buffer's default directory."
      inferior-octave-completion-table
      nil nil nil nil def)))
 
-(defun octave-goto-function-definition ()
-  "Go to the first function definition."
+(defun octave-goto-function-definition (fn)
+  "Go to the function definition of FN in current buffer."
   (goto-char (point-min))
-  (if (not (re-search-forward octave-function-header-regexp nil t))
-      (forward-comment (point-max))
-    (goto-char (match-beginning 3))
-    (match-string 3)))
+  (let ((search
+         (lambda (re sub)
+           (let (done)
+             (while (and (not done) (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)))))))
+    (pcase (file-name-extension (buffer-file-name))
+      (`"cc" (funcall search
+                      "\\_<DEFUN\\s-*(\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)" 1))
+      (t (funcall search octave-function-header-regexp 3)))))
 
 (defun octave-function-file-p ()
   "Return non-nil if the first token is \"function\".
@@ -1686,7 +1694,7 @@ if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n"
       (setq file (funcall octave-find-definition-filename-function file))
       (when file
         (find-file file)
-        (octave-goto-function-definition)))))
+        (octave-goto-function-definition fn)))))
 
 
 (provide 'octave)