emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master d9d5b2b 2/2: * lisp/progmodes/octave.el: Register o


From: Stefan Monnier
Subject: [Emacs-diffs] master d9d5b2b 2/2: * lisp/progmodes/octave.el: Register on auto-mode-alist
Date: Mon, 15 Oct 2018 21:24:20 -0400 (EDT)

branch: master
commit d9d5b2b7af69ff4697ab0be8e9c4a83e06eb8367
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * lisp/progmodes/octave.el: Register on auto-mode-alist
    
    (octave-maybe-mode): New function.
---
 etc/NEWS                 |  4 ++++
 lisp/progmodes/octave.el | 25 +++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 946a823..b46dcae 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 984bb73..13510ee 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]