From: Leo Liu Date: Fri, 26 Apr 2013 16:44:38 +0000 (+0800) Subject: * progmodes/octave.el (octave-sync-function-file-names): New function. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2026^2~359^2~5 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e55d3b0408c33aef72cddb6076617dacbf9ea4c0;p=emacs.git * progmodes/octave.el (octave-sync-function-file-names): New function. (octave-mode): Use it in before-save-hook. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 290f23a3550..f57bf838cd5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-04-26 Leo Liu + + * progmodes/octave.el (octave-sync-function-file-names): New function. + (octave-mode): Use it in before-save-hook. + 2013-04-26 Stefan Monnier * emacs-lisp/tabulated-list.el (tabulated-list-mode): Disable undo diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index c5f83a50654..3c24205eb8e 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -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)))))) + ;;; Indentation