-
-
Notifications
You must be signed in to change notification settings - Fork 389
/
helm-files.el
6697 lines (6178 loc) · 301 KB
/
helm-files.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
;;; helm-files.el --- helm file browser and related. -*- lexical-binding: t -*-
;; Copyright (C) 2012 ~ 2023 Thierry Volpiatto
;; 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 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(require 'cl-lib)
(require 'helm)
(require 'helm-types)
(require 'helm-utils)
(require 'helm-grep)
(require 'helm-help)
(require 'helm-locate)
(require 'helm-tags)
(require 'helm-buffers)
(require 'tramp)
(eval-when-compile
(require 'thingatpt)
(require 'ffap)
(require 'dired-aux)
(require 'dired-x))
(require 'filenotify)
(require 'image-mode)
(require 'image-dired)
(declare-function find-library-name "find-func.el" (library))
(declare-function w32-shell-execute "ext:w32fns.c" (operation document &optional parameters show-flag))
(declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
(declare-function eshell-read-aliases-list "em-alias")
(declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
(declare-function eshell-kill-input "esh-mode")
(declare-function eshell-bol "esh-mode")
(declare-function eshell-reset "esh-mode.el")
(declare-function eshell/cd "em-dirs.el")
(declare-function eshell-next-prompt "em-prompt.el")
(declare-function eshell-resume-eval "esh-cmd")
(declare-function helm-ls-git "ext:helm-ls-git")
(declare-function helm-hg-find-files-in-project "ext:helm-ls-hg")
(declare-function helm-gid "helm-id-utils.el")
(declare-function helm-find-1 "helm-find")
(declare-function helm-fd-1 "helm-fd")
(declare-function helm-get-default-program-for-file "helm-external")
(declare-function helm-open-file-externally "helm-external")
(declare-function helm-comp-read "helm-mode")
(declare-function helm-read-file-name "helm-mode")
(declare-function term-line-mode "term")
(declare-function term-char-mode "term")
(declare-function term-send-input "term")
(declare-function term-next-prompt "term")
(declare-function term-process-mark "term")
(declare-function bookmark-prop-get "bookmark")
(declare-function comint-next-prompt "comint")
(declare-function comint-delete-input "comint")
(declare-function comint-send-input "comint")
(declare-function comint-goto-process-mark "comint")
(declare-function tramp-dissect-file-name "tramp")
(declare-function tramp-get-completion-function "tramp")
(declare-function seconds-to-time "time-date")
(declare-function ffap-fixup-url "ffap")
(declare-function ffap-url-at-point "ffap")
(declare-function ffap-file-at-point "ffap")
(declare-function dired-create-files "dired-aux")
(declare-function dired-goto-file "dired")
(declare-function dired-move-to-filename "dired")
(declare-function dired-move-to-end-of-filename "dired")
(declare-function dired-get-filename "dired")
(declare-function dired-get-marked-files "dired")
(declare-function tramp-list-connections "tramp-cache")
(declare-function tramp-get-connection-process "tramp")
(declare-function tramp-buffer-name "tramp")
(declare-function tramp-make-tramp-file-name "tramp")
(declare-function tramp-cleanup-connection "tramp-cmds")
(declare-function dired-async-processes "ext:dired-async.el")
(declare-function dired-async-mode-line-message "ext:dired-async.el")
(declare-function dired-async--modeline-mode "ext:dired-async.el")
(declare-function all-the-icons-icon-for-file "ext:all-the-icons.el")
(declare-function all-the-icons-octicon "ext:all-the-icons.el")
(declare-function all-the-icons-match-to-alist "ext:all-the-icons.el")
(declare-function helm-adaptive-sort "ext:helm-adaptive.el")
(declare-function wfnames-setup-buffer "ext:wfnames.el")
(defvar all-the-icons-dir-icon-alist)
(defvar term-char-mode-point-at-process-mark)
(defvar term-char-mode-buffer-read-only)
(defvar recentf-list)
(defvar helm-mm-matching-method)
(defvar dired-async-mode)
(defvar org-directory)
(defvar eshell-current-command)
(defvar eshell-debug-command)
(defvar eshell-current-command)
(defvar tramp-archive-enabled)
(defvar tramp-tolerate-tilde)
(defvar password-cache)
(defvar helm-fd-executable)
(defvar wfnames-buffer)
;;; Internal vars
;;
(defvar helm-ff-last-expanded-candidate-regexp "^[[:multibyte:] ]*%s"
"Regexp that retrieve previous candidate when going up one level.
The default value matching a multibyte char at bol allows
prefixing candidate with an icon. The format part will be
replaced by the display part of the candidate regexp quoted.
This should be used for all preselection code for helm-find-files
to handle icons.")
(defvar helm-find-files-doc-header " (\\<helm-find-files-map>\\[helm-find-files-up-one-level]: Go up one level)"
"*The doc that is inserted in the Name header of a find-files or dired source.")
(defvar helm-ff-auto-update-flag nil
"Internal, flag to turn on/off auto-update in `helm-find-files'.
Don't set it directly, use instead `helm-ff-auto-update-initial-value'.")
(defvar helm-ff-last-expanded nil
"Store last expanded directory or file.")
(defvar helm-ff-default-directory nil)
(defvar helm-ff-history nil)
(defvar helm-ff-url-regexp
"\\`\\(news\\(post\\)?:\\|nntp:\\|mailto:\\|file:\\|\\(ftp\\|https?\\|telnet\\|gopher\\|www\\|wais\\):/?/?\\).*"
"Same as `ffap-url-regexp' but match earlier possible url.")
;; helm-tramp-file-name-regexp is based on old version of
;; tramp-file-name-regexp i.e. "\\`/\\([^[/:]+\\|[^/]+]\\):" but it
;; seems it is wrong and a simpler regexp is enough, let's try it and
;; watch out!
(defvar helm-tramp-file-name-regexp "\\`/\\([^/:|]+\\):")
(defvar helm-ff-tramp-method-regexp "[/|]:\\([^:]*\\)")
(defvar helm-marked-buffer-name "*helm marked*")
(defvar helm-ff--auto-update-state nil)
(defvar helm-ff--deleting-char-backward nil)
(defvar helm-multi-files--toggle-locate nil)
(defvar helm-ff--move-to-first-real-candidate t)
(defvar helm-find-files--toggle-bookmark nil)
(defvar helm-ff--tramp-methods nil)
(defvar helm-ff--directory-files-length (make-hash-table :test 'equal)
"Used to count number of candidates in directory.
candidate-number-limit is set to this value if this value is bigger
than `helm-candidate-number-limit'.")
(defvar helm-ff--list-directory-cache (make-hash-table :test 'equal)
"Cache for `helm-find-files' candidates.")
(defvar helm-ff--file-notify-watchers (make-hash-table :test 'equal)
"File-notify watchers for `helm-find-files' are stored here.")
(defvar helm-ff-history-buffer-name "*helm-find-files history*")
(defvar helm-rsync-command-history nil)
(defvar helm-rsync--last-progress-bar-alist nil
"Used to store last valid rsync progress bar.")
(defvar helm-rsync-process-buffer "*helm-rsync*")
(defvar helm-rsync-progress-str-alist nil)
(defvar helm-ff--trash-directory-regexp "\\.?Trash[/0-9]+files/?\\'")
(defvar helm-ff--show-directories-only nil)
(defvar helm-ff--show-files-only nil)
(defvar helm-ff--trashed-files nil
"[INTERNAL] Files already trashed are stored here during file deletion.
This is used only as a let binding.")
(defvar helm-ff--show-thumbnails nil)
(defvar helm-ff--thumbnailed-directories nil)
;;; Helm-find-files - The helm file browser.
;;
;; Keymaps
(defvar helm-find-files-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map helm-map)
(define-key map (kbd "RET") 'helm-ff-RET)
(define-key map (kbd "C-]") 'helm-ff-run-toggle-basename)
(define-key map (kbd "C-x C-f") 'helm-ff-run-locate)
(define-key map (kbd "C-x C-d") 'helm-ff-run-browse-project)
(define-key map (kbd "C-x r m") 'helm-ff-bookmark-set)
(define-key map (kbd "C-x r b") 'helm-find-files-switch-to-bookmark)
(define-key map (kbd "C-x C-q") 'helm-ff-run-edit-marked-files)
(define-key map (kbd "C-s") 'helm-ff-run-grep)
(define-key map (kbd "M-g s") 'helm-ff-run-grep)
(define-key map (kbd "M-g p") 'helm-ff-run-pdfgrep)
(define-key map (kbd "M-g z") 'helm-ff-run-zgrep)
(define-key map (kbd "M-g a") 'helm-ff-run-grep-ag)
(define-key map (kbd "M-g g") 'helm-ff-run-git-grep)
(define-key map (kbd "M-g i") 'helm-ff-run-gid)
(define-key map (kbd "M-.") 'helm-ff-run-etags)
(define-key map (kbd "M-R") 'helm-ff-run-rename-file)
(define-key map (kbd "M-C") 'helm-ff-run-copy-file)
(define-key map (kbd "M-k") 'helm-ff-run-kill-default-directory)
(when (executable-find "rsync")
(define-key map (kbd "M-V") 'helm-ff-run-rsync-file))
(define-key map (kbd "C-M-SPC") 'helm-ff-mark-similar-files)
(define-key map (kbd "C-M-c") 'helm-ff-run-mcp)
(define-key map (kbd "M-B") 'helm-ff-run-byte-compile-file)
(define-key map (kbd "M-L") 'helm-ff-run-load-file)
(define-key map (kbd "M-S") 'helm-ff-run-symlink-file)
(define-key map (kbd "M-Y") 'helm-ff-run-relsymlink-file)
(define-key map (kbd "M-H") 'helm-ff-run-hardlink-file)
(define-key map (kbd "M-D") 'helm-ff-run-delete-file)
(define-key map (kbd "M-K") 'helm-ff-run-kill-buffer-persistent)
(define-key map (kbd "M-T") 'helm-ff-run-touch-files)
(define-key map (kbd "M-M") 'helm-ff-run-chmod)
(define-key map (kbd "C-c d") 'helm-ff-persistent-delete)
(define-key map (kbd "M-e") 'helm-ff-run-switch-to-shell)
(define-key map (kbd "C-c i") 'helm-ff-run-complete-fn-at-point)
(define-key map (kbd "C-c o") 'helm-ff-run-switch-other-window)
(define-key map (kbd "C-c C-o") 'helm-ff-run-switch-other-frame)
(define-key map (kbd "C-c C-x") 'helm-ff-run-open-file-externally)
(define-key map (kbd "C-c C-v") 'helm-ff-run-preview-file-externally)
(define-key map (kbd "C-c X") 'helm-ff-run-open-file-with-default-tool)
(define-key map (kbd "C-c t") 'helm-ff-toggle-thumbnails)
(define-key map (kbd "M-!") 'helm-ff-run-eshell-command-on-file)
(define-key map (kbd "M-@") 'helm-ff-run-query-replace-fnames-on-marked)
(define-key map (kbd "M-%") 'helm-ff-run-query-replace)
(define-key map (kbd "C-M-%") 'helm-ff-run-query-replace-regexp)
(define-key map (kbd "C-c =") 'helm-ff-run-ediff-file)
(define-key map (kbd "M-=") 'helm-ff-run-ediff-merge-file)
(define-key map (kbd "M-p") 'helm-find-files-history)
(define-key map (kbd "C-c h") 'helm-ff-file-name-history)
(define-key map (kbd "M-i") 'helm-ff-properties-persistent)
(define-key map (kbd "C-}") 'helm-narrow-window)
(define-key map (kbd "C-{") 'helm-enlarge-window)
(define-key map (kbd "C-<backspace>") 'helm-ff-run-toggle-auto-update)
(define-key map (kbd "C-c <DEL>") 'helm-ff-run-toggle-auto-update)
(define-key map (kbd "C-c C-a") 'helm-ff-run-mail-attach-files)
(define-key map (kbd "C-c p") 'helm-ff-run-print-file)
(define-key map (kbd "C-c /") 'helm-ff-run-find-sh-command)
(define-key map (kbd "C-/") 'helm-ff-run-fd)
;; Next 2 have no effect if candidate is not an image file.
(define-key map (kbd "M-l") 'helm-ff-rotate-left-persistent)
(define-key map (kbd "M-r") 'helm-ff-rotate-right-persistent)
(define-key map (kbd "M-+") 'helm-ff-increase-image-size-persistent)
(define-key map (kbd "M--") 'helm-ff-decrease-image-size-persistent)
(define-key map (kbd "C-l") 'helm-find-files-up-one-level)
(define-key map (kbd "C-:") 'helm-ff-complete-tramp-methods)
(define-key map (kbd "C-_") 'helm-ff-undo)
(define-key map (kbd "C-r") 'helm-find-files-down-last-level)
(define-key map (kbd "C-c r") 'helm-ff-run-find-file-as-root)
(define-key map (kbd "C-x C-v") 'helm-ff-run-find-alternate-file)
(define-key map (kbd "C-c @") 'helm-ff-run-insert-org-link)
(define-key map (kbd "S-<f1>") 'helm-ff-sort-alpha)
(define-key map (kbd "S-<f2>") 'helm-ff-sort-by-newest)
(define-key map (kbd "S-<f3>") 'helm-ff-sort-by-size)
(define-key map (kbd "S-<f4>") 'helm-ff-toggle-dirs-only)
(define-key map (kbd "S-<f5>") 'helm-ff-toggle-files-only)
(define-key map (kbd "S-<f6>") 'helm-ff-sort-by-ext)
(helm-define-key-with-subkeys map (kbd "DEL") ?\d 'helm-ff-delete-char-backward
'((C-backspace . helm-ff-run-toggle-auto-update)
([C-c DEL] . helm-ff-run-toggle-auto-update))
nil 'helm-ff-delete-char-backward--exit-fn)
(when (fboundp 'tab-bar-mode)
(define-key map (kbd "C-c C-t") 'helm-ff-find-file-other-tab))
map)
"Keymap for `helm-find-files'.")
(defvar helm-read-file-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map helm-map)
(define-key map (kbd "<C-return>") 'helm-cr-empty-string)
(define-key map (kbd "M-RET") 'helm-cr-empty-string)
(define-key map (kbd "C-]") 'helm-ff-run-toggle-basename)
(define-key map (kbd "C-.") 'helm-find-files-up-one-level)
(define-key map (kbd "C-l") 'helm-find-files-up-one-level)
(define-key map (kbd "C-:") 'helm-ff-complete-tramp-methods)
(define-key map (kbd "C-_") 'helm-ff-undo)
(define-key map (kbd "C-r") 'helm-find-files-down-last-level)
(define-key map (kbd "C-c h") 'helm-ff-file-name-history)
(define-key map (kbd "C-<backspace>") 'helm-ff-run-toggle-auto-update)
(define-key map (kbd "C-c <DEL>") 'helm-ff-run-toggle-auto-update)
(define-key map (kbd "C-c t") 'helm-ff-toggle-thumbnails)
(define-key map (kbd "S-<f1>") 'helm-ff-sort-alpha)
(define-key map (kbd "S-<f2>") 'helm-ff-sort-by-newest)
(define-key map (kbd "S-<f3>") 'helm-ff-sort-by-size)
(define-key map (kbd "S-<f6>") 'helm-ff-sort-by-ext)
(define-key map (kbd "RET") 'helm-ff-RET)
(helm-define-key-with-subkeys map (kbd "DEL") ?\d 'helm-ff-delete-char-backward
'((C-backspace . helm-ff-run-toggle-auto-update)
([C-c DEL] . helm-ff-run-toggle-auto-update))
nil 'helm-ff-delete-char-backward--exit-fn)
map)
"Keymap for `helm-read-file-name'.")
;;; User variables
;;
(defgroup helm-files nil
"Files applications and libraries for Helm."
:group 'helm)
(defcustom helm-tramp-verbose 0
"Just like `tramp-verbose' but specific to Helm.
When set to 0 don't show tramp messages in Helm.
If you want to have the default tramp messages set it to 3."
:type 'integer)
(defcustom helm-ff-auto-update-initial-value nil
"Auto update when only one candidate directory is matched.
Default value when starting `helm-find-files' is nil to not
confuse new users.
For a better experience with `helm-find-files' set this to
non-nil and use C-<backspace> to toggle it."
:type 'boolean)
(defcustom helm-ff-history-max-length 100
"Number of elements shown in `helm-find-files' history."
:type 'integer)
(defcustom helm-ff-fuzzy-matching t
"Enable fuzzy matching for `helm-find-files' when non--nil.
See `helm-ff--transform-pattern-for-completion' for more info."
:type 'boolean)
(defcustom helm-ff-exif-data-program "exiftran"
"Program used to extract exif data of an image file."
:type 'string)
(defcustom helm-ff-exif-data-program-args "-d"
"Arguments used for `helm-ff-exif-data-program'."
:type 'string)
(defcustom helm-ff-newfile-prompt-p t
"Whether Prompt or not when creating new file.
This set `ffap-newfile-prompt'."
:type 'boolean)
(defcustom helm-ff-avfs-directory "~/.avfs"
"The default avfs directory, usually \\='~/.avfs'.
When this is set you will be able to expand archive filenames
with `C-j' inside an avfs directory mounted with mountavfs.
See <http://sourceforge.net/projects/avf/>."
:type 'string)
(defcustom helm-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
"Minimal list of compressed files extension."
:type '(repeat (choice string)))
(defcustom helm-ff-printer-list nil
"A list of available printers on your system.
When non-nil let you choose a printer to print file.
Otherwise when nil the variable `printer-name' will be used.
On Unix based systems (lpstat command needed) you don't need to
set this, `helm-ff-find-printers' will find a list of available
printers for you."
:type '(repeat (choice string)))
(defcustom helm-ff-transformer-show-only-basename t
"Show only basename of candidates in `helm-find-files'.
This can be toggled at anytime from `helm-find-files' with \
\\<helm-find-files-map>\\[helm-ff-run-toggle-basename]."
:type 'boolean)
(defcustom helm-ff-signal-error-on-dot-files t
"Signal error when file is `.' or `..' on file deletion when non-nil.
Default is non-nil.
WARNING: Setting this to nil is unsafe and can cause deletion of
a whole tree."
:type 'boolean)
(defcustom helm-ff-search-library-in-sexp nil
"Search for library in `require' and `declare-function' sexp."
:type 'boolean)
(defcustom helm-tooltip-hide-delay 25
"Hide tooltips automatically after this many seconds."
:type 'integer)
(defcustom helm-ff-file-name-history-use-recentf nil
"Use `recentf-list' instead of `file-name-history' in `helm-find-files'."
:type 'boolean)
(defcustom helm-ff-skip-boring-files nil
"Non-nil to skip boring files.
I.e. the files matching regexps in `helm-boring-file-regexp-list'.
This takes effect in `helm-find-files' and file completion used by
`helm-mode' i.e. `helm-read-file-name'.
Note that when non-nil this will slow down slightly `helm-find-files'."
:type 'boolean)
(defcustom helm-ff-skip-git-ignored-files nil
"Non-nil to skip git ignored files.
This take effect only in `helm-find-files'.
Check is not done on remote files.
Note that when non-nil this will slow down slightly
`helm-find-files'."
:type 'boolean)
(defcustom helm-ff-candidate-number-limit 5000
"The `helm-candidate-number-limit' for `helm-find-files' and friends.
Note that when going one level up with
`\\<helm-find-files-map>\\[helm-find-files-up-one-level]' the
length of directory will be used instead if it is higher than
this value. This is to avoid failing to preselect the previous
directory/file if this one is situated lower than
`helm-ff-candidate-number-limit' num candidate."
:type 'integer)
(defcustom helm-ff-preselect-ignore-large-dirs nil
"Preselect directory belonging to current-buffer even if large."
:type 'boolean)
(defcustom helm-ff-up-one-level-preselect t
"Always preselect previous directory when going one level up.
When non-nil `candidate-number-limit' source value is modified
dynamically when going one level up if the position of previous
candidate in its directory is > to
`helm-ff-candidate-number-limit'.
It can be helpful to disable this and reduce
`helm-ff-candidate-number-limit' if you often navigate across
very large directories."
:type 'boolean)
(defcustom helm-files-save-history-extra-sources
'("Find" "Locate" "Recentf"
"Files from Current Directory" "File Cache")
"Extras source that save candidate to `file-name-history'."
:type '(repeat (choice string)))
(defcustom helm-find-files-before-init-hook nil
"Hook that run before initialization of `helm-find-files'."
:type 'hook)
(defcustom helm-find-files-after-init-hook nil
"Hook that run after initialization of `helm-find-files'."
:type 'hook)
(defcustom helm-find-files-bookmark-prefix nil
"bookmark name prefix of `helm-find-files' sessions."
:type 'string)
(defcustom helm-ff-guess-ffap-filenames nil
"Use ffap to guess local filenames at point in `helm-find-files'.
This doesn't disable url or mail at point, see
`helm-ff-guess-ffap-urls' for this."
:type 'boolean)
(defcustom helm-ff-guess-ffap-urls t
"Use ffap to guess local urls at point in `helm-find-files'.
This doesn't disable guessing filenames at point, see
`helm-ff-guess-ffap-filenames' for this.
See also `ffap-url-unwrap-remote' that may override this
variable."
:type 'boolean)
(defcustom helm-ff-no-preselect nil
"When non-nil `helm-find-files' starts at root of current directory."
:type 'boolean)
(defcustom helm-ff-allow-non-existing-file-at-point nil
"Use non existing file-at-point as initial input in `helm-find-files'."
:type 'boolean)
(defcustom helm-find-files-ignore-thing-at-point nil
"Use only `default-directory' as default input in `helm-find-files'.
I.e. text under cursor in `current-buffer' is ignored.
Note that when non-nil you will be unable to complete filename at
point in `current-buffer'."
:type 'boolean)
(defcustom helm-substitute-in-filename-stay-on-remote nil
"Don't switch back to local filesystem when expanding pattern with / or ~/."
:type 'boolean)
(defcustom helm-ff-goto-first-real-dired-exceptions '(dired-goto-file)
"Dired commands that are allowed moving to first real candidate."
:type '(repeat (choice symbol)))
(defcustom helm-mounted-network-directories nil
"A list of directories used for mounting remotes filesystem.
When nil `helm-file-on-mounted-network-p' always return nil
otherwise check if a file is in one of these directories.
Remote filesystem are generally mounted with sshfs."
:type '(repeat string))
(defcustom helm-browse-project-default-find-files-fn
(cond ((or (executable-find "fd")
(executable-find "fdfind"))
#'helm-browse-project-fd-find-files)
((executable-find "rg")
#'helm-browse-project-rg-find-files)
((executable-find "ag")
#'helm-browse-project-ag-find-files)
(t #'helm-browse-project-walk-directory))
"The default function to retrieve files in a non-vc directory.
A function that takes a directory name as only arg."
:type 'function)
(defcustom helm-ff-kill-or-find-buffer-fname-fn
#'helm-ff-kill-or-find-buffer-fname
"Default function used to expand non-directory filenames in `helm-find-files'.
This variable will take effect only in `helm-find-files'. It
affects the behavior of persistent-action on filenames and
non-existing filenames.
The default is to expand filename on first hit on
\\<helm-map>\\[helm-execute-persistent-action], pop buffer in
other window on second hit and finally kill this buffer on third
hit. This is very handy to create several new buffers, or when
navigating, show quickly the buffer of file to see its contents
briefly before killing it and continue navigating.
However some users may not want this, so to disable this behaviour
just set this to `ignore' function.
Of course you can also write your own function to do something
else."
:type 'function)
(defcustom helm-modes-using-escaped-strings
'(eshell-mode shell-mode term-mode)
"Modes that requires string's insertion to be escaped."
:type '(repeat symbol))
(defcustom helm-ff-allow-recursive-deletes nil
"When \\='always don't prompt for recursive deletion of directories.
When nil, will ask for recursive deletion.
Note that when deleting multiple directories you can answer !
when prompted to avoid being asked for next directories, so it
is probably better to not modify this variable."
:type '(choice
(const :tag "Delete non-empty directories" t)
(const :tag "Confirm for each directory" nil)))
(defcustom helm-ff-delete-files-function #'helm-delete-marked-files
"The function to use by default to delete files.
Default is to delete files synchronously, other choice is to
delete files asynchronously.
BE AWARE that when deleting async you will not be warned about
recursive deletion of directories, IOW non-empty directories will
be deleted with no warnings in background!!!
It is the function that will be used when using
`\\<helm-find-files-map>\\[helm-ff-run-delete-file]' from
`helm-find-files'."
:type '(choice (function :tag "Delete files synchronously."
helm-delete-marked-files)
(function :tag "Delete files asynchronously."
helm-delete-marked-files-async)))
(defcustom helm-trash-remote-files nil
"Allow trashing remote files when non-nil.
Trashing remote files with tramp doesn't work out of the box
unless the \\='trash-cli' package is installed. This is why trashing
remote files from Helm is disabled by default.
Tramp is using external \\='trash' command in its `delete-file' and
`delete-directory' handlers when using
`delete-by-moving-to-trash', which is documented nowhere in
Emacs.
If you want to enable this you will have to install the \\='trash'
command on remote (and/or locally if you want to trash as root).
On Ubuntu-based distributions it is \\='trash-cli'."
:type 'boolean)
(defcustom helm-list-directory-function
(cl-case system-type
(gnu/linux #'helm-list-dir-external)
(berkeley-unix #'helm-list-dir-lisp)
(windows-nt #'helm-list-dir-lisp)
(t #'helm-list-dir-lisp))
"The function used in `helm-find-files' to list remote directories.
Actually Helm provides two functions to do this:
`helm-list-dir-lisp' and `helm-list-dir-external'.
Using `helm-list-dir-external' will provide a similar display to
what is provided with local files i.e. colorized symlinks,
executables files etc., whereas using `helm-list-dir-lisp' will
allow colorizing only directories but it is more portable.
NOTE: `helm-list-dir-external' needs ls and awk as dependencies.
Also the ls version installed on the remote side should support
the same arguments as the GNU/ls version, which are -A -1 -F -b
and -Q. So even if you are using a GNU/ls version locally and you
want to connect e.g. on a Freebsd server, you may have failures
due to the incompatible ls version installed on remote server. In
such case use `helm-list-dir-lisp' which works everywhere but is
slower and less featured (only directories colorized)."
:type 'function)
(defcustom helm-ff-initial-sort-method nil
"Sort method to use when initially listing a directory.
It is better to keep this nil globally and turn it on only when needed
otherwise it may be slightly slower specially with `ext' method which
BTW is not provided on remote files (helm will fallback on nil in such
case).
Note that this have no effect as soon as you start narrowing directory
i.e. filtering filenames inside directory."
:type '(choice
(const :tag "alphabetically" nil)
(const :tag "newest" newest)
(const :tag "size" size)
(const :tag "extensions" ext)))
(defcustom helm-ff-rotate-image-program "exiftran"
"External program used to rotate images.
When nil and `helm-ff-display-image-native' is enabled, fallback to
`image-rotate' without modification of exif data i.e. rotation is not
persistent otherwise an error is returned when not using
`helm-ff-display-image-native' i.e. using image-dired."
:type '(choice
(const :tag "Mogrify" "mogrify")
(const :tag "Exiftran" "exiftran")
(const :tag "Jpegtran" "jpegtran")))
(defcustom helm-ff-rotate-image-switch '("-i")
"Options used with `helm-ff-rotate-image-program'.
If you are using Mogrify or Jpegtran mandatory option is
\"-rotate\", with Exiftran mandatory option is \"-i\"."
:type '(repeat string))
(defcustom helm-ff-preferred-shell-mode 'eshell-mode
"Shell to use to switch to a shell buffer from `helm-find-files'.
Possible values are `shell-mode', `eshell-mode' and `term-mode'.
This affects `\\<helm-find-files-map>\\[helm-ff-run-switch-to-shell]' keybinding."
:type '(choice
(const :tag "Use Eshell" eshell-mode)
(const :tag "Use Shell" shell-mode)
(const :tag "Use Shell" term-mode)))
(defcustom helm-rsync-no-mode-line-update nil
"When non nil don't update mode-line when rsync is running.
This is useful if you display the progress bar somewhere else,
e.g. with minibuffer-line in minibuffer, in this case updating
mode-line may create flickering in other frame's mode-line."
:type 'boolean)
(defcustom helm-rsync-switches '("-a" "-z" "-h" "-s" "--info=all2")
"Rsync options to use with HFF Rsync action.
Note: Using \"--info=all2\" allows having the name of the file
currently transfered in an help-echo in mode-line, if you use
\"--info=progress2\" you will not have this information."
:type '(repeat string))
(defcustom helm-rsync-percent-sign "%"
"Percentage unicode sign to use in Rsync reporter."
:type 'string)
(defcustom helm-trash-default-directory nil
"The default trash directory.
You probably don't need to set this when using a Linux system using
standard settings.
Should be the directory file name i.e. don't add final slash.
When nil helm will compute a default value according to freedesktop
specs.
It is generally \"~/.local/share/Trash\"."
:type 'string)
(defcustom helm-ff-lynx-style-map t
"Use arrow keys to navigate with `helm-find-files'.
Note that if you define this variable with `setq' your change
will have no effect, use customize instead."
:type 'boolean
:set (lambda (var val)
(set var val)
(if val
(progn
(define-key helm-find-files-map (kbd "<right>") 'helm-execute-persistent-action)
(define-key helm-find-files-map (kbd "<left>") 'helm-find-files-up-one-level)
(define-key helm-read-file-map (kbd "<right>") 'helm-execute-persistent-action)
(define-key helm-read-file-map (kbd "<left>") 'helm-find-files-up-one-level))
(define-key helm-find-files-map (kbd "<right>") nil)
(define-key helm-find-files-map (kbd "<left>") nil)
(define-key helm-read-file-map (kbd "<right>") nil)
(define-key helm-read-file-map (kbd "<left>") nil))))
(defcustom helm-ff-DEL-up-one-level-maybe nil
"Use DEL to maybe go up one level when non nil.
Going up one level works only when pattern is a directory endings
with \"/\", otherwise this command deletes char backward.
When nil always delete char backward."
:type 'boolean)
(defcustom helm-ff-display-image-native t
"Use native `image-mode' when non nil.
You should use this only with Emacs>= 27 and `image-auto-resize'
enabled to have images resized properly. When this is enabled,
you have new commands to zoom in/out images. See
`image-transform-resize' and `image-auto-resize'. Otherwise,
when nil `image-dired' is used, using imagemagick as backend.
NOTE: On Emacs-29 `image-dired' is no more using external program
image-magick to display image, so this is used inconditionally even
when value is nil."
:type 'boolean)
(defcustom helm-ff-reset-filters-on-update t
"Reset filter variables when changing directory.
When filtering directories/files only, switch back to a \"show all\" view
when moving out of directory when non nil."
:type 'boolean)
(defcustom helm-ff-eshell-unwanted-aliases nil
"A list of eshell aliases to not display."
:type '(repeat string))
(defcustom helm-find-files-actions
(helm-make-actions
"Find File" 'helm-find-file-or-marked
"Find file in Dired" 'helm-point-file-in-dired
"View file" 'view-file
"Query replace fnames on marked `M-@'" 'helm-ff-query-replace-fnames-on-marked
"Marked files in dired `C-x C-q'" 'helm-ff-edit-marked-files
"Query replace contents on marked `M-%'" 'helm-ff-query-replace
"Query replace regexp contents on marked `C-M-%'" 'helm-ff-query-replace-regexp
"Attach file(s) to mail buffer `C-c C-a'" 'helm-ff-mail-attach-files
"Serial rename files" 'helm-ff-serial-rename
"Serial rename by symlinking files" 'helm-ff-serial-rename-by-symlink
"Serial rename by copying files" 'helm-ff-serial-rename-by-copying
"Open file with default tool" 'helm-open-file-with-default-tool
"Find file in hex dump" 'hexl-find-file
"Browse project `C-x C-d'" 'helm-ff-browse-project
"Complete at point `C-c i'" 'helm-insert-file-name-completion-at-point
"Insert as org link `C-c @'" 'helm-files-insert-as-org-link
"Find shell command `C-c /'" 'helm-ff-find-sh-command
"Fd shell command (C-/)" 'helm-ff-fd
"Find files in file" 'helm-find-files-in-file
"Add marked files to file-cache" 'helm-ff-cache-add-file
"Open file externally `C-c C-x, C-u to choose'" 'helm-open-file-externally
"Grep File(s) `C-s, C-u Recurse'" 'helm-find-files-grep
"Grep current directory with AG `M-g a, C-u select type'" 'helm-find-files-ag
"Git grep `M-g g, C-u from root'" 'helm-ff-git-grep
"Zgrep File(s) `M-g z, C-u Recurse'" 'helm-ff-zgrep
"Pdf Grep File(s)" 'helm-ff-pdfgrep
"Gid `M-g i'" 'helm-ff-gid
"Switch to Eshell `M-e'" 'helm-ff-switch-to-shell
"Etags `M-., C-u reload tag file'" 'helm-ff-etags-select
"Eshell command on file(s) `M-!, C-u take all marked as arguments.'"
'helm-find-files-eshell-command-on-file
"Find file as root `C-c r'" 'helm-find-file-as-root
"Find alternate file `C-x C-v'" 'find-alternate-file
"Ediff File `C-c ='" 'helm-find-files-ediff-files
"Ediff Merge File `M-='" 'helm-find-files-ediff-merge-files
(lambda () (format "Delete File(s)%s `M-D' (C-u reverse trash)"
(if (eq helm-ff-delete-files-function
'helm-delete-marked-files-async)
" async" "")))
'helm-ff-delete-files
"Touch File(s) `M-T'" 'helm-ff-touch-files
"Copy file(s) `M-C, C-u to follow'" 'helm-find-files-copy
(lambda ()
(and (executable-find "rsync")
"Rsync file(s) `M-V' (C-u edit command)"))
'helm-find-files-rsync
"Rename file(s) `M-R, C-u to follow'" 'helm-find-files-rename
"Backup files" 'helm-find-files-backup
"Copy file to dir(s) `C-M-c'" 'helm-ff-mcp
"Symlink files(s) `M-S, C-u to follow'" 'helm-find-files-symlink
"Relsymlink file(s) `M-Y, C-u to follow'" 'helm-find-files-relsymlink
"Hardlink file(s) `M-H, C-u to follow'" 'helm-find-files-hardlink
"Change mode on file(s) `M-M'" 'helm-ff-chmod
"Find file other window `C-c o'" 'helm-find-files-other-window
"Find file other frame `C-c C-o'" 'find-file-other-frame
(lambda () (and (fboundp 'tab-bar-mode)
"Find file other tab `C-c C-t'"))
'find-file-other-tab
"Print File `C-c p, C-u to refresh'" 'helm-ff-print
"Locate `C-x C-f, C-u to specify locate db'" 'helm-ff-locate)
"Actions for `helm-find-files'."
:type '(alist :key-type string :value-type function))
(defcustom helm-dwim-target nil
"Default target directory for file actions.
Define the directory where you want to start navigating for the
target directory when copying, renaming, etc.. You can use the
`default-directory' of `next-window', the visited directory, the
current `default-directory' or have completion on all the
directories belonging to each visible windows."
:type '(radio :tag "Define default target directory for file actions."
(const :tag "Directory belonging to next window"
next-window)
(const :tag "Completion on directories belonging to each window"
completion)
(const :tag "Use initial directory or `default-directory'"
default-directory)
(const :tag "Use visited directory"
nil)))
(defcustom helm-ff-use-notify t
"Watch directories visited with `helm-find-files' when non nil.
If your system have no file notification package available turn this
to nil to avoid error messages when using `helm-find-files'."
:type 'boolean
:set (lambda (var val)
(set-default var val)
(unless (symbol-value var)
(cl-loop for dir being the hash-keys of helm-ff--file-notify-watchers
do (remhash dir helm-ff--list-directory-cache)))))
(defcustom helm-ff-inotify-unsupported-methods '("adb")
"Tramp methods unsupported by file-notify."
:type '(repeat string))
(defcustom helm-ff-image-cache-max-len 5
"The last seen image number to keep in cache."
:type 'integer)
(defcustom helm-ff-image-cache-max-len 5
"The last seen image number to keep in cache."
:type 'integer)
(defcustom helm-ff-slideshow-default-delay 3
"Delay in seconds between each image in slideshow."
:type 'integer)
(defcustom helm-file-name-history-hide-deleted nil
"Hide deleted files in file-name-history when non nil.
This can be toggled at any time from `helm-ff-file-name-history' with \
\\<helm-file-name-history-map>\\[helm-file-name-history-show-or-hide-deleted]."
:type 'boolean)
(defcustom helm-file-name-history-max-length 72
"Max length of candidates in helm file name history before truncating."
:type 'integer)
(defcustom helm-ff-follow-blacklist-file-exts '("gpg" "doc" "docx" "mp3" "ogg")
"File extensions we don't want to follow when helm-follow-mode is enabled.
Note that image files are always followed even if their extensions is
present in this list."
:type '(repeat string))
(defcustom helm-ff-nohighlight-matches t
"Highlight matches in `helm-find-files' when nil."
:type 'boolean
:initialize 'custom-initialize-changed
:set (lambda (var val)
(set var val)
(setq helm-source-find-files nil)
(when helm-ff-icon-mode
(helm-ff-icon-mode 1))))
(defcustom helm-ff-edit-marked-files-fn (if (< emacs-major-version 29)
#'helm-ff-wfnames
#'helm-marked-files-in-dired)
"A function to edit filenames in a special buffer."
:type '(choice (function :tag "Use Wfnames package to edit filenames."
helm-ff-wfnames)
(function :tag "Use Wdired package to edit filenames."
helm-marked-files-in-dired)))
;;; Faces
;;
;;
(defgroup helm-files-faces nil
"Customize the appearance of helm-files."
:prefix "helm-"
:group 'helm-files
:group 'helm-faces)
(defface helm-ff-prefix
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:background "yellow" :foreground "black"))
"Face used to prefix new file or url paths in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-executable
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "green"))
"Face used for executable files in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-suid
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:background "red" :foreground "white"))
"Face used for suid files in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-directory
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "DarkRed" :background "LightGray"))
"Face used for directories in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-dotted-directory
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "black" :background "DimGray"))
"Face used for dotted directories in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-dotted-symlink-directory
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "DarkOrange" :background "DimGray"))
"Face used for dotted symlinked directories in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-symlink
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:inherit font-lock-comment-face))
"Face used for symlinks in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-invalid-symlink
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "black" :background "red"))
"Face used for invalid symlinks in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-denied
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "red" :background "black"))
"Face used for non accessible files in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-file
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:inherit font-lock-builtin-face))
"Face used for file names in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-nofile
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:inherit helm-ff-file))
"Face used for file names in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-truename
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:inherit font-lock-string-face))
"Face used for symlink truenames in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-dirs
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:inherit font-lock-function-name-face))
"Face used for file names in recursive dirs completion in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-socket
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "DeepPink"))
"Face used for socket files in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-pipe
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "yellow" :background "black"))
"Face used for named pipes and character device files in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-file-extension
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "magenta"))
"Face used for file extensions in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-ff-backup-file
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "DimGray"))
"Face used for backup files in `helm-find-files'."
:group 'helm-files-faces)
(defface helm-history-deleted
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:inherit helm-ff-invalid-symlink))
"Face used for deleted files in `file-name-history'."
:group 'helm-files-faces)
(defface helm-history-remote
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "Indianred1"))
"Face used for remote files in `file-name-history'."
:group 'helm-files-faces)
(defface helm-delete-async-message
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:foreground "yellow"))
"Face used for mode-line message."
:group 'helm-files-faces)
(defface helm-ff-rsync-progress
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
:inherit font-lock-warning-face))
"Face used for rsync mode-line indicator."
:group 'helm-files-faces)
;;; Helm-find-files
;;
;;
(defvar helm-source-find-files nil
"The main source to browse files.
Should not be used among other sources.")