leoliu pushed a commit to branch master
in repository elpa.
commit 7498c8570f3b9ca173e249db46d39172e4c72cb0
Author: Leo Liu <[email protected]>
Date: Fri Apr 11 11:08:07 2014 +0800
Show tooltip describing kill candidate and echo js2 node
---
README.rst | 9 +++++++++
easy-kill.el | 23 ++++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/README.rst b/README.rst
index c7fbb52..548b074 100644
--- a/README.rst
+++ b/README.rst
@@ -83,6 +83,15 @@ convention, or by defining new functions named like
``easy-kill-on-THING-NAME``. See ``easy-kill-on-buffer-file-name`` and
``easy-kill-on-url`` for examples.
+NEWS
+~~~~
+
+0.9.2
++++++
+
+#. Mouse over the selection now shows description.
+#. Echo js2 node name
+
Bugs
~~~~
diff --git a/easy-kill.el b/easy-kill.el
index fa8135e..6823d6a 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -166,13 +166,19 @@ Use `setf' to change property value."
(`end '(overlay-end easy-kill-candidate))
(`bounds '(easy-kill--bounds))
(`buffer '(overlay-buffer easy-kill-candidate))
+ (`properties '(append (list 'start (easy-kill-get start))
+ (list 'end (easy-kill-get end))
+ (overlay-properties easy-kill-candidate)))
(_ `(overlay-get easy-kill-candidate ',prop))))
(defun easy-kill-init-candidate (n)
+ ;; Manipulate `easy-kill-candidate' directly during initialisation;
+ ;; should use `easy-kill-get' elsewhere.
(let ((o (make-overlay (point) (point))))
(unless easy-kill-mark
(overlay-put o 'face 'easy-kill-selection))
(overlay-put o 'origin (point))
+ (overlay-put o 'help-echo #'easy-kill-describe-candidate)
;; Use higher priority to avoid shadowing by, for example,
;; `hl-line-mode'.
(overlay-put o 'priority 999)
@@ -217,6 +223,18 @@ Otherwise, it is the value of the overlay's candidate
property."
(`(,beg . ,end) (filter-buffer-substring beg end)))
"")))
+(defun easy-kill-describe-candidate (&rest _)
+ "Return a string that describes current kill candidate."
+ (let* ((props (cl-loop for k in '(thing start end origin)
+ with all = (easy-kill-get properties)
+ ;; Allow describe-PROP to provide customised
+ ;; description.
+ for dk = (intern-soft (format "describe-%s" k))
+ for v = (or (plist-get all dk) (plist-get all k))
+ when v collect (format "%s:\t%s" k v)))
+ (txt (mapconcat #'identity props "\n")))
+ (format "cmd:\t%s\n%s" (if easy-kill-mark "easy-mark" "easy-kill") txt)))
+
(defun easy-kill-adjust-candidate (thing &optional beg end)
"Adjust kill candidate to THING, BEG, END.
If BEG is a string, shrink the overlay to zero length and set its
@@ -563,7 +581,10 @@ inspected."
(_ (js2-node-at-point)))))
(easy-kill-adjust-candidate 'list
(js2-node-abs-pos node)
- (js2-node-abs-end node))))
+ (js2-node-abs-end node))
+ (setf (easy-kill-get describe-thing)
+ (format "list (%s)" (js2-node-short-name node)))
+ (easy-kill-echo "%s" (js2-node-short-name node))))
(defun easy-kill-on-list (n)
(cond