summaryrefslogtreecommitdiff
path: root/lisp/progmodes/octave-mod.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2010-10-29 15:20:28 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2010-10-29 15:20:28 -0400
commitc4d17d50ea180c405fc58f9ffe693b6c633571ac (patch)
treef1bf3bbd1d417fa9853b6a98260e25a42083b638 /lisp/progmodes/octave-mod.el
parent2ec4c9665d3766eea7bf2d131cabbc177d049b6b (diff)
downloademacs-c4d17d50ea180c405fc58f9ffe693b6c633571ac.tar.gz
SMIE: change indent rules format, improve smie-setup.
* lisp/emacs-lisp/smie.el (smie-precs-precedence-table) (smie-merge-prec2s, smie-bnf-precedence-table, smie-prec2-levels): Mark them pure so the tables gets built at compile time. (smie-bnf-precedence-table): Store the closer-alist in the table. (smie-prec2-levels): Preserve the closer-alist. (smie-blink-matching-open): Be more forgiving in case of indentation. (smie-hanging-p): Rename from smie-indent--hanging-p. (smie-bolp): Rename from smie-indent--bolp. (smie--parent, smie--after): New dynamic vars. (smie-parent-p, smie-next-p, smie-prev-p): New funs. (smie-indent-rules): Remove. (smie-indent--offset-rule): Remove fun. (smie-rules-function): New var. (smie-indent--rule): New fun. (smie-indent--offset, smie-indent-keyword, smie-indent-after-keyword) (smie-indent-exps): Use it. (smie-setup): Setup paren blinking; add keyword args for token functions; extract closer-alist from op-levels. (smie-indent-debug-log): Remove var. (smie-indent-debug): Remove fun. * lisp/progmodes/prolog.el (prolog-smie-indent-rules): Remove. (prolog-smie-rules): New fun to replace it. (prolog-mode-variables): Simplify. * lisp/progmodes/octave-mod.el (octave-smie-closer-alist): Remove, now that it's setup automatically. (octave-smie-indent-rules): Remove. (octave-smie-rules): New fun to replace it. (octave-mode): Simplify.
Diffstat (limited to 'lisp/progmodes/octave-mod.el')
-rw-r--r--lisp/progmodes/octave-mod.el55
1 files changed, 19 insertions, 36 deletions
diff --git a/lisp/progmodes/octave-mod.el b/lisp/progmodes/octave-mod.el
index 40931c3d54d..fdd5e867b7b 100644
--- a/lisp/progmodes/octave-mod.el
+++ b/lisp/progmodes/octave-mod.el
@@ -446,9 +446,6 @@ Non-nil means always go to the next Octave code line after sending."
;; (fundesc (atom "=" atom))
))
-(defconst octave-smie-closer-alist
- (smie-bnf-closer-alist octave-smie-bnf-table))
-
(defconst octave-smie-op-levels
(smie-prec2-levels
(smie-merge-prec2s
@@ -521,15 +518,18 @@ Non-nil means always go to the next Octave code line after sending."
(t
(smie-default-forward-token))))
-(defconst octave-smie-indent-rules
- '((";"
- (:parent ("function" "if" "while" "else" "elseif" "for" "otherwise"
- "case" "try" "catch" "unwind_protect" "unwind_protect_cleanup")
- ;; FIXME: don't hardcode 2.
- (+ parent octave-block-offset))
- ;; (:parent "switch" 4) ;For (invalid) code between switch and case.
- 0)
- ((:before . "case") octave-block-offset)))
+(defun octave-smie-rules (kind token)
+ (pcase (cons kind token)
+ (`(:elem . basic) octave-block-offset)
+ (`(:before . "case") 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)
+ ;; For (invalid) code between switch and case.
+ ;; (if (smie-parent-p "switch") 4)
+ 0))))
(defvar electric-indent-chars)
@@ -619,32 +619,15 @@ already added. You just need to add a description of the problem,
including a reproducible test case and send the message."
(setq local-abbrev-table octave-abbrev-table)
- (smie-setup octave-smie-op-levels octave-smie-indent-rules)
+ (smie-setup octave-smie-op-levels #'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)
- (set (make-local-variable 'smie-backward-token-function)
- 'octave-smie-backward-token)
- (set (make-local-variable 'smie-forward-token-function)
- 'octave-smie-forward-token)
- (set (make-local-variable 'forward-sexp-function)
- 'smie-forward-sexp-command)
- (set (make-local-variable 'smie-closer-alist) octave-smie-closer-alist)
- ;; Only needed for interactive calls to blink-matching-open.
- (set (make-local-variable 'blink-matching-check-function)
- #'smie-blink-matching-check)
-
- (when octave-blink-matching-block
- (add-hook 'post-self-insert-hook #'smie-blink-matching-open 'append 'local)
+
(set (make-local-variable 'smie-blink-matching-triggers)
- (append smie-blink-matching-triggers '(\;)
- ;; Rather than wait for SPC or ; to blink, try to blink as
- ;; soon as we type the last char of a block ender.
- ;; But strip ?d from this list so that we don't blink twice
- ;; when the user writes "endif" (once at "end" and another
- ;; time at "endif").
- (delq ?d (delete-dups
- (mapcar (lambda (kw)
- (aref (cdr kw) (1- (length (cdr kw)))))
- smie-closer-alist))))))
+ (cons ?\; smie-blink-matching-triggers))
+ (unless octave-blink-matching-block
+ (remove-hook 'post-self-insert-hook #'smie-blink-matching-open 'local))
(set (make-local-variable 'electric-indent-chars)
(cons ?\; electric-indent-chars))