[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 73/77: Support list expand/shrink on js2 nodes
From: |
Leo Liu |
Subject: |
[elpa] 73/77: Support list expand/shrink on js2 nodes |
Date: |
Sat, 05 Apr 2014 04:08:28 +0000 |
leoliu pushed a commit to branch master
in repository elpa.
commit 7c0d5c4eda616fe87dfc3159368208526399ac7d
Author: Leo Liu <address@hidden>
Date: Sat Feb 8 12:25:14 2014 +0800
Support list expand/shrink on js2 nodes
---
easy-kill.el | 87 ++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 61 insertions(+), 26 deletions(-)
diff --git a/easy-kill.el b/easy-kill.el
index dcbbae4..07c8a37 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -43,27 +43,31 @@
(require 'thingatpt)
(eval-and-compile
- (or (fboundp 'set-temporary-overlay-map) ; new in 24.3
- (defun set-temporary-overlay-map (map &optional keep-pred)
- (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map"))
- (overlaysym (make-symbol "t"))
- (alist (list (cons overlaysym map)))
- (clearfun
- `(lambda ()
- (unless ,(cond ((null keep-pred) nil)
- ((eq t keep-pred)
- `(eq this-command
- (lookup-key ',map
-
(this-command-keys-vector))))
- (t `(funcall ',keep-pred)))
- (set ',overlaysym nil) ;Just in case.
- (remove-hook 'pre-command-hook ',clearfunsym)
- (setq emulation-mode-map-alists
- (delq ',alist emulation-mode-map-alists))))))
- (set overlaysym overlaysym)
- (fset clearfunsym clearfun)
- (add-hook 'pre-command-hook clearfunsym)
- (push alist emulation-mode-map-alists)))))
+ (cond
+ ((fboundp 'set-transient-map) nil)
+ ((fboundp 'set-temporary-overlay-map) ; new in 24.3
+ (defalias 'set-transient-map 'set-temporary-overlay-map))
+ (t
+ (defun set-transient-map (map &optional keep-pred)
+ (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map"))
+ (overlaysym (make-symbol "t"))
+ (alist (list (cons overlaysym map)))
+ (clearfun
+ `(lambda ()
+ (unless ,(cond ((null keep-pred) nil)
+ ((eq t keep-pred)
+ `(eq this-command
+ (lookup-key ',map
+ (this-command-keys-vector))))
+ (t `(funcall ',keep-pred)))
+ (set ',overlaysym nil) ;Just in case.
+ (remove-hook 'pre-command-hook ',clearfunsym)
+ (setq emulation-mode-map-alists
+ (delq ',alist emulation-mode-map-alists))))))
+ (set overlaysym overlaysym)
+ (fset clearfunsym clearfun)
+ (add-hook 'pre-command-hook clearfunsym)
+ (push alist emulation-mode-map-alists))))))
(defcustom easy-kill-alist
'((?w . word)
@@ -341,7 +345,7 @@ candidate property instead."
(defun easy-kill-activate-keymap ()
(let ((map (easy-kill-map)))
- (set-temporary-overlay-map
+ (set-transient-map
map
(lambda ()
;; Prevent any error from activating the keymap forever.
@@ -515,10 +519,42 @@ inspected."
(easy-kill-thing 'sexp n t)
(overlay-put easy-kill-candidate 'thing 'list))))))
+(defun easy-kill-find-js2-node (beg end &optional inner)
+ (eval-and-compile (require 'js2-mode))
+ (let* ((node (js2-node-at-point))
+ (last-node node))
+ (while (progn
+ (if (or (js2-ast-root-p node)
+ (and (<= (js2-node-abs-pos node) beg)
+ (>= (js2-node-abs-end node) end)
+ (or inner
+ (not (and (= (js2-node-abs-pos node) beg)
+ (= (js2-node-abs-end node) end))))))
+ nil
+ (setq last-node node
+ node (js2-node-parent node))
+ t)))
+ (if inner last-node node)))
+
+(defun easy-kill-on-js2-node (n)
+ (let ((node (pcase n
+ ((or `+ `-)
+ (easy-kill-find-js2-node (overlay-start easy-kill-candidate)
+ (overlay-end easy-kill-candidate)
+ (eq n '-)))
+ ((guard (eq 'list (overlay-get easy-kill-candidate 'thing)))
+ (error "List forward not supported in js2-mode"))
+ (_ (js2-node-at-point)))))
+ (easy-kill-adjust-candidate 'list
+ (js2-node-abs-pos node)
+ (js2-node-abs-end node))))
+
(defun easy-kill-on-list (n)
(cond
((derived-mode-p 'nxml-mode)
(easy-kill-on-nxml-element n))
+ ((derived-mode-p 'js2-mode)
+ (easy-kill-on-js2-node n))
((memq n '(+ -))
(let ((bounds (easy-kill-bounds-of-list n)))
(when bounds
@@ -526,10 +562,9 @@ inspected."
(t (easy-kill-thing 'list n t))))
(defun easy-kill-on-sexp (n)
- (let ((nxml-sexp-element-flag t))
- (if (memq n '(+ -))
- (easy-kill-on-list n)
- (easy-kill-thing 'sexp n t))))
+ (if (memq n '(+ -))
+ (easy-kill-on-list n)
+ (easy-kill-thing 'sexp n t)))
(provide 'easy-kill)
;;; easy-kill.el ends here
- [elpa] 61/77: Optimise easy-kill-thing-forward when n is 0, (continued)
- [elpa] 61/77: Optimise easy-kill-thing-forward when n is 0, Leo Liu, 2014/04/05
- [elpa] 62/77: Small tweak to easy-kill-on-nxml-element, Leo Liu, 2014/04/05
- [elpa] 60/77: Make easy-kill-on-buffer-file-name do nothing in easy-mark, Leo Liu, 2014/04/05
- [elpa] 68/77: Fix easy-kill-append to update clipboard, Leo Liu, 2014/04/05
- [elpa] 65/77: Fix #8: Don't strip trailing blank chars, Leo Liu, 2014/04/05
- [elpa] 67/77: New handler for defun-name and bind it to `D', Leo Liu, 2014/04/05
- [elpa] 66/77: Fix #9: Work around fixed bug in thingatpt.el, Leo Liu, 2014/04/05
- [elpa] 71/77: In no case should easy-kill-activate-keymap err, Leo Liu, 2014/04/05
- [elpa] 70/77: Adapt to upstream change, Leo Liu, 2014/04/05
- [elpa] 72/77: Rename easy-kill-backward-down to easy-kill-forward-down, Leo Liu, 2014/04/05
- [elpa] 73/77: Support list expand/shrink on js2 nodes,
Leo Liu <=
- [elpa] 74/77: Require cl-lib, Leo Liu, 2014/04/05
- [elpa] 76/77: Add easy-kill to externals-list, Leo Liu, 2014/04/05
- [elpa] 77/77: Merge easy-kill as packages/easy-kill, Leo Liu, 2014/04/05
- [elpa] 75/77: Cleanup and preparation for inclusion in GNU ELPA, Leo Liu, 2014/04/05
- [elpa] 69/77: Consolidate easy-mark and easy-mark-sexp into one command, Leo Liu, 2014/04/05