+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
(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))
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