Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dumb-jump-selector for helm #96

Merged
merged 3 commits into from
Dec 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Dumb Jump will automatically look for a project root. If it's not finding one th
* To support more languages and/or definition types use `add-to-list` on `dumb-jump-find-rules` (see source code).
* `(add-hook 'dumb-jump-after-jump-hook 'some-function)` to execute code after you jump
* `(setq dumb-jump-selector 'ivy)` to use [ivy](https://github.com/abo-abo/swiper#ivy) instead of the default popup for multiple options.
* `(setq dumb-jump-selector 'helm)` to use [helm](https://github.com/emacs-helm/helm) instead of the default popup for multiple options.

##### `use-package` example configuration.

Expand Down
15 changes: 10 additions & 5 deletions dumb-jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@

(defcustom dumb-jump-selector
'popup
"Which selector to use when there is multiple choices. `ivy` also supported."
"Which selector to use when there is multiple choices. `ivy` and `helm' are also supported."
:group 'dumb-jump
:type '(choice (const :tag "Popup" popup)
(const :tag "Helm" helm)
(const :tag "Ivy" other)))

(defcustom dumb-jump-grep-prefix
Expand Down Expand Up @@ -925,16 +926,20 @@ Optionally pass t for RUN-NOT-TESTS to see a list of all failed rules"
(dumb-jump-result-follow result))))

(defun dumb-jump-prompt-user-for-choice (proj results)
"Put a PROJ's list of RESULTS in a 'popup-menu' (or ivy) for user to select. Filters PROJ path from files for display."
"Put a PROJ's list of RESULTS in a 'popup-menu' (or helm/ivy) for user to select. Filters PROJ path from files for display."
(let* ((choices (-map (lambda (result)
(format "%s:%s %s"
(s-replace proj "" (plist-get result :path))
(plist-get result :line)
(s-trim (plist-get result :context))))
results)))
(if (and (eq dumb-jump-selector 'ivy) (fboundp 'ivy-read))
(dumb-jump-to-selected results choices (ivy-read "Jump to: " choices))
(dumb-jump-to-selected results choices (popup-menu* choices)))))
(cond
((and (eq dumb-jump-selector 'ivy) (fboundp 'ivy-read))
(dumb-jump-to-selected results choices (ivy-read "Jump to: " choices)))
((and (eq dumb-jump-selector 'helm) (fboundp 'helm))
(dumb-jump-to-selected results choices (helm :sources (helm-build-sync-source "Jump to: " :candidates choices))))
(t
(dumb-jump-to-selected results choices (popup-menu* choices))))))

(defun dumb-jump-get-project-root (filepath)
"Keep looking at the parent dir of FILEPATH until a denoter file/dir is found."
Expand Down
10 changes: 10 additions & 0 deletions test/dumb-jump-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@
(mock (dumb-jump-result-follow '(:path "/usr/blah/test2.txt" :line 52 :context "var thing = function()" :target "a")))
(dumb-jump-prompt-user-for-choice "/usr/blah" results))))

(ert-deftest dumb-jump-prompt-user-for-choice-correct-helm-test ()
(let* ((dumb-jump-selector 'helm)
(results '((:path "/usr/blah/test.txt" :line 54 :context "function thing()")
(:path "/usr/blah/test2.txt" :line 52 :context "var thing = function()" :target "a"))))
(with-mock
(mock (helm-build-sync-source * :candidates *))
(mock (helm * *) => "/test2.txt:52 var thing = function()")
(mock (dumb-jump-result-follow '(:path "/usr/blah/test2.txt" :line 52 :context "var thing = function()" :target "a")))
(dumb-jump-prompt-user-for-choice "/usr/blah" results))))

(ert-deftest dumb-jump-prompt-user-for-choice-correct-ivy-test ()
(let* ((dumb-jump-selector 'ivy)
(results '((:path "/usr/blah/test.txt" :line 54 :context "function thing()")
Expand Down