;;; octave-mod.el --- editing Octave source files under Emacs
-;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
;; Free Software Foundation, Inc.
;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs 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 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; 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, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; It defines Octave mode, a major mode for editing
;; Octave code.
-;; The file octave-hlp.el provides `octave-help', a facility for looking up
-;; documentation on a symbol in the Octave info files.
-
;; The file octave-inf.el contains code for interacting with an inferior
;; Octave process using comint.
-;; See the documentation of `octave-mode', `octave-help' and
+;; See the documentation of `octave-mode' and
;; `run-octave' for further information on usage and customization.
;;; Code:
(defvar inferior-octave-output-string nil)
(defvar inferior-octave-receive-in-progress nil)
+(declare-function inferior-octave-send-list-and-digest "octave-inf" (list))
+
(defconst octave-maintainer-address
"Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>, bug-gnu-emacs@gnu.org"
"Current maintainer of the Emacs Octave package.")
-(defvar octave-abbrev-table nil
+(define-abbrev-table 'octave-abbrev-table
+ (mapcar (lambda (e) (append e '(nil 0 t)))
+ '(("`a" "all_va_args")
+ ("`b" "break")
+ ("`cs" "case")
+ ("`ca" "catch")
+ ("`c" "continue")
+ ("`el" "else")
+ ("`eli" "elseif")
+ ("`et" "end_try_catch")
+ ("`eu" "end_unwind_protect")
+ ("`ef" "endfor")
+ ("`efu" "endfunction")
+ ("`ei" "endif")
+ ("`es" "endswitch")
+ ("`ew" "endwhile")
+ ("`f" "for")
+ ("`fu" "function")
+ ("`gl" "global")
+ ("`gp" "gplot")
+ ("`gs" "gsplot")
+ ("`if" "if ()")
+ ("`o" "otherwise")
+ ("`rp" "replot")
+ ("`r" "return")
+ ("`s" "switch")
+ ("`t" "try")
+ ("`u" "until ()")
+ ("`up" "unwind_protect")
+ ("`upc" "unwind_protect_cleanup")
+ ("`w" "while ()")))
"Abbrev table for Octave's reserved words.
Used in `octave-mode' and inferior-octave-mode buffers.
-All Octave abbrevs start with a grave accent (`).")
-(unless octave-abbrev-table
- (define-abbrev-table 'octave-abbrev-table ()))
-
-(let ((abbrevs-changed abbrevs-changed))
- (define-abbrev octave-abbrev-table "`a" "all_va_args" nil 0 t)
- (define-abbrev octave-abbrev-table "`b" "break" nil 0 t)
- (define-abbrev octave-abbrev-table "`cs" "case" nil 0 t)
- (define-abbrev octave-abbrev-table "`ca" "catch" nil 0 t)
- (define-abbrev octave-abbrev-table "`c" "continue" nil 0 t)
- (define-abbrev octave-abbrev-table "`el" "else" nil 0 t)
- (define-abbrev octave-abbrev-table "`eli" "elseif" nil 0 t)
- (define-abbrev octave-abbrev-table "`et" "end_try_catch" nil 0 t)
- (define-abbrev octave-abbrev-table "`eu" "end_unwind_protect" nil 0 t)
- (define-abbrev octave-abbrev-table "`ef" "endfor" nil 0 t)
- (define-abbrev octave-abbrev-table "`efu" "endfunction" nil 0 t)
- (define-abbrev octave-abbrev-table "`ei" "endif" nil 0 t)
- (define-abbrev octave-abbrev-table "`es" "endswitch" nil 0 t)
- (define-abbrev octave-abbrev-table "`ew" "endwhile" nil 0 t)
- (define-abbrev octave-abbrev-table "`f" "for" nil 0 t)
- (define-abbrev octave-abbrev-table "`fu" "function" nil 0 t)
- (define-abbrev octave-abbrev-table "`gl" "global" nil 0 t)
- (define-abbrev octave-abbrev-table "`gp" "gplot" nil 0 t)
- (define-abbrev octave-abbrev-table "`gs" "gsplot" nil 0 t)
- (define-abbrev octave-abbrev-table "`if" "if ()" nil 0 t)
- (define-abbrev octave-abbrev-table "`o" "otherwise" nil 0 t)
- (define-abbrev octave-abbrev-table "`rp" "replot" nil 0 t)
- (define-abbrev octave-abbrev-table "`r" "return" nil 0 t)
- (define-abbrev octave-abbrev-table "`s" "switch" nil 0 t)
- (define-abbrev octave-abbrev-table "`t" "try" nil 0 t)
- (define-abbrev octave-abbrev-table "`u" "until ()" nil 0 t)
- (define-abbrev octave-abbrev-table "`up" "unwind_protect" nil 0 t)
- (define-abbrev octave-abbrev-table "`upc" "unwind_protect_cleanup" nil 0 t)
- (define-abbrev octave-abbrev-table "`w" "while ()" nil 0 t))
+All Octave abbrevs start with a grave accent (`)."
+ :regexp "\\(?:[^`]\\|^\\)\\(\\(?:\\<\\|`\\)\\w+\\)\\W*")
(defvar octave-comment-char ?#
"Character to start an Octave comment.")
(defvar octave-mode-menu
'("Octave"
- '("Lines"
+ ("Lines"
["Previous Code Line" octave-previous-code-line t]
["Next Code Line" octave-next-code-line t]
["Begin of Continuation" octave-beginning-of-line t]
["End of Continuation" octave-end-of-line t]
["Split Line at Point" octave-indent-new-comment-line t])
- '("Blocks"
+ ("Blocks"
["Next Block" octave-forward-block t]
["Previous Block" octave-backward-block t]
["Down Block" octave-down-block t]
["Up Block" octave-backward-up-block t]
["Mark Block" octave-mark-block t]
["Close Block" octave-close-block t])
- '("Functions"
+ ("Functions"
["Begin of Function" octave-beginning-of-defun t]
["End of Function" octave-end-of-defun t]
["Mark Function" octave-mark-defun t]
["Indent Function" octave-indent-defun t]
["Insert Function" octave-insert-defun t])
"-"
- '("Debug"
+ ("Debug"
["Send Current Line" octave-send-line t]
["Send Current Block" octave-send-block t]
["Send Current Function" octave-send-defun t]
(modify-syntax-entry ?! "." table)
(modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?\' "." table)
- (modify-syntax-entry ?\` "w" table)
+ ;; Was "w" for abbrevs, but now that it's not necessary any more,
+ (modify-syntax-entry ?\` "." table)
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?. "w" table)
(modify-syntax-entry ?_ "w" table)
(octave-add-octave-menu)
(octave-initialize-completions)
(run-mode-hooks 'octave-mode-hook))
+
+(defun octave-help ()
+ "Get help on Octave symbols from the Octave info files.
+Look up symbol in the function, operator and variable indices of the info files."
+ (let ((info-lookup-mode 'octave-mode))
+ (call-interactively 'info-lookup-symbol)))
\f
;;; Miscellaneous useful functions
(defun octave-describe-major-mode ()
(error nil))
(< pos (point)))))
+(defun octave-looking-at-kw (regexp)
+ "Like `looking-at', but sets `case-fold-search' nil."
+ (let ((case-fold-search nil))
+ (looking-at regexp)))
+
+(defun octave-re-search-forward-kw (regexp count)
+ "Like `re-search-forward', but sets `case-fold-search' nil, and moves point."
+ (let ((case-fold-search nil))
+ (re-search-forward regexp nil 'move count)))
+
+(defun octave-re-search-backward-kw (regexp count)
+ "Like `re-search-backward', but sets `case-fold-search' nil, and moves point."
+ (let ((case-fold-search nil))
+ (re-search-backward regexp nil 'move count)))
+
(defun octave-in-defun-p ()
"Return t if point is inside an Octave function declaration.
The function is taken to start at the `f' of `function' and to end after
the end keyword."
(let ((pos (point)))
(save-excursion
- (or (and (looking-at "\\<function\\>")
+ (or (and (octave-looking-at-kw "\\<function\\>")
(octave-not-in-string-or-comment-p))
(and (octave-beginning-of-defun)
(condition-case nil
(delete-horizontal-space)
(insert (concat " " octave-continuation-string))))
-(defvar octave-xemacs-p
- (string-match "XEmacs\\|Lucid" emacs-version))
-
;;; Comments
(defun octave-comment-region (beg end &optional arg)
"Comment or uncomment each line in the region as Octave code.
(while (< (point) eol)
(if (octave-not-in-string-or-comment-p)
(cond
- ((looking-at "\\<switch\\>")
+ ((octave-looking-at-kw "\\<switch\\>")
(setq icol (+ icol (* 2 octave-block-offset))))
- ((looking-at octave-block-begin-regexp)
+ ((octave-looking-at-kw octave-block-begin-regexp)
(setq icol (+ icol octave-block-offset)))
- ((looking-at octave-block-else-regexp)
+ ((octave-looking-at-kw octave-block-else-regexp)
(if (= bot (point))
(setq icol (+ icol octave-block-offset))))
- ((looking-at octave-block-end-regexp)
+ ((octave-looking-at-kw octave-block-end-regexp)
(if (not (= bot (point)))
(setq icol (- icol
(octave-block-end-offset)))))))
(save-excursion
(back-to-indentation)
(cond
- ((and (looking-at octave-block-else-regexp)
+ ((and (octave-looking-at-kw octave-block-else-regexp)
(octave-not-in-string-or-comment-p))
(setq icol (- icol octave-block-offset)))
- ((and (looking-at octave-block-end-regexp)
+ ((and (octave-looking-at-kw octave-block-end-regexp)
(octave-not-in-string-or-comment-p))
(setq icol (- icol (octave-block-end-offset))))
((or (looking-at "\\s<\\s<\\s<\\S<")
(save-excursion
(while (/= count 0)
(catch 'foo
- (while (or (re-search-forward
- octave-block-begin-or-end-regexp nil 'move inc)
+ (while (or (octave-re-search-forward-kw
+ octave-block-begin-or-end-regexp inc)
(if (/= depth 0)
(error "Unbalanced block")))
(if (octave-not-in-string-or-comment-p)
(looking-at "\\>")
(save-excursion
(skip-syntax-backward "w")
- (looking-at octave-block-else-or-end-regexp)))
+ (octave-looking-at-kw octave-block-else-or-end-regexp)))
(save-excursion
(cond
((match-end 1)
(inc (if (> arg 0) 1 -1))
(found))
(and (not (eobp))
- (not (and (> arg 0) (looking-at "\\<function\\>")))
+ (not (and (> arg 0) (octave-looking-at-kw "\\<function\\>")))
(skip-syntax-forward "w"))
(while (and (/= arg 0)
(setq found
- (re-search-backward "\\<function\\>" nil 'move inc)))
+ (octave-re-search-backward-kw "\\<function\\>" inc)))
(if (octave-not-in-string-or-comment-p)
(setq arg (- arg inc))))
(if found
(save-excursion
(beginning-of-line)
(and auto-fill-inhibit-regexp
- (looking-at auto-fill-inhibit-regexp))))
+ (octave-looking-at-kw auto-fill-inhibit-regexp))))
nil ; Can't do anything
(if (and (not (octave-in-comment-p))
(> (current-column) fc))
(display-completion-list list string))
(message "Hit space to flush")
(let (key first)
- (if (save-excursion
- (set-buffer (get-buffer "*Completions*"))
+ (if (with-current-buffer (get-buffer "*Completions*")
(setq key (read-key-sequence nil)
first (aref key 0))
(and (consp first) (consp (event-start first))
(self-insert-command 1)
(let (c)
(insert last-command-char)
- (if (if octave-xemacs-p
+ (if (if (featurep 'xemacs)
(or (eq (event-to-character (setq c (next-event))) ??)
(eq (event-to-character c) help-char))
(or (eq (setq c (read-event)) ??)
(let ((proc inferior-octave-process)
(string (buffer-substring-no-properties beg end))
line)
- (save-excursion
- (set-buffer inferior-octave-buffer)
+ (with-current-buffer inferior-octave-buffer
(setq inferior-octave-output-list nil)
(while (not (string-equal string ""))
(if (string-match "\n" string)
'octave-comment-char
'octave-continuation-offset
'octave-continuation-string
- 'octave-help-files
'octave-send-echo-input
'octave-send-line-auto-forward
'octave-send-show-buffer))))
-;;; provide ourself
+;; provide ourself
(provide 'octave-mod)