Function: octave-maybe-mode

octave-maybe-mode is an autoloaded and byte-compiled function defined in octave.el.gz.

Signature

(octave-maybe-mode)

Documentation

Select octave-mode if the current buffer seems to hold Octave code.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/octave.el.gz
;; 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))))))