From a906b82788ee0bd234b1c313e56d5282d71d344a Mon Sep 17 00:00:00 2001 From: fuxialexander Date: Wed, 4 Jul 2018 23:59:18 +0800 Subject: [PATCH 1/3] add action for `counsel-find-file` --- modules/completion/ivy/autoload/ivy.el | 16 ++++++++++++++++ modules/completion/ivy/config.el | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 5df991833..d8b02bc14 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -198,6 +198,22 @@ search current file. See `+ivy-task-tags' to customize what this searches for." (selected-window)))))) +;;;###autoload +(defun +ivy/reloading (cmd) + (lambda (x) + (funcall cmd x) + (ivy--reset-state ivy-last))) + +;;;###autoload +(defun +ivy/given-file (cmd prompt) + (lambda (source) + (let ((target + (let ((enable-recursive-minibuffers t)) + (read-file-name + (format "%s %s to:" prompt source))))) + (funcall cmd source target 1)))) + + ;; ;; File searching ;; diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index b57eab9f0..8a8e5f8fc 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -98,6 +98,21 @@ immediately runs it on the current candidate (ending the ivy session)." ;; Dim recentf entries that are not in the current project. (ivy-set-display-transformer #'counsel-recentf #'+ivy-recentf-transformer) + ;; Configure `counsel-find-file' + (ivy-add-actions + 'counsel-find-file + `(("c" ,(+ivy/given-file #'copy-file "Copy file") "copy file") + ("d" ,(+ivy/reloading #'+ivy/confirm-delete-file) "delete") + ("r" (lambda (path) (rename-file path (read-string "New name: "))) "Rename") + ("m" ,(+ivy/reloading (+ivy/given-file #'rename-file "Move")) "move") + ("f" find-file-other-window "other window") + ("p" (lambda (path) (with-ivy-window (insert (file-relative-name path default-directory)))) "Insert relative path") + ("P" (lambda (path) (with-ivy-window (insert path))) "Insert absolute path") + ("l" (lambda (path) "Insert org-link with relative path" + (with-ivy-window (insert (format "[[./%s]]" (file-relative-name path default-directory))))) "Insert org-link (rel. path)") + ("L" (lambda (path) "Insert org-link with absolute path" + (with-ivy-window (insert (format "[[%s]]" path)))) "Insert org-link (abs. path)"))) + ;; Configure `counsel-rg', `counsel-ag' & `counsel-pt' (dolist (cmd '(counsel-ag counsel-rg counsel-pt)) (ivy-add-actions From 8f74ce982d88432c07452a053445daf90b587f18 Mon Sep 17 00:00:00 2001 From: fuxialexander Date: Wed, 4 Jul 2018 23:59:36 +0800 Subject: [PATCH 2/3] add action for counsel-projectile-switch-project --- modules/feature/workspaces/config.el | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/feature/workspaces/config.el b/modules/feature/workspaces/config.el index 5c06728a3..8875de6ab 100644 --- a/modules/feature/workspaces/config.el +++ b/modules/feature/workspaces/config.el @@ -140,7 +140,27 @@ Uses `+workspaces-main' to determine the name of the main workspace." ;; per-project workspaces, but reuse current workspace if empty (setq projectile-switch-project-action #'+workspaces|set-project-action - counsel-projectile-switch-project-action #'+workspaces|switch-to-project) + counsel-projectile-switch-project-action + '(1 ("o" +workspaces|switch-to-project "open project in new workspace") + ("O" counsel-projectile-switch-project-action "jump to a project buffer or file") + ("f" counsel-projectile-switch-project-action-find-file "jump to a project file") + ("d" counsel-projectile-switch-project-action-find-dir "jump to a project directory") + ("b" counsel-projectile-switch-project-action-switch-to-buffer "jump to a project buffer") + ("m" counsel-projectile-switch-project-action-find-file-manually "find file manually from project root") + ("w" counsel-projectile-switch-project-action-save-all-buffers "save all project buffers") + ("k" counsel-projectile-switch-project-action-kill-buffers "kill all project buffers") + ("r" counsel-projectile-switch-project-action-remove-known-project "remove project from known projects") + ("c" counsel-projectile-switch-project-action-compile "run project compilation command") + ("C" counsel-projectile-switch-project-action-configure "run project configure command") + ("e" counsel-projectile-switch-project-action-edit-dir-locals "edit project dir-locals") + ("v" counsel-projectile-switch-project-action-vc "open project in vc-dir / magit / monky") + ("s" (lambda (project) (let ((projectile-switch-project-action (lambda () (call-interactively #'+ivy/project-search)))) + (counsel-projectile-switch-project-by-name project))) "search project") + ("xs" counsel-projectile-switch-project-action-run-shell "invoke shell from project root") + ("xe" counsel-projectile-switch-project-action-run-eshell "invoke eshell from project root") + ("xt" counsel-projectile-switch-project-action-run-term "invoke term from project root") + ("X" counsel-projectile-switch-project-action-org-capture "org-capture into project"))) + (add-hook 'projectile-after-switch-project-hook #'+workspaces|switch-to-project) ;; In some scenarios, persp-mode throws error an error when Emacs tries to From 0df9bae16b6a5b65bd90f365510c8b6c825c4cae Mon Sep 17 00:00:00 2001 From: fuxialexander Date: Thu, 5 Jul 2018 00:38:41 +0800 Subject: [PATCH 3/3] don't override original actions --- modules/completion/ivy/config.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index 8a8e5f8fc..eb49c9022 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -101,17 +101,21 @@ immediately runs it on the current candidate (ending the ivy session)." ;; Configure `counsel-find-file' (ivy-add-actions 'counsel-find-file - `(("c" ,(+ivy/given-file #'copy-file "Copy file") "copy file") + `(("b" counsel-find-file-cd-bookmark-action "cd bookmark") + ("s" counsel-find-file-as-root "open as root") + ("m" counsel-find-file-mkdir-action "mkdir") + ("c" ,(+ivy/given-file #'copy-file "Copy file") "copy file") ("d" ,(+ivy/reloading #'+ivy/confirm-delete-file) "delete") - ("r" (lambda (path) (rename-file path (read-string "New name: "))) "Rename") - ("m" ,(+ivy/reloading (+ivy/given-file #'rename-file "Move")) "move") + ("r" (lambda (path) (rename-file path (read-string "New name: "))) "rename") + ("R" ,(+ivy/reloading (+ivy/given-file #'rename-file "Move")) "move") ("f" find-file-other-window "other window") - ("p" (lambda (path) (with-ivy-window (insert (file-relative-name path default-directory)))) "Insert relative path") - ("P" (lambda (path) (with-ivy-window (insert path))) "Insert absolute path") + ("F" find-file-other-frame "other frame") + ("p" (lambda (path) (with-ivy-window (insert (file-relative-name path default-directory)))) "insert relative path") + ("P" (lambda (path) (with-ivy-window (insert path))) "insert absolute path") ("l" (lambda (path) "Insert org-link with relative path" - (with-ivy-window (insert (format "[[./%s]]" (file-relative-name path default-directory))))) "Insert org-link (rel. path)") + (with-ivy-window (insert (format "[[./%s]]" (file-relative-name path default-directory))))) "insert org-link (rel. path)") ("L" (lambda (path) "Insert org-link with absolute path" - (with-ivy-window (insert (format "[[%s]]" path)))) "Insert org-link (abs. path)"))) + (with-ivy-window (insert (format "[[%s]]" path)))) "insert org-link (abs. path)"))) ;; Configure `counsel-rg', `counsel-ag' & `counsel-pt' (dolist (cmd '(counsel-ag counsel-rg counsel-pt))