Skip to content

Commit 7f7627b

Browse files
committed
Allow specifying project name in the dirconfig file
* projectile.el (projectile-dirconfig-name-prefix): Add option. (projectile-project-default-project-name): Use the project name in dirconfig when given, use the directory name otherwise. (projectile-parse-dirconfig-file): Parse and return the project name as the fourth element.
1 parent 6838628 commit 7f7627b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

projectile.el

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ Similar to '#' in .gitignore files."
371371
:type 'character
372372
:package-version '(projectile . "2.2.0"))
373373

374+
(defcustom projectile-dirconfig-name-prefix
375+
nil
376+
"Projectile config file (.projectile) name start marker.
377+
If specified, starting a line in a project's .projectile file with
378+
`projectile-dirconfig-name-prefix' followed by this character marks that
379+
line as the name of the project instead of a pattern."
380+
:group 'projectile
381+
:type 'character)
382+
374383
(defcustom projectile-globally-ignored-files
375384
(list projectile-tags-file-name)
376385
"A list of files globally ignored by projectile.
@@ -1299,7 +1308,9 @@ explicitly."
12991308
(defun projectile-default-project-name (project-root)
13001309
"Default function used to create the project name.
13011310
The project name is based on the value of PROJECT-ROOT."
1302-
(file-name-nondirectory (directory-file-name project-root)))
1311+
(or (let ((default-directory project-root))
1312+
(nth 3 (projectile-parse-dirconfig-file)))
1313+
(file-name-nondirectory (directory-file-name project-root))))
13031314

13041315
(defun projectile-project-name (&optional project)
13051316
"Return project name.
@@ -1954,7 +1965,7 @@ Strings starting with + will be added to the list of directories
19541965
to keep, and strings starting with - will be added to the list of
19551966
directories to ignore. For backward compatibility, without a
19561967
prefix the string will be assumed to be an ignore string."
1957-
(let (keep ignore ensure (dirconfig (projectile-dirconfig-file)))
1968+
(let (name keep ignore ensure (dirconfig (projectile-dirconfig-file)))
19581969
(when (projectile-file-exists-p dirconfig)
19591970
(with-temp-buffer
19601971
(insert-file-contents dirconfig)
@@ -1965,7 +1976,9 @@ prefix the string will be assumed to be an ignore string."
19651976
(and projectile-dirconfig-comment-prefix
19661977
(eql leading-char
19671978
projectile-dirconfig-comment-prefix))))
1968-
nil)
1979+
(when (eql projectile-dirconfig-name-prefix
1980+
(char-after (1+ (point))))
1981+
(setq name (buffer-substring (+ (point) 2) (line-end-position)))))
19691982
(?+ (push (buffer-substring (1+ (point)) (line-end-position)) keep))
19701983
(?- (push (buffer-substring (1+ (point)) (line-end-position)) ignore))
19711984
(?! (push (buffer-substring (1+ (point)) (line-end-position)) ensure))
@@ -1976,7 +1989,8 @@ prefix the string will be assumed to be an ignore string."
19761989
(mapcar #'string-trim
19771990
(delete "" (reverse ignore)))
19781991
(mapcar #'string-trim
1979-
(delete "" (reverse ensure)))))))
1992+
(delete "" (reverse ensure)))
1993+
name))))
19801994

19811995
(defun projectile-expand-root (name)
19821996
"Expand NAME to project root.

0 commit comments

Comments
 (0)