Skip to content

Commit c797ee2

Browse files
committed
lispy.el: update goto machinery
* lispy.el (lispy-goto): Now takes arg. When non-nil, call `lispy-goto-projectile'. (lispy-goto-local): Deactivate mark. (lispy-goto-projectile): New function. (lispy--fetch-tags-recursive): Omit .cask. (lispy--fetch-tags-projectile): New function. (lispy--fetch-this-file-tags): Use full file name. (lispy--current-tag): New function. (lispy--select-candidate): Use helm's :preselect. ("goto"): re-define "f","l","b", add "p". ("other"): add "g".
1 parent 0afdaa5 commit c797ee2

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

lispy.el

+50-20
Original file line numberDiff line numberDiff line change
@@ -1921,11 +1921,15 @@ Quote newlines if ARG isn't 1."
19211921
t)))
19221922

19231923
;; ——— Locals: tags ———————————————————————————————————————————————————————————
1924-
(defun lispy-goto ()
1925-
"Jump to symbol within files in current directory."
1926-
(interactive)
1924+
(defun lispy-goto (&optional arg)
1925+
"Jump to symbol within files in current directory.
1926+
When ARG isn't nil, call `lispy-goto-projectile' instead."
1927+
(interactive "P")
19271928
(deactivate-mark)
1928-
(lispy--goto 'lispy--fetch-tags))
1929+
(lispy--goto
1930+
(if arg
1931+
#'lispy--fetch-tags-projectile
1932+
#'lispy--fetch-tags)))
19291933

19301934
(defun lispy-goto-recursive ()
19311935
"Jump to symbol within files in current directory and its subdiretories."
@@ -1936,8 +1940,15 @@ Quote newlines if ARG isn't 1."
19361940
(defun lispy-goto-local ()
19371941
"Jump to symbol within current file."
19381942
(interactive)
1943+
(deactivate-mark)
19391944
(lispy--goto 'lispy--fetch-this-file-tags))
19401945

1946+
(defun lispy-goto-projectile ()
1947+
"Jump to symbol within files in (`projectile-project-root')."
1948+
(interactive)
1949+
(deactivate-mark)
1950+
(lispy--goto 'lispy--fetch-tags-projectile))
1951+
19411952
(defun lispy-goto-def-down (arg)
19421953
"Jump to definition of ARGth element of current list."
19431954
(interactive "p")
@@ -2564,6 +2575,7 @@ With ARG, use the contents of `lispy-store-region-and-buffer' instead."
25642575

25652576
(declare-function projectile-find-file "ext:projectile")
25662577
(declare-function projectile-find-file-other-window "ext:projectile")
2578+
(declare-function projectile-project-root "ext:projectile")
25672579

25682580
(defun lispy-visit (arg)
25692581
"Forward to find file in project depending on ARG."
@@ -3155,12 +3167,17 @@ For example, a `setq' statement is amended with variable name that it uses."
31553167
(let ((dirs
31563168
(split-string
31573169
(shell-command-to-string
3158-
(format "find %s -type d ! -regex \".*\\.git.*\"" default-directory))
3170+
(format "find %s -type d ! -regex \".*\\(\\.git\\|\\.cask\\).*\"" default-directory))
31593171
"\n"
31603172
t)))
31613173
(apply #'append
31623174
(mapcar #'lispy--fetch-tags dirs))))
31633175

3176+
(defun lispy--fetch-tags-projectile ()
3177+
"Fetch all tags in the projectile directory recursively."
3178+
(let ((default-directory (projectile-project-root)))
3179+
(lispy--fetch-tags-recursive)))
3180+
31643181
(defun lispy--set-file-to-tags (file tags)
31653182
"Put FILE as property of each tag in TAGS."
31663183
(mapcar
@@ -3185,7 +3202,7 @@ For example, a `setq' statement is amended with variable name that it uses."
31853202
"Fetch this file tags."
31863203
(let ((tags
31873204
(lispy--set-file-to-tags
3188-
(file-name-nondirectory (buffer-file-name))
3205+
(buffer-file-name)
31893206
(semantic-fetch-tags))))
31903207
(when (memq major-mode '(lisp-mode emacs-lisp-mode))
31913208
(lexical-let ((arity (cdr (assoc major-mode lispy-tag-arity)))
@@ -3859,6 +3876,15 @@ Unless inside string or comment, or `looking-back' at CONTEXT."
38593876

38603877
(declare-function helm "ext:helm")
38613878

3879+
(defun lispy--current-tag ()
3880+
"Forward to `semantic-current-tag'.
3881+
Try to refresh if nil is returned."
3882+
(let ((tag (semantic-current-tag)))
3883+
(unless tag
3884+
(semantic-clear-toplevel-cache)
3885+
(semantic-fetch-tags))
3886+
(semantic-tag-name tag)))
3887+
38623888
(defun lispy--select-candidate (candidates action)
38633889
"Select from CANDIDATES list with `helm'.
38643890
ACTION is called for the selected candidate."
@@ -3877,7 +3903,9 @@ ACTION is called for the selected candidate."
38773903
(cons (car x) x))
38783904
x))
38793905
candidates))
3880-
(action . ,action)))))
3906+
(action . ,action))
3907+
:preselect (regexp-quote (or (lispy--current-tag)
3908+
"")))))
38813909

38823910
(defun lispy--action-jump (tag)
38833911
"Jump to TAG."
@@ -3888,8 +3916,8 @@ ACTION is called for the selected candidate."
38883916
(semantic--tag-set-overlay
38893917
tag
38903918
(setq overlay
3891-
(make-overlay (aref overlay 0)
3892-
(aref overlay 1)
3919+
(make-overlay (or (aref overlay 0) 1)
3920+
(or (aref overlay 1) 1)
38933921
(find-file (aref overlay 2))))))
38943922
(t (error "Unexpected")))
38953923
(push-mark)
@@ -4413,25 +4441,27 @@ FUNC is obtained from (`lispy--insert-or-call' DEF PLIST)"
44134441
(eldoc-add-command func)
44144442
(define-key keymap (kbd key) func)))
44154443

4416-
(lispy-defverb
4417-
"other"
4418-
(("h" lispy-move-left)
4419-
("j" lispy-down-slurp)
4420-
("k" lispy-up-slurp)
4421-
("l" lispy-move-right)
4422-
("SPC" lispy-other-space)))
4423-
44244444
(lispy-defverb
44254445
"goto"
44264446
(("d" lispy-goto)
4427-
("f" lispy-goto-local)
4447+
("l" lispy-goto-local)
44284448
("r" lispy-goto-recursive)
4429-
("c" lispy-follow)
4430-
("b" pop-global-mark)
4449+
("p" lispy-goto-projectile)
4450+
("f" lispy-follow)
4451+
("b" pop-tag-mark)
44314452
("q" lispy-quit)
44324453
("j" lispy-goto-def-down)
44334454
("a" lispy-goto-def-ace)))
44344455

4456+
(lispy-defverb
4457+
"other"
4458+
(("h" lispy-move-left)
4459+
("j" lispy-down-slurp)
4460+
("k" lispy-up-slurp)
4461+
("l" lispy-move-right)
4462+
("SPC" lispy-other-space)
4463+
("g" lispy-goto-mode)))
4464+
44354465
(lispy-defverb
44364466
"transform"
44374467
(("o" lispy-oneline)

0 commit comments

Comments
 (0)