gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

octave mode end keyword problem fix


From: daniel l elliott
Subject: octave mode end keyword problem fix
Date: Wed, 17 Dec 2008 13:55:49 -0800 (PST)
User-agent: G2/1.0

Hello.  I previously posted this on the emacs bug group.  This is my
attempt at a fix for the problem where the end keyword used as an
array index is treated as the end of a block of code (e.g. if block).
Previously this problem had been fixed by not considering "end" as a
valid way to close code blocks which is just as unsatisfying for
people who want to write code that is compatible with Matlab.

It has the negative aspect of identifying all end keywords
between parens as not block-ending keywords.  However,
I doubt that is a problem.

I've used this for a couple days and everything seems fine.  I'm also
not certain if we can add end as a valid keyword for things in the
octave-block-match-alist.

- dan elliott

--- octave-mod.bak.el   2008-12-16 14:35:14.000000000 -0700
+++ octave-mod.el       2008-12-16 14:45:53.000000000 -0700
@@ -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
@@ -346,13 +344,13 @@
 ;; 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 +678,8 @@
                        (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)))
+                                (not (octave-end-as-array-index-
p))) ;special case for end keyword but is applied to all keywords
                            (setq icol (- icol
                                          (octave-block-end-
offset)))))))
                  (forward-char)))
@@ -1525,3 +1524,14 @@

 ;; arch-tag: 05f1ce09-be87-4c00-803e-4919ffa26c23
 ;;; octave-mod.el ends here
+
+
+;; TODO: this should probably also make sure we are actually looking
at and "end" keyword
+(defun octave-end-as-array-index-p ()
+  "pos is the position of the end keyword (end 'e', 'n', or 'd')"
+  (save-excursion
+    (condition-case nil                        ;test if point is
between parens
+       (progn
+         (up-list 1)
+         t)
+      (error nil))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]