comparison lisp/progmodes/octave-mod.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 0d8b17d428b5
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; octave-mod.el --- editing Octave source files under Emacs 1 ;;; octave-mod.el --- editing Octave source files under Emacs
2 2
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005
4 4 ;; Free Software Foundation, Inc.
5 ;; Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> 5
6 ;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
6 ;; Author: John Eaton <jwe@bevo.che.wisc.edu> 7 ;; Author: John Eaton <jwe@bevo.che.wisc.edu>
7 ;; Maintainer: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> 8 ;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
8 ;; Keywords: languages 9 ;; Keywords: languages
9 10
10 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
11 12
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;; GNU Emacs is free software; you can redistribute it and/or modify
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details. 21 ;; GNU General Public License for more details.
21 22
22 ;; You should have received a copy of the GNU General Public License 23 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02111-1307, USA. 26 ;; Boston, MA 02110-1301, USA.
26 27
27 ;;; Commentary: 28 ;;; Commentary:
28 29
29 ;; This package provides Emacs support for Octave. 30 ;; This package provides Emacs support for Octave.
30 ;; It defines Octave mode, a major mode for editing 31 ;; It defines Octave mode, a major mode for editing
42 ;;; Code: 43 ;;; Code:
43 (require 'custom) 44 (require 'custom)
44 45
45 (defgroup octave nil 46 (defgroup octave nil
46 "Major mode for editing Octave source files." 47 "Major mode for editing Octave source files."
48 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
47 :group 'languages) 49 :group 'languages)
48 50
49 (defvar inferior-octave-output-list nil) 51 (defvar inferior-octave-output-list nil)
50 (defvar inferior-octave-output-string nil) 52 (defvar inferior-octave-output-string nil)
51 (defvar inferior-octave-receive-in-progress nil) 53 (defvar inferior-octave-receive-in-progress nil)
52 54
53 (defconst octave-maintainer-address 55 (defconst octave-maintainer-address
54 "Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>, bug-gnu-emacs@gnu.org" 56 "Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>, bug-gnu-emacs@gnu.org"
55 "Current maintainer of the Emacs Octave package.") 57 "Current maintainer of the Emacs Octave package.")
56 58
57 (defvar octave-abbrev-table nil 59 (defvar octave-abbrev-table nil
58 "Abbrev table for Octave's reserved words. 60 "Abbrev table for Octave's reserved words.
59 Used in `octave-mode' and inferior-octave-mode buffers. 61 Used in `octave-mode' and inferior-octave-mode buffers.
92 (setq abbrevs-changed ac))) 94 (setq abbrevs-changed ac)))
93 95
94 (defvar octave-comment-char ?# 96 (defvar octave-comment-char ?#
95 "Character to start an Octave comment.") 97 "Character to start an Octave comment.")
96 (defvar octave-comment-start 98 (defvar octave-comment-start
97 (concat (make-string 1 octave-comment-char) " ") 99 (string octave-comment-char ?\ )
98 "String to insert to start a new Octave in-line comment.") 100 "String to insert to start a new Octave in-line comment.")
99 (defvar octave-comment-start-skip "\\s<+\\s-*" 101 (defvar octave-comment-start-skip "\\s<+\\s-*"
100 "Regexp to match the start of an Octave comment up to its body.") 102 "Regexp to match the start of an Octave comment up to its body.")
101 103
102 (defvar octave-begin-keywords 104 (defvar octave-begin-keywords
285 "-" 287 "-"
286 ["Describe Octave Mode" octave-describe-major-mode t] 288 ["Describe Octave Mode" octave-describe-major-mode t]
287 ["Lookup Octave Index" octave-help t]) 289 ["Lookup Octave Index" octave-help t])
288 "Menu for Octave mode.") 290 "Menu for Octave mode.")
289 291
290 (defvar octave-mode-syntax-table nil 292 (defvar octave-mode-syntax-table
291 "Syntax table in use in octave-mode buffers.")
292 (if octave-mode-syntax-table
293 ()
294 (let ((table (make-syntax-table))) 293 (let ((table (make-syntax-table)))
295 (modify-syntax-entry ?\r " " table) 294 (modify-syntax-entry ?\r " " table)
296 (modify-syntax-entry ?+ "." table) 295 (modify-syntax-entry ?+ "." table)
297 (modify-syntax-entry ?- "." table) 296 (modify-syntax-entry ?- "." table)
298 (modify-syntax-entry ?= "." table) 297 (modify-syntax-entry ?= "." table)
307 (modify-syntax-entry ?\' "." table) 306 (modify-syntax-entry ?\' "." table)
308 (modify-syntax-entry ?\` "w" table) 307 (modify-syntax-entry ?\` "w" table)
309 (modify-syntax-entry ?\" "\"" table) 308 (modify-syntax-entry ?\" "\"" table)
310 (modify-syntax-entry ?. "w" table) 309 (modify-syntax-entry ?. "w" table)
311 (modify-syntax-entry ?_ "w" table) 310 (modify-syntax-entry ?_ "w" table)
312 (modify-syntax-entry ?\% "." table) 311 (modify-syntax-entry ?\% "<" table)
313 (modify-syntax-entry ?\# "<" table) 312 (modify-syntax-entry ?\# "<" table)
314 (modify-syntax-entry ?\n ">" table) 313 (modify-syntax-entry ?\n ">" table)
315 (setq octave-mode-syntax-table table))) 314 table)
315 "Syntax table in use in `octave-mode' buffers.")
316 316
317 (defcustom octave-auto-indent nil 317 (defcustom octave-auto-indent nil
318 "*Non-nil means indent line after a semicolon or space in Octave mode." 318 "*Non-nil means indent line after a semicolon or space in Octave mode."
319 :type 'boolean 319 :type 'boolean
320 :group 'octave) 320 :group 'octave)
555 (setq imenu-generic-expression octave-mode-imenu-generic-expression 555 (setq imenu-generic-expression octave-mode-imenu-generic-expression
556 imenu-case-fold-search nil) 556 imenu-case-fold-search nil)
557 557
558 (octave-add-octave-menu) 558 (octave-add-octave-menu)
559 (octave-initialize-completions) 559 (octave-initialize-completions)
560 (run-hooks 'octave-mode-hook)) 560 (run-mode-hooks 'octave-mode-hook))
561 561
562 ;;; Miscellaneous useful functions 562 ;;; Miscellaneous useful functions
563 (defun octave-describe-major-mode () 563 (defun octave-describe-major-mode ()
564 "Describe the current major mode." 564 "Describe the current major mode."
565 (interactive) 565 (interactive)
566 (describe-function major-mode)) 566 (describe-function major-mode))
567 567
568 (defun octave-point (position)
569 "Returns the value of point at certain positions."
570 (save-excursion
571 (cond
572 ((eq position 'bol) (beginning-of-line))
573 ((eq position 'eol) (end-of-line))
574 ((eq position 'boi) (back-to-indentation))
575 ((eq position 'bonl) (forward-line 1))
576 ((eq position 'bopl) (forward-line -1))
577 (t (error "unknown buffer position requested: %s" position)))
578 (point)))
579
580 (defsubst octave-in-comment-p () 568 (defsubst octave-in-comment-p ()
581 "Returns t if point is inside an Octave comment, nil otherwise." 569 "Returns t if point is inside an Octave comment, nil otherwise."
582 (interactive) 570 (interactive)
583 (save-excursion 571 (save-excursion
584 (nth 4 (parse-partial-sexp (octave-point 'bol) (point))))) 572 (nth 4 (parse-partial-sexp (line-beginning-position) (point)))))
585 573
586 (defsubst octave-in-string-p () 574 (defsubst octave-in-string-p ()
587 "Returns t if point is inside an Octave string, nil otherwise." 575 "Returns t if point is inside an Octave string, nil otherwise."
588 (interactive) 576 (interactive)
589 (save-excursion 577 (save-excursion
590 (nth 3 (parse-partial-sexp (octave-point 'bol) (point))))) 578 (nth 3 (parse-partial-sexp (line-beginning-position) (point)))))
591 579
592 (defsubst octave-not-in-string-or-comment-p () 580 (defsubst octave-not-in-string-or-comment-p ()
593 "Returns t iff point is not inside an Octave string or comment." 581 "Returns t iff point is not inside an Octave string or comment."
594 (let ((pps (parse-partial-sexp (octave-point 'bol) (point)))) 582 (let ((pps (parse-partial-sexp (line-beginning-position) (point))))
595 (not (or (nth 3 pps) (nth 4 pps))))) 583 (not (or (nth 3 pps) (nth 4 pps)))))
596 584
597 (defun octave-in-block-p () 585 (defun octave-in-block-p ()
598 "Returns t if point is inside an Octave block, nil otherwise. 586 "Returns t if point is inside an Octave block, nil otherwise.
599 The block is taken to start at the first letter of the begin keyword and 587 The block is taken to start at the first letter of the begin keyword and
680 (progn 668 (progn
681 (octave-beginning-of-line) 669 (octave-beginning-of-line)
682 (back-to-indentation) 670 (back-to-indentation)
683 (setq icol (current-column)) 671 (setq icol (current-column))
684 (let ((bot (point)) 672 (let ((bot (point))
685 (eol (octave-point 'eol))) 673 (eol (line-end-position)))
686 (while (< (point) eol) 674 (while (< (point) eol)
687 (if (octave-not-in-string-or-comment-p) 675 (if (octave-not-in-string-or-comment-p)
688 (cond 676 (cond
689 ((looking-at "\\<switch\\>") 677 ((looking-at "\\<switch\\>")
690 (setq icol (+ icol (* 2 octave-block-offset)))) 678 (setq icol (+ icol (* 2 octave-block-offset))))
1015 (setq pos (match-end 0) 1003 (setq pos (match-end 0)
1016 bb-keyword 1004 bb-keyword
1017 (buffer-substring-no-properties 1005 (buffer-substring-no-properties
1018 (match-beginning 0) pos) 1006 (match-beginning 0) pos)
1019 pos (+ pos 1) 1007 pos (+ pos 1)
1020 eol (octave-point 'eol) 1008 eol (line-end-position)
1021 bb-arg 1009 bb-arg
1022 (save-excursion 1010 (save-excursion
1023 (save-restriction 1011 (save-restriction
1024 (goto-char pos) 1012 (goto-char pos)
1025 (while (and (skip-syntax-forward "^<" eol) 1013 (while (and (skip-syntax-forward "^<" eol)
1121 ;; If we're in a comment line, don't break after the 1109 ;; If we're in a comment line, don't break after the
1122 ;; comment chars 1110 ;; comment chars
1123 (if (save-excursion 1111 (if (save-excursion
1124 (skip-syntax-backward " <") 1112 (skip-syntax-backward " <")
1125 (bolp)) 1113 (bolp))
1126 (re-search-forward "[ \t]" (octave-point 'eol) 1114 (re-search-forward "[ \t]" (line-end-position)
1127 'move)) 1115 'move))
1128 ;; If we're not in a comment line and just ahead the 1116 ;; If we're not in a comment line and just ahead the
1129 ;; continuation string, don't break here. 1117 ;; continuation string, don't break here.
1130 (if (and (not (octave-in-comment-p)) 1118 (if (and (not (octave-in-comment-p))
1131 (looking-at 1119 (looking-at
1263 (let ((list (all-completions string octave-completion-alist)) 1251 (let ((list (all-completions string octave-completion-alist))
1264 (conf (current-window-configuration))) 1252 (conf (current-window-configuration)))
1265 ;; Taken from comint.el 1253 ;; Taken from comint.el
1266 (message "Making completion list...") 1254 (message "Making completion list...")
1267 (with-output-to-temp-buffer "*Completions*" 1255 (with-output-to-temp-buffer "*Completions*"
1268 (display-completion-list list)) 1256 (display-completion-list list string))
1269 (message "Hit space to flush") 1257 (message "Hit space to flush")
1270 (let (key first) 1258 (let (key first)
1271 (if (save-excursion 1259 (if (save-excursion
1272 (set-buffer (get-buffer "*Completions*")) 1260 (set-buffer (get-buffer "*Completions*"))
1273 (setq key (read-key-sequence nil) 1261 (setq key (read-key-sequence nil)
1321 "Insert a space in Octave mode. 1309 "Insert a space in Octave mode.
1322 Maybe expand abbrevs and blink matching block open keywords. 1310 Maybe expand abbrevs and blink matching block open keywords.
1323 Reindent the line of `octave-auto-indent' is non-nil." 1311 Reindent the line of `octave-auto-indent' is non-nil."
1324 (interactive) 1312 (interactive)
1325 (setq last-command-char ? ) 1313 (setq last-command-char ? )
1326 (if (not (octave-not-in-string-or-comment-p)) 1314 (if (and octave-auto-indent
1315 (not (octave-not-in-string-or-comment-p)))
1327 (progn 1316 (progn
1328 (indent-according-to-mode) 1317 (indent-according-to-mode)
1329 (self-insert-command 1)) 1318 (self-insert-command 1))
1330 (if abbrev-mode (expand-abbrev)) 1319 (if abbrev-mode (expand-abbrev))
1331 (if octave-blink-matching-block 1320 (if octave-blink-matching-block
1533 1522
1534 ;;; provide ourself 1523 ;;; provide ourself
1535 1524
1536 (provide 'octave-mod) 1525 (provide 'octave-mod)
1537 1526
1527 ;;; arch-tag: 05f1ce09-be87-4c00-803e-4919ffa26c23
1538 ;;; octave-mod.el ends here 1528 ;;; octave-mod.el ends here