-
-
Notifications
You must be signed in to change notification settings - Fork 583
/
projectile.el
6332 lines (5543 loc) · 269 KB
/
projectile.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; projectile.el --- Manage and navigate projects in Emacs easily -*- lexical-binding: t -*-
;; Copyright © 2011-2024 Bozhidar Batsov <[email protected]>
;; Author: Bozhidar Batsov <[email protected]>
;; URL: https://github.com/bbatsov/projectile
;; Keywords: project, convenience
;; Version: 2.9.0-snapshot
;; Package-Requires: ((emacs "25.1"))
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; This library provides easy project management and navigation. The
;; concept of a project is pretty basic - just a folder containing
;; special file. Currently git, mercurial and bazaar repos are
;; considered projects by default. If you want to mark a folder
;; manually as a project just create an empty .projectile file in
;; it. See the README for more details.
;;
;;; Code:
(require 'cl-lib)
(require 'thingatpt)
(require 'ibuffer)
(require 'ibuf-ext)
(require 'compile)
(require 'grep)
(require 'lisp-mnt)
(eval-when-compile
(require 'find-dired)
(require 'subr-x))
;;; Declarations
;;
;; A bunch of variable and function declarations
;; needed to appease the byte-compiler.
(defvar ido-mode)
(defvar ivy-mode)
(defvar helm-mode)
(defvar ag-ignore-list)
(defvar ggtags-completion-table)
(defvar tags-completion-table)
(defvar tags-loop-scan)
(defvar tags-loop-operate)
(defvar eshell-buffer-name)
(defvar explicit-shell-file-name)
(defvar grep-files-aliases)
(defvar grep-find-ignored-directories)
(defvar grep-find-ignored-files)
(declare-function tags-completion-table "etags")
(declare-function make-term "term")
(declare-function term-mode "term")
(declare-function term-char-mode "term")
(declare-function term-ansi-make-term "term")
(declare-function eshell-search-path "esh-ext")
(declare-function vc-dir "vc-dir")
(declare-function vc-dir-busy "vc-dir")
(declare-function string-trim "subr-x")
(declare-function fileloop-continue "fileloop")
(declare-function fileloop-initialize-replace "fileloop")
(declare-function tramp-archive-file-name-p "tramp-archive")
(declare-function helm-grep-get-file-extensions "helm-grep")
(declare-function ggtags-ensure-project "ext:ggtags")
(declare-function ggtags-update-tags "ext:ggtags")
(declare-function ripgrep-regexp "ext:ripgrep")
(declare-function rg-run "ext:rg")
(declare-function vterm "ext:vterm")
(declare-function vterm-other-window "ext:vterm")
(declare-function vterm-send-return "ext:vterm")
(declare-function vterm-send-string "ext:vterm")
;;; Customization
(defgroup projectile nil
"Manage and navigate projects easily."
:group 'tools
:group 'convenience
:link '(url-link :tag "GitHub" "https://github.com/bbatsov/projectile")
:link '(url-link :tag "Online Manual" "https://docs.projectile.mx/")
:link '(emacs-commentary-link :tag "Commentary" "projectile"))
(defcustom projectile-indexing-method
(if (eq system-type 'windows-nt) 'native 'alien)
"Specifies the indexing method used by Projectile.
There are three indexing methods - native, hybrid and alien.
The native method is implemented in Emacs Lisp (therefore it is
native to Emacs). Its advantage is that it is portable and will
work everywhere that Emacs does. Its disadvantage is that it is a
bit slow (especially for large projects). Generally it's a good
idea to pair the native indexing method with caching.
The hybrid indexing method uses external tools (e.g. git, find,
etc) to speed up the indexing process. Still, the files will be
post-processed by Projectile for sorting/filtering purposes.
In this sense that approach is a hybrid between native indexing
and alien indexing.
The alien indexing method optimizes to the limit the speed
of the hybrid indexing method. This means that Projectile will
not do any processing of the files returned by the external
commands and you're going to get the maximum performance
possible. This behaviour makes a lot of sense for most people,
as they'd typically be putting ignores in their VCS config and
won't care about any additional ignores/unignores/sorting that
Projectile might also provide.
The disadvantage of the hybrid and alien methods is that they are not well
supported on Windows systems. That's why by default alien indexing is the
default on all operating systems, except Windows."
:group 'projectile
:type '(radio
(const :tag "Native" native)
(const :tag "Hybrid" hybrid)
(const :tag "Alien" alien)))
(defcustom projectile-enable-caching (eq projectile-indexing-method 'native)
"When t enables project files caching.
Project caching is automatically enabled by default if you're
using the native indexing method."
:group 'projectile
:type 'boolean)
(defcustom projectile-kill-buffers-filter 'kill-all
"Determine which buffers are killed by `projectile-kill-buffers'.
When the kill-all option is selected, kills each buffer.
When the kill-only-files option is selected, kill only the buffer
associated to a file.
Otherwise, it should be a predicate that takes one argument: the buffer to
be killed."
:group 'projectile
:type '(radio
(const :tag "All project buffers" kill-all)
(const :tag "Project file buffers" kill-only-files)
(function :tag "Predicate")))
(defcustom projectile-file-exists-local-cache-expire nil
"Number of seconds before the local file existence cache expires.
Local refers to a file on a local file system.
A value of nil disables this cache.
See `projectile-file-exists-p' for details."
:group 'projectile
:type '(choice (const :tag "Disabled" nil)
(integer :tag "Seconds")))
(defcustom projectile-file-exists-remote-cache-expire (* 5 60)
"Number of seconds before the remote file existence cache expires.
Remote refers to a file on a remote file system such as tramp.
A value of nil disables this cache.
See `projectile-file-exists-p' for details."
:group 'projectile
:type '(choice (const :tag "Disabled" nil)
(integer :tag "Seconds")))
(defcustom projectile-files-cache-expire nil
"Number of seconds before project files list cache expires.
A value of nil means the cache never expires."
:group 'projectile
:type '(choice (const :tag "Disabled" nil)
(integer :tag "Seconds")))
(defcustom projectile-auto-discover t
"Whether to discover projects when `projectile-mode' is activated."
:group 'projectile
:type 'boolean
:package-version '(projectile . "2.3.0"))
(defcustom projectile-auto-update-cache t
"Whether cache is automatically updated when files are opened or deleted."
:group 'projectile
:type 'boolean)
(defcustom projectile-require-project-root 'prompt
"Require the presence of a project root to operate when true.
When set to `prompt' Projectile will ask you to select a project
directory if you're not in a project.
When nil Projectile will consider the current directory the project root."
:group 'projectile
:type '(choice (const :tag "No" nil)
(const :tag "Yes" t)
(const :tag "Prompt for project" prompt)))
(defcustom projectile-completion-system 'auto
"The completion system to be used by Projectile."
:group 'projectile
:type '(radio
(const :tag "Auto-detect" auto)
(const :tag "Ido" ido)
(const :tag "Helm" helm)
(const :tag "Ivy" ivy)
(const :tag "Default" default)
(function :tag "Custom function")))
(defcustom projectile-keymap-prefix nil
"Projectile keymap prefix."
:group 'projectile
:type 'string)
(defcustom projectile-cache-file
(expand-file-name "projectile.cache" user-emacs-directory)
"The name of Projectile's cache file."
:group 'projectile
:type 'string)
(defcustom projectile-tags-file-name "TAGS"
"The tags filename Projectile's going to use."
:group 'projectile
:type 'string)
(defcustom projectile-tags-command "ctags -Re -f \"%s\" %s \"%s\""
"The command Projectile's going to use to generate a TAGS file."
:group 'projectile
:type 'string)
(defcustom projectile-tags-backend 'auto
"The tag backend that Projectile should use.
If set to `auto', `projectile-find-tag' will automatically choose
which backend to use. Preference order is ggtags -> xref
-> etags-select -> `find-tag'. Variable can also be set to specify which
backend to use. If selected backend is unavailable, fall back to
`find-tag'.
If this variable is set to `auto' and ggtags is available, or if
set to `ggtags', then ggtags will be used for
`projectile-regenerate-tags'. For all other settings
`projectile-tags-command' will be used."
:group 'projectile
:type '(radio
(const :tag "auto" auto)
(const :tag "xref" xref)
(const :tag "ggtags" ggtags)
(const :tag "etags" etags-select)
(const :tag "standard" find-tag))
:package-version '(projectile . "0.14.0"))
(defcustom projectile-sort-order 'default
"The sort order used for a project's files.
Note that files aren't sorted if `projectile-indexing-method'
is set to `alien'."
:group 'projectile
:type '(radio
(const :tag "Default (no sorting)" default)
(const :tag "Recently opened files" recentf)
(const :tag "Recently active buffers, then recently opened files" recently-active)
(const :tag "Access time (atime)" access-time)
(const :tag "Modification time (mtime)" modification-time)))
(defcustom projectile-verbose t
"Echo messages that are not errors."
:group 'projectile
:type 'boolean)
(defcustom projectile-buffers-filter-function nil
"A function used to filter the buffers in `projectile-project-buffers'.
The function should accept and return a list of Emacs buffers.
Two example filter functions are shipped by default -
`projectile-buffers-with-file' and
`projectile-buffers-with-file-or-process'."
:group 'projectile
:type 'function)
(defcustom projectile-project-name nil
"If this value is non-nil, it will be used as project name.
It has precedence over function `projectile-project-name-function'."
:group 'projectile
:type 'string
:package-version '(projectile . "0.14.0"))
(defcustom projectile-project-name-function 'projectile-default-project-name
"A function that receives the project-root and returns the project name.
If variable `projectile-project-name' is non-nil, this function will not be
used."
:group 'projectile
:type 'function
:package-version '(projectile . "0.14.0"))
(defcustom projectile-project-root-files
'(
"GTAGS" ; GNU Global tags
"TAGS" ; etags/ctags are usually in the root of project
"configure.ac" ; autoconf new style
"configure.in" ; autoconf old style
"cscope.out" ; cscope
)
"A list of files considered to mark the root of a project.
The topmost match has precedence.
See `projectile-register-project-type'."
:group 'projectile
:type '(repeat string))
(defcustom projectile-project-root-files-bottom-up
'(".git" ; Git VCS root dir
".hg" ; Mercurial VCS root dir
".fslckout" ; Fossil VCS root dir
"_FOSSIL_" ; Fossil VCS root DB on Windows
".bzr" ; Bazaar VCS root dir
"_darcs" ; Darcs VCS root dir
".pijul" ; Pijul VCS root dir
".sl" ; Sapling VCS root dir
".jj" ; Jujutsu VCS root dir
)
"A list of files considered to mark the root of a project.
The bottommost (parentmost) match has precedence."
:group 'projectile
:type '(repeat string))
(defcustom projectile-project-root-files-top-down-recurring
'(".svn" ; Svn VCS root dir
"CVS" ; Csv VCS root dir
"Makefile")
"A list of files considered to mark the root of a project.
The search starts at the top and descends down till a directory
that contains a match file but its parent does not. Thus, it's a
bottommost match in the topmost sequence of directories
containing a root file."
:group 'projectile
:type '(repeat string))
(define-obsolete-variable-alias 'projectile-project-root-files-functions 'projectile-project-root-functions "2.4")
(defcustom projectile-project-root-functions
'(projectile-root-local
projectile-root-marked
projectile-root-bottom-up
projectile-root-top-down
projectile-root-top-down-recurring)
"A list of functions for finding project root folders.
The functions will be run until one of them returns a project folder.
Reordering the default functions will alter the project discovery
algorithm."
:group 'projectile
:type '(repeat function))
(defcustom projectile-dirconfig-file
".projectile"
"The file which serves both as a project marker and configuration file.
This should _not_ be set via .dir-locals.el."
:group 'projectile
:type 'file
:package-version '(projectile . "2.7.0"))
(defcustom projectile-dirconfig-comment-prefix
nil
"`projectile-dirconfig-file` comment start marker.
If specified, starting a line in a project's .projectile file with this
character marks that line as a comment instead of a pattern.
Similar to '#' in .gitignore files."
:group 'projectile
:type 'character
:package-version '(projectile . "2.2.0"))
(defcustom projectile-globally-ignored-files
(list projectile-tags-file-name)
"A list of files globally ignored by projectile.
Note that files aren't filtered if `projectile-indexing-method'
is set to `alien'."
:group 'projectile
:type '(repeat string))
(defcustom projectile-globally-unignored-files nil
"A list of files globally unignored by projectile.
Regular expressions can be used.
Note that files aren't filtered if `projectile-indexing-method'
is set to `alien'."
:group 'projectile
:type '(repeat string)
:package-version '(projectile . "0.14.0"))
(defcustom projectile-globally-ignored-file-suffixes
nil
"A list of file suffixes globally ignored by projectile.
Note that files aren't filtered if `projectile-indexing-method'
is set to `alien'."
:group 'projectile
:type '(repeat string))
(defcustom projectile-globally-ignored-directories
'("^\\.idea$"
"^\\.vscode$"
"^\\.ensime_cache$"
"^\\.eunit$"
"^\\.git$"
"^\\.hg$"
"^\\.fslckout$"
"^_FOSSIL_$"
"^\\.bzr$"
"^_darcs$"
"^\\.pijul$"
"^\\.tox$"
"^\\.svn$"
"^\\.stack-work$"
"^\\.ccls-cache$"
"^\\.cache$"
"^\\.clangd$"
"^\\.sl$"
"^\\.jj$")
"A list of directories globally ignored by projectile.
Regular expressions can be used.
Strings that don't start with * are only ignored at the top level
of the project. Strings that start with * are ignored everywhere
in the project, as if there was no *. So note that * when used as
a prefix is not a wildcard; it is an indicator that the directory
should be ignored at all levels, not just root.
Examples: \"tmp\" ignores only ./tmp at the top level of the
project, but not ./src/tmp. \"*tmp\" will ignore both ./tmp and
./src/tmp, but not ./not-a-tmp or ./src/not-a-tmp.
Note that files aren't filtered if `projectile-indexing-method'
is set to `alien'."
:safe (lambda (x) (not (remq t (mapcar #'stringp x))))
:group 'projectile
:type '(repeat string))
(defcustom projectile-globally-unignored-directories nil
"A list of directories globally unignored by projectile.
Note that files aren't filtered if `projectile-indexing-method'
is set to `alien'."
:group 'projectile
:type '(repeat string)
:package-version '(projectile . "0.14.0"))
(defcustom projectile-globally-ignored-modes
'("erc-mode"
"help-mode"
"completion-list-mode"
"Buffer-menu-mode"
"gnus-.*-mode"
"occur-mode")
"A list of regular expressions for major modes ignored by projectile.
If a buffer is using a given major mode, projectile will ignore
it for functions working with buffers."
:group 'projectile
:type '(repeat string))
(defcustom projectile-globally-ignored-buffers
'("*scratch*"
"*lsp-log*")
"A list of buffer-names ignored by projectile.
You can use either exact buffer names or regular expressions.
If a buffer is in the list projectile will ignore it for
functions working with buffers."
:group 'projectile
:type '(repeat string)
:package-version '(projectile . "0.12.0"))
(defcustom projectile-find-file-hook nil
"Hooks run when a file is opened with `projectile-find-file'."
:group 'projectile
:type 'hook)
(defcustom projectile-find-dir-hook nil
"Hooks run when a directory is opened with `projectile-find-dir'."
:group 'projectile
:type 'hook)
(defcustom projectile-switch-project-action 'projectile-find-file
"Action invoked after switching projects with `projectile-switch-project'.
Any function that does not take arguments will do."
:group 'projectile
:type 'function)
(defcustom projectile-find-dir-includes-top-level nil
"If true, add top-level dir to options offered by `projectile-find-dir'."
:group 'projectile
:type 'boolean)
(defcustom projectile-use-git-grep nil
"If true, use `vc-git-grep' in git projects."
:group 'projectile
:type 'boolean)
(defcustom projectile-grep-finished-hook nil
"Hooks run when `projectile-grep' finishes."
:group 'projectile
:type 'hook
:package-version '(projectile . "0.14.0"))
(defcustom projectile-test-prefix-function 'projectile-test-prefix
"Function to find test files prefix based on PROJECT-TYPE."
:group 'projectile
:type 'function)
(defcustom projectile-test-suffix-function 'projectile-test-suffix
"Function to find test files suffix based on PROJECT-TYPE."
:group 'projectile
:type 'function)
(defcustom projectile-related-files-fn-function 'projectile-related-files-fn
"Function to find related files based on PROJECT-TYPE."
:group 'projectile
:type 'function)
(defcustom projectile-dynamic-mode-line t
"If true, update the mode-line dynamically.
Only file buffers are affected by this, as the update happens via
`find-file-hook'.
See also `projectile-mode-line-function' and `projectile-update-mode-line'."
:group 'projectile
:type 'boolean
:package-version '(projectile . "2.0.0"))
(defcustom projectile-mode-line-function 'projectile-default-mode-line
"The function to use to generate project-specific mode-line.
The default function adds the project name and type to the mode-line.
See also `projectile-update-mode-line'."
:group 'projectile
:type 'function
:package-version '(projectile . "2.0.0"))
(defcustom projectile-default-src-directory "src/"
"The default value of a project's src-dir property.
It's used as a fallback in the case the property is not set for a project
type when `projectile-toggle-between-implementation-and-test' is used."
:group 'projectile
:type 'string)
(defcustom projectile-default-test-directory "test/"
"The default value of a project's test-dir property.
It's used as a fallback in the case the property is not set for a project
type when `projectile-toggle-between-implementation-and-test' is used."
:group 'projectile
:type 'string)
;;; Idle Timer
(defvar projectile-idle-timer nil
"The timer object created when `projectile-enable-idle-timer' is non-nil.")
(defcustom projectile-idle-timer-seconds 30
"The idle period to use when `projectile-enable-idle-timer' is non-nil."
:group 'projectile
:type 'number)
(defcustom projectile-idle-timer-hook '(projectile-regenerate-tags)
"The hook run when `projectile-enable-idle-timer' is non-nil."
:group 'projectile
:type '(repeat symbol))
(defcustom projectile-enable-idle-timer nil
"Enables idle timer hook `projectile-idle-timer-functions'.
When `projectile-enable-idle-timer' is non-nil, the hook
`projectile-idle-timer-hook' is run each time Emacs has been idle
for `projectile-idle-timer-seconds' seconds and we're in a
project."
:group 'projectile
:set (lambda (symbol value)
(set symbol value)
(when projectile-idle-timer
(cancel-timer projectile-idle-timer))
(setq projectile-idle-timer nil)
(when projectile-enable-idle-timer
(setq projectile-idle-timer (run-with-idle-timer
projectile-idle-timer-seconds t
(lambda ()
(when (projectile-project-p)
(run-hooks 'projectile-idle-timer-hook)))))))
:type 'boolean)
(defvar projectile-projects-cache nil
"A hashmap used to cache project file names to speed up related operations.")
(defvar projectile-projects-cache-time nil
"A hashmap used to record when we populated `projectile-projects-cache'.")
(defvar projectile-project-root-cache (make-hash-table :test 'equal)
"Cached value of function `projectile-project-root`.")
(defvar projectile-project-type-cache (make-hash-table :test 'equal)
"A hashmap used to cache project type to speed up related operations.")
(defvar projectile-known-projects nil
"List of locations where we have previously seen projects.
The list of projects is ordered by the time they have been accessed.
See also `projectile-remove-known-project',
`projectile-cleanup-known-projects' and `projectile-clear-known-projects'.")
(defvar projectile-known-projects-on-file nil
"List of known projects reference point.
Contains a copy of `projectile-known-projects' when it was last
synchronized with `projectile-known-projects-file'.")
(defcustom projectile-known-projects-file
(expand-file-name "projectile-bookmarks.eld"
user-emacs-directory)
"Name and location of the Projectile's known projects file."
:group 'projectile
:type 'string)
(defcustom projectile-ignored-projects nil
"A list of projects not to be added to `projectile-known-projects'."
:group 'projectile
:type '(repeat :tag "Project list" directory)
:package-version '(projectile . "0.11.0"))
(defcustom projectile-ignored-project-function nil
"Function to decide if a project is added to `projectile-known-projects'.
Can be either nil, or a function that takes the truename of the
project root as argument and returns non-nil if the project is to
be ignored or nil otherwise.
This function is only called if the project is not listed in
the variable `projectile-ignored-projects'.
A suitable candidate would be `file-remote-p' to ignore remote
projects."
:group 'projectile
:type '(choice
(const :tag "Nothing" nil)
(const :tag "Remote files" file-remote-p)
function)
:package-version '(projectile . "0.13.0"))
(defcustom projectile-track-known-projects-automatically t
"Controls whether Projectile will automatically register known projects.
When set to nil you'll have always add projects explicitly with
`projectile-add-known-project'."
:group 'projectile
:type 'boolean
:package-version '(projectile . "1.0.0"))
(defcustom projectile-project-search-path nil
"List of folders where projectile is automatically going to look for projects.
You can think of something like $PATH, but for projects instead of executables.
Examples of such paths might be ~/projects, ~/work, (~/github . 1) etc.
For elements of form (DIRECTORY . DEPTH), DIRECTORY has to be a
directory and DEPTH an integer that specifies the depth at which to
look for projects. A DEPTH of 0 means check DIRECTORY. A depth of 1
means check all the subdirectories of DIRECTORY. Etc."
:group 'projectile
:type '(repeat (choice directory (cons directory (integer :tag "Depth"))))
:package-version '(projectile . "1.0.0"))
(defcustom projectile-fd-executable
(cond
((executable-find "fdfind") "fdfind")
((executable-find "fd") "fd"))
"Path or name of fd executable used by Projectile if enabled.
Nil means fd is not installed or should not be used."
:type 'string
:package-version '(projectile . "2.8.0"))
(defcustom projectile-git-use-fd (when projectile-fd-executable t)
"Non-nil means use fd to implement git ls-files.
This may change Projectile's performance in large Git repositories
depending on your system, but it will also work around the Git behavior
that causes deleted files to still be shown in Projectile listings until
their deletions are staged."
:type 'boolean
:package-version '(projectile . "2.8.0"))
(defcustom projectile-git-command "git ls-files -zco --exclude-standard"
"Command used by projectile to get the files in a git project."
:group 'projectile
:type 'string)
(defcustom projectile-git-fd-args "-H -0 -E .git -tf --strip-cwd-prefix -c never"
"Arguments to fd used to re-implement `git ls-files'.
This is used with `projectile-fd-executable' when `projectile-git-use-fd'
is non-nil."
:group 'projectile
:type 'string
:package-version '(projectile . "2.8.0"))
(defcustom projectile-git-submodule-command "git submodule --quiet foreach 'echo $displaypath' | tr '\\n' '\\0'"
"Command used by projectile to list submodules of a given git repository.
Set to nil to disable listing submodules contents."
:group 'projectile
:type 'string)
(defcustom projectile-git-ignored-command "git ls-files -zcoi --exclude-standard"
"Command used by projectile to get the ignored files in a git project."
:group 'projectile
:type 'string
:package-version '(projectile . "0.14.0"))
(defcustom projectile-hg-command "hg locate -f -0 -I ."
"Command used by projectile to get the files in a hg project."
:group 'projectile
:type 'string)
(defcustom projectile-jj-command "jj files --no-pager . | tr '\\n' '\\0'"
"Command used by projectile to get the files in a Jujutsu project."
:group 'projectile
:type 'string
:package-version '(projectile . "2.9.0"))
(defcustom projectile-sapling-command "sl locate -0 -I ."
"Command used by projectile to get the files in a Sapling project."
:group 'projectile
:type 'string
:package-version '(projectile . "2.9.0"))
(defcustom projectile-fossil-command (concat "fossil ls | "
(when (string-equal system-type
"windows-nt")
"dos2unix | ")
"tr '\\n' '\\0'")
"Command used by projectile to get the files in a fossil project."
:group 'projectile
:type 'string)
(defcustom projectile-bzr-command "bzr ls -R --versioned -0"
"Command used by projectile to get the files in a bazaar project."
:group 'projectile
:type 'string)
(defcustom projectile-darcs-command "darcs show files -0 . "
"Command used by projectile to get the files in a darcs project."
:group 'projectile
:type 'string)
(defcustom projectile-pijul-command "pijul list | tr '\\n' '\\0'"
"Command used by projectile to get the files in a pijul project."
:group 'projectile
:type 'string)
(defcustom projectile-svn-command "svn list -R . | grep -v '$/' | tr '\\n' '\\0'"
"Command used by projectile to get the files in a svn project."
:group 'projectile
:type 'string)
(defcustom projectile-generic-command
(cond
;; we prefer fd over find
;; note that --strip-cwd-prefix is only available in version 8.3.0+
(projectile-fd-executable
(format "%s . -0 --type f --color=never --strip-cwd-prefix" projectile-fd-executable))
;; with find we have to be careful to strip the ./ from the paths
;; see https://stackoverflow.com/questions/2596462/how-to-strip-leading-in-unix-find
(t "find . -type f | cut -c3- | tr '\\n' '\\0'"))
"Command used by projectile to get the files in a generic project."
:group 'projectile
:type 'string)
(defcustom projectile-vcs-dirty-state '("edited" "unregistered" "needs-update" "needs-merge" "unlocked-changes" "conflict")
"List of states checked by `projectile-browse-dirty-projects'.
Possible checked states are:
\"edited\", \"unregistered\", \"needs-update\", \"needs-merge\",
\"unlocked-changes\" and \"conflict\",
as defined in `vc.el'."
:group 'projectile
:type '(repeat (string))
:package-version '(projectile . "1.0.0"))
(defcustom projectile-other-file-alist
'( ;; handle C/C++ extensions
("cpp" . ("h" "hpp" "ipp"))
("ipp" . ("h" "hpp" "cpp"))
("hpp" . ("h" "ipp" "cpp" "cc"))
("cxx" . ("h" "hxx" "ixx"))
("ixx" . ("h" "hxx" "cxx"))
("hxx" . ("h" "ixx" "cxx"))
("c" . ("h"))
("m" . ("h"))
("mm" . ("h"))
("h" . ("c" "cc" "cpp" "ipp" "hpp" "cxx" "ixx" "hxx" "m" "mm"))
("cc" . ("h" "hh" "hpp"))
("hh" . ("cc"))
;; OCaml extensions
("ml" . ("mli"))
("mli" . ("ml" "mll" "mly"))
("mll" . ("mli"))
("mly" . ("mli"))
("eliomi" . ("eliom"))
("eliom" . ("eliomi"))
;; vertex shader and fragment shader extensions in glsl
("vert" . ("frag"))
("frag" . ("vert"))
;; handle files with no extension
(nil . ("lock" "gpg"))
("lock" . (""))
("gpg" . (""))
)
"Alist of extensions for switching to file with the same name,
using other extensions based on the extension of current
file."
:type 'alist)
(defcustom projectile-create-missing-test-files nil
"During toggling, if non-nil enables creating test files if not found.
When not-nil, every call to projectile-find-implementation-or-test-*
creates test files if not found on the file system. Defaults to nil.
It assumes the test/ folder is at the same level as src/."
:group 'projectile
:type 'boolean)
(defcustom projectile-per-project-compilation-buffer nil
"When non-nil, the compilation command makes the per-project compilation buffer."
:group 'projectile
:type 'boolean
:package-version '(projectile . "2.6.0"))
(defcustom projectile-after-switch-project-hook nil
"Hooks run right after project is switched."
:group 'projectile
:type 'hook)
(defcustom projectile-before-switch-project-hook nil
"Hooks run when right before project is switched."
:group 'projectile
:type 'hook)
(defcustom projectile-current-project-on-switch 'remove
"Determines whether to display current project when switching projects.
When set to `remove' current project is not included, `move-to-end'
will display current project and the end of the list of known
projects, `keep' will leave the current project at the default
position."
:group 'projectile
:type '(radio
(const :tag "Remove" remove)
(const :tag "Move to end" move-to-end)
(const :tag "Keep" keep)))
(defcustom projectile-max-file-buffer-count nil
"Maximum number of file buffers per project that are kept open.
If the value is nil, there is no limit to the opend buffers count."
:group 'projectile
:type 'integer
:package-version '(projectile . "2.2.0"))
(defcustom projectile-cmd-hist-ignoredups t
"Controls when inputs are added to projectile's command history.
A value of t means consecutive duplicates are ignored.
A value of `erase' means only the last duplicate is kept.
A value of nil means nothing is ignored."
:type '(choice (const :tag "Don't ignore anything" nil)
(const :tag "Ignore consecutive duplicates" t)
(const :tag "Only keep last duplicate" erase))
:package-version '(projectile . "2.9.0"))
(defvar projectile-project-test-suffix nil
"Use this variable to override the current project's test-suffix property.
It takes precedence over the test-suffix for the project type when set.
Should be set via .dir-locals.el.")
(defvar projectile-project-test-prefix nil
"Use this variable to override the current project's test-prefix property.
It takes precedence over the test-prefix for the project type when set.
Should be set via .dir-locals.el.")
(defvar projectile-project-related-files-fn nil
"Use this variable to override the current project's related-files-fn property.
It takes precedence over the related-files-fn attribute for the project type
when set. Should be set via .dir-locals.el.")
(defvar projectile-project-src-dir nil
"Use this variable to override the current project's src-dir property.
It takes precedence over the src-dir for the project type when set.
Should be set via .dir-locals.el.")
(defvar projectile-project-test-dir nil
"Use this variable to override the current project's test-dir property.
It takes precedence over the test-dir for the project type when set.
Should be set via .dir-locals.el.")
;;; Version information
(defconst projectile-version "2.9.0-snapshot"
"The current version of Projectile.")
(defun projectile--pkg-version ()
"Extract Projectile's package version from its package metadata."
;; Use `cond' below to avoid a compiler unused return value warning
;; when `package-get-version' returns nil. See #3181.
;; FIXME: Inline the logic from package-get-version and adapt it
(cond ((fboundp 'package-get-version)
(package-get-version))))
;;;###autoload
(defun projectile-version (&optional show-version)
"Get the Projectile version as string.
If called interactively or if SHOW-VERSION is non-nil, show the
version in the echo area and the messages buffer.
The returned string includes both, the version from package.el
and the library version, if both a present and different.
If the version number could not be determined, signal an error,
if called interactively, or if SHOW-VERSION is non-nil, otherwise
just return nil."
(interactive (list t))
(let ((version (or (projectile--pkg-version) projectile-version)))
(if show-version
(message "Projectile %s" version)
version)))
;;; Misc utility functions
(defun projectile-difference (list1 list2)
(cl-remove-if
(lambda (x) (member x list2))
list1))
(defun projectile-unixy-system-p ()
"Check to see if unixy text utilities are installed."
(cl-every
(lambda (x) (executable-find x))
'("grep" "cut" "uniq")))
(defun projectile-symbol-or-selection-at-point ()
"Get the symbol or selected text at point."
(if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(projectile-symbol-at-point)))
(defun projectile-symbol-at-point ()
"Get the symbol at point and strip its properties."
(substring-no-properties (or (thing-at-point 'symbol) "")))
(defun projectile-generate-process-name (process make-new &optional project)
"Infer the buffer name for PROCESS or generate a new one if MAKE-NEW is true.
The function operates on the current project by default, but you can also
specify a project explicitly via the optional PROJECT param."
(let* ((project (or project (projectile-acquire-root)))
(base-name (format "*%s %s*" process (projectile-project-name project))))
(if make-new
(generate-new-buffer-name base-name)
base-name)))
;;; Serialization
(defun projectile-serialize (data filename)
"Serialize DATA to FILENAME.
The saved data can be restored with `projectile-unserialize'."
(if (file-writable-p filename)
(with-temp-file filename
(insert (let (print-length) (prin1-to-string data))))
(message "Projectile cache '%s' not writeable" filename)))
(defun projectile-unserialize (filename)
"Read data serialized by `projectile-serialize' from FILENAME."
(with-demoted-errors
"Error during file deserialization: %S"
(when (file-exists-p filename)
(with-temp-buffer
(insert-file-contents filename)
;; this will blow up if the contents of the file aren't
;; lisp data structures
(read (buffer-string))))))
;;; Caching
(defvar projectile-file-exists-cache