diff --git a/projectile.el b/projectile.el index 8bcb39646..8e30eebdd 100644 --- a/projectile.el +++ b/projectile.el @@ -371,6 +371,15 @@ Similar to '#' in .gitignore files." :type 'character :package-version '(projectile . "2.2.0")) +(defcustom projectile-dirconfig-name-prefix + nil + "Projectile config file (.projectile) name start marker. +If specified, starting a line in a project's .projectile file with +`projectile-dirconfig-name-prefix' followed by this character marks that +line as the name of the project instead of a pattern." + :group 'projectile + :type 'character) + (defcustom projectile-globally-ignored-files (list projectile-tags-file-name) "A list of files globally ignored by projectile. @@ -1299,7 +1308,19 @@ explicitly." (defun projectile-default-project-name (project-root) "Default function used to create the project name. The project name is based on the value of PROJECT-ROOT." - (file-name-nondirectory (directory-file-name project-root))) + (or (when-let* + ((comment-prefix projectile-dirconfig-comment-prefix) + (name-prefix projectile-dirconfig-name-prefix) + (default-directory project-root) + (dirconfig (projectile-dirconfig-file))) + (when (projectile-file-exists-p dirconfig) + (with-temp-buffer + (insert-file-contents dirconfig) + (when (re-search-forward + (format "^%c%c\\(.*\\)$" comment-prefix name-prefix) + nil t) + (match-string 1))))) + (file-name-nondirectory (directory-file-name project-root)))) (defun projectile-project-name (&optional project) "Return project name. @@ -1954,7 +1975,7 @@ Strings starting with + will be added to the list of directories to keep, and strings starting with - will be added to the list of directories to ignore. For backward compatibility, without a prefix the string will be assumed to be an ignore string." - (let (keep ignore ensure (dirconfig (projectile-dirconfig-file))) + (let (name keep ignore ensure (dirconfig (projectile-dirconfig-file))) (when (projectile-file-exists-p dirconfig) (with-temp-buffer (insert-file-contents dirconfig) @@ -1965,7 +1986,9 @@ prefix the string will be assumed to be an ignore string." (and projectile-dirconfig-comment-prefix (eql leading-char projectile-dirconfig-comment-prefix)))) - nil) + (when (eql projectile-dirconfig-name-prefix + (char-after (1+ (point)))) + (setq name (buffer-substring (+ (point) 2) (line-end-position))))) (?+ (push (buffer-substring (1+ (point)) (line-end-position)) keep)) (?- (push (buffer-substring (1+ (point)) (line-end-position)) ignore)) (?! (push (buffer-substring (1+ (point)) (line-end-position)) ensure)) @@ -1976,7 +1999,8 @@ prefix the string will be assumed to be an ignore string." (mapcar #'string-trim (delete "" (reverse ignore))) (mapcar #'string-trim - (delete "" (reverse ensure))))))) + (delete "" (reverse ensure))) + name)))) (defun projectile-expand-root (name) "Expand NAME to project root. diff --git a/test/projectile-test.el b/test/projectile-test.el index 875b01ec5..5ea3478bd 100644 --- a/test/projectile-test.el +++ b/test/projectile-test.el @@ -422,7 +422,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'. "no-prefix" "left-wspace" "right-wspace") - nil)) + nil nil)) ;; same test - but with comment lines enabled using prefix '#' (let ((projectile-dirconfig-comment-prefix ?#)) (expect (projectile-parse-dirconfig-file) :to-equal '(("include/") @@ -430,7 +430,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'. "no-prefix" "left-wspace" "right-wspace") - nil))) + nil nil))) )) (describe "projectile-get-project-directories"