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

Enable custom project names #928

Merged
merged 1 commit into from
Dec 23, 2015
Merged

Enable custom project names #928

merged 1 commit into from
Dec 23, 2015

Conversation

fvaresi
Copy link
Contributor

@fvaresi fvaresi commented Dec 11, 2015

This enables the user to customize the project name based on project-root. This is helpful in situations where the project base dir is not descriptive enough.

As an example, I use it like this:

     (defun fvaresi/projectile-custom-project-name (project-root)
        (cond
         ((string-match "/Plugins/\\([^/]+\\)/\\(?:branches\\|tags\\)\\(?:.*\\)/\\([^/]+\\)" project-root)
          (let* ((product-name (match-string 1 project-root))
                 (branch-name (match-string 2 project-root)))
            (concat product-name "/" branch-name))) ;

         ((string-match "/Plugins/\\([^/]+\\)/trunk" project-root)
                (let* ((product-name (match-string 1 project-root)))
                  (concat product-name "/trunk")))

         ;; do the default
         (t
          (projectile-default-project-name project-root))))

      (setq projectile-project-name-function 'fvaresi/projectile-custom-project-name)

(defcustom projectile-project-name-function 'projectile-default-project-name
"A function that receives the project-root and returns the project name to be displayed."
:group 'projectile
:type 'symbol)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a package-version properly.

@bbatsov
Copy link
Owner

bbatsov commented Dec 16, 2015

This should be extended a bit further. If there's a buffer-local variable - projectile-project-name it should take precedence over calling this function IMO. The ultimate flexibility.

@fvaresi
Copy link
Contributor Author

fvaresi commented Dec 17, 2015

Thanks for the feedback. I'll implement these changes as soon as I get a moment.

@bbatsov
Copy link
Owner

bbatsov commented Dec 17, 2015

You'll also have to rebase on top of the current master.

@fvaresi
Copy link
Contributor Author

fvaresi commented Dec 17, 2015

I started implementing the precedence of a buffer-local-variable but saw some issues while testing this. I'm guessing this local variable would be for referencing projects in an external directory. Is this the use case you were thinking about?

I think using this would also require to use the variable proposed for customizing project-root (#929), otherwise it won't be able to find the project root.

Thanks again for your efforts and sorry about being so slow (these are my first baby steps in contributing to OS).

@bbatsov
Copy link
Owner

bbatsov commented Dec 20, 2015

I think using this would also require to use the variable proposed for customizing project-root (#929), otherwise it won't be able to find the project root.

It's totally unrelated. The idea is to be able to set the project name via .dir-locals.el, without having to deal with custom name functions. Extremely useful if you don't really want to derive the project name from some directory, but would rather set it explicitly.

@fvaresi
Copy link
Contributor Author

fvaresi commented Dec 21, 2015

I now see what you meant and implemented the suggested changes. I think tests are currently giving an error cause helm-projectile was moved to its own repo.

Also, since persp-projectile was also moved I'll send a new pull request for changes related to this one, once this pull request is approved.

@bbatsov
Copy link
Owner

bbatsov commented Dec 21, 2015

The changes look good. Just squash the 3 commits together and we're good to go.

@fvaresi
Copy link
Contributor Author

fvaresi commented Dec 21, 2015

It's done, thanks.

@bbatsov
Copy link
Owner

bbatsov commented Dec 21, 2015

And drop that . from the commit message - titles shouldn't end with ..

@fvaresi
Copy link
Contributor Author

fvaresi commented Dec 21, 2015

Ok, modified commit message.

bbatsov added a commit that referenced this pull request Dec 23, 2015
@bbatsov bbatsov merged commit 537691e into bbatsov:master Dec 23, 2015
@bbatsov
Copy link
Owner

bbatsov commented Dec 23, 2015

👍 Thanks!

@ReneFroger
Copy link

@fvaresi could you tell more how you could specifice a custom project name inside a project? I couldn't figure it out from your code and the changes.

@fvaresi
Copy link
Contributor Author

fvaresi commented Dec 26, 2015

@ReneFroger if the custom project name is a function depending on the project root, you can set projectile-project-name-function as shown in the first comment of this pull request.

If you want to customize the project name just for one project, it's easier to set the local variable projectile-project-name using directory variables. This is probably the simplest way, since you just need to add a .dir-locals.el file in the project root.

For example:

((nil . ((projectile-project-name . "my-super-project"))))

@ReneFroger
Copy link

Thanks for your answer, but I got the asking message everytime:

"The local variables in [project folder] contains values that may not be safe (*)

Do you want to apply it? 

y
n
!

* projectile-project-name . "my-super-project"

Is there any way to turn that confirmation message off? Typing ! didn't help
after I visit the project again.

@fvaresi
Copy link
Contributor Author

fvaresi commented Dec 27, 2015

In my setup using ! will just add one safe value. If you want to say that all strings are safe values to be used you can add this to your emacs config:

(put 'projectile-project-name 'safe-local-variable #'stringp)

@ReneFroger
Copy link

@fvaresi thanks for your helpful response. It works like a charm, and integrates well with my yasnippets (#848), thanks for your contribution, it's appreciated!

fvaresi added a commit to fvaresi/config that referenced this pull request Dec 29, 2015
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

Successfully merging this pull request may close these issues.

None yet

3 participants