1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 02:31:03 -08:00

* emacs-lisp/smie.el (smie-next-sexp): Break inf-loop at BOB.

(smie-backward-sexp, smie-forward-sexp): Remove boundary condition now
handled in smie-next-sexp.
(smie-indent-calculate): Provide a starting indentation (so the
recursion is well-founded ;-).
This commit is contained in:
Stefan Monnier 2010-05-18 15:24:24 -04:00
parent 60dd06a082
commit 224b70cbc5
2 changed files with 17 additions and 7 deletions

View file

@ -1,5 +1,11 @@
2010-05-18 Stefan Monnier <monnier@iro.umontreal.ca> 2010-05-18 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/smie.el (smie-next-sexp): Break inf-loop at BOB.
(smie-backward-sexp, smie-forward-sexp): Remove boundary condition now
handled in smie-next-sexp.
(smie-indent-calculate): Provide a starting indentation (so the
recursion is well-founded ;-).
Fix handling of non-associative equal levels. Fix handling of non-associative equal levels.
* emacs-lisp/smie.el (smie-prec2-levels): Choose distinct levels even * emacs-lisp/smie.el (smie-prec2-levels): Choose distinct levels even
when it's not needed. when it's not needed.

View file

@ -348,10 +348,13 @@ Possible return values:
(cond (cond
((null toklevels) ((null toklevels)
(if (equal token "") (when (equal token "")
(condition-case err (condition-case err
(progn (goto-char pos) (funcall next-sexp 1) nil) (progn (goto-char pos) (funcall next-sexp 1) nil)
(scan-error (throw 'return (list t (caddr err))))))) (scan-error (throw 'return (list t (caddr err)))))
(if (eq pos (point))
;; We did not move, so let's abort the loop.
(throw 'return (list t (point))))))
((null (funcall op-back toklevels)) ((null (funcall op-back toklevels))
;; A token like a paren-close. ;; A token like a paren-close.
(assert (funcall op-forw toklevels)) ;Otherwise, why mention it? (assert (funcall op-forw toklevels)) ;Otherwise, why mention it?
@ -401,15 +404,13 @@ Possible return values:
(t POS TOKEN): same thing but for an open-paren or the beginning of buffer. (t POS TOKEN): same thing but for an open-paren or the beginning of buffer.
(nil POS TOKEN): we skipped over a paren-like pair. (nil POS TOKEN): we skipped over a paren-like pair.
nil: we skipped over an identifier, matched parentheses, ..." nil: we skipped over an identifier, matched parentheses, ..."
(if (bobp) (list t (point))
(smie-next-sexp (smie-next-sexp
(lambda () (forward-comment (- (point-max))) (smie-backward-token)) (lambda () (forward-comment (- (point-max))) (smie-backward-token))
(indirect-function 'backward-sexp) (indirect-function 'backward-sexp)
(indirect-function 'smie-op-left) (indirect-function 'smie-op-left)
(indirect-function 'smie-op-right) (indirect-function 'smie-op-right)
halfsexp))) halfsexp))
;; Mirror image, not used for indentation.
(defun smie-forward-sexp (&optional halfsexp) (defun smie-forward-sexp (&optional halfsexp)
"Skip over one sexp. "Skip over one sexp.
HALFSEXP if non-nil, means skip over a partial sexp if needed. I.e. if the HALFSEXP if non-nil, means skip over a partial sexp if needed. I.e. if the
@ -421,13 +422,12 @@ Possible return values:
(t POS TOKEN): same thing but for an open-paren or the beginning of buffer. (t POS TOKEN): same thing but for an open-paren or the beginning of buffer.
(nil POS TOKEN): we skipped over a paren-like pair. (nil POS TOKEN): we skipped over a paren-like pair.
nil: we skipped over an identifier, matched parentheses, ..." nil: we skipped over an identifier, matched parentheses, ..."
(if (eobp) (list t (point))
(smie-next-sexp (smie-next-sexp
(lambda () (forward-comment (point-max)) (smie-forward-token)) (lambda () (forward-comment (point-max)) (smie-forward-token))
(indirect-function 'forward-sexp) (indirect-function 'forward-sexp)
(indirect-function 'smie-op-right) (indirect-function 'smie-op-right)
(indirect-function 'smie-op-left) (indirect-function 'smie-op-left)
halfsexp))) halfsexp))
(defun smie-backward-sexp-command (&optional n) (defun smie-backward-sexp-command (&optional n)
"Move backward through N logical elements." "Move backward through N logical elements."
@ -514,6 +514,10 @@ VIRTUAL can take two different non-nil values:
(and virtual (and virtual
(if (eq virtual :hanging) (not (smie-indent-hanging-p)) (smie-bolp)) (if (eq virtual :hanging) (not (smie-indent-hanging-p)) (smie-bolp))
(current-column)) (current-column))
;; Start the file at column 0.
(save-excursion
(forward-comment (- (point-max)))
(if (bobp) 0))
;; Align close paren with opening paren. ;; Align close paren with opening paren.
(save-excursion (save-excursion
;; (forward-comment (point-max)) ;; (forward-comment (point-max))