changeset 106716:4039413a8b1d

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.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 02 Jan 2010 14:40:59 -0500
parents 428005d3198e
children 15eb515afd85
files lisp/ChangeLog lisp/progmodes/octave-mod.el
diffstat 2 files changed, 26 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Jan 02 14:18:44 2010 -0500
+++ b/lisp/ChangeLog	Sat Jan 02 14:40:59 2010 -0500
@@ -1,3 +1,11 @@
+2010-01-02  Daniel Elliott  <danelliottster@gmail.com>  (tiny change)
+
+	* 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.
+
 2010-01-02  Karl Fogel  <kfogel@red-bean.com>
 
 	* bookmark.el: Consistently put the text property on the bookmark name.
--- a/lisp/progmodes/octave-mod.el	Sat Jan 02 14:18:44 2010 -0500
+++ b/lisp/progmodes/octave-mod.el	Sat Jan 02 14:40:59 2010 -0500
@@ -101,11 +101,9 @@
   '("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"))
+    "end_unwind_protect" "endwhile" "until" "end"))
 
 (defvar octave-reserved-words
   (append octave-begin-keywords
@@ -342,17 +340,15 @@
   (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"))
+    ("for" . ("endfor" "end"))
     ("function" . ("endfunction"))
-    ("if" . ("else" "elseif" "endif"))
-    ("switch" . ("case" "otherwise" "endswitch"))
+    ("if" . ("else" "elseif" "endif" "end"))
+    ("switch" . ("case" "otherwise" "endswitch" "end"))
     ("try" . ("catch" "end_try_catch"))
     ("unwind_protect" . ("unwind_protect_cleanup" "end_unwind_protect"))
-    ("while" . ("endwhile")))
+    ("while" . ("endwhile" "end")))
   "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.")
@@ -680,7 +676,10 @@
 			(if (= bot (point))
 			    (setq icol (+ icol octave-block-offset))))
 		       ((octave-looking-at-kw octave-block-end-regexp)
-			(if (not (= bot (point)))
+			(if (and (not (= bot (point)))
+				 ;; special case for `end' keyword,
+				 ;; applied to all keywords
+				 (not (octave-end-as-array-index-p)))
 			    (setq icol (- icol
 					  (octave-block-end-offset)))))))
 		  (forward-char)))
@@ -702,6 +701,15 @@
 	(setq icol (list comment-column icol)))))
     icol))
 
+;; FIXME: this should probably also make sure we are actually looking
+;; at the "end" keyword.
+(defun octave-end-as-array-index-p ()
+  (save-excursion
+    (condition-case nil
+	;; Check if point is between parens
+	(progn (up-list 1) t)
+      (error nil))))
+
 (defun octave-block-end-offset ()
   (save-excursion
     (octave-backward-up-block 1)