projectile icon indicating copy to clipboard operation
projectile copied to clipboard

Commands to switch project and find files in other window/frame

Open pkryger opened this issue 6 months ago • 1 comments

Motivation

The idea is to have commands that will switch to a project and then find a file in the project displaying the file in other window or other frame. The natural bindings for it seem to be C-c p 4 p and C-c p 5 p.

I've been using a custom implementation based on helm-projectile for a last few years and I think it may be generalised to projectile. I have been thinking how to do that and since I couldn't decide what would be the best way to approach the implementation I decided to reach here. For brevity, I will only consider the other window version, but the same applies for other frame.

Solution 1

Utilise existing functionality and simply set projectile-switch-project-action to projectile-find-file-other-window and call projectile-switch-project-by-name. Caveat is that a natural command name (IMHO the best one), i.e., projectile-switch-project-other-window would have different semantics to projectile-switch-project. If that's an issue then perhaps come up with a distinct name the new command, e.g. projectile-switch-project-and-find-file-other-window. But I think such a name is too mouthful and would vote for different semantics with a mention in docstring.

FWIW I implemented a solution that bases on this idea in helm-projectile.

Solution 2

To mimic projectile-switch-project semantics (to a degree), try to find a function named after the vale of projectile-switch-project-action that matches the intention. E.g. append -other-window suffix to a current value of the action variable and if such a function exists then call it. The bit that doesn't have so clear answer is what to do when such a function doesn't exist. Calling a hardcoded projectile-find-file-other-window may be surprising for someone who set the action to something completely different.

Solution 3

To preserve projectile-switch-project semantics add a new variable projectile-switch-project-other-window-action with default vale of projectile-find-file-other-window and replicate semantics of projectile-switch-project. This may be a bit of overkill though.

Please let me know what you think. I am happy to cut a PR with whatever solution you think is best.

pkryger avatar Jul 23 '25 08:07 pkryger

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed soon if no further activity occurs. Thank you for your contribution and understanding!

github-actions[bot] avatar Oct 22 '25 02:10 github-actions[bot]