Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add a custom Project name? #848

Closed
ReneFroger opened this issue Aug 25, 2015 · 7 comments
Closed

Ability to add a custom Project name? #848

ReneFroger opened this issue Aug 25, 2015 · 7 comments

Comments

@ReneFroger
Copy link

I use Yasnippet in pair with Projectile. Is there any way to prefer custom project names above the current project names?

For example in this Yasnippet:

#include <iostream>

int main () {
try  {
}
catch (int e)  {
        cout << "The `(buffer-name)` from `(project-name)`) encountered an error. Exception Nr. " << e << '\n';
    }
return 0;
}

Sometimes a project does have a unclear name, e.g. ws_project_fooBAR12. So I get unclear snippets. Is it possible to have any ability in Projectile to define custom project names?

@glucas
Copy link

glucas commented Aug 26, 2015

+1, I have some projects for which I'd like to have a more meaningful name without having to change my directory structure.

@ehartc
Copy link
Contributor

ehartc commented Aug 28, 2015

You could easily create a function for that, e.g:

(defun my-own-project-name ()
;; Checks if Projectile is currently active, or this will ever run into undefinable errors.
(when (featurep 'projectile)
    ;; Checks if the file ".custom-project-name" is currently located in the project root. 
    (if (file-exists-p (concat (expand-file-name (projectile-project-root)) ".custom-project-name"))
        ;; If that's the case, write their contents into the buffer. 
        (with-temp-buffer
        (insert-file-contents (concat (expand-file-name (projectile-project-root)) ".custom-project-name"))
        (buffer-string))
    ;; If not, then extract the projectname.
    (replace-regexp-in-string "/proj/\\(.*?\\)/.*"
                                "\\1"
                                (projectile-project-name)))))

After evaluating the function above, create the file .custom-name, which contains your own projectname and located in the current project root.
If you don't have created the file (yet), it will use the current projectname instead.

@glucas
Copy link

glucas commented Aug 31, 2015

Thanks for the suggestion @ehartc, but it looks at least a bit more involved than that.

In addition to replacing (with advice, I guess) the default implementation of projectile-project-name with a function like the one suggested, it looks like there are a number of places where projectile assumes the project name is actually a directory path and uses it that way: functions that let-bind default-directory to the project name, for example.

edit Sorry, I see your suggestion was for the case of having a custom function to use e.g. in a snippet that would return a custom name or fall back to the projectile name. I understood this feature request to mean that projectile itself would support custom project names.

@bbatsov
Copy link
Owner

bbatsov commented Aug 31, 2015

The best way to implement this functionality would be simply to augment the existing project tracking. Basically there should be some function which allows you to name a project and it will be saved in the list of known projects as name + folder. All the code dealing with known projects should be updated to reflect this as well. Not a lot of work, but as usual - I'm pretty low on free time.

@dustinpaluch
Copy link

+1. I work on WordPress websites, and the convention at my company is to use wp-content as the git root directory, so regardless of the project I'm working on, my mode line always says Projectile[wp-content], which isn't very helpful.

@ReneFroger
Copy link
Author

Is anyone except Batsov willing to look into Projectile source code? My Lisp knowhow is not enough for this.

@bbatsov
Copy link
Owner

bbatsov commented Dec 25, 2015

See #928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants