<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0058)http://www.mathworks.com/matlabcentral/files/104/matlab.el -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY><PRE>;;; matlab.el --- major mode for MATLAB dot-m files
;;
;; Author: Matt Wette <mwette@alumni.caltech.edu>,
;; Eric M. Ludlam <eludlam@mathworks.com>
;; Maintainer: Eric M. Ludlam <eludlam@mathworks.com>
;; Created: 04 Jan 91
;; Version: 2.3.1
;; Keywords: MATLAB
;;
;; Copyright (C) 1997-2003 Eric M. Ludlam
;; Copyright (C) 1991-1997 Matthew R. Wette
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;;
;;; Commentary:
;;
;; This major mode for GNU Emacs provides support for editing MATLAB dot-m
;; files. It automatically indents for block structures, line continuations
;; (e.g., ...), and comments.
;;
;; Additional features include auto-fill including auto-additions of
;; ellipsis for commands, and even strings. Block/end construct
;; highlighting as you edit. Primitive code-verification and
;; identification. Templates and other code editing functions.
;; Advanced symbol completion. Code highlighting via font-lock.
;; There are many navigation commands that let you move across blocks
;; of code at different levels.
;;
;; Lastly, there is support for running MATLAB in an Emacs buffer,
;; with full shell history and debugger support (when used with the db
;; commands.) The shell can be used as an online help while editing
;; code, providing help on functions, variables, or running arbitrary
;; blocks of code from the buffer you are editing.
;;; Finding Updates:
;;
;; The latest stable version of matlab.el can be found on MATLAB Central:
;;
;; Catagory:
;; http://www.mathworks.com/matlabcentral/fileexchange/loadCategory.do?objectId=19&objectType=Category
;; This File
;; http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=104&objectType=file
;;
;; Older versions of matlab.el can be found in as matlab.el.1.10.1
;; for emacsen that do not have the latest additional utilities such
;; as tempo and derived.
;;; Installation:
;;
;; Put the this file as "matlab.el" somewhere on your load path, then
;; add this to your .emacs or site-init.el file:
;;
;; (autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
;; (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
;; (autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)
;;
;; User Level customizations (You need not use them all):
;; (setq matlab-indent-function t) ; if you want function bodies indented
;; (setq matlab-verify-on-save-flag nil) ; turn off auto-verify on save
;; (defun my-matlab-mode-hook ()
;; (setq fill-column 76)) ; where auto-fill should wrap
;; (add-hook 'matlab-mode-hook 'my-matlab-mode-hook)
;; (defun my-matlab-shell-mode-hook ()
;; '())
;; (add-hook 'matlab-shell-mode-hook 'my-matlab-shell-mode-hook)
;;
;; If you are using a version of MATLAB with the Desktop enabled,
;; you may need to add this:
;;
;; (setq matlab-shell-command-swithes '("-nojvm"))
;;
;; Please read the mode help for matlab-mode for additional
;; configuration options.
;;
;; Syntax highlighting:
;; To get font-lock try adding this for older emacsen:
;; (font-lock-mode 1)
;; Or for newer versions of Emacs:
;; (global-font-lock-mode t)
;; To get hilit19 support try adding:
;; (matlab-mode-hilit)
;;
;; This package requires easymenu, tempo, and derived.
;; This package will optionally use custom, shell, and gud.
;; This package supports language specific extensions in imenu, func-menu,
;; speedbar, font-lock, and hilit19.
;;; Mailing List:
;;
;; A mailing list has been set up where beta versions of matlab.el are
;; posted, and where comments, questions, bug reports, and answers to
;; questions can be sent.
;;
;; To subscribe send email to "lists@mathworks.com" with a body of:
;; "subscribe matlab-emacs"
;; to unsubscribe, send email with the body of: "unsubscribe matlab-emacs"
;;; Code:
(require 'easymenu)
(require 'tempo)
(require 'derived)
(defconst matlab-mode-version "2.3"
"Current version of MATLAB mode.")
;; From custom web page for compatibility between versions of custom:
(eval-and-compile
(condition-case ()
(require 'custom)
(error nil))
(if (and (featurep 'custom) (fboundp 'custom-declare-variable))
nil ;; We've got what we needed
;; We have the old custom-library, hack around it!
(defmacro defgroup (&rest args)
nil)
(defmacro custom-add-option (&rest args)
nil)
(defmacro defface (&rest args) nil)
(defmacro defcustom (var value doc &rest args)
(` (defvar (, var) (, value) (, doc))))))
;; compatibility
(if (string-match "X[Ee]macs" emacs-version)
(progn
(defalias 'matlab-make-overlay 'make-extent)
(defalias 'matlab-overlay-put 'set-extent-property)
(defalias 'matlab-delete-overlay 'delete-extent)
(defalias 'matlab-overlay-start 'extent-start)
(defalias 'matlab-overlay-end 'extent-end)
(defalias 'matlab-cancel-timer 'delete-itimer)
(defun matlab-run-with-idle-timer (secs repeat function &rest args)
(condition-case nil
(apply 'start-itimer
"matlab" function secs
(if repeat secs nil) t
t args)
(error
;; If the above doesn't work, then try this old version of
;; start itimer.
(start-itimer "matlab" function secs (if repeat secs nil)))))
)
(defalias 'matlab-make-overlay 'make-overlay)
(defalias 'matlab-overlay-put 'overlay-put)
(defalias 'matlab-delete-overlay 'delete-overlay)
(defalias 'matlab-overlay-start 'overlay-start)
(defalias 'matlab-overlay-end 'overlay-end)
(defalias 'matlab-cancel-timer 'cancel-timer)
(defalias 'matlab-run-with-idle-timer 'run-with-idle-timer)
)
(cond ((fboundp 'point-at-bol)
(defalias 'matlab-point-at-bol 'point-at-bol)
(defalias 'matlab-point-at-eol 'point-at-eol))
;; Emacs 20.4
((fboundp 'line-beginning-position)
(defalias 'matlab-point-at-bol 'line-beginning-position)
(defalias 'matlab-point-at-eol 'line-end-position))
(t
(defmacro matlab-point-at-bol ()
(save-excursion (beginning-of-line) (point)))
(defmacro matlab-point-at-eol ()
(save-excursion (end-of-line) (point)))))
(defmacro matlab-run-in-matlab-mode-only (&rest body)
"Execute BODY only if the active buffer is a MATLAB
M-file buffer."
`(if (eq major-mode 'matlab-mode)
(progn
,@body)
(error "This command works only in a MATLAB M-file buffer.")))
(defun matlab-with-emacs-link ()
"Return non-nil if Emacs Link is running."
(and (featurep 'matlab-eei)
matlab-eei-process))
;;; User-changeable variables =================================================
;; Variables which the user can change
(defgroup matlab nil
"MATLAB mode."
:prefix "matlab-"
:group 'languages)
(defcustom matlab-indent-level 2
"*The basic indentation amount in `matlab-mode'."
:group 'matlab
:type '