aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2010-01-02 14:40:59 -0500
committerChong Yidong2010-01-02 14:40:59 -0500
commitb2ad70b67bb8760a53192322a351b3c8d7376c64 (patch)
treefc6be6723a390bfc42be94f4d79f18c4d21de162
parent61f49e0bb661c3adbcc088bfc23a2e759561099f (diff)
downloademacs-b2ad70b67bb8760a53192322a351b3c8d7376c64.tar.gz
emacs-b2ad70b67bb8760a53192322a351b3c8d7376c64.zip
Allow use of "end" keyword for terminating Octave-mode blocks.
* progmodes/octave-mod.el (octave-end-keywords) (octave-block-begin-or-end-regexp, octave-block-match-alist): Add "end" keyword (Bug#3061). (octave-end-as-array-index-p): New function. (calculate-octave-indent): Use it.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/progmodes/octave-mod.el28
2 files changed, 26 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 965d4780ae2..a6ca9dd4dde 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12010-01-02 Daniel Elliott <danelliottster@gmail.com> (tiny change)
2
3 * progmodes/octave-mod.el (octave-end-keywords)
4 (octave-block-begin-or-end-regexp, octave-block-match-alist): Add
5 "end" keyword (Bug#3061).
6 (octave-end-as-array-index-p): New function.
7 (calculate-octave-indent): Use it.
8
12010-01-02 Karl Fogel <kfogel@red-bean.com> 92010-01-02 Karl Fogel <kfogel@red-bean.com>
2 10
3 * bookmark.el: Consistently put the text property on the bookmark name. 11 * bookmark.el: Consistently put the text property on the bookmark name.
diff --git a/lisp/progmodes/octave-mod.el b/lisp/progmodes/octave-mod.el
index 7f09d83399b..5c5e9851dcb 100644
--- a/lisp/progmodes/octave-mod.el
+++ b/lisp/progmodes/octave-mod.el
@@ -101,11 +101,9 @@ All Octave abbrevs start with a grave accent (`)."
101 '("do" "for" "function" "if" "switch" "try" "unwind_protect" "while")) 101 '("do" "for" "function" "if" "switch" "try" "unwind_protect" "while"))
102(defvar octave-else-keywords 102(defvar octave-else-keywords
103 '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup")) 103 '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup"))
104;; FIXME: only use specific "end" tokens here to avoid confusion when "end"
105;; is used in indexing (the real fix is much more complex).
106(defvar octave-end-keywords 104(defvar octave-end-keywords
107 '("endfor" "endfunction" "endif" "endswitch" "end_try_catch" 105 '("endfor" "endfunction" "endif" "endswitch" "end_try_catch"
108 "end_unwind_protect" "endwhile" "until")) 106 "end_unwind_protect" "endwhile" "until" "end"))
109 107
110(defvar octave-reserved-words 108(defvar octave-reserved-words
111 (append octave-begin-keywords 109 (append octave-begin-keywords
@@ -342,17 +340,15 @@ newline or semicolon after an else or end keyword."
342 (concat octave-block-begin-regexp "\\|" octave-block-end-regexp)) 340 (concat octave-block-begin-regexp "\\|" octave-block-end-regexp))
343(defvar octave-block-else-or-end-regexp 341(defvar octave-block-else-or-end-regexp
344 (concat octave-block-else-regexp "\\|" octave-block-end-regexp)) 342 (concat octave-block-else-regexp "\\|" octave-block-end-regexp))
345;; FIXME: only use specific "end" tokens here to avoid confusion when "end"
346;; is used in indexing (the real fix is much more complex).
347(defvar octave-block-match-alist 343(defvar octave-block-match-alist
348 '(("do" . ("until")) 344 '(("do" . ("until"))
349 ("for" . ("endfor")) 345 ("for" . ("endfor" "end"))
350 ("function" . ("endfunction")) 346 ("function" . ("endfunction"))
351 ("if" . ("else" "elseif" "endif")) 347 ("if" . ("else" "elseif" "endif" "end"))
352 ("switch" . ("case" "otherwise" "endswitch")) 348 ("switch" . ("case" "otherwise" "endswitch" "end"))
353 ("try" . ("catch" "end_try_catch")) 349 ("try" . ("catch" "end_try_catch"))
354 ("unwind_protect" . ("unwind_protect_cleanup" "end_unwind_protect")) 350 ("unwind_protect" . ("unwind_protect_cleanup" "end_unwind_protect"))
355 ("while" . ("endwhile"))) 351 ("while" . ("endwhile" "end")))
356 "Alist with Octave's matching block keywords. 352 "Alist with Octave's matching block keywords.
357Has Octave's begin keywords as keys and a list of the matching else or 353Has Octave's begin keywords as keys and a list of the matching else or
358end keywords as associated values.") 354end keywords as associated values.")
@@ -680,7 +676,10 @@ level."
680 (if (= bot (point)) 676 (if (= bot (point))
681 (setq icol (+ icol octave-block-offset)))) 677 (setq icol (+ icol octave-block-offset))))
682 ((octave-looking-at-kw octave-block-end-regexp) 678 ((octave-looking-at-kw octave-block-end-regexp)
683 (if (not (= bot (point))) 679 (if (and (not (= bot (point)))
680 ;; special case for `end' keyword,
681 ;; applied to all keywords
682 (not (octave-end-as-array-index-p)))
684 (setq icol (- icol 683 (setq icol (- icol
685 (octave-block-end-offset))))))) 684 (octave-block-end-offset)))))))
686 (forward-char))) 685 (forward-char)))
@@ -702,6 +701,15 @@ level."
702 (setq icol (list comment-column icol))))) 701 (setq icol (list comment-column icol)))))
703 icol)) 702 icol))
704 703
704;; FIXME: this should probably also make sure we are actually looking
705;; at the "end" keyword.
706(defun octave-end-as-array-index-p ()
707 (save-excursion
708 (condition-case nil
709 ;; Check if point is between parens
710 (progn (up-list 1) t)
711 (error nil))))
712
705(defun octave-block-end-offset () 713(defun octave-block-end-offset ()
706 (save-excursion 714 (save-excursion
707 (octave-backward-up-block 1) 715 (octave-backward-up-block 1)