Commit c4d17d50 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

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.
parent 2ec4c966
......@@ -587,6 +587,8 @@ Notifications API. It requires D-Bus for communication.
* Incompatible Lisp Changes in Emacs 24.1
** Remove obsolete name `e' (use `float-e' instead).
** A backquote not followed by a space is now always treated as new-style.
** Test for special mode-class was moved from view-file to view-buffer.
......
2010-10-29 Stefan Monnier <monnier@iro.umontreal.ca>
SMIE: change indent rules format, improve smie-setup.
* 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.
* progmodes/prolog.el (prolog-smie-indent-rules): Remove.
(prolog-smie-rules): New fun to replace it.
(prolog-mode-variables): Simplify.
* 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.
2010-10-29 Glenn Morris <rgm@gnu.org>
* files.el (temporary-file-directory): Remove (already defined in C).
......
This diff is collapsed.
......@@ -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))
......
......@@ -173,10 +173,11 @@ When nil, send actual operating system end of file."
)
"Precedence levels of infix operators.")
(defconst prolog-smie-indent-rules
'((":-")
("->"))
"Prolog indentation rules.")
(defun prolog-smie-rules (kind token)
(pcase (cons kind token)
(`(:elem . basic) prolog-indent-width)
(`(:after . ".") 0) ;; To work around smie-closer-alist.
(`(:after . ,(or `":-" `"->")) prolog-indent-width)))
(defun prolog-mode-variables ()
(make-local-variable 'paragraph-separate)
......@@ -185,19 +186,17 @@ When nil, send actual operating system end of file."
(setq paragraph-ignore-fill-prefix t)
(make-local-variable 'imenu-generic-expression)
(setq imenu-generic-expression '((nil "^\\sw+" 0)))
(smie-setup prolog-smie-op-levels prolog-smie-indent-rules)
(set (make-local-variable 'smie-forward-token-function)
#'prolog-smie-forward-token)
(set (make-local-variable 'smie-backward-token-function)
#'prolog-smie-backward-token)
(set (make-local-variable 'forward-sexp-function)
'smie-forward-sexp-command)
(set (make-local-variable 'smie-indent-basic) prolog-indent-width)
;; Setup SMIE.
(smie-setup prolog-smie-op-levels #'prolog-smie-rules
:forward-token #'prolog-smie-forward-token
:backward-token #'prolog-smie-backward-token)
(set (make-local-variable 'smie-blink-matching-triggers) '(?.))
(set (make-local-variable 'smie-closer-alist) '((t . ".")))
(add-hook 'post-self-insert-hook #'smie-blink-matching-open 'append 'local)
;; There's no real closer in Prolog anyway.
(set (make-local-variable 'smie-blink-matching-inners) t)
(make-local-variable 'comment-start)
(setq comment-start "%")
(make-local-variable 'comment-start-skip)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment