From: Stefan Monnier Date: Tue, 16 Oct 2018 01:24:14 +0000 (-0400) Subject: * lisp/progmodes/octave.el: Register on auto-mode-alist X-Git-Tag: emacs-27.0.90~4291 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d9d5b2b7af69ff4697ab0be8e9c4a83e06eb8367;p=emacs.git * lisp/progmodes/octave.el: Register on auto-mode-alist (octave-maybe-mode): New function. --- diff --git a/etc/NEWS b/etc/NEWS index 946a823173a..b46dcae9c23 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -287,6 +287,10 @@ in (info "(emacs) Directory Variables") * Changes in Specialized Modes and Packages in Emacs 27.1 +** Octave mode +The mode is automatically enabled in files that start with the +'function' keyword. + ** project.el *** New commands project-search and project-query-replace diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index 984bb73c73e..13510eef805 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -170,8 +170,8 @@ parenthetical grouping.") (modify-syntax-entry ?. "." table) (modify-syntax-entry ?\" "\"" table) (modify-syntax-entry ?_ "_" table) - ;; The "b" flag only applies to the second letter of the comstart - ;; and the first letter of the comend, i.e. the "4b" below is ineffective. + ;; The "b" flag only applies to the second letter of the comstart and + ;; the first letter of the comend, i.e. a "4b" below would be ineffective. ;; If we try to put `b' on the single-line comments, we get a similar ;; problem where the % and # chars appear as first chars of the 2-char ;; comend, so the multi-line ender is also turned into style-b. @@ -533,6 +533,27 @@ Non-nil means always go to the next Octave code line after sending." (defvar electric-layout-rules) +;; FIXME: cc-mode.el also adds an entry for .m files, mapping them to +;; objc-mode. We here rely on the fact that loaddefs.el is filled in +;; alphabetical order, so cc-mode.el comes before octave-mode.el, which lets +;; our entry come first! +;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . octave-maybe-mode)) + +;;;###autoload +(defun octave-maybe-mode () + "Select `octave-mode' if the current buffer seems to hold Octave code." + (if (save-excursion + (with-syntax-table octave-mode-syntax-table + (goto-char (point-min)) + (forward-comment (point-max)) + ;; FIXME: What about Octave files which don't start with "function"? + (looking-at "function"))) + (octave-mode) + (let ((x (rassq 'octave-maybe-mode auto-mode-alist))) + (when x + (let ((auto-mode-alist (remove x auto-mode-alist))) + (set-auto-mode)))))) + ;;;###autoload (define-derived-mode octave-mode prog-mode "Octave" "Major mode for editing Octave code.