From a624a5fbbb74451451cba863ea04fb4806164e19 Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Thu, 15 Dec 2016 17:23:49 +0000 Subject: [PATCH 1/3] Add `dumb-jump-selector` for `helm` This commit adds an additional option for `dumb-jumb-selector` for using Helm to browse multi-choice jumps. A `if` clause has been changed to a `cond` to accomodate the additional rule in a more elegant manner, but the code is otherwise fairly similar to work done for `ivy` support. Tests are forthcoming. --- README.md | 1 + dumb-jump.el | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2b305a3..c1adeac 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/dumb-jump.el b/dumb-jump.el index b1ea4f1..1f873cc 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -3,6 +3,7 @@ ;; Copyright (C) 2015-2016 jack angers ;; Author: jack angers ;; Version: 0.4.3 +;; Package-Version: 20161126.2045 ;; Package-Requires: ((emacs "24.3") (f "0.17.3") (s "1.11.0") (dash "2.9.0") (popup "0.5.3")) ;; Keywords: programming @@ -55,9 +56,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 @@ -932,9 +934,16 @@ Optionally pass t for RUN-NOT-TESTS to see a list of all failed rules" (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 + :fuzzy-match t) + :buffer "*helm dumb-jump*"))) + (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." From 6a642f968191f9e1336b3fd5a742d5913900553c Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Thu, 15 Dec 2016 23:11:26 +0000 Subject: [PATCH 2/3] Fix formatting in Helm conditional --- dumb-jump.el | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index 1f873cc..31da376 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -3,7 +3,6 @@ ;; Copyright (C) 2015-2016 jack angers ;; Author: jack angers ;; Version: 0.4.3 -;; Package-Version: 20161126.2045 ;; Package-Requires: ((emacs "24.3") (f "0.17.3") (s "1.11.0") (dash "2.9.0") (popup "0.5.3")) ;; Keywords: programming @@ -938,9 +937,7 @@ Optionally pass t for RUN-NOT-TESTS to see a list of all failed rules" ((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 - :fuzzy-match t) + (dumb-jump-to-selected results choices (helm :sources (helm-build-sync-source "Jump to:" :candidates choices :fuzzy-match t) :buffer "*helm dumb-jump*"))) (t (dumb-jump-to-selected results choices (popup-menu* choices)))))) From 69c6d2512f621f79d9b8ac7347aaa0079d38aa31 Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Sat, 17 Dec 2016 21:37:20 +0000 Subject: [PATCH 3/3] Fix formatting, add tests for `helm' selector --- dumb-jump.el | 5 ++--- test/dumb-jump-test.el | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index 31da376..03c0c3c 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -926,7 +926,7 @@ 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)) @@ -937,8 +937,7 @@ Optionally pass t for RUN-NOT-TESTS to see a list of all failed rules" ((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 :fuzzy-match t) - :buffer "*helm dumb-jump*"))) + (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)))))) diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index 793f878..8c43477 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -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()")