aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1997-03-12 00:35:32 +0000
committerKarl Heuer1997-03-12 00:35:32 +0000
commit6e6d2764daa62739966c565be9abff3c09b202ca (patch)
treebf29bf547f6727a2457f639b9cf8733d92c1409f
parent15c2d736a0b58bb746124a7ce98f7956a6f54a0b (diff)
downloademacs-6e6d2764daa62739966c565be9abff3c09b202ca.tar.gz
emacs-6e6d2764daa62739966c565be9abff3c09b202ca.zip
(octave-abbrev-table): Add abbrevs for switch,
case, otherwise, and endswitch. (octave-begin-keywords): Add switch. (octave-else-keywords): Add case and otherwise. (octave-end-keywords): Add endswitch. (octave-block-match-alist): Add an entry for switch syntax. (calculate-octave-indent): Add support for switch syntax. (octave-block-end-offset): New function. (octave-comment-indent): Fix typo.
-rw-r--r--lisp/progmodes/octave-mod.el34
1 files changed, 26 insertions, 8 deletions
diff --git a/lisp/progmodes/octave-mod.el b/lisp/progmodes/octave-mod.el
index ff27f06fd5f..f91a268f832 100644
--- a/lisp/progmodes/octave-mod.el
+++ b/lisp/progmodes/octave-mod.el
@@ -55,6 +55,7 @@ All Octave abbrevs start with a grave accent (`).")
55 (define-abbrev-table 'octave-abbrev-table ()) 55 (define-abbrev-table 'octave-abbrev-table ())
56 (define-abbrev octave-abbrev-table "`a" "all_va_args" nil) 56 (define-abbrev octave-abbrev-table "`a" "all_va_args" nil)
57 (define-abbrev octave-abbrev-table "`b" "break" nil) 57 (define-abbrev octave-abbrev-table "`b" "break" nil)
58 (define-abbrev octave-abbrev-table "`cs" "case" nil)
58 (define-abbrev octave-abbrev-table "`ca" "catch" nil) 59 (define-abbrev octave-abbrev-table "`ca" "catch" nil)
59 (define-abbrev octave-abbrev-table "`c" "continue" nil) 60 (define-abbrev octave-abbrev-table "`c" "continue" nil)
60 (define-abbrev octave-abbrev-table "`el" "else" nil) 61 (define-abbrev octave-abbrev-table "`el" "else" nil)
@@ -64,6 +65,7 @@ All Octave abbrevs start with a grave accent (`).")
64 (define-abbrev octave-abbrev-table "`ef" "endfor" nil) 65 (define-abbrev octave-abbrev-table "`ef" "endfor" nil)
65 (define-abbrev octave-abbrev-table "`efu" "endfunction" nil) 66 (define-abbrev octave-abbrev-table "`efu" "endfunction" nil)
66 (define-abbrev octave-abbrev-table "`ei" "endif" nil) 67 (define-abbrev octave-abbrev-table "`ei" "endif" nil)
68 (define-abbrev octave-abbrev-table "`es" "endswitch" nil)
67 (define-abbrev octave-abbrev-table "`ew" "endwhile" nil) 69 (define-abbrev octave-abbrev-table "`ew" "endwhile" nil)
68 (define-abbrev octave-abbrev-table "`f" "for" nil) 70 (define-abbrev octave-abbrev-table "`f" "for" nil)
69 (define-abbrev octave-abbrev-table "`fu" "function" nil) 71 (define-abbrev octave-abbrev-table "`fu" "function" nil)
@@ -71,8 +73,10 @@ All Octave abbrevs start with a grave accent (`).")
71 (define-abbrev octave-abbrev-table "`gp" "gplot" nil) 73 (define-abbrev octave-abbrev-table "`gp" "gplot" nil)
72 (define-abbrev octave-abbrev-table "`gs" "gsplot" nil) 74 (define-abbrev octave-abbrev-table "`gs" "gsplot" nil)
73 (define-abbrev octave-abbrev-table "`if" "if ()" nil) 75 (define-abbrev octave-abbrev-table "`if" "if ()" nil)
76 (define-abbrev octave-abbrev-table "`o" "otherwise" nil)
74 (define-abbrev octave-abbrev-table "`rp" "replot" nil) 77 (define-abbrev octave-abbrev-table "`rp" "replot" nil)
75 (define-abbrev octave-abbrev-table "`r" "return" nil) 78 (define-abbrev octave-abbrev-table "`r" "return" nil)
79 (define-abbrev octave-abbrev-table "`s" "switch" nil)
76 (define-abbrev octave-abbrev-table "`t" "try" nil) 80 (define-abbrev octave-abbrev-table "`t" "try" nil)
77 (define-abbrev octave-abbrev-table "`up" "unwind_protect" nil) 81 (define-abbrev octave-abbrev-table "`up" "unwind_protect" nil)
78 (define-abbrev octave-abbrev-table "`upc" "unwind_protect_cleanup" nil) 82 (define-abbrev octave-abbrev-table "`upc" "unwind_protect_cleanup" nil)
@@ -88,15 +92,17 @@ All Octave abbrevs start with a grave accent (`).")
88 "Regexp to match the start of an Octave comment up to its body.") 92 "Regexp to match the start of an Octave comment up to its body.")
89 93
90(defvar octave-begin-keywords 94(defvar octave-begin-keywords
91 '("for" "function" "if" "try" "unwind_protect" "while")) 95 '("for" "function" "if" "switch" "try" "unwind_protect" "while"))
92(defvar octave-else-keywords 96(defvar octave-else-keywords
93 '("catch" "else" "elseif" "unwind_protect_cleanup")) 97 '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup"))
94(defvar octave-end-keywords 98(defvar octave-end-keywords
95 '("end" "endfor" "endfunction" "endif" "end_try_catch" 99 '("end" "endfor" "endfunction" "endif" "endswitch" "end_try_catch"
96 "end_unwind_protect" "endwhile")) 100 "end_unwind_protect" "endwhile"))
97 101
98(defvar octave-reserved-words 102(defvar octave-reserved-words
99 (append octave-begin-keywords octave-else-keywords octave-end-keywords 103 (append octave-begin-keywords
104 octave-else-keywords
105 octave-end-keywords
100 '("all_va_args" "break" "continue" "global" "gplot" "gsplot" 106 '("all_va_args" "break" "continue" "global" "gplot" "gsplot"
101 "replot" "return")) 107 "replot" "return"))
102 "Reserved words in Octave.") 108 "Reserved words in Octave.")
@@ -319,6 +325,7 @@ newline or semicolon after an else or end keyword.")
319 '(("for" . ("end" "endfor")) 325 '(("for" . ("end" "endfor"))
320 ("function" . ("end" "endfunction")) 326 ("function" . ("end" "endfunction"))
321 ("if" . ("else" "elseif" "end" "endif")) 327 ("if" . ("else" "elseif" "end" "endif"))
328 ("switch" . ("case" "end" "endswitch" "otherwise"))
322 ("try" . ("catch" "end" "end_try_catch")) 329 ("try" . ("catch" "end" "end_try_catch"))
323 ("unwind_protect" . ("unwind_protect_cleanup" "end" 330 ("unwind_protect" . ("unwind_protect_cleanup" "end"
324 "end_unwind_protect")) 331 "end_unwind_protect"))
@@ -618,6 +625,8 @@ level."
618 (while (< (point) eol) 625 (while (< (point) eol)
619 (if (octave-not-in-string-or-comment-p) 626 (if (octave-not-in-string-or-comment-p)
620 (cond 627 (cond
628 ((looking-at "\\<switch\\>")
629 (setq icol (+ icol (* 2 octave-block-offset))))
621 ((looking-at octave-block-begin-regexp) 630 ((looking-at octave-block-begin-regexp)
622 (setq icol (+ icol octave-block-offset))) 631 (setq icol (+ icol octave-block-offset)))
623 ((looking-at octave-block-else-regexp) 632 ((looking-at octave-block-else-regexp)
@@ -625,30 +634,39 @@ level."
625 (setq icol (+ icol octave-block-offset)))) 634 (setq icol (+ icol octave-block-offset))))
626 ((looking-at octave-block-end-regexp) 635 ((looking-at octave-block-end-regexp)
627 (if (not (= bot (point))) 636 (if (not (= bot (point)))
628 (setq icol (- icol octave-block-offset)))))) 637 (setq icol (- icol
638 (octave-block-end-offset)))))))
629 (forward-char))) 639 (forward-char)))
630 (if is-continuation-line 640 (if is-continuation-line
631 (setq icol (+ icol octave-continuation-offset))))))) 641 (setq icol (+ icol octave-continuation-offset)))))))
632 (save-excursion 642 (save-excursion
633 (back-to-indentation) 643 (back-to-indentation)
634 (cond 644 (cond
635 ((and (or (looking-at octave-block-else-regexp) 645 ((and (looking-at octave-block-else-regexp)
636 (looking-at octave-block-end-regexp))
637 (octave-not-in-string-or-comment-p)) 646 (octave-not-in-string-or-comment-p))
638 (setq icol (- icol octave-block-offset))) 647 (setq icol (- icol octave-block-offset)))
648 ((and (looking-at octave-block-end-regexp)
649 (octave-not-in-string-or-comment-p))
650 (setq icol (- icol (octave-block-end-offset))))
639 ((looking-at "\\s<\\s<\\s<\\S<") 651 ((looking-at "\\s<\\s<\\s<\\S<")
640 (setq icol (list 0 icol))) 652 (setq icol (list 0 icol)))
641 ((looking-at "\\s<\\S<") 653 ((looking-at "\\s<\\S<")
642 (setq icol (list comment-column icol))))) 654 (setq icol (list comment-column icol)))))
643 icol)) 655 icol))
644 656
657(defun octave-block-end-offset ()
658 (save-excursion
659 (octave-backward-up-block 1)
660 (* octave-block-offset
661 (if (string-match (match-string 0) "switch") 2 1))))
662
645(defun octave-comment-indent () 663(defun octave-comment-indent ()
646 (if (looking-at "\\s<\\s<\\s<") 664 (if (looking-at "\\s<\\s<\\s<")
647 0 665 0
648 (if (looking-at "\\s<\\s<") 666 (if (looking-at "\\s<\\s<")
649 (calculate-octave-indent) 667 (calculate-octave-indent)
650 (skip-syntax-backward " ") 668 (skip-syntax-backward " ")
651 (max (if (bolp) 0 (+ (current-column))) 669 (max (if (bolp) 0 (+ 1 (current-column)))
652 comment-column)))) 670 comment-column))))
653 671
654(defun octave-indent-for-comment () 672(defun octave-indent-for-comment ()