]> git.eshelyaron.com Git - emacs.git/commitdiff
* progmodes/octave.el (octave-sync-function-file-names): New function.
authorLeo Liu <sdl.web@gmail.com>
Fri, 26 Apr 2013 16:44:38 +0000 (00:44 +0800)
committerLeo Liu <sdl.web@gmail.com>
Fri, 26 Apr 2013 16:44:38 +0000 (00:44 +0800)
(octave-mode): Use it in before-save-hook.

lisp/ChangeLog
lisp/progmodes/octave.el

index 290f23a355057794a3de3bfc6e56c95e321a3309..f57bf838cd5ed1db65fc436d3465d4d10688491f 100644 (file)
@@ -1,3 +1,8 @@
+2013-04-26  Leo Liu  <sdl.web@gmail.com>
+
+       * progmodes/octave.el (octave-sync-function-file-names): New function.
+       (octave-mode): Use it in before-save-hook.
+
 2013-04-26  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * emacs-lisp/tabulated-list.el (tabulated-list-mode): Disable undo
index c5f83a5065449f50b6c8de1aefa30de8ccac206a..3c24205eb8ef8e1d99b5dc841836ac49851c5aef 100644 (file)
@@ -626,6 +626,7 @@ including a reproducible test case and send the message."
 
   (add-hook 'completion-at-point-functions
             'octave-completion-at-point-function nil t)
+  (add-hook 'before-save-hook 'octave-sync-function-file-names nil t)
   (setq-local beginning-of-defun-function 'octave-beginning-of-defun)
 
   (easy-menu-add octave-mode-menu))
@@ -1008,6 +1009,26 @@ directory and makes this the current buffer's default directory."
       nil
     (delete-horizontal-space)
     (insert (concat " " octave-continuation-string))))
+
+(defun octave-sync-function-file-names ()
+  "Ensure function name agree with function file name.
+See Info node `(octave)Function Files'."
+  (interactive)
+  (save-excursion
+    (when (and buffer-file-name
+               (prog2
+                   (goto-char (point-min))
+                   (equal (funcall smie-forward-token-function) "function")
+                 (forward-word -1)))
+      (let ((file (file-name-sans-extension
+                   (file-name-nondirectory buffer-file-name)))
+            (func (and (re-search-forward octave-function-header-regexp nil t)
+                       (match-string 3))))
+        (when (and (not (equal file func))
+                   (yes-or-no-p
+                    "Function name different from file name. Fix? "))
+          (replace-match file nil nil nil 3))))))
+
 \f
 ;;; Indentation