bbatsov / helm-projectile

Helm UI for Projectile
327 stars 71 forks source link

Use helm-projectile interface after helm-projectile-switch-project #142

Closed obar closed 3 years ago

obar commented 4 years ago

When switching projects in helm-projectile, the default action takes the user to a helm completion buffer with the only source being the projectile files. It's not the same as the normal helm-projectile interface, with recentf and existing project buffers as sources.

I'd rather it went to the helm-projectile interface; those additional sources are useful!

I have a hack of a solution to this, and it doesn't look like a much more elegant approach could be used without changing projectile itself. For example, projectile-recentf-files doesn't take arguments so it can't be told to look at a different project.

At any rate, I thought I would share what I'm using in case others want to get the same results. Instead of flet one could use noflet, but perhaps that's still too much of a hack to put into the package :) Is it worth a pull request, perhaps behind a customization? Or is there another approach that I'm missing, without redefining functions to get this result?

(use-package helm-projectile
  :chords ("hj" . helm-projectile)
  :config
  (setq helm-source-projectile-projects-actions
        (helm-make-actions
         "Switch to project" (lambda (project)
                               (let ((project-path (expand-file-name project)))
                                 (flet ((projectile-project-root (&rest ARGS) project-path))
                                   (helm-projectile))))
         "Open Dired in project's directory `C-d'" #'dired
         "Open project root in vc-dir or magit `M-g'" #'helm-projectile-vc
         "Switch to Eshell `M-e'" #'helm-projectile-switch-to-eshell
         "Grep in projects `C-s'" #'helm-projectile-grep
         "Compile project `M-c'. With C-u, new compile command" #'helm-projectile-compile-project
         "Remove project(s) from project list `M-D'" #'helm-projectile-remove-known-project)))
obar commented 4 years ago

Actually, using cl-letf can do the same job without noflet and without depreciation messages:

(use-package helm-projectile
  :chords ("hj" . helm-projectile)
  :config
  (setq helm-source-projectile-projects-actions
        (helm-make-actions
         "Switch to project" (lambda (project)
                               (let ((project-path (expand-file-name project)))
                                 (cl-letf (((symbol-function 'projectile-project-root)
                                            (lambda (&rest ARGS) project-path)))
                                   (helm-projectile))))
         "Open Dired in project's directory `C-d'" #'dired
         "Open project root in vc-dir or magit `M-g'" #'helm-projectile-vc
         "Switch to Eshell `M-e'" #'helm-projectile-switch-to-eshell
         "Grep in projects `C-s'" #'helm-projectile-grep
         "Compile project `M-c'. With C-u, new compile command" #'helm-projectile-compile-project
         "Remove project(s) from project list `M-D'" #'helm-projectile-remove-known-project)))
bbatsov commented 4 years ago

PRs welcome! :-)