Mercurial > hg > octave-max
changeset 10856:dea165ff6d74
Remove emacs directory from Mercurial.
Emacs octave mode scripts have been a part of the emacs distribution,
not the Octave distribution, for many years. Their continued
presence and distribution in Octave tarballs was confusing.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 05 Aug 2010 07:51:16 -0700 |
parents | 5162c67c949e |
children | 2224236440c0 |
files | ChangeLog Makefile.am emacs/NEWS emacs/README emacs/TODO emacs/info-emacs-info emacs/info-emacs-octave-help emacs/module.mk emacs/octave-hlp.el emacs/octave-inf.el emacs/octave-mod.el emacs/octave-tags emacs/octave-tags.1 |
diffstat | 13 files changed, 9 insertions(+), 2527 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-08-05 Rik <octave@nomad.inbox5.com> + + * Makefile.am: Remove distribution of emacs directory + + * emacs/info-emacs-info, emacs/info-emacs-octave-help, emacs/module.mk, + emacs/NEWS, emacs/octave-hlp.el, emacs/octave-inf.el, + emacs/octave-mod.el, emacs/octave-tags, emacs/octave-tags.1, + emacs/README, emacs/TODO: Remove from further hg checkouts. + 2010-08-05 Rik <octave@nomad.inbox5.com> * ChangeLog: Correct date in version upgrade 3.3.52+ comment.
--- a/Makefile.am +++ b/Makefile.am @@ -66,7 +66,6 @@ octave-sh \ run-octave.in -include emacs/module.mk include m4/module.mk # Subdirectories in which to run `make all'.
deleted file mode 100644 --- a/emacs/NEWS +++ /dev/null @@ -1,225 +0,0 @@ -Changes in version 0.8 -********************** - -* Comment types. - -Octave mode can now distinguish between various types of comments, -similar to Emacs Lisp: - -`#' To be aligned to the same column on the right of the source - code. - -`##' To be aligned to the same level of indentation as the code. - -`###' To start at the left margin. - -(Without this distinction, things like - - code # This is an inline comment which extends - # across on line - -were not uniquely identifiable, because the second line of the in-line -comment could not be distinguished from a full-line comment.) - -* Inferior Octave support. - -It is now possible to run Octave from within Emacs, either by directly -entering commands at the prompt in a buffer in Inferior Octave mode, or -by interacting with Octave from within a file with Octave code. This is -useful in particular for debugging Octave code. - -For more details, see the Texinfo documentation. - -* New function `octave-insert-defun' to reduce typing effort. - - -Changes in version 0.7 -********************** - -This version is a rather complete rewrite of 0.6. - -In general, it was attempted to use standard Emacs features and -functions as much as possible. - -* Font Lock support was improved and enhanced. - -Function declarations are now fontified correctly. Builtin keywords -(reserved words and text functions) and variables are now fontified as -well. - -* Partial Imenu support was added. - -Function declarations can now be indexed. - -* A completion mechanism for builtin keywords and variables was added. - -Completion can be performed by pressing M-TAB (octave-complete-symbol) -after typing the initial characters of the keyword. - -In a future release, completion (as well as imenu and font locking) may -also include user defined variables. - -* Bug reporting. - -The function octave-submit-bug-report was added. - -* Commands for dealing with blocks. - -The functions for dealing with begin-else-end blocks were rewritten from -scratch. They are now based on the function octave-scan-blocks, which -works similar to the standard Emacs scan-lists function. One can now go -forward and backward across balanced blocks, and go up and down block -levels. It is no longer required that extended `end' keywords are used; -in fact, an error message will be issued in the case of nonmatching -block keywords. Matching is achieved through one general function, and -now also works for else keywords. - -The block motion commands are - - octave-forward-block - octave-backward-block - octave-down-block - octave-up-block - octave-backward-up-block - -One can also mark the `current' block (the innermost block containing -point) using octave-mark-block. - -* Commands for dealing with functions. - -Moving across functions, as well as marking and indenting them now works -as for defuns in Lisp mode. - -* Filling. - -The code for auto-filling was rewritten, and octave-fill-paragraph was -added. The code for filling is far from perfection yet. In future -releases, a function for filling the region will be added. - -The problem of getting the right fill function after toggling Auto-Fill -mode was solved by an advice to auto-fill-mode. - -* Abbrevs. - -The mechanism of listing all abbrevs using `? or ` was retained. All -other abbrev code was dropped---why should Octave mode only use its own -abbrevs? - -* Comments. - -As the comment syntax and comment-start are specified correctly, one can -use the standard comment-region. The function octave-uncomment-region -is still provided, but now based on comment-region. - -The special treatment of commenting regions was removed, but may easily -be added again. - -* Paragraphs. - -Empty lines and form feeds are now recognized as separating paragraphs -of Octave code, so one can now move across them and fill them. - -* Indentation. - -Indentation should work without problems now, assuming `sane' coding. -The problems in 0.6 which came from assuming that only one else or end -keyword would occur in one line should now have disappeared. - -The user-level variables for customizing indentation were renamed as -follows: - - 0.7 0.6 - - octave-block-offset octave-stmt-indent - octave-continuation-offset octave-continuation-indent - -Of course, it is still easy to write code in a way that makes Octave -mode get the indentations wrong. For example, - - if (something) \ - -will result in having octave-continuation-offset added although this is -wrong. Or, - - printf ("This is some stupid %s \ - for getting indentation wrong.", - "text") - -is what you deserve anyway :-) Octave mode currently assumes that -strings do not extend across lines ... - -* Other commands for moving. - -The functions octave-previous-statement and octave-next-statement were -removed, partially because their names do not coincide with the usage of -`statement' in the Octave manual. The functions now provided are - - octave-previous-code-line - octave-next-code-line - octave-beginning-of-line - octave-end-of-line - -The first two look for the previous or next `code' line, i.e., they skip -across all empty or comment lines. The latter two also go understand -continuation lines, and move to their beginning and end, respectively. - -The effect of the former octave-previous-statement can now be achieved -upon following octave-previous-code-line by octave-beginning-of-line. - -* Special insertions: LFD, SPC and semicolon. - -These characters are now `electric', doing a little extra work. All -three expand abbrevs if abbrev mode is on and blink matching blocks if -octave-blink-matching-blocks is t. - -In future versions, SPC might also do auto-newlining after certain -keywords (or e.g., a continuation character). - -* User-level customization. - -The variables for customizing Octave mode are as follows. - -** As in 0.6. - - octave-auto-newline - octave-comment-column - octave-comment-start - octave-continuation-string - -** Different from 0.6. - - 0.7 0.6 - - octave-blink-matching-block octave-blink-matching-blocks - octave-block-offset octave-statement-indent - octave-continuation-offset octave-continuation-indent - octave-inhibit-startup-message octave-startup-message - -The first three have only been renamed. (The first in analogy to the -standard blink-matching-paren, the others because they are really extra -offsets and not the absolute indentations.) - -Controlling startup messages now works as in Emacs itself. - -** New in 0.7. - - octave-fill-column - -** Removed from 0.7. - - octave-comment-indent-style - octave-comment-indent-char - octave-comment-region - -* Help - -A mechanism for looking up entries in the indices of ALL info files with -documentation for Octave (as specified by octave-help-files) was added -(octave-help). If multiple matches are found, one can cycle through the -matches. - -* Other changes. - -octave-comment-hook was removed. One can instead use the standard Emacs -indent-for-comment. -
deleted file mode 100644 --- a/emacs/README +++ /dev/null @@ -1,20 +0,0 @@ -These lisp files should work under recent versions (19 onwards) of -both Emacs and XEmacs. See the Octave documentation (info node -`Emacs') on how to install and use these packages. - -These files use the custom package so that user variables can be -changed easily. The custom package has been included in Emacs since -around version 19.34. If you have an old version of Emacs without the -custom package, you should get the following error when trying to load -the octave files: - - Cannot open load file: custom - -In this case, you should use the simple replacement custom library -here, renaming it to custom.el so that Emacs can find it: - -% mv custom-old.el custom.el - -But remember when you upgrade Emacs to version 20 and beyond, you -should delete this primitive custom file and use the built-in version -instead.
deleted file mode 100644 --- a/emacs/TODO +++ /dev/null @@ -1,25 +0,0 @@ -* Write a function octave-debug which just provides the debugging -features in a restricted keymap (i.e., <prefix> l, b, f, ..., q). - -* Make (un)commenting work with indented comments. Perhaps one can simply -provide an extended comment prefix which includes leading spaces? - -* Maybe also work with strings generated by single apostrophs. (NOT for -font locking, though.) This would require cranking up a specialized -version of octave-in-string-p. - -* Bug fixes. - -** Filling. - -The whole code related to filling needs to be redone. For example, - - [a b c d e] = sscanf ("This %s is %s another %s %s string", s, "C") - -followed by RET will comment the "C" if auto-filling is on because the -standard function indent-new-comment-line things that it is within a -comment (because of the comment start syntax class of `%' for MATLAB -compatibility). - -As long as single apostroph strings are not supported, one could simply -remove all MATLAB compatibility and change the syntax class of `%'.
deleted file mode 100755 --- a/emacs/info-emacs-info +++ /dev/null @@ -1,34 +0,0 @@ -#! /bin/sh -# info-emacs-info -# -# Copyright (C) 1996, 2005, 2007 Kurt Hornik -# -# This file is part of Octave. -# -# Octave 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 of the License, or (at -# your option) any later version. -# -# Octave 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 Octave; see the file COPYING. If not, see -# <http://www.gnu.org/licenses/>. - -# Written by Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> on 1996/07/01 - -# Make Octave's `help -i' use Emacs info. -# Requires a running Emacs and gnuserv. -cmd="(Info-find-node \"$2\" \"Top\")" -if [ $3 = "--directory" ]; -then - cmd="(add-to-list 'Info-directory-list \"$4\") $cmd" - shift 2 -fi -cmd="(require 'info) $cmd" -[ $4 ] && cmd="$cmd (Info-index \"$4\")" -gnuclient -batch -q -eval "$cmd"
deleted file mode 100755 --- a/emacs/info-emacs-octave-help +++ /dev/null @@ -1,35 +0,0 @@ -#! /bin/sh -# info-emacs-octave-help -# -# Copyright (C) 1996, 1997, 2005, 2007 Kurt Hornik -# -# This file is part of Octave. -# -# Octave 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 of the License, or (at -# your option) any later version. -# -# Octave 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 Octave; see the file COPYING. If not, see -# <http://www.gnu.org/licenses/>. - -# Written by KH <Kurt.Hornik@wu-wien.ac.at> on 1996/07/01 -# Updated by KH on 1997/03/04 - -# Make Octave's `help -i' use Emacs octave-help. -# Requires a running Emacs and gnuserv. - -cmd="(require 'octave-hlp)" -if [ $3 = "--directory" ]; -then - cmd="$cmd (add-to-list 'Info-directory-list \"$4\")" - shift 2 -fi -cmd="$cmd (octave-help \"$4\")" -gnuclient -batch -q -eval "$cmd"
deleted file mode 100644 --- a/emacs/module.mk +++ /dev/null @@ -1,15 +0,0 @@ -dist_archlib_SCRIPTS = emacs/info-emacs-info emacs/info-emacs-octave-help - -EXTRA_DIST += \ - emacs/NEWS \ - emacs/README \ - emacs/TODO \ - emacs/info-emacs-info \ - emacs/info-emacs-octave-help \ - emacs/module.mk \ - emacs/octave-hlp.el \ - emacs/octave-inf.el \ - emacs/octave-mod.el \ - emacs/octave-tags \ - emacs/octave-tags.1 -
deleted file mode 100644 --- a/emacs/octave-hlp.el +++ /dev/null @@ -1,138 +0,0 @@ -;;; octave-hlp.el --- getting help on Octave symbols using info - -;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007 -;; Free Software Foundation, Inc. - -;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> -;; Author: John Eaton <jwe@octave.org> -;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> -;; Keywords: languages - -;; This file is part of GNU Emacs. - -;; 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. - -;; GNU Emacs 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, see -;; <http://www.gnu.org/licenses>. - -;;; Commentary: - -;; Provides the command `octave-help' which allows index lookup of a -;; symbol in the Octave-related info files, as specified by the list -;; `octave-help-files'. - -;; Other features may be added in future versions. - -;;; Code: - -(require 'octave-mod) -(require 'info) - -(defvar octave-help-files '("octave") - "List of info files with documentation for Octave. -Default is (\"octave\").") - -(defvar octave-help-lookup-alist nil - "Alist of Octave index entries for lookup.") - -(defvar octave-help-completion-alist nil - "Alist of Octave index entries for completion. -The entries are of the form (VAR . VAR), where VAR runs through all -different keys in `octave-help-lookup-alist'.") - -;;;###autoload -(defun octave-help (key) - "Get help on Octave symbols from the Octave info files. -Look up KEY in the function, operator and variable indices of the files -specified by `octave-help-files'. -If KEY is not a string, prompt for it with completion." - (interactive - (list - (completing-read (format "Describe Octave symbol: ") - (octave-help-get-completion-alist) - nil t))) - (if (get-buffer "*info*") - (set-buffer "*info*")) - (if (zerop (length key)) - (Info-find-node (car octave-help-files) "Top") - (let ((alist (copy-alist (octave-help-get-lookup-alist))) - entry matches) - (while (setq entry (car alist)) - (if (string-match key (car entry)) - (add-to-list 'matches entry)) - (setq alist (cdr alist))) - (if matches - (progn - (setq Info-index-alternatives matches) - (Info-index-next 0)))))) - -(defun octave-help-get-lookup-alist () - "Build the index lookup alist from all Octave info files. -The files specified by `octave-help-files' are searched." - (if octave-help-lookup-alist - () - (message "Building help lookup alist...") - (let ((files octave-help-files) file key node) - (save-window-excursion - (while files - (setq file (car files)) - (Info-goto-node (concat "(" file ")")) - (condition-case nil - (progn - (Info-index "") - (while - (progn - (while (re-search-forward - "^\\* \\([^(:]+\\)[^:]*: *\\(.+\\)\\.$" - nil t) - (setq key (match-string 1) - node (concat "(" file ")" (match-string 2))) - (and (string-match "\\(.*\\>\\) *$" key) - (setq key (replace-match "\\1" t nil key))) - (add-to-list 'octave-help-lookup-alist - (list key - node - (concat (concat "(" file ")") - Info-current-node) - 0))) - (and (setq node (Info-extract-pointer "next" t)) - (string-match - (concat "\\(Function\\|Operator\\|Variable\\) " - "\\<Index\\>") - node))) - (Info-goto-node node))) - (error nil)) - (setq files (cdr files))))) - (message "Building help lookup alist...done")) - octave-help-lookup-alist) - -(defun octave-help-get-completion-alist () - "Build the index completion alist from all Octave info files. -The files specified by `octave-help-files' are searched." - (if octave-help-completion-alist - () - (message "Building help completion alist...") - (let ((alist (octave-help-get-lookup-alist)) entry) - (while alist - (setq entry (car alist)) - (add-to-list 'octave-help-completion-alist - (cons (car entry) (car entry))) - (setq alist (cdr alist)))) - (message "Building help completion alist...done")) - octave-help-completion-alist) - -;;; provide ourself - -(provide 'octave-hlp) - -;;; arch-tag: df5ef8fa-76c9-44e5-9835-cb5a502c6282 -;;; octave-hlp.el ends here
deleted file mode 100644 --- a/emacs/octave-inf.el +++ /dev/null @@ -1,408 +0,0 @@ -;;; octave-inf.el --- running Octave as an inferior Emacs process - -;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007 -;; Free Software Foundation, Inc. - -;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> -;; Author: John Eaton <jwe@octave.org> -;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> -;; Keywords: languages - -;; This file is part of GNU Emacs. - -;; 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. - -;; GNU Emacs 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, see -;; <http://www.gnu.org/licenses>. - -;;; Commentary: - -;;; Code: - -(require 'octave-mod) -(require 'comint) - -(defgroup octave-inferior nil - "Running Octave as an inferior Emacs process." - :group 'octave) - -(defcustom inferior-octave-program "octave" - "Program invoked by `inferior-octave'." - :type 'string - :group 'octave-inferior) - -(defcustom inferior-octave-prompt - "\\(^octave\\(\\|.bin\\|.exe\\)\\(-[.0-9]+\\)?\\(:[0-9]+\\)?\\|^debug\\|^\\)>+ " - "Regexp to match prompts for the inferior Octave process." - :type 'regexp - :group 'octave-inferior) - -(defcustom inferior-octave-startup-file nil - "Name of the inferior Octave startup file. -The contents of this file are sent to the inferior Octave process on -startup." - :type '(choice (const :tag "None" nil) - file) - :group 'octave-inferior) - -(defcustom inferior-octave-startup-args nil - "List of command line arguments for the inferior Octave process. -For example, for suppressing the startup message and using `traditional' -mode, set this to (\"-q\" \"--traditional\")." - :type '(repeat string) - :group 'octave-inferior) - -(defvar inferior-octave-mode-map - (let ((map (make-sparse-keymap))) - (set-keymap-parent map comint-mode-map) - (define-key map "\t" 'comint-dynamic-complete) - (define-key map "\M-?" 'comint-dynamic-list-filename-completions) - (define-key map "\C-c\C-l" 'inferior-octave-dynamic-list-input-ring) - (define-key map [menu-bar inout list-history] - '("List Input History" . inferior-octave-dynamic-list-input-ring)) - (define-key map "\C-c\C-h" 'octave-help) - map) - "Keymap used in Inferior Octave mode.") - -(defvar inferior-octave-mode-syntax-table - (let ((table (make-syntax-table))) - (modify-syntax-entry ?\` "w" table) - (modify-syntax-entry ?\# "<" table) - (modify-syntax-entry ?\n ">" table) - table) - "Syntax table in use in inferior-octave-mode buffers.") - -(defcustom inferior-octave-mode-hook nil - "*Hook to be run when Inferior Octave mode is started." - :type 'hook - :group 'octave-inferior) - -(defvar inferior-octave-font-lock-keywords - (list - (cons inferior-octave-prompt 'font-lock-type-face)) - ;; Could certainly do more font locking in inferior Octave ... - "Additional expressions to highlight in Inferior Octave mode.") - - -;;; Compatibility functions -(if (not (fboundp 'comint-line-beginning-position)) - ;; comint-line-beginning-position is defined in Emacs 21 - (defun comint-line-beginning-position () - "Returns the buffer position of the beginning of the line, after any prompt. -The prompt is assumed to be any text at the beginning of the line matching -the regular expression `comint-prompt-regexp', a buffer local variable." - (save-excursion (comint-bol nil) (point)))) - - -(defvar inferior-octave-output-list nil) -(defvar inferior-octave-output-string nil) -(defvar inferior-octave-receive-in-progress nil) - -(defvar inferior-octave-startup-hook nil) - -(defvar inferior-octave-complete-impossible nil - "Non-nil means that `inferior-octave-complete' is impossible.") - -(defvar inferior-octave-has-built-in-variables nil - "Non-nil means that Octave has built-in variables.") - -(defvar inferior-octave-dynamic-complete-functions - '(inferior-octave-complete comint-dynamic-complete-filename) - "List of functions called to perform completion for inferior Octave. -This variable is used to initialize `comint-dynamic-complete-functions' -in the Inferior Octave buffer.") - -(defun inferior-octave-mode () - "Major mode for interacting with an inferior Octave process. -Runs Octave as a subprocess of Emacs, with Octave I/O through an Emacs -buffer. - -Entry to this mode successively runs the hooks `comint-mode-hook' and -`inferior-octave-mode-hook'." - (interactive) - (delay-mode-hooks (comint-mode)) - (setq comint-prompt-regexp inferior-octave-prompt - major-mode 'inferior-octave-mode - mode-name "Inferior Octave" - mode-line-process '(":%s") - local-abbrev-table octave-abbrev-table) - (use-local-map inferior-octave-mode-map) - (set-syntax-table inferior-octave-mode-syntax-table) - - (make-local-variable 'comment-start) - (setq comment-start octave-comment-start) - (make-local-variable 'comment-end) - (setq comment-end "") - (make-local-variable 'comment-column) - (setq comment-column 32) - (make-local-variable 'comment-start-skip) - (setq comment-start-skip octave-comment-start-skip) - - (make-local-variable 'font-lock-defaults) - (setq font-lock-defaults '(inferior-octave-font-lock-keywords nil nil)) - - (setq comint-input-ring-file-name - (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist") - comint-input-ring-size (or (getenv "OCTAVE_HISTSIZE") 1024)) - (set (make-local-variable 'comint-dynamic-complete-functions) - inferior-octave-dynamic-complete-functions) - (add-hook 'comint-input-filter-functions - 'inferior-octave-directory-tracker nil t) - (comint-read-input-ring t) - - (run-mode-hooks 'inferior-octave-mode-hook)) - -;;;###autoload -(defun inferior-octave (&optional arg) - "Run an inferior Octave process, I/O via `inferior-octave-buffer'. -This buffer is put in Inferior Octave mode. See `inferior-octave-mode'. - -Unless ARG is non-nil, switches to this buffer. - -The elements of the list `inferior-octave-startup-args' are sent as -command line arguments to the inferior Octave process on startup. - -Additional commands to be executed on startup can be provided either in -the file specified by `inferior-octave-startup-file' or by the default -startup file, `~/.emacs-octave'." - (interactive "P") - (let ((buffer inferior-octave-buffer)) - (get-buffer-create buffer) - (if (comint-check-proc buffer) - () - (save-excursion - (set-buffer buffer) - (comint-mode) - (inferior-octave-startup) - (inferior-octave-mode))) - (if (not arg) - (pop-to-buffer buffer)))) - -;;;###autoload -(defalias 'run-octave 'inferior-octave) - -(defun inferior-octave-startup () - "Start an inferior Octave process." - (let ((proc (comint-exec-1 - (substring inferior-octave-buffer 1 -1) - inferior-octave-buffer - inferior-octave-program - (append (list "-i" "--no-line-editing") - inferior-octave-startup-args)))) - (set-process-filter proc 'inferior-octave-output-digest) - (setq comint-ptyp process-connection-type - inferior-octave-process proc - inferior-octave-output-list nil - inferior-octave-output-string nil - inferior-octave-receive-in-progress t) - - ;; This may look complicated ... However, we need to make sure that - ;; we additional startup code only AFTER Octave is ready (otherwise, - ;; output may be mixed up). Hence, we need to digest the Octave - ;; output to see when it issues a prompt. - (while inferior-octave-receive-in-progress - (accept-process-output inferior-octave-process)) - (goto-char (point-max)) - (set-marker (process-mark proc) (point)) - (insert-before-markers - (concat - (if (not (bobp)) "\n") - (if inferior-octave-output-list - (concat (mapconcat - 'identity inferior-octave-output-list "\n") - "\n")))) - - ;; Find out whether Octave has built-in variables. - (inferior-octave-send-list-and-digest - (list "exist \"LOADPATH\"\n")) - (setq inferior-octave-has-built-in-variables - (string-match "101$" (car inferior-octave-output-list))) - - ;; An empty secondary prompt, as e.g. obtained by '--braindead', - ;; means trouble. - (inferior-octave-send-list-and-digest (list "PS2\n")) - (if (string-match "\\(PS2\\|ans\\) = *$" (car inferior-octave-output-list)) - (inferior-octave-send-list-and-digest - (list (if inferior-octave-has-built-in-variables - "PS2 = \"> \"\n" - "PS2 (\"> \");\n")))) - - ;; O.k., now we are ready for the Inferior Octave startup commands. - (let* (commands - (program (file-name-nondirectory inferior-octave-program)) - (file (or inferior-octave-startup-file - (concat "~/.emacs-" program)))) - (setq commands - (list "more off;\n" - (if (not (string-equal - inferior-octave-output-string ">> ")) - (if inferior-octave-has-built-in-variables - "PS1=\"\\\\s> \";\n" - "PS1 (\"\\\\s> \");\n")) - (if (file-exists-p file) - (format "source (\"%s\");\n" file)))) - (inferior-octave-send-list-and-digest commands)) - (insert-before-markers - (concat - (if inferior-octave-output-list - (concat (mapconcat - 'identity inferior-octave-output-list "\n") - "\n")) - inferior-octave-output-string)) - ;; Next, we check whether Octave supports `completion_matches' ... - (inferior-octave-send-list-and-digest - (list "exist \"completion_matches\"\n")) - (setq inferior-octave-complete-impossible - (not (string-match "5$" (car inferior-octave-output-list)))) - - ;; And finally, everything is back to normal. - (set-process-filter proc 'inferior-octave-output-filter) - (run-hooks 'inferior-octave-startup-hook) - (run-hooks 'inferior-octave-startup-hook) - ;; Just in case, to be sure a cd in the startup file - ;; won't have detrimental effects. - (inferior-octave-resync-dirs))) - - -(defun inferior-octave-complete () - "Perform completion on the Octave symbol preceding point. -This is implemented using the Octave command `completion_matches' which -is NOT available with versions of Octave prior to 2.0." - (interactive) - (let* ((end (point)) - (command - (save-excursion - (skip-syntax-backward "w_" (comint-line-beginning-position)) - (buffer-substring-no-properties (point) end))) - (proc (get-buffer-process inferior-octave-buffer))) - (cond (inferior-octave-complete-impossible - (error (concat - "Your Octave does not have `completion_matches'. " - "Please upgrade to version 2.X."))) - ((string-equal command "") - (message "Cannot complete an empty string")) - (t - (inferior-octave-send-list-and-digest - (list (concat "completion_matches (\"" command "\");\n"))) - ;; Sort the list - (setq inferior-octave-output-list - (sort inferior-octave-output-list 'string-lessp)) - ;; Remove duplicates - (let* ((x inferior-octave-output-list) - (y (cdr x))) - (while y - (if (string-equal (car x) (car y)) - (setcdr x (setq y (cdr y))) - (setq x y - y (cdr y))))) - ;; And let comint handle the rest - (comint-dynamic-simple-complete - command inferior-octave-output-list))))) - -(defun inferior-octave-dynamic-list-input-ring () - "List the buffer's input history in a help buffer." - ;; We cannot use `comint-dynamic-list-input-ring', because it replaces - ;; "completion" by "history reference" ... - (interactive) - (if (or (not (ring-p comint-input-ring)) - (ring-empty-p comint-input-ring)) - (message "No history") - (let ((history nil) - (history-buffer " *Input History*") - (index (1- (ring-length comint-input-ring))) - (conf (current-window-configuration))) - ;; We have to build up a list ourselves from the ring vector. - (while (>= index 0) - (setq history (cons (ring-ref comint-input-ring index) history) - index (1- index))) - ;; Change "completion" to "history reference" - ;; to make the display accurate. - (with-output-to-temp-buffer history-buffer - (display-completion-list history) - (set-buffer history-buffer)) - (message "Hit space to flush") - (let ((ch (read-event))) - (if (eq ch ?\ ) - (set-window-configuration conf) - (setq unread-command-events (list ch))))))) - -(defun inferior-octave-strip-ctrl-g (string) - "Strip leading `^G' character. -If STRING starts with a `^G', ring the bell and strip it." - (if (string-match "^\a" string) - (progn - (ding) - (setq string (substring string 1)))) - string) - -(defun inferior-octave-output-filter (proc string) - "Standard output filter for the inferior Octave process. -Ring Emacs bell if process output starts with an ASCII bell, and pass -the rest to `comint-output-filter'." - (comint-output-filter proc (inferior-octave-strip-ctrl-g string))) - -(defun inferior-octave-output-digest (proc string) - "Special output filter for the inferior Octave process. -Save all output between newlines into `inferior-octave-output-list', and -the rest to `inferior-octave-output-string'." - (setq string (concat inferior-octave-output-string string)) - (while (string-match "\n" string) - (setq inferior-octave-output-list - (append inferior-octave-output-list - (list (substring string 0 (match-beginning 0)))) - string (substring string (match-end 0)))) - (if (string-match inferior-octave-prompt string) - (setq inferior-octave-receive-in-progress nil)) - (setq inferior-octave-output-string string)) - -(defun inferior-octave-send-list-and-digest (list) - "Send LIST to the inferior Octave process and digest the output. -The elements of LIST have to be strings and are sent one by one. All -output is passed to the filter `inferior-octave-output-digest'." - (let* ((proc inferior-octave-process) - (filter (process-filter proc)) - string) - (set-process-filter proc 'inferior-octave-output-digest) - (setq inferior-octave-output-list nil) - (unwind-protect - (while (setq string (car list)) - (setq inferior-octave-output-string nil - inferior-octave-receive-in-progress t) - (comint-send-string proc string) - (while inferior-octave-receive-in-progress - (accept-process-output proc)) - (setq list (cdr list))) - (set-process-filter proc filter)))) - -(defun inferior-octave-directory-tracker (string) - "Tracks `cd' commands issued to the inferior Octave process. -Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused." - (cond - ((string-match "^[ \t]*cd[ \t;]*$" string) - (cd "~")) - ((string-match "^[ \t]*cd[ \t]+\\([^ \t\n;]*\\)[ \t\n;]*" string) - (cd (substring string (match-beginning 1) (match-end 1)))))) - -(defun inferior-octave-resync-dirs () - "Resync the buffer's idea of the current directory. -This command queries the inferior Octave process about its current -directory and makes this the current buffer's default directory." - (interactive) - (inferior-octave-send-list-and-digest '("disp (pwd ())\n")) - (cd (car inferior-octave-output-list))) - -;;; provide ourself - -(provide 'octave-inf) - -;; arch-tag: bdce0395-24d1-4bb4-bfba-6fb1eeb1a660 -;;; octave-inf.el ends here
deleted file mode 100644 --- a/emacs/octave-mod.el +++ /dev/null @@ -1,1515 +0,0 @@ -;;; octave-mod.el --- editing Octave source files under Emacs - -;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 -;; Free Software Foundation, Inc. - -;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> -;; Author: John Eaton <jwe@octave.org> -;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> -;; Keywords: languages - -;; This file is part of GNU Emacs. - -;; 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. - -;; GNU Emacs 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, see -;; <http://www.gnu.org/licenses>. - -;;; Commentary: - -;; This package provides Emacs support for Octave. -;; 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 -;; `run-octave' for further information on usage and customization. - -;;; Code: -(require 'custom) - -(defgroup octave nil - "Major mode for editing Octave source files." - :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) - :group 'languages) - -(defvar inferior-octave-output-list nil) -(defvar inferior-octave-output-string nil) -(defvar inferior-octave-receive-in-progress nil) - -(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 - "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) - (define-abbrev octave-abbrev-table "`b" "break" nil) - (define-abbrev octave-abbrev-table "`cs" "case" nil) - (define-abbrev octave-abbrev-table "`ca" "catch" nil) - (define-abbrev octave-abbrev-table "`c" "continue" nil) - (define-abbrev octave-abbrev-table "`el" "else" nil) - (define-abbrev octave-abbrev-table "`eli" "elseif" nil) - (define-abbrev octave-abbrev-table "`et" "end_try_catch" nil) - (define-abbrev octave-abbrev-table "`eu" "end_unwind_protect" nil) - (define-abbrev octave-abbrev-table "`ef" "endfor" nil) - (define-abbrev octave-abbrev-table "`efu" "endfunction" nil) - (define-abbrev octave-abbrev-table "`ei" "endif" nil) - (define-abbrev octave-abbrev-table "`es" "endswitch" nil) - (define-abbrev octave-abbrev-table "`ew" "endwhile" nil) - (define-abbrev octave-abbrev-table "`f" "for" nil) - (define-abbrev octave-abbrev-table "`fu" "function" nil) - (define-abbrev octave-abbrev-table "`gl" "global" nil) - (define-abbrev octave-abbrev-table "`gp" "gplot" nil) - (define-abbrev octave-abbrev-table "`gs" "gsplot" nil) - (define-abbrev octave-abbrev-table "`if" "if ()" nil) - (define-abbrev octave-abbrev-table "`o" "otherwise" nil) - (define-abbrev octave-abbrev-table "`rp" "replot" nil) - (define-abbrev octave-abbrev-table "`r" "return" nil) - (define-abbrev octave-abbrev-table "`s" "switch" nil) - (define-abbrev octave-abbrev-table "`t" "try" nil) - (define-abbrev octave-abbrev-table "`u" "until ()" nil) - (define-abbrev octave-abbrev-table "`up" "unwind_protect" nil) - (define-abbrev octave-abbrev-table "`upc" "unwind_protect_cleanup" nil) - (define-abbrev octave-abbrev-table "`w" "while ()" nil)) - -(defvar octave-comment-char ?# - "Character to start an Octave comment.") -(defvar octave-comment-start - (string octave-comment-char ?\ ) - "String to insert to start a new Octave in-line comment.") -(defvar octave-comment-start-skip "\\s<+\\s-*" - "Regexp to match the start of an Octave comment up to its body.") - -(defvar octave-begin-keywords - '("do" "for" "function" "if" "switch" "try" "unwind_protect" "while")) -(defvar octave-else-keywords - '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup")) -;; FIXME: only use specific "end" tokens here to avoid confusion when "end" -;; is used in indexing (the real fix is much more complex). -(defvar octave-end-keywords - '("endfor" "endfunction" "endif" "endswitch" "end_try_catch" - "end_unwind_protect" "endwhile" "until")) - -(defvar octave-reserved-words - (append octave-begin-keywords - octave-else-keywords - octave-end-keywords - '("break" "continue" "end" "global" "persistent" "return")) - "Reserved words in Octave.") - -(defvar octave-text-functions - '("casesen" "cd" "chdir" "clear" "diary" "dir" "document" "echo" - "edit_history" "format" "help" "history" "hold" - "load" "ls" "more" "run_history" "save" "type" - "which" "who" "whos") - "Text functions in Octave.") - -(defvar octave-variables - '("DEFAULT_EXEC_PATH" "DEFAULT_LOADPATH" - "EDITOR" "EXEC_PATH" "F_DUPFD" "F_GETFD" "F_GETFL" "F_SETFD" - "F_SETFL" "I" "IMAGE_PATH" "Inf" "J" - "NaN" "OCTAVE_VERSION" "O_APPEND" "O_CREAT" "O_EXCL" - "O_NONBLOCK" "O_RDONLY" "O_RDWR" "O_TRUNC" "O_WRONLY" "PAGER" "PS1" - "PS2" "PS4" "PWD" "SEEK_CUR" "SEEK_END" "SEEK_SET" "__F_DUPFD__" - "__F_GETFD__" "__F_GETFL__" "__F_SETFD__" "__F_SETFL__" "__I__" - "__Inf__" "__J__" "__NaN__" "__OCTAVE_VERSION__" "__O_APPEND__" - "__O_CREAT__" "__O_EXCL__" "__O_NONBLOCK__" "__O_RDONLY__" - "__O_RDWR__" "__O_TRUNC__" "__O_WRONLY__" "__PWD__" "__SEEK_CUR__" - "__SEEK_END__" "__SEEK_SET__" "__argv__" "__e__" "__eps__" - "__i__" "__inf__" "__j__" "__nan__" "__pi__" - "__program_invocation_name__" "__program_name__" "__realmax__" - "__realmin__" "__stderr__" "__stdin__" "__stdout__" "ans" "argv" - "beep_on_error" "completion_append_char" - "crash_dumps_octave_core" "default_save_format" - "e" "echo_executing_commands" "eps" - "error_text" "gnuplot_binary" "history_file" - "history_size" "ignore_function_time_stamp" - "inf" "nan" "nargin" "output_max_field_width" "output_precision" - "page_output_immediately" "page_screen_output" "pi" - "print_answer_id_name" "print_empty_dimensions" - "program_invocation_name" "program_name" - "realmax" "realmin" "save_precision" - "saving_history" "sighup_dumps_octave_core" "sigterm_dumps_octave_core" - "silent_functions" "split_long_rows" "stderr" "stdin" "stdout" - "string_fill_char" "struct_levels_to_print" - "suppress_verbose_help_message") - "Builtin variables in Octave.") - -(defvar octave-function-header-regexp - (concat "^\\s-*\\<\\(function\\)\\>" - "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\w+\\)\\>") - "Regexp to match an Octave function header. -The string `function' and its name are given by the first and third -parenthetical grouping.") - -(defvar octave-font-lock-keywords - (list - ;; Fontify all builtin keywords. - (cons (concat "\\<\\(" - (mapconcat 'identity octave-reserved-words "\\|") - (mapconcat 'identity octave-text-functions "\\|") - "\\)\\>") - 'font-lock-keyword-face) - ;; Fontify all builtin operators. - (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)" - (if (boundp 'font-lock-builtin-face) - 'font-lock-builtin-face - 'font-lock-preprocessor-face)) - ;; Fontify all builtin variables. - (cons (concat "\\<\\(" - (mapconcat 'identity octave-variables "\\|") - "\\)\\>") - 'font-lock-variable-name-face) - ;; Fontify all function declarations. - (list octave-function-header-regexp - '(1 font-lock-keyword-face) - '(3 font-lock-function-name-face nil t))) - "Additional Octave expressions to highlight.") - -(defcustom inferior-octave-buffer "*Inferior Octave*" - "Name of buffer for running an inferior Octave process." - :type 'string - :group 'octave-inferior) - -(defvar inferior-octave-process nil) - -(defvar octave-mode-map - (let ((map (make-sparse-keymap))) - (define-key map "`" 'octave-abbrev-start) - (define-key map ";" 'octave-electric-semi) - (define-key map " " 'octave-electric-space) - (define-key map "\n" 'octave-reindent-then-newline-and-indent) - (define-key map "\e;" 'octave-indent-for-comment) - (define-key map "\e\n" 'octave-indent-new-comment-line) - (define-key map "\e\t" 'octave-complete-symbol) - (define-key map "\M-\C-a" 'octave-beginning-of-defun) - (define-key map "\M-\C-e" 'octave-end-of-defun) - (define-key map "\M-\C-h" 'octave-mark-defun) - (define-key map "\M-\C-q" 'octave-indent-defun) - (define-key map "\C-c;" 'octave-comment-region) - (define-key map "\C-c:" 'octave-uncomment-region) - (define-key map "\C-c\C-b" 'octave-submit-bug-report) - (define-key map "\C-c\C-p" 'octave-previous-code-line) - (define-key map "\C-c\C-n" 'octave-next-code-line) - (define-key map "\C-c\C-a" 'octave-beginning-of-line) - (define-key map "\C-c\C-e" 'octave-end-of-line) - (define-key map "\C-c\M-\C-n" 'octave-forward-block) - (define-key map "\C-c\M-\C-p" 'octave-backward-block) - (define-key map "\C-c\M-\C-u" 'octave-backward-up-block) - (define-key map "\C-c\M-\C-d" 'octave-down-block) - (define-key map "\C-c\M-\C-h" 'octave-mark-block) - (define-key map "\C-c]" 'octave-close-block) - (define-key map "\C-c\C-f" 'octave-insert-defun) - (define-key map "\C-c\C-h" 'octave-help) - (define-key map "\C-c\C-il" 'octave-send-line) - (define-key map "\C-c\C-ib" 'octave-send-block) - (define-key map "\C-c\C-if" 'octave-send-defun) - (define-key map "\C-c\C-ir" 'octave-send-region) - (define-key map "\C-c\C-is" 'octave-show-process-buffer) - (define-key map "\C-c\C-ih" 'octave-hide-process-buffer) - (define-key map "\C-c\C-ik" 'octave-kill-process) - (define-key map "\C-c\C-i\C-l" 'octave-send-line) - (define-key map "\C-c\C-i\C-b" 'octave-send-block) - (define-key map "\C-c\C-i\C-f" 'octave-send-defun) - (define-key map "\C-c\C-i\C-r" 'octave-send-region) - (define-key map "\C-c\C-i\C-s" 'octave-show-process-buffer) - (define-key map "\C-c\C-i\C-h" 'octave-hide-process-buffer) - (define-key map "\C-c\C-i\C-k" 'octave-kill-process) - map) - "Keymap used in Octave mode.") - - -(defvar octave-mode-menu - '("Octave" - '("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" - ["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" - ["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" - ["Send Current Line" octave-send-line t] - ["Send Current Block" octave-send-block t] - ["Send Current Function" octave-send-defun t] - ["Send Region" octave-send-region t] - ["Show Process Buffer" octave-show-process-buffer t] - ["Hide Process Buffer" octave-hide-process-buffer t] - ["Kill Process" octave-kill-process t]) - "-" - ["Indent Line" indent-according-to-mode t] - ["Complete Symbol" octave-complete-symbol t] - "-" - ["Toggle Abbrev Mode" abbrev-mode t] - ["Toggle Auto-Fill Mode" auto-fill-mode t] - "-" - ["Submit Bug Report" octave-submit-bug-report t] - "-" - ["Describe Octave Mode" octave-describe-major-mode t] - ["Lookup Octave Index" octave-help t]) - "Menu for Octave mode.") - -(defvar octave-mode-syntax-table - (let ((table (make-syntax-table))) - (modify-syntax-entry ?\r " " table) - (modify-syntax-entry ?+ "." table) - (modify-syntax-entry ?- "." table) - (modify-syntax-entry ?= "." table) - (modify-syntax-entry ?* "." table) - (modify-syntax-entry ?/ "." table) - (modify-syntax-entry ?> "." table) - (modify-syntax-entry ?< "." table) - (modify-syntax-entry ?& "." table) - (modify-syntax-entry ?| "." table) - (modify-syntax-entry ?! "." table) - (modify-syntax-entry ?\\ "\\" table) - (modify-syntax-entry ?\' "." table) - (modify-syntax-entry ?\` "w" table) - (modify-syntax-entry ?\" "\"" table) - (modify-syntax-entry ?. "w" table) - (modify-syntax-entry ?_ "w" table) - (modify-syntax-entry ?\% "<" table) - (modify-syntax-entry ?\# "<" table) - (modify-syntax-entry ?\n ">" table) - table) - "Syntax table in use in `octave-mode' buffers.") - -(defcustom octave-auto-indent nil - "Non-nil means indent line after a semicolon or space in Octave mode." - :type 'boolean - :group 'octave) - -(defcustom octave-auto-newline nil - "Non-nil means automatically newline after a semicolon in Octave mode." - :type 'boolean - :group 'octave) - -(defcustom octave-blink-matching-block t - "Control the blinking of matching Octave block keywords. -Non-nil means show matching begin of block when inserting a space, -newline or semicolon after an else or end keyword." - :type 'boolean - :group 'octave) -(defcustom octave-block-offset 2 - "Extra indentation applied to statements in Octave block structures." - :type 'integer - :group 'octave) - -(defvar octave-block-begin-regexp - (concat "\\<\\(" - (mapconcat 'identity octave-begin-keywords "\\|") - "\\)\\>")) -(defvar octave-block-else-regexp - (concat "\\<\\(" - (mapconcat 'identity octave-else-keywords "\\|") - "\\)\\>")) -(defvar octave-block-end-regexp - (concat "\\<\\(" - (mapconcat 'identity octave-end-keywords "\\|") - "\\)\\>")) -(defvar octave-block-begin-or-end-regexp - (concat octave-block-begin-regexp "\\|" octave-block-end-regexp)) -(defvar octave-block-else-or-end-regexp - (concat octave-block-else-regexp "\\|" octave-block-end-regexp)) -;; FIXME: only use specific "end" tokens here to avoid confusion when "end" -;; is used in indexing (the real fix is much more complex). -(defvar octave-block-match-alist - '(("do" . ("until")) - ("for" . ("endfor")) - ("function" . ("endfunction")) - ("if" . ("else" "elseif" "endif")) - ("switch" . ("case" "otherwise" "endswitch")) - ("try" . ("catch" "end_try_catch")) - ("unwind_protect" . ("unwind_protect_cleanup" "end_unwind_protect")) - ("while" . ("endwhile"))) - "Alist with Octave's matching block keywords. -Has Octave's begin keywords as keys and a list of the matching else or -end keywords as associated values.") - -(defvar octave-block-comment-start - (concat (make-string 2 octave-comment-char) " ") - "String to insert to start a new Octave comment on an empty line.") - -(defcustom octave-continuation-offset 4 - "Extra indentation applied to Octave continuation lines." - :type 'integer - :group 'octave) -(defvar octave-continuation-regexp - "[^#%\n]*\\(\\\\\\|\\.\\.\\.\\)\\s-*\\(\\s<.*\\)?$") -(defcustom octave-continuation-string "\\" - "Character string used for Octave continuation lines. Normally \\." - :type 'string - :group 'octave) - -(defvar octave-completion-alist nil - "Alist of Octave symbols for completion in Octave mode. -Each element looks like (VAR . VAR), where the car and cdr are the same -symbol (an Octave command or variable name). -Currently, only builtin variables can be completed.") - -(defvar octave-mode-imenu-generic-expression - (list - ;; Functions - (list nil octave-function-header-regexp 3)) - "Imenu expression for Octave mode. See `imenu-generic-expression'.") - -(defcustom octave-mode-hook nil - "Hook to be run when Octave mode is started." - :type 'hook - :group 'octave) - -(defcustom octave-send-show-buffer t - "Non-nil means display `inferior-octave-buffer' after sending to it." - :type 'boolean - :group 'octave) -(defcustom octave-send-line-auto-forward t - "Control auto-forward after sending to the inferior Octave process. -Non-nil means always go to the next Octave code line after sending." - :type 'boolean - :group 'octave) -(defcustom octave-send-echo-input t - "Non-nil means echo input sent to the inferior Octave process." - :type 'boolean - :group 'octave) - - -;;;###autoload -(defun octave-mode () - "Major mode for editing Octave code. - -This mode makes it easier to write Octave code by helping with -indentation, doing some of the typing for you (with Abbrev mode) and by -showing keywords, comments, strings, etc.. in different faces (with -Font Lock mode on terminals that support it). - -Octave itself is a high-level language, primarily intended for numerical -computations. It provides a convenient command line interface for -solving linear and nonlinear problems numerically. Function definitions -can also be stored in files, and it can be used in a batch mode (which -is why you need this mode!). - -The latest released version of Octave is always available via anonymous -ftp from ftp.octave.org in the directory `/pub/octave'. Complete -source and binaries for several popular systems are available. - -Type \\[list-abbrevs] to display the built-in abbrevs for Octave keywords. - -Keybindings -=========== - -\\{octave-mode-map} - -Variables you can use to customize Octave mode -============================================== - -`octave-auto-indent' - Non-nil means indent current line after a semicolon or space. - Default is nil. - -`octave-auto-newline' - Non-nil means auto-insert a newline and indent after a semicolon. - Default is nil. - -`octave-blink-matching-block' - Non-nil means show matching begin of block when inserting a space, - newline or semicolon after an else or end keyword. Default is t. - -`octave-block-offset' - Extra indentation applied to statements in block structures. - Default is 2. - -`octave-continuation-offset' - Extra indentation applied to Octave continuation lines. - Default is 4. - -`octave-continuation-string' - String used for Octave continuation lines. - Default is a backslash. - -`octave-send-echo-input' - Non-nil means always display `inferior-octave-buffer' after sending a - command to the inferior Octave process. - -`octave-send-line-auto-forward' - Non-nil means always go to the next unsent line of Octave code after - sending a line to the inferior Octave process. - -`octave-send-echo-input' - Non-nil means echo input sent to the inferior Octave process. - -Turning on Octave mode runs the hook `octave-mode-hook'. - -To begin using this mode for all `.m' files that you edit, add the -following lines to your `.emacs' file: - - (add-to-list 'auto-mode-alist '(\"\\\\.m\\\\'\" . octave-mode)) - -To automatically turn on the abbrev and auto-fill features, -add the following lines to your `.emacs' file as well: - - (add-hook 'octave-mode-hook - (lambda () - (abbrev-mode 1) - (auto-fill-mode 1))) - -To submit a problem report, enter \\[octave-submit-bug-report] from \ -an Octave mode buffer. -This automatically sets up a mail buffer with version information -already added. You just need to add a description of the problem, -including a reproducible test case and send the message." - (interactive) - (kill-all-local-variables) - - (use-local-map octave-mode-map) - (setq major-mode 'octave-mode) - (setq mode-name "Octave") - (setq local-abbrev-table octave-abbrev-table) - (set-syntax-table octave-mode-syntax-table) - - (make-local-variable 'indent-line-function) - (setq indent-line-function 'octave-indent-line) - - (make-local-variable 'comment-start) - (setq comment-start octave-comment-start) - (make-local-variable 'comment-end) - (setq comment-end "") - (make-local-variable 'comment-column) - (setq comment-column 32) - (make-local-variable 'comment-start-skip) - (setq comment-start-skip "\\s<+\\s-*") - (make-local-variable 'comment-indent-function) - (setq comment-indent-function 'octave-comment-indent) - - (make-local-variable 'parse-sexp-ignore-comments) - (setq parse-sexp-ignore-comments t) - (make-local-variable 'paragraph-start) - (setq paragraph-start (concat "\\s-*$\\|" page-delimiter)) - (make-local-variable 'paragraph-separate) - (setq paragraph-separate paragraph-start) - (make-local-variable 'paragraph-ignore-fill-prefix) - (setq paragraph-ignore-fill-prefix t) - (make-local-variable 'fill-paragraph-function) - (setq fill-paragraph-function 'octave-fill-paragraph) - (make-local-variable 'adaptive-fill-regexp) - (setq adaptive-fill-regexp nil) - (make-local-variable 'fill-column) - (setq fill-column 72) - (make-local-variable 'normal-auto-fill-function) - (setq normal-auto-fill-function 'octave-auto-fill) - - (make-local-variable 'font-lock-defaults) - (setq font-lock-defaults '(octave-font-lock-keywords nil nil)) - - (make-local-variable 'imenu-generic-expression) - (setq imenu-generic-expression octave-mode-imenu-generic-expression - imenu-case-fold-search nil) - - (octave-add-octave-menu) - (octave-initialize-completions) - (run-mode-hooks 'octave-mode-hook)) - -;;; Miscellaneous useful functions -(defun octave-describe-major-mode () - "Describe the current major mode." - (interactive) - (describe-function major-mode)) - -(defsubst octave-in-comment-p () - "Return t if point is inside an Octave comment." - (interactive) - (save-excursion - (nth 4 (parse-partial-sexp (line-beginning-position) (point))))) - -(defsubst octave-in-string-p () - "Return t if point is inside an Octave string." - (interactive) - (save-excursion - (nth 3 (parse-partial-sexp (line-beginning-position) (point))))) - -(defsubst octave-not-in-string-or-comment-p () - "Return t if point is not inside an Octave string or comment." - (let ((pps (parse-partial-sexp (line-beginning-position) (point)))) - (not (or (nth 3 pps) (nth 4 pps))))) - -(defun octave-in-block-p () - "Return t if point is inside an Octave block. -The block is taken to start at the first letter of the begin keyword and -to end after the end keyword." - (let ((pos (point))) - (save-excursion - (condition-case nil - (progn - (skip-syntax-forward "w") - (octave-up-block -1) - (octave-forward-block) - t) - (error nil)) - (< pos (point))))) - -(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\\>") - (octave-not-in-string-or-comment-p)) - (and (octave-beginning-of-defun) - (condition-case nil - (progn - (octave-forward-block) - t) - (error nil)) - (< pos (point))))))) - -(defun octave-maybe-insert-continuation-string () - (if (or (octave-in-comment-p) - (save-excursion - (beginning-of-line) - (looking-at octave-continuation-regexp))) - 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. -See `comment-region'." - (interactive "r\nP") - (let ((comment-start (char-to-string octave-comment-char))) - (comment-region beg end arg))) - -(defun octave-uncomment-region (beg end &optional arg) - "Uncomment each line in the region as Octave code." - (interactive "r\nP") - (or arg (setq arg 1)) - (octave-comment-region beg end (- arg))) - - -;;; Indentation -(defun calculate-octave-indent () - "Return appropriate indentation for current line as Octave code. -Returns an integer (the column to indent to) unless the line is a -comment line with fixed goal golumn. In that case, returns a list whose -car is the column to indent to, and whose cdr is the current indentation -level." - (let ((is-continuation-line - (save-excursion - (if (zerop (octave-previous-code-line)) - (looking-at octave-continuation-regexp)))) - (icol 0)) - (save-excursion - (beginning-of-line) - ;; If we can move backward out one level of parentheses, take 1 - ;; plus the indentation of that parenthesis. Otherwise, go back - ;; to the beginning of the previous code line, and compute the - ;; offset this line gives. - (if (condition-case nil - (progn - (up-list -1) - t) - (error nil)) - (setq icol (+ 1 (current-column))) - (if (zerop (octave-previous-code-line)) - (progn - (octave-beginning-of-line) - (back-to-indentation) - (setq icol (current-column)) - (let ((bot (point)) - (eol (line-end-position))) - (while (< (point) eol) - (if (octave-not-in-string-or-comment-p) - (cond - ((looking-at "\\<switch\\>") - (setq icol (+ icol (* 2 octave-block-offset)))) - ((looking-at octave-block-begin-regexp) - (setq icol (+ icol octave-block-offset))) - ((looking-at octave-block-else-regexp) - (if (= bot (point)) - (setq icol (+ icol octave-block-offset)))) - ((looking-at octave-block-end-regexp) - (if (not (= bot (point))) - (setq icol (- icol - (octave-block-end-offset))))))) - (forward-char))) - (if is-continuation-line - (setq icol (+ icol octave-continuation-offset))))))) - (save-excursion - (back-to-indentation) - (cond - ((and (looking-at octave-block-else-regexp) - (octave-not-in-string-or-comment-p)) - (setq icol (- icol octave-block-offset))) - ((and (looking-at 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<") - (octave-before-magic-comment-p)) - (setq icol (list 0 icol))) - ((looking-at "\\s<\\S<") - (setq icol (list comment-column icol))))) - icol)) - -(defun octave-block-end-offset () - (save-excursion - (octave-backward-up-block 1) - (* octave-block-offset - (if (string-match (match-string 0) "switch") 2 1)))) - -(defun octave-before-magic-comment-p () - (save-excursion - (beginning-of-line) - (and (bobp) (looking-at "\\s-*#!")))) - -(defun octave-comment-indent () - (if (or (looking-at "\\s<\\s<\\s<") - (octave-before-magic-comment-p)) - 0 - (if (looking-at "\\s<\\s<") - (calculate-octave-indent) - (skip-syntax-backward " ") - (max (if (bolp) 0 (+ 1 (current-column))) - comment-column)))) - -(defun octave-indent-for-comment () - "Maybe insert and indent an Octave comment. -If there is no comment already on this line, create a code-level comment -\(started by two comment characters) if the line is empty, or an in-line -comment (started by one comment character) otherwise. -Point is left after the start of the comment which is properly aligned." - (interactive) - (beginning-of-line) - (if (looking-at "^\\s-*$") - (insert octave-block-comment-start) - (indent-for-comment)) - (indent-according-to-mode)) - -(defun octave-indent-line (&optional arg) - "Indent current line as Octave code. -With optional ARG, use this as offset unless this line is a comment with -fixed goal column." - (interactive) - (or arg (setq arg 0)) - (let ((icol (calculate-octave-indent)) - (relpos (- (current-column) (current-indentation)))) - (if (listp icol) - (setq icol (car icol)) - (setq icol (+ icol arg))) - (if (< icol 0) - (error "Unmatched end keyword") - (indent-line-to icol) - (if (> relpos 0) - (move-to-column (+ icol relpos)))))) - -(defun octave-indent-new-comment-line () - "Break Octave line at point, continuing comment if within one. -If within code, insert `octave-continuation-string' before breaking the -line. If within a string, signal an error. -The new line is properly indented." - (interactive) - (delete-horizontal-space) - (cond - ((octave-in-comment-p) - (indent-new-comment-line)) - ((octave-in-string-p) - (error "Cannot split a code line inside a string")) - (t - (insert (concat " " octave-continuation-string)) - (octave-reindent-then-newline-and-indent)))) - -(defun octave-indent-defun () - "Properly indent the Octave function which contains point." - (interactive) - (save-excursion - (octave-mark-defun) - (message "Indenting function...") - (indent-region (point) (mark) nil)) - (message "Indenting function...done.")) - - -;;; Motion -(defun octave-next-code-line (&optional arg) - "Move ARG lines of Octave code forward (backward if ARG is negative). -Skips past all empty and comment lines. Default for ARG is 1. - -On success, return 0. Otherwise, go as far as possible and return -1." - (interactive "p") - (or arg (setq arg 1)) - (beginning-of-line) - (let ((n 0) - (inc (if (> arg 0) 1 -1))) - (while (and (/= arg 0) (= n 0)) - (setq n (forward-line inc)) - (while (and (= n 0) - (looking-at "\\s-*\\($\\|\\s<\\)")) - (setq n (forward-line inc))) - (setq arg (- arg inc))) - n)) - -(defun octave-previous-code-line (&optional arg) - "Move ARG lines of Octave code backward (forward if ARG is negative). -Skips past all empty and comment lines. Default for ARG is 1. - -On success, return 0. Otherwise, go as far as possible and return -1." - (interactive "p") - (or arg (setq arg 1)) - (octave-next-code-line (- arg))) - -(defun octave-beginning-of-line () - "Move point to beginning of current Octave line. -If on an empty or comment line, go to the beginning of that line. -Otherwise, move backward to the beginning of the first Octave code line -which is not inside a continuation statement, i.e., which does not -follow a code line ending in `...' or `\\', or is inside an open -parenthesis list." - (interactive) - (beginning-of-line) - (if (not (looking-at "\\s-*\\($\\|\\s<\\)")) - (while (or (condition-case nil - (progn - (up-list -1) - (beginning-of-line) - t) - (error nil)) - (and (or (looking-at "\\s-*\\($\\|\\s<\\)") - (save-excursion - (if (zerop (octave-previous-code-line)) - (looking-at octave-continuation-regexp)))) - (zerop (forward-line -1))))))) - -(defun octave-end-of-line () - "Move point to end of current Octave line. -If on an empty or comment line, go to the end of that line. -Otherwise, move forward to the end of the first Octave code line which -does not end in `...' or `\\' or is inside an open parenthesis list." - (interactive) - (end-of-line) - (if (save-excursion - (beginning-of-line) - (looking-at "\\s-*\\($\\|\\s<\\)")) - () - (while (or (condition-case nil - (progn - (up-list 1) - (end-of-line) - t) - (error nil)) - (and (save-excursion - (beginning-of-line) - (or (looking-at "\\s-*\\($\\|\\s<\\)") - (looking-at octave-continuation-regexp))) - (zerop (forward-line 1))))) - (end-of-line))) - -(defun octave-scan-blocks (count depth) - "Scan from point by COUNT Octave begin-end blocks. -Returns the character number of the position thus found. - -If DEPTH is nonzero, block depth begins counting from that value. -Only places where the depth in blocks becomes zero are candidates for -stopping; COUNT such places are counted. - -If the beginning or end of the buffer is reached and the depth is wrong, -an error is signaled." - (let ((min-depth (if (> depth 0) 0 depth)) - (inc (if (> count 0) 1 -1))) - (save-excursion - (while (/= count 0) - (catch 'foo - (while (or (re-search-forward - octave-block-begin-or-end-regexp nil 'move inc) - (if (/= depth 0) - (error "Unbalanced block"))) - (if (octave-not-in-string-or-comment-p) - (progn - (cond - ((match-end 1) - (setq depth (+ depth inc))) - ((match-end 2) - (setq depth (- depth inc)))) - (if (< depth min-depth) - (error "Containing expression ends prematurely")) - (if (= depth 0) - (throw 'foo nil)))))) - (setq count (- count inc))) - (point)))) - -(defun octave-forward-block (&optional arg) - "Move forward across one balanced Octave begin-end block. -With argument, do it that many times. -Negative arg -N means move backward across N blocks." - (interactive "p") - (or arg (setq arg 1)) - (goto-char (or (octave-scan-blocks arg 0) (buffer-end arg)))) - -(defun octave-backward-block (&optional arg) - "Move backward across one balanced Octave begin-end block. -With argument, do it that many times. -Negative arg -N means move forward across N blocks." - (interactive "p") - (or arg (setq arg 1)) - (octave-forward-block (- arg))) - -(defun octave-down-block (arg) - "Move forward down one begin-end block level of Octave code. -With argument, do this that many times. -A negative argument means move backward but still go down a level. -In Lisp programs, an argument is required." - (interactive "p") - (let ((inc (if (> arg 0) 1 -1))) - (while (/= arg 0) - (goto-char (or (octave-scan-blocks inc -1) - (buffer-end arg))) - (setq arg (- arg inc))))) - -(defun octave-backward-up-block (arg) - "Move backward out of one begin-end block level of Octave code. -With argument, do this that many times. -A negative argument means move forward but still to a less deep spot. -In Lisp programs, an argument is required." - (interactive "p") - (octave-up-block (- arg))) - -(defun octave-up-block (arg) - "Move forward out of one begin-end block level of Octave code. -With argument, do this that many times. -A negative argument means move backward but still to a less deep spot. -In Lisp programs, an argument is required." - (interactive "p") - (let ((inc (if (> arg 0) 1 -1))) - (while (/= arg 0) - (goto-char (or (octave-scan-blocks inc 1) - (buffer-end arg))) - (setq arg (- arg inc))))) - -(defun octave-mark-block () - "Put point at the beginning of this Octave block, mark at the end. -The block marked is the one that contains point or follows point." - (interactive) - (let ((pos (point))) - (if (or (and (octave-in-block-p) - (skip-syntax-forward "w")) - (condition-case nil - (progn - (octave-down-block 1) - (octave-in-block-p)) - (error nil))) - (progn - (octave-up-block -1) - (push-mark (point)) - (octave-forward-block) - (exchange-point-and-mark)) - (goto-char pos) - (message "No block to mark found")))) - -(defun octave-close-block () - "Close the current Octave block on a separate line. -An error is signaled if no block to close is found." - (interactive) - (let (bb-keyword) - (condition-case nil - (progn - (save-excursion - (octave-backward-up-block 1) - (setq bb-keyword (buffer-substring-no-properties - (match-beginning 1) (match-end 1)))) - (if (save-excursion - (beginning-of-line) - (looking-at "^\\s-*$")) - (indent-according-to-mode) - (octave-reindent-then-newline-and-indent)) - (insert (car (reverse - (assoc bb-keyword - octave-block-match-alist)))) - (octave-reindent-then-newline-and-indent) - t) - (error (message "No block to close found"))))) - -(defun octave-blink-matching-block-open () - "Blink the matching Octave begin block keyword. -If point is right after an Octave else or end type block keyword, move -cursor momentarily to the corresponding begin keyword. -Signal an error if the keywords are incompatible." - (interactive) - (let (bb-keyword bb-arg eb-keyword pos eol) - (if (and (octave-not-in-string-or-comment-p) - (looking-at "\\>") - (save-excursion - (skip-syntax-backward "w") - (looking-at octave-block-else-or-end-regexp))) - (save-excursion - (cond - ((match-end 1) - (setq eb-keyword - (buffer-substring-no-properties - (match-beginning 1) (match-end 1))) - (octave-backward-up-block 1)) - ((match-end 2) - (setq eb-keyword - (buffer-substring-no-properties - (match-beginning 2) (match-end 2))) - (octave-backward-block))) - (setq pos (match-end 0) - bb-keyword - (buffer-substring-no-properties - (match-beginning 0) pos) - pos (+ pos 1) - eol (line-end-position) - bb-arg - (save-excursion - (save-restriction - (goto-char pos) - (while (and (skip-syntax-forward "^<" eol) - (octave-in-string-p) - (not (forward-char 1)))) - (skip-syntax-backward " ") - (buffer-substring-no-properties pos (point))))) - (if (member eb-keyword - (cdr (assoc bb-keyword octave-block-match-alist))) - (progn - (message "Matches `%s %s'" bb-keyword bb-arg) - (if (pos-visible-in-window-p) - (sit-for blink-matching-delay))) - (error "Block keywords `%s' and `%s' do not match" - bb-keyword eb-keyword)))))) - -(defun octave-beginning-of-defun (&optional arg) - "Move backward to the beginning of an Octave function. -With positive ARG, do it that many times. Negative argument -N means -move forward to Nth following beginning of a function. -Returns t unless search stops at the beginning or end of the buffer." - (interactive "p") - (let* ((arg (or arg 1)) - (inc (if (> arg 0) 1 -1)) - (found)) - (and (not (eobp)) - (not (and (> arg 0) (looking-at "\\<function\\>"))) - (skip-syntax-forward "w")) - (while (and (/= arg 0) - (setq found - (re-search-backward "\\<function\\>" nil 'move inc))) - (if (octave-not-in-string-or-comment-p) - (setq arg (- arg inc)))) - (if found - (progn - (and (< inc 0) (goto-char (match-beginning 0))) - t)))) - -(defun octave-end-of-defun (&optional arg) - "Move forward to the end of an Octave function. -With positive ARG, do it that many times. Negative argument -N means -move back to Nth preceding end of a function. - -An end of a function occurs right after the end keyword matching the -`function' keyword that starts the function." - (interactive "p") - (or arg (setq arg 1)) - (and (< arg 0) (skip-syntax-backward "w")) - (and (> arg 0) (skip-syntax-forward "w")) - (if (octave-in-defun-p) - (setq arg (- arg 1))) - (if (= arg 0) (setq arg -1)) - (if (octave-beginning-of-defun (- arg)) - (octave-forward-block))) - -(defun octave-mark-defun () - "Put point at the beginning of this Octave function, mark at its end. -The function marked is the one containing point or following point." - (interactive) - (let ((pos (point))) - (if (or (octave-in-defun-p) - (and (octave-beginning-of-defun -1) - (octave-in-defun-p))) - (progn - (skip-syntax-forward "w") - (octave-beginning-of-defun) - (push-mark (point)) - (octave-end-of-defun) - (exchange-point-and-mark)) - (goto-char pos) - (message "No function to mark found")))) - - -;;; Filling -(defun octave-auto-fill () - "Perform auto-fill in Octave mode. -Returns nil if no feasible place to break the line could be found, and t -otherwise." - (let (fc give-up) - (if (or (null (setq fc (current-fill-column))) - (save-excursion - (beginning-of-line) - (and auto-fill-inhibit-regexp - (looking-at auto-fill-inhibit-regexp)))) - nil ; Can't do anything - (if (and (not (octave-in-comment-p)) - (> (current-column) fc)) - (setq fc (- fc (+ (length octave-continuation-string) 1)))) - (while (and (not give-up) (> (current-column) fc)) - (let* ((opoint (point)) - (fpoint - (save-excursion - (move-to-column (+ fc 1)) - (skip-chars-backward "^ \t\n") - ;; If we're at the beginning of the line, break after - ;; the first word - (if (bolp) - (re-search-forward "[ \t]" opoint t)) - ;; If we're in a comment line, don't break after the - ;; comment chars - (if (save-excursion - (skip-syntax-backward " <") - (bolp)) - (re-search-forward "[ \t]" (line-end-position) - 'move)) - ;; If we're not in a comment line and just ahead the - ;; continuation string, don't break here. - (if (and (not (octave-in-comment-p)) - (looking-at - (concat "\\s-*" - (regexp-quote - octave-continuation-string) - "\\s-*$"))) - (end-of-line)) - (skip-chars-backward " \t") - (point)))) - (if (save-excursion - (goto-char fpoint) - (not (or (bolp) (eolp)))) - (let ((prev-column (current-column))) - (if (save-excursion - (skip-chars-backward " \t") - (= (point) fpoint)) - (progn - (octave-maybe-insert-continuation-string) - (indent-new-comment-line t)) - (save-excursion - (goto-char fpoint) - (octave-maybe-insert-continuation-string) - (indent-new-comment-line t))) - (if (>= (current-column) prev-column) - (setq give-up t))) - (setq give-up t)))) - (not give-up)))) - -(defun octave-fill-paragraph (&optional arg) - "Fill paragraph of Octave code, handling Octave comments." - ;; FIXME: now that the default fill-paragraph takes care of similar issues, - ;; this seems obsolete. --Stef - (interactive "P") - (save-excursion - (let ((end (progn (forward-paragraph) (point))) - (beg (progn - (forward-paragraph -1) - (skip-chars-forward " \t\n") - (beginning-of-line) - (point))) - (cfc (current-fill-column)) - (ind (calculate-octave-indent)) - comment-prefix) - (save-restriction - (goto-char beg) - (narrow-to-region beg end) - (if (listp ind) (setq ind (nth 1 ind))) - (while (not (eobp)) - (condition-case nil - (octave-indent-line ind) - (error nil)) - (if (and (> ind 0) - (not - (save-excursion - (beginning-of-line) - (looking-at "^\\s-*\\($\\|\\s<+\\)")))) - (setq ind 0)) - (move-to-column cfc) - ;; First check whether we need to combine non-empty comment lines - (if (and (< (current-column) cfc) - (octave-in-comment-p) - (not (save-excursion - (beginning-of-line) - (looking-at "^\\s-*\\s<+\\s-*$")))) - ;; This is a nonempty comment line which does not extend - ;; past the fill column. If it is followed by a nonempty - ;; comment line with the same comment prefix, try to - ;; combine them, and repeat this until either we reach the - ;; fill-column or there is nothing more to combine. - (progn - ;; Get the comment prefix - (save-excursion - (beginning-of-line) - (while (and (re-search-forward "\\s<+") - (not (octave-in-comment-p)))) - (setq comment-prefix (match-string 0))) - ;; And keep combining ... - (while (and (< (current-column) cfc) - (save-excursion - (forward-line 1) - (and (looking-at - (concat "^\\s-*" - comment-prefix - "\\S<")) - (not (looking-at - (concat "^\\s-*" - comment-prefix - "\\s-*$")))))) - (delete-char 1) - (re-search-forward comment-prefix) - (delete-region (match-beginning 0) (match-end 0)) - (fixup-whitespace) - (move-to-column cfc)))) - ;; We might also try to combine continued code lines> Perhaps - ;; some other time ... - (skip-chars-forward "^ \t\n") - (delete-horizontal-space) - (if (or (< (current-column) cfc) - (and (= (current-column) cfc) (eolp))) - (forward-line 1) - (if (not (eolp)) (insert " ")) - (or (octave-auto-fill) - (forward-line 1))))) - t))) - - -;;; Completions -(defun octave-initialize-completions () - "Create an alist for Octave completions." - (if octave-completion-alist - () - (setq octave-completion-alist - (mapcar '(lambda (var) (cons var var)) - (append octave-reserved-words - octave-text-functions - octave-variables))))) - -(defun octave-complete-symbol () - "Perform completion on Octave symbol preceding point. -Compare that symbol against Octave's reserved words and builtin -variables." - ;; This code taken from lisp-complete-symbol - (interactive) - (let* ((end (point)) - (beg (save-excursion (backward-sexp 1) (point))) - (string (buffer-substring-no-properties beg end)) - (completion (try-completion string octave-completion-alist))) - (cond ((eq completion t)) ; ??? - ((null completion) - (message "Can't find completion for \"%s\"" string) - (ding)) - ((not (string= string completion)) - (delete-region beg end) - (insert completion)) - (t - (let ((list (all-completions string octave-completion-alist)) - (conf (current-window-configuration))) - ;; Taken from comint.el - (message "Making completion list...") - (with-output-to-temp-buffer "*Completions*" - (display-completion-list list string)) - (message "Hit space to flush") - (let (key first) - (if (save-excursion - (set-buffer (get-buffer "*Completions*")) - (setq key (read-key-sequence nil) - first (aref key 0)) - (and (consp first) (consp (event-start first)) - (eq (window-buffer (posn-window (event-start - first))) - (get-buffer "*Completions*")) - (eq (key-binding key) 'mouse-choose-completion))) - (progn - (mouse-choose-completion first) - (set-window-configuration conf)) - (if (eq first ?\ ) - (set-window-configuration conf) - (setq unread-command-events - (listify-key-sequence key)))))))))) - - -;;; Electric characters && friends -(defun octave-reindent-then-newline-and-indent () - "Reindent current Octave line, insert newline, and indent the new line. -If Abbrev mode is on, expand abbrevs first." - (interactive) - (if abbrev-mode (expand-abbrev)) - (if octave-blink-matching-block - (octave-blink-matching-block-open)) - (save-excursion - (delete-region (point) (progn (skip-chars-backward " \t") (point))) - (indent-according-to-mode)) - (insert "\n") - (indent-according-to-mode)) - -(defun octave-electric-semi () - "Insert a semicolon in Octave mode. -Maybe expand abbrevs and blink matching block open keywords. -Reindent the line of `octave-auto-indent' is non-nil. -Insert a newline if `octave-auto-newline' is non-nil." - (interactive) - (if (not (octave-not-in-string-or-comment-p)) - (insert ";") - (if abbrev-mode (expand-abbrev)) - (if octave-blink-matching-block - (octave-blink-matching-block-open)) - (if octave-auto-indent - (indent-according-to-mode)) - (insert ";") - (if octave-auto-newline - (newline-and-indent)))) - -(defun octave-electric-space () - "Insert a space in Octave mode. -Maybe expand abbrevs and blink matching block open keywords. -Reindent the line of `octave-auto-indent' is non-nil." - (interactive) - (setq last-command-char ? ) - (if (and octave-auto-indent - (not (octave-not-in-string-or-comment-p))) - (progn - (indent-according-to-mode) - (self-insert-command 1)) - (if abbrev-mode (expand-abbrev)) - (if octave-blink-matching-block - (octave-blink-matching-block-open)) - (if (and octave-auto-indent - (save-excursion - (skip-syntax-backward " ") - (not (bolp)))) - (indent-according-to-mode)) - (self-insert-command 1))) - -(defun octave-abbrev-start () - "Start entering an Octave abbreviation. -If Abbrev mode is turned on, typing ` (grave accent) followed by ? or -\\[help-command] lists all Octave abbrevs. Any other key combination is -executed normally. -Note that all Octave mode abbrevs start with a grave accent." - (interactive) - (if (not abbrev-mode) - (self-insert-command 1) - (let (c) - (insert last-command-char) - (if (if octave-xemacs-p - (or (eq (event-to-character (setq c (next-event))) ??) - (eq (event-to-character c) help-char)) - (or (eq (setq c (read-event)) ??) - (eq c help-char))) - (let ((abbrev-table-name-list '(octave-abbrev-table))) - (list-abbrevs)) - (setq unread-command-events (list c)))))) - -(defun octave-insert-defun (name args vals) - "Insert an Octave function skeleton. -Prompt for the function's name, arguments and return values (to be -entered without parens)." - (interactive - (list - (read-from-minibuffer "Function name: " - (substring (buffer-name) 0 -2)) - (read-from-minibuffer "Arguments: ") - (read-from-minibuffer "Return values: "))) - (let ((string (format "%s %s (%s)" - (cond - ((string-equal vals "") - vals) - ((string-match "[ ,]" vals) - (concat " [" vals "] =")) - (t - (concat " " vals " ="))) - name - args)) - (prefix octave-block-comment-start)) - (if (not (bobp)) (newline)) - (insert "function" string) - (indent-according-to-mode) - (newline 2) - (insert prefix "usage: " string) - (reindent-then-newline-and-indent) - (insert prefix) - (reindent-then-newline-and-indent) - (insert prefix) - (indent-according-to-mode) - (save-excursion - (newline 2) - (insert "endfunction") - (indent-according-to-mode)))) - - -;;; Menu -(defun octave-add-octave-menu () - "Add the `Octave' menu to the menu bar in Octave mode." - (require 'easymenu) - (easy-menu-define octave-mode-menu-map octave-mode-map - "Menu keymap for Octave mode." octave-mode-menu) - (easy-menu-add octave-mode-menu-map octave-mode-map)) - - -;;; Communication with the inferior Octave process -(defun octave-kill-process () - "Kill inferior Octave process and its buffer." - (interactive) - (if inferior-octave-process - (progn - (process-send-string inferior-octave-process "quit;\n") - (accept-process-output inferior-octave-process))) - (if inferior-octave-buffer - (kill-buffer inferior-octave-buffer))) - -(defun octave-show-process-buffer () - "Make sure that `inferior-octave-buffer' is displayed." - (interactive) - (if (get-buffer inferior-octave-buffer) - (display-buffer inferior-octave-buffer) - (message "No buffer named %s" inferior-octave-buffer))) - -(defun octave-hide-process-buffer () - "Delete all windows that display `inferior-octave-buffer'." - (interactive) - (if (get-buffer inferior-octave-buffer) - (delete-windows-on inferior-octave-buffer) - (message "No buffer named %s" inferior-octave-buffer))) - -(defun octave-send-region (beg end) - "Send current region to the inferior Octave process." - (interactive "r") - (inferior-octave t) - (let ((proc inferior-octave-process) - (string (buffer-substring-no-properties beg end)) - line) - (save-excursion - (set-buffer inferior-octave-buffer) - (setq inferior-octave-output-list nil) - (while (not (string-equal string "")) - (if (string-match "\n" string) - (setq line (substring string 0 (match-beginning 0)) - string (substring string (match-end 0))) - (setq line string string "")) - (setq inferior-octave-receive-in-progress t) - (inferior-octave-send-list-and-digest (list (concat line "\n"))) - (while inferior-octave-receive-in-progress - (accept-process-output proc)) - (insert-before-markers - (mapconcat 'identity - (append - (if octave-send-echo-input (list line) (list "")) - (mapcar 'inferior-octave-strip-ctrl-g - inferior-octave-output-list) - (list inferior-octave-output-string)) - "\n"))))) - (if octave-send-show-buffer - (display-buffer inferior-octave-buffer))) - -(defun octave-send-block () - "Send current Octave block to the inferior Octave process." - (interactive) - (save-excursion - (octave-mark-block) - (octave-send-region (point) (mark)))) - -(defun octave-send-defun () - "Send current Octave function to the inferior Octave process." - (interactive) - (save-excursion - (octave-mark-defun) - (octave-send-region (point) (mark)))) - -(defun octave-send-line (&optional arg) - "Send current Octave code line to the inferior Octave process. -With positive prefix ARG, send that many lines. -If `octave-send-line-auto-forward' is non-nil, go to the next unsent -code line." - (interactive "P") - (or arg (setq arg 1)) - (if (> arg 0) - (let (beg end) - (beginning-of-line) - (setq beg (point)) - (octave-next-code-line (- arg 1)) - (end-of-line) - (setq end (point)) - (if octave-send-line-auto-forward - (octave-next-code-line 1)) - (octave-send-region beg end)))) - -(defun octave-eval-print-last-sexp () - "Evaluate Octave sexp before point and print value into current buffer." - (interactive) - (inferior-octave t) - (let ((standard-output (current-buffer)) - (print-escape-newlines nil) - (opoint (point))) - (terpri) - (prin1 - (save-excursion - (forward-sexp -1) - (inferior-octave-send-list-and-digest - (list (concat (buffer-substring-no-properties (point) opoint) - "\n"))) - (mapconcat 'identity inferior-octave-output-list "\n"))) - (terpri))) - -;;; Bug reporting -(defun octave-submit-bug-report () - "Submit a bug report on the Emacs Octave package via mail." - (interactive) - (require 'reporter) - (and - (y-or-n-p "Do you want to submit a bug report? ") - (reporter-submit-bug-report - octave-maintainer-address - (concat "Emacs version " emacs-version) - (list - 'octave-auto-indent - 'octave-auto-newline - 'octave-blink-matching-block - 'octave-block-offset - '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 'octave-mod) - -;; arch-tag: 05f1ce09-be87-4c00-803e-4919ffa26c23 -;;; octave-mod.el ends here
deleted file mode 100644 --- a/emacs/octave-tags +++ /dev/null @@ -1,47 +0,0 @@ -#! /bin/sh -# -# Copyright (C) 1998, 2002, 2003, 2006, 2007 Mario Storti -# -# This file is part of Octave. -# -# Octave 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 of the License, or (at -# your option) any later version. -# -# Octave 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 Octave; see the file COPYING. If not, see -# <http://www.gnu.org/licenses/>. - -# Author: Mario Storti <mstorti@minerva.unl.edu.ar> - -# Generate a TAGS file from a set of Octave .m files for use with Emacs. -# -# Run as '$ octave-tags' in the given Octave directory to generate a -# TAGS file. If you want to include another directory, add a line -# prior to the "*.m" line containing something like -# `--include=/path/to/other/directory/TAGS" \'. - -# Tags are generated for function names and for global variables. For -# global variables it doesn't work for more than one line global -# variables. :-( - -# Tags are also created for lines of the form '###key foobar' so that -# you can jump to this specific place just by typing `M-. foobar'. -# Note that tags are not generated for scripts so that you have to add -# a line by yourself of the form `###key <script-name>' if you want to -# jump to it. :-( - -etags --lang=none \ - --regex='/[ \t]*function.*=[ \t]*\([^ \t()]*\)[ \t]*(/\1/' \ - --regex='/[ \t]*function.*=[ \t]*\([^ \t()]*\)[ \t]*$/\1/' \ - --regex='/[ \t]*function[ \t]*\([^ \t()]*\)[ \t]*(/\1/' \ - --regex='/[ \t]*function[ \t]*\([^ \t()]*\)[ \t]*$/\1/' \ - --regex='/###key \(.*\)/\1/' \ - --regex='/[ \t]*global[ \t].*/' \ - *.m
deleted file mode 100644 --- a/emacs/octave-tags.1 +++ /dev/null @@ -1,64 +0,0 @@ -.\" Copyright (C) 2003, 2006, 2007 Dirk Eddelbuettel -.\" -.\" This file is part of Octave. -.\" -.\" Octave 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 of the License, or (at -.\" your option) any later version. -.\" -.\" Octave 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 Octave; see the file COPYING. If not, see -.\" <http://www.gnu.org/licenses/>. -.\" -.\" This page was contributed by Dirk Eddelbuettel <edd@debian.org> -.\" -.TH OCTAVE-TAGS 1 "31 October 2001" "GNU Octave" -.SH NAME -OCTAVE-TAGS - Generate Emacs tags file from GNU Octave code -.SH SYNOPSIS -.BR octave-tags\ [--include\ dir] -\fIfile\fP .\|.\|. -.SH DESCRIPTION -.PP -.B octave-tags -program is used to create a tag table file, in a format understood by -.BR emacs (1) -and -.BR xemacs (1). -.B octave-tags -reads the files specified on the command line, and write a tag table -(defaults: `TAGS') in the current working directory. Files specified with -relative file names will be recorded in the tag table with file names -relative to the directory where the tag table resides. Files specified with -absolute file names will be recorded with absolute file names. - -The -.I --include -option can be used to specify another directoy with Octave files for which -tags shall be generated. - -Tags are generated for function names and for global variables. For -global variables it doesn't work for more than one line global -variables. - -Tags are also created for lines of the form '###key foobar' so that -you can jump to this specific place just by typing `M-. foobar'. -Note that tags are not generated for scripts so that you have to add -a line by yourself of the form `###key <script-name>' if you want to -jump to it. - -.SH SEE ALSO -.BR etags (1). - -.SH AUTHORS -Mario Storti <mstorti@minerva.unl.edu.ar> - -This manual page was contributed by Dirk Eddelbuettel -<edd@debian.org> for the Debian GNU/Linux distribution but -may be used by others.