emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]