Merge pull request #740 from fuxialexander/counsel_find_file_action
Add ivy action to counsel-find-file and counsel-projectile-switch-project
This commit is contained in:
commit
cd26e11e94
3 changed files with 56 additions and 1 deletions
|
@ -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
|
||||
;;
|
||||
|
|
|
@ -98,6 +98,25 @@ 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
|
||||
`(("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")
|
||||
("R" ,(+ivy/reloading (+ivy/given-file #'rename-file "Move")) "move")
|
||||
("f" find-file-other-window "other window")
|
||||
("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)")
|
||||
("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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue