diff lisp/progmodes/octave-mod.el @ 111440:b72ff43b041f

* lisp/emacs-lisp/smie.el: Simplify the smie-rules-function return values. (smie-precs->prec2): Rename from smie-precs-precedence-table. (smie-bnf->prec2): Rename from smie-bnf-precedence-table. (smie-prec2->grammar): Rename from smie-prec2-levels. (smie-grammar): Rename from smie-op-levels. (smie-indent--hanging-p): Rename from smie-hanging-p. (smie-rule-hanging-p): New alias. (smie-indent--bolp): Rename from smie-bolp. (smie-indent--hanging-p): New alias. (smie--token): New dynamically bound variable. (smie-indent--parent): New function. (smie-rule-parent-p): Use it; rename from smie-parent-p. (smie-rule-next-p): Rename from smie-next-p. (smie-rule-prev-p): Rename from smie-prev-p. (smie-rule-sibling-p, smie-rule-parent) (smie-indent--separator-outdent, smie-rule-separator): New functions. (smie-rule-separator-outdent): New var. (smie-indent--rule): Merge with smie-indent--column. (smie-indent-forward-token, smie-indent-backward-token): Also recognize close parens. (smie-indent-keyword): Don't use smie-indent--column any more. (smie-indent-after-keyword): Ignore closers by default. (smie-indent-line): Use with-demoted-errors. * lisp/progmodes/octave-mod.el (octave-smie-grammar): Rename from octave-smie-op-levels. (octave-smie-rules): Adjust to new behavior. * lisp/progmodes/prolog.el (prolog-smie-grammar): Rename from prolog-smie-op-levels.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 07 Nov 2010 10:45:45 -0500
parents a9904c1962db
children 66c9a8999fbb
line wrap: on
line diff
--- a/lisp/progmodes/octave-mod.el	Sun Nov 07 12:25:55 2010 +0100
+++ b/lisp/progmodes/octave-mod.el	Sun Nov 07 10:45:45 2010 -0500
@@ -446,14 +446,13 @@
     ;; (fundesc (atom "=" atom))
     ))
 
-(defconst octave-smie-op-levels
-  (smie-prec2-levels
+(defconst octave-smie-grammar
+  (smie-prec2->grammar
    (smie-merge-prec2s
-    (smie-bnf-precedence-table
-     octave-smie-bnf-table
-     '((assoc "\n" ";")))
+    (smie-bnf->prec2 octave-smie-bnf-table
+                     '((assoc "\n" ";")))
 
-    (smie-precs-precedence-table octave-operator-table))))
+    (smie-precs->prec2 octave-operator-table))))
 
 ;; Tokenizing needs to be refined so that ";;" is treated as two
 ;; tokens and also so as to recognize the \n separator (and
@@ -520,13 +519,19 @@
 
 (defun octave-smie-rules (kind token)
   (pcase (cons kind token)
+    ;; We could set smie-indent-basic instead, but that would have two
+    ;; disadvantages:
+    ;; - changes to octave-block-offset wouldn't take effect immediately.
+    ;; - edebug wouldn't show the use of this variable.
     (`(:elem . basic) octave-block-offset)
-    (`(:before . "case") octave-block-offset)
+    ;; Since "case" is in the same BNF rules as switch..end, SMIE by default
+    ;; aligns it with "switch".
+    (`(:before . "case") (if (not (smie-rule-sibling-p)) octave-block-offset))
     (`(:after . ";")
-     (if (smie-parent-p "function" "if" "while" "else" "elseif" "for"
-                        "otherwise" "case" "try" "catch" "unwind_protect"
-                        "unwind_protect_cleanup")
-         '(+ parent octave-block-offset)
+     (if (smie-rule-parent-p "function" "if" "while" "else" "elseif" "for"
+                             "otherwise" "case" "try" "catch" "unwind_protect"
+                             "unwind_protect_cleanup")
+         (smie-rule-parent octave-block-offset)
        ;; For (invalid) code between switch and case.
        ;; (if (smie-parent-p "switch") 4)
        0))))
@@ -619,7 +624,7 @@
 including a reproducible test case and send the message."
   (setq local-abbrev-table octave-abbrev-table)
 
-  (smie-setup octave-smie-op-levels #'octave-smie-rules
+  (smie-setup octave-smie-grammar #'octave-smie-rules
               :forward-token  #'octave-smie-forward-token
               :backward-token #'octave-smie-backward-token)
   (set (make-local-variable 'smie-indent-basic) 'octave-block-offset)