Closed swarnendubiswas closed 4 years ago
Thanks for the suggestion. Perhaps a good approach would be to indeed have a variable counsel-projectile-default-files
containing a list of files that should appear first in counsel-projectile-find-file
and just after open buffers in counsel-projectile
. I'll try to think about how to implement this. One possibility would be to use ivy's sorting mechanism, although that might not be optimal for large projects.
Here is the original question from Emacs on SE.
If you want the same thing as in that question in counsel-projectile you can try something like the following (untested):
(defvar counsel-projectile-default-file nil
"Default file to to open with `counsel-projectile-default-file'.")
(defun counsel-projectile-open-default-file ()
"Open the current project's default file.
This file is specified in `counsel-projectile-default-file'."
(interactive)
(let ((file counsel-projectile-default-file))
(if (and file
(setq file (projectile-expand-root file))
(file-exists-p file))
(find-file file)
(message "File %s doesn't exist." file))))
(defun counsel-projectile-switch-project-action-default-file (project)
"Open PROJECT's default file.
This file is specified in `counsel-projectile-default-file'."
(let ((projectile-switch-project-action #'counsel-projectile-open-default-file))
(counsel-projectile-switch-project-by-name project)))
Then you can set the variable globally or in .dir-locals.el
, you can set a key binding to the first function to call it from inside a project, and you can add the second function the the action list of counsel-projectile-switch-project
.
Thanks, it works like a charm!
This is a feature request, and I think it can be useful.
When I open a new project, there are often default landing files that I want to set. For example, I usually open
paper.tex
for all my LaTeX projects. Is it possible to automate opening a default file per-project? A custom variable would be good, then we can set that in.dir-locals.el
. I am not sure whether this can already be done with the default actions.