-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpophint-tags.el
53 lines (48 loc) · 2.47 KB
/
pophint-tags.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
(require 'pophint)
(require 'pophint-sym)
(defvar pophint-tags--current-mode nil)
;;;###autoload
(cl-defmacro pophint-tags:advice-command (command &key (point-arg-index nil))
"Set advice to move the point selected hint-tip before COMMAND.
If COMMAND receives the point by interactive,
give the argument index as POINT-ARG-INDEX."
(declare (indent 0))
(let ((advice-name (intern (format "%s-advice-around-do-pophint" command))))
`(progn
(defun ,advice-name (orig &rest args)
(pophint--trace "start as substitute for %s" (symbol-name ',command))
(let* ((pophint-tags--current-mode major-mode)
(currwnd (get-buffer-window))
(currpt (point))
(startpt (progn
;; move to head of current symbol
(skip-syntax-backward "w_")
(point)))
(hint (pophint:do :allwindow t
:direction 'around
:source `((activebufferp . (lambda (b)
(eq pophint-tags--current-mode
(buffer-local-value 'major-mode b))))
,@pophint:source-symbol)
:action-name "TagJump"
:action 'hint))
(wnd (when hint (pophint:hint-window hint)))
(beforept (when wnd (window-point wnd))))
(when wnd
(with-selected-window wnd
(goto-char (pophint:hint-startpt hint))
(when ,point-arg-index
(setf (nth ,point-arg-index args) (point)))
(apply orig args))
(when (and (window-live-p wnd)
(eq (window-point wnd) (pophint:hint-startpt hint)))
;; if jumped into other window, move active window point to before jump
(set-window-point wnd beforept))
(when (and (window-live-p currwnd)
(eq (window-point currwnd) startpt))
;; if jumped into other window, move active window point to before jump
(set-window-point currwnd currpt)))))
(advice-add ',command :around ',advice-name))))
(define-obsolete-function-alias 'pophint-config:set-tag-jump-command 'pophint-tags:advice-command "1.1.0")
(provide 'pophint-tags)
;;; pophint-tags.el ends here