leoliu pushed a commit to branch master in repository elpa. commit 26288e78efc586fc6ff4dcf4d348d906f7f2c0fe Author: Leo Liu <sdl....@gmail.com> Date: Wed Oct 9 11:49:12 2013 +0800
Improve list expand/shrink support in smie-based modes such as octave, ruby, css etc. --- easy-kill.el | 40 +++++++++++++++++++++++++++------------- 1 files changed, 27 insertions(+), 13 deletions(-) diff --git a/easy-kill.el b/easy-kill.el index 82baa79..6d37b7f 100644 --- a/easy-kill.el +++ b/easy-kill.el @@ -295,20 +295,35 @@ inspected." (easy-kill-adjust-candidate 'url url) (return url))))))) +(defun easy-kill-backward-up () + (condition-case nil + (up-list -1) + (scan-error (let ((ppss (syntax-ppss))) + (and (nth 3 ppss) (goto-char (nth 8 ppss))))))) + +(defun easy-kill-backward-down (point &optional bound) + (condition-case nil + (progn + (easy-kill-backward-up) + (if (or (not bound) + (and (> (point) bound) (/= point (point)))) + (easy-kill-backward-down (point) bound) + point)) + (scan-error point))) + (defun easy-kill-bounds-of-list (n) (save-excursion (pcase n - (`+ (goto-char (overlay-start easy-kill-candidate)) - (ignore-errors - (up-list -1) - (cons (point) (progn (forward-sexp) (point))))) - (`- (let ((depth (car (parse-partial-sexp - (overlay-start easy-kill-candidate) (point))))) - (if (> depth 1) - (ignore-errors - (goto-char (scan-lists (point) -1 (1- depth))) - (cons (point) (progn (forward-sexp 1) (point)))) - (bounds-of-thing-at-point 'sexp)))) + (`+ (let ((start (overlay-start easy-kill-candidate))) + (goto-char start) + (easy-kill-backward-up) + (when (/= start (point)) + (cons (point) (progn (forward-sexp) (point)))))) + (`- (let ((pt (point))) + (goto-char (easy-kill-backward-down + (point) (overlay-start easy-kill-candidate))) + (when (/= pt (point)) + (cons (point) (progn (forward-sexp 1) (point)))))) (_ (error "Unsupported argument `%s'" n))))) (defun easy-kill-on-list (n) @@ -319,8 +334,7 @@ inspected." (defun easy-kill-on-sexp (n) (if (memq n '(+ -)) - (let ((bounds (easy-kill-bounds-of-list n))) - (easy-kill-adjust-candidate 'sexp (car bounds) (cdr bounds))) + (easy-kill-on-list n) (easy-kill-thing 'sexp n nil t))) (provide 'easy-kill)