Mercurial > emacs
comparison lisp/progmodes/octave-mod.el @ 89909:68c22ea6027c
Sync to HEAD
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 16 Apr 2004 12:51:06 +0000 |
parents | 375f2633d815 |
children | 01137c1fdbe9 |
comparison
equal
deleted
inserted
replaced
89908:ee1402f7b568 | 89909:68c22ea6027c |
---|---|
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, 2003 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> | 5 ;; Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> |
6 ;; Author: John Eaton <jwe@bevo.che.wisc.edu> | 6 ;; Author: John Eaton <jwe@bevo.che.wisc.edu> |
7 ;; Maintainer: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> | 7 ;; Maintainer: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> |
8 ;; Keywords: languages | 8 ;; Keywords: languages |
92 (setq abbrevs-changed ac))) | 92 (setq abbrevs-changed ac))) |
93 | 93 |
94 (defvar octave-comment-char ?# | 94 (defvar octave-comment-char ?# |
95 "Character to start an Octave comment.") | 95 "Character to start an Octave comment.") |
96 (defvar octave-comment-start | 96 (defvar octave-comment-start |
97 (concat (make-string 1 octave-comment-char) " ") | 97 (string octave-comment-char ?\ ) |
98 "String to insert to start a new Octave in-line comment.") | 98 "String to insert to start a new Octave in-line comment.") |
99 (defvar octave-comment-start-skip "\\s<+\\s-*" | 99 (defvar octave-comment-start-skip "\\s<+\\s-*" |
100 "Regexp to match the start of an Octave comment up to its body.") | 100 "Regexp to match the start of an Octave comment up to its body.") |
101 | 101 |
102 (defvar octave-begin-keywords | 102 (defvar octave-begin-keywords |
285 "-" | 285 "-" |
286 ["Describe Octave Mode" octave-describe-major-mode t] | 286 ["Describe Octave Mode" octave-describe-major-mode t] |
287 ["Lookup Octave Index" octave-help t]) | 287 ["Lookup Octave Index" octave-help t]) |
288 "Menu for Octave mode.") | 288 "Menu for Octave mode.") |
289 | 289 |
290 (defvar octave-mode-syntax-table nil | 290 (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))) | 291 (let ((table (make-syntax-table))) |
295 (modify-syntax-entry ?\r " " table) | 292 (modify-syntax-entry ?\r " " table) |
296 (modify-syntax-entry ?+ "." table) | 293 (modify-syntax-entry ?+ "." table) |
297 (modify-syntax-entry ?- "." table) | 294 (modify-syntax-entry ?- "." table) |
298 (modify-syntax-entry ?= "." table) | 295 (modify-syntax-entry ?= "." table) |
307 (modify-syntax-entry ?\' "." table) | 304 (modify-syntax-entry ?\' "." table) |
308 (modify-syntax-entry ?\` "w" table) | 305 (modify-syntax-entry ?\` "w" table) |
309 (modify-syntax-entry ?\" "\"" table) | 306 (modify-syntax-entry ?\" "\"" table) |
310 (modify-syntax-entry ?. "w" table) | 307 (modify-syntax-entry ?. "w" table) |
311 (modify-syntax-entry ?_ "w" table) | 308 (modify-syntax-entry ?_ "w" table) |
312 (modify-syntax-entry ?\% "." table) | 309 (modify-syntax-entry ?\% "<" table) |
313 (modify-syntax-entry ?\# "<" table) | 310 (modify-syntax-entry ?\# "<" table) |
314 (modify-syntax-entry ?\n ">" table) | 311 (modify-syntax-entry ?\n ">" table) |
315 (setq octave-mode-syntax-table table))) | 312 table) |
313 "Syntax table in use in `octave-mode' buffers.") | |
316 | 314 |
317 (defcustom octave-auto-indent nil | 315 (defcustom octave-auto-indent nil |
318 "*Non-nil means indent line after a semicolon or space in Octave mode." | 316 "*Non-nil means indent line after a semicolon or space in Octave mode." |
319 :type 'boolean | 317 :type 'boolean |
320 :group 'octave) | 318 :group 'octave) |
563 (defun octave-describe-major-mode () | 561 (defun octave-describe-major-mode () |
564 "Describe the current major mode." | 562 "Describe the current major mode." |
565 (interactive) | 563 (interactive) |
566 (describe-function major-mode)) | 564 (describe-function major-mode)) |
567 | 565 |
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 () | 566 (defsubst octave-in-comment-p () |
581 "Returns t if point is inside an Octave comment, nil otherwise." | 567 "Returns t if point is inside an Octave comment, nil otherwise." |
582 (interactive) | 568 (interactive) |
583 (save-excursion | 569 (save-excursion |
584 (nth 4 (parse-partial-sexp (octave-point 'bol) (point))))) | 570 (nth 4 (parse-partial-sexp (line-beginning-position) (point))))) |
585 | 571 |
586 (defsubst octave-in-string-p () | 572 (defsubst octave-in-string-p () |
587 "Returns t if point is inside an Octave string, nil otherwise." | 573 "Returns t if point is inside an Octave string, nil otherwise." |
588 (interactive) | 574 (interactive) |
589 (save-excursion | 575 (save-excursion |
590 (nth 3 (parse-partial-sexp (octave-point 'bol) (point))))) | 576 (nth 3 (parse-partial-sexp (line-beginning-position) (point))))) |
591 | 577 |
592 (defsubst octave-not-in-string-or-comment-p () | 578 (defsubst octave-not-in-string-or-comment-p () |
593 "Returns t iff point is not inside an Octave string or comment." | 579 "Returns t iff point is not inside an Octave string or comment." |
594 (let ((pps (parse-partial-sexp (octave-point 'bol) (point)))) | 580 (let ((pps (parse-partial-sexp (line-beginning-position) (point)))) |
595 (not (or (nth 3 pps) (nth 4 pps))))) | 581 (not (or (nth 3 pps) (nth 4 pps))))) |
596 | 582 |
597 (defun octave-in-block-p () | 583 (defun octave-in-block-p () |
598 "Returns t if point is inside an Octave block, nil otherwise. | 584 "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 | 585 The block is taken to start at the first letter of the begin keyword and |
680 (progn | 666 (progn |
681 (octave-beginning-of-line) | 667 (octave-beginning-of-line) |
682 (back-to-indentation) | 668 (back-to-indentation) |
683 (setq icol (current-column)) | 669 (setq icol (current-column)) |
684 (let ((bot (point)) | 670 (let ((bot (point)) |
685 (eol (octave-point 'eol))) | 671 (eol (line-end-position))) |
686 (while (< (point) eol) | 672 (while (< (point) eol) |
687 (if (octave-not-in-string-or-comment-p) | 673 (if (octave-not-in-string-or-comment-p) |
688 (cond | 674 (cond |
689 ((looking-at "\\<switch\\>") | 675 ((looking-at "\\<switch\\>") |
690 (setq icol (+ icol (* 2 octave-block-offset)))) | 676 (setq icol (+ icol (* 2 octave-block-offset)))) |
1015 (setq pos (match-end 0) | 1001 (setq pos (match-end 0) |
1016 bb-keyword | 1002 bb-keyword |
1017 (buffer-substring-no-properties | 1003 (buffer-substring-no-properties |
1018 (match-beginning 0) pos) | 1004 (match-beginning 0) pos) |
1019 pos (+ pos 1) | 1005 pos (+ pos 1) |
1020 eol (octave-point 'eol) | 1006 eol (line-end-position) |
1021 bb-arg | 1007 bb-arg |
1022 (save-excursion | 1008 (save-excursion |
1023 (save-restriction | 1009 (save-restriction |
1024 (goto-char pos) | 1010 (goto-char pos) |
1025 (while (and (skip-syntax-forward "^<" eol) | 1011 (while (and (skip-syntax-forward "^<" eol) |
1121 ;; If we're in a comment line, don't break after the | 1107 ;; If we're in a comment line, don't break after the |
1122 ;; comment chars | 1108 ;; comment chars |
1123 (if (save-excursion | 1109 (if (save-excursion |
1124 (skip-syntax-backward " <") | 1110 (skip-syntax-backward " <") |
1125 (bolp)) | 1111 (bolp)) |
1126 (re-search-forward "[ \t]" (octave-point 'eol) | 1112 (re-search-forward "[ \t]" (line-end-position) |
1127 'move)) | 1113 'move)) |
1128 ;; If we're not in a comment line and just ahead the | 1114 ;; If we're not in a comment line and just ahead the |
1129 ;; continuation string, don't break here. | 1115 ;; continuation string, don't break here. |
1130 (if (and (not (octave-in-comment-p)) | 1116 (if (and (not (octave-in-comment-p)) |
1131 (looking-at | 1117 (looking-at |
1533 | 1519 |
1534 ;;; provide ourself | 1520 ;;; provide ourself |
1535 | 1521 |
1536 (provide 'octave-mod) | 1522 (provide 'octave-mod) |
1537 | 1523 |
1524 ;;; arch-tag: 05f1ce09-be87-4c00-803e-4919ffa26c23 | |
1538 ;;; octave-mod.el ends here | 1525 ;;; octave-mod.el ends here |