-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpophint-mark.el
91 lines (80 loc) · 3.6 KB
/
pophint-mark.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(require 'pophint)
;;;###autoload
(defcustom pophint-mark:enable t
"Whether to enable feature."
:type 'boolean
:group 'pophint)
(make-obsolete 'pophint-config:set-automatically-when-marking 'pophint-mark:enable "1.1.0")
(defcustom pophint-mark:yank-immediately-on-marking-p nil
"Whether to yank immediately when select hint-tip
after `set-mark-command' or `cua-set-mark'."
:type 'boolean
:group 'pophint)
(make-obsolete 'pophint-config:set-yank-immediately-when-marking 'pophint-mark:yank-immediately-on-marking-p "1.1.0")
(defcustom pophint-mark:direction 'forward
"Set direction when select hint-tip after `set-mark-command' or `cua-set-mark'."
:type 'symbol
:group 'pophint)
(make-obsolete 'pophint-config:set-mark-direction 'pophint-mark:direction "1.1.0")
(defadvice set-mark-command (after do-pophint disable)
(let ((pophint-mark--user-start (point))
(action-name (if pophint-mark:yank-immediately-on-marking-p
"Yank"
"Focus"))
(action (lambda (hint)
(let ((currpt (point)))
(goto-char (pophint:hint-startpt hint))
(when pophint-mark:yank-immediately-on-marking-p
(kill-ring-save currpt (point)))))))
(cl-case pophint-mark:direction
(forward
(pophint-region:narrow-or-wide :narrow-limit (pos-eol)
:use-pos-tip nil
:action-name action-name
:action action))
(backward
(pophint-region:narrow-or-wide :backward-p t
:narrow-limit (pos-bol)
:use-pos-tip nil
:action-name action-name
:action action))
(t
(pophint:do :not-highlight t
:not-switch-window t
:use-pos-tip nil
:direction pophint-mark:direction
:source '((shown . "Region")
(method . (lambda ()
(when (= (point) pophint-mark--user-start)
(pophint:inch-forward))
(pophint:make-hint-with-inch-forward))))
:action-name action-name
:action action)))))
(defadvice cua-set-mark (after do-pophint disable)
(pophint:do :not-highlight t
:not-switch-window t
:use-pos-tip nil
:direction pophint-mark:direction
:source '((shown . "Region")
(regexp . "[^a-zA-Z0-9]+")
(action . (lambda (hint)
(let* ((currpt (point)))
(goto-char (pophint:hint-startpt hint))
(when pophint-mark:yank-immediately-on-marking-p
(kill-ring-save currpt (point)))))))))
;;;###autoload
(defun pophint-mark:provision (activate)
(interactive)
(cond (activate
(ad-enable-advice 'set-mark-command 'after 'do-pophint)
(ad-enable-advice 'cua-set-mark 'after 'do-pophint))
(t
(ad-disable-advice 'set-mark-command 'after 'do-pophint)
(ad-disable-advice 'cua-set-mark 'after 'do-pophint)))
(ad-activate 'set-mark-command)
(ad-activate 'cua-set-mark))
;;;###autoload
(with-eval-after-load 'pophint
(when pophint-mark:enable (pophint-mark:provision t)))
(provide 'pophint-mark)
;;; pophint-mark.el ends here