summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2010-08-31 14:22:40 +0200
committerStefan Monnier <monnier@iro.umontreal.ca>2010-08-31 14:22:40 +0200
commitc8977b2e622e2c1ff46a160b252feff30bc1025e (patch)
treeea06e1aa16a296cd4ce3a545873582733f2e67c9 /lisp/emacs-lisp
parentec5d3ff71f442d8d867082669ab6bcbdbb24a24b (diff)
downloademacs-c8977b2e622e2c1ff46a160b252feff30bc1025e.tar.gz
emacs-c8977b2e622e2c1ff46a160b252feff30bc1025e.tar.bz2
emacs-c8977b2e622e2c1ff46a160b252feff30bc1025e.zip
* lisp/emacs-lisp/smie.el (smie-down-list): New command.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/smie.el36
1 files changed, 36 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index c9876c55014..e8b5c2448e8 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -560,6 +560,42 @@ Possible return values:
(indent-according-to-mode)
(reindent-then-newline-and-indent))))
+(defun smie-down-list (&optional arg)
+ "Move forward down one level paren-like blocks. Like `down-list'.
+With argument ARG, do this that many times.
+A negative argument means move backward but still go down a level.
+This command assumes point is not in a string or comment."
+ (interactive "p")
+ (let ((start (point))
+ (inc (if (< arg 0) -1 1))
+ (offset (if (< arg 0) 1 0))
+ (next-token (if (< arg 0)
+ smie-backward-token-function
+ smie-forward-token-function)))
+ (while (/= arg 0)
+ (setq arg (- arg inc))
+ (while
+ (let* ((pos (point))
+ (token (funcall next-token))
+ (levels (assoc token smie-op-levels)))
+ (cond
+ ((zerop (length token))
+ (if (if (< inc 0) (looking-back "\\s(\\|\\s)" (1- (point)))
+ (looking-at "\\s(\\|\\s)"))
+ ;; Go back to `start' in case of an error. This presumes
+ ;; none of the token we've found until now include a ( or ).
+ (progn (goto-char start) (down-list inc) nil)
+ (forward-sexp inc)
+ (/= (point) pos)))
+ ((and levels (null (nth (+ 1 offset) levels))) nil)
+ ((and levels (null (nth (- 2 offset) levels)))
+ (let ((end (point)))
+ (goto-char start)
+ (signal 'scan-error
+ (list "Containing expression ends prematurely"
+ pos end))))
+ (t)))))))
+
;;; The indentation engine.
(defcustom smie-indent-basic 4