mirrored from git://git.sv.gnu.org/emacs.git
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathdired.el
5409 lines (4946 loc) · 217 KB
/
dired.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
;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*-
;; Copyright (C) 1985-1986, 1992-1997, 2000-2025 Free Software
;; Foundation, Inc.
;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
;; Maintainer: emacs-devel@gnu.org
;; Keywords: files
;; Package: emacs
;; This file is part of GNU Emacs.
;; GNU Emacs 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.
;; GNU Emacs 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. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This is a major mode for directory browsing and editing.
;; It is documented in the Emacs manual.
;; Rewritten in 1990/1991 to add tree features, file marking and
;; sorting by Sebastian Kremer <sk@thp.uni-koeln.de>.
;; Finished up by rms in 1992.
;;; Code:
(eval-when-compile (require 'subr-x))
(eval-when-compile (require 'cl-lib))
(eval-when-compile (require 'autorevert))
;; When bootstrapping dired-loaddefs has not been generated.
(require 'dired-loaddefs nil t)
(require 'dnd)
;;; Customizable variables
(defgroup dired nil
"Directory editing."
:link '(custom-manual "(emacs)Dired")
:group 'files)
(defgroup dired-mark nil
"Handling marks in Dired."
:prefix "dired-"
:group 'dired)
(defgroup dired-guess nil
"Guess shell command in Dired."
:prefix "dired-"
:group 'dired)
;;;###autoload
(defcustom dired-listing-switches "-al"
"Switches passed to `ls' for Dired. MUST contain the `l' option.
May contain all other options that don't contradict `-l';
may contain even `F', `b', `i' and `s'. See also the variable
`dired-ls-F-marks-symlinks' concerning the `F' switch.
If you have files with names with embedded newline characters, adding
`b' to the switches will allow Dired to handle those files better.
Options that include embedded whitespace must be quoted
like this: \"--option=value with spaces\"; you can use
`combine-and-quote-strings' to produce the correct quoting of
each option.
On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
some of the `ls' switches are not supported; see the doc string of
`insert-directory' in `ls-lisp.el' for more details.
For remote Dired buffers, this option supports connection-local values."
:type 'string
:group 'dired)
(defcustom dired-subdir-switches nil
"If non-nil, switches passed to `ls' for inserting subdirectories.
If nil, `dired-listing-switches' is used."
:group 'dired
:type '(choice (const :tag "Use dired-listing-switches" nil)
(string :tag "Switches")))
(defcustom dired-maybe-use-globstar nil
"If non-nil, enable globstar if the shell supports it.
Some shells enable this feature by default (e.g. zsh or fish).
See `dired-enable-globstar-in-shell' for a list of shells
that support globstar and disable it by default.
Note that the implementations of globstar have small differences
between shells. You must check your shell documentation to see
what to expect."
:type 'boolean
:group 'dired
:version "28.1")
(defconst dired-enable-globstar-in-shell
'(("ksh" . "set -G")
("bash" . "shopt -s globstar"))
"Alist of (SHELL . COMMAND), where COMMAND enables globstar in SHELL.
If `dired-maybe-use-globstar' is non-nil, then `dired-insert-directory'
checks this alist to enable globstar in the shell subprocess.")
(defcustom dired-chown-program
(cond ((executable-find "chown") "chown")
((file-executable-p "/usr/sbin/chown") "/usr/sbin/chown")
((file-executable-p "/etc/chown") "/etc/chown")
(t "chown"))
"Name of chown command (usually `chown')."
:group 'dired
:type 'file)
(defcustom dired-use-ls-dired 'unspecified
"Non-nil means Dired should pass the \"--dired\" option to \"ls\".
If nil, don't pass \"--dired\" to \"ls\".
The special value of `unspecified' means to check whether
`insert-directory-program' supports the \"--dired\" option, and save
the result in this variable.
This is performed the first time `dired-insert-directory'
invokes `insert-directory-program'.
Note that if you set this option to nil, either through choice or
because your \"ls\" program does not support \"--dired\", Dired
will fail to parse some \"unusual\" file names, e.g. those with leading
spaces. You might want to install ls from GNU Coreutils, which does
support this option. Alternatively, you might want to use Emacs's
own emulation of \"ls\", by using:
(setq ls-lisp-use-insert-directory-program nil)
(require \\='ls-lisp)
This is used by default on MS Windows, which does not have an \"ls\" program.
Note that `ls-lisp' does not support as many options as GNU ls, though.
For more details, see Info node `(emacs)ls in Lisp'."
:group 'dired
:type '(choice (const :tag
"Use --dired only if `ls' supports it" unspecified)
(const :tag "Do not use --dired" nil)
(other :tag "Always use --dired" t)))
(defvar dired-chmod-program "chmod"
"Name of chmod command (usually `chmod').")
(make-obsolete-variable 'dired-chmod-program nil "28.1")
(defcustom dired-touch-program "touch"
"Name of touch command (usually `touch')."
:group 'dired
:type 'file)
(defcustom dired-ls-F-marks-symlinks nil
"Informs Dired about how `ls -lF' marks symbolic links.
Set this to t if `ls' (or whatever program is specified by
`insert-directory-program') with `-lF' marks the symbolic link
itself with a trailing @ (usually the case under Ultrix and macOS).
Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
nil (the default), if it gives `bar@ -> foo', set it to t.
Dired checks if there is really a @ appended. Thus, if you have a
marking `ls' program on one host and a non-marking on another host, and
don't care about symbolic links which really end in a @, you can
always set this variable to t."
:type 'boolean
:group 'dired-mark)
(defcustom dired-trivial-filenames "\\`\\.\\.?\\'\\|\\`\\.?#"
"Regexp of files to skip when finding first file of a directory.
A value of nil means move to the subdir line.
A value of t means move to first file."
:type '(choice (const :tag "Move to subdir" nil)
(const :tag "Move to first" t)
regexp)
:group 'dired)
(defcustom dired-keep-marker-rename t
;; Use t as default so that moved files "take their markers with them".
"Controls marking of renamed files.
If t, files keep their previous marks when they are renamed.
If a character, renamed files (whether previously marked or not)
are afterward marked with that character.
This option affects only files renamed by `dired-do-rename' and
`dired-do-rename-regexp'. See `wdired-keep-marker-rename'
if you want to do the same for files renamed in WDired mode."
:type '(choice (const :tag "Keep" t)
(character :tag "Mark" :value ?R))
:group 'dired-mark)
(defcustom dired-keep-marker-copy ?C
"Controls marking of copied files.
If t, copied files are marked if and as the corresponding original files were.
If a character, copied files are unconditionally marked with that character."
:type '(choice (const :tag "Keep" t)
(character :tag "Mark"))
:group 'dired-mark)
(defcustom dired-keep-marker-hardlink ?H
"Controls marking of newly made hard links.
If t, they are marked if and as the files linked to were marked.
If a character, new links are unconditionally marked with that character."
:type '(choice (const :tag "Keep" t)
(character :tag "Mark"))
:group 'dired-mark)
(defcustom dired-keep-marker-symlink ?Y
"Controls marking of newly made symbolic links.
If t, they are marked if and as the files linked to were marked.
If a character, new links are unconditionally marked with that character."
:type '(choice (const :tag "Keep" t)
(character :tag "Mark"))
:group 'dired-mark)
(defvar dired-keep-marker-relsymlink ?S
"Controls marking of newly made relative symbolic links.
If t, they are marked if and as the files linked to were marked.
If a character, new links are unconditionally marked with that character.")
(defcustom dired-free-space 'first
"Whether and how to display the disk space usage info in Dired buffers.
If nil, don't display.
If `separate', display on a separate line, and include both the used
and the free disk space.
If `first', the default, display only the free disk space on the first
line, following the directory name."
:type '(choice (const
:tag
"On separate line, display both used and free space" separate)
(const
:tag
"On first line, after directory name, display only free space" first)
(const :tag "Don't display disk space usage" nil))
:version "29.1"
:group 'dired)
(defcustom dired-dwim-target nil
"If non-nil, Dired tries to guess a default target directory.
This means: if there is a Dired buffer displayed in some window,
use its current directory, instead of this Dired buffer's
current directory.
You can customize it to prefer either the next window with a Dired buffer,
or the most recently used window with a Dired buffer, or to use any other
function. When the value is a function, it will be called with no
arguments and is expected to return a list of directories which will
be used as defaults (i.e. default target and \"future history\")
\(though, `dired-dwim-target-defaults' might modify it a bit).
The value t prefers the next windows on the same frame.
The target is used in the prompt for file copy, rename etc."
:type '(choice
(const :tag "No guess" nil)
(function-item :tag "Prefer next windows on the same frame"
dired-dwim-target-next)
(function-item :tag "Prefer next windows on visible frames"
dired-dwim-target-next-visible)
(function-item :tag "Prefer most recently used windows"
dired-dwim-target-recent)
(function :tag "Custom function")
(other :tag "Try to guess" t))
:group 'dired)
(defcustom dired-mouse-drag-files nil
"If non-nil, allow the mouse to drag files from inside a Dired buffer.
Dragging the mouse and then releasing it over the window of
another program will result in that program opening or creating a
copy of the file underneath the mouse pointer (or all marked
files if it was marked). This feature is supported only on X
Windows, Haiku, and Nextstep (macOS or GNUstep).
If the value is `link', then a symbolic link will be created to
the file instead by the other program (usually a file manager).
If the value is `move', then the default action will be for the
other program to move the file to a different location. For this
to work optimally, `auto-revert-mode' should be enabled in the
Dired buffer.
If the Meta key is held down when the mouse button is pressed,
then this will always be equivalent to `link'.
If the Control key is held down when the mouse button is pressed,
then dragging the file will always copy it to the new location.
If the Shift key is held down when the mouse button is pressed,
then this will always be equivalent to `move'."
:set (lambda (option value)
(set-default option value)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'dired-mode)
(revert-buffer nil t)))))
:type '(choice (const :tag "Don't allow dragging" nil)
(const :tag "Copy file to new location" t)
(const :tag "Move file to new location" move)
(const :tag "Create symbolic link to file" link))
:group 'dired
:version "29.1")
(defcustom dired-copy-preserve-time t
"If non-nil, Dired preserves the last-modified time in a file copy.
\(This works on only some systems.)"
:type 'boolean
:group 'dired)
(defcustom dired-copy-dereference nil
"If non-nil, Dired dereferences symlinks when copying them.
This is similar to the \"-L\" option for the \"cp\" shell command."
:type 'boolean
:group 'dired)
;; These variables were deleted and the replacements are in files.el.
;; We leave aliases behind for back-compatibility.
(define-obsolete-variable-alias 'dired-free-space-program
'directory-free-space-program "27.1")
(define-obsolete-variable-alias 'dired-free-space-args
'directory-free-space-args "27.1")
(defcustom dired-load-hook nil
"Run after loading Dired.
You can customize key bindings or load extensions with this."
:group 'dired
:type 'hook)
(make-obsolete-variable 'dired-load-hook
"use `with-eval-after-load' instead." "28.1")
(defcustom dired-mode-hook nil
"Run at the very end of `dired-mode'."
:group 'dired
:type 'hook)
(defcustom dired-before-readin-hook nil
"This hook is run before a Dired buffer is read in (created or reverted)."
:group 'dired
:type 'hook)
(defcustom dired-after-readin-hook nil
"Hook run after each time a file or directory is read by Dired.
After each listing of a file or directory, this hook is run
with the buffer narrowed to the listing."
:group 'dired
:type 'hook)
;; Note this can't simply be run inside function `dired-ls' as the hook
;; functions probably depend on the dired-subdir-alist to be OK.
(defcustom dired-make-directory-clickable t
"When non-nil, make the directory at the start of the Dired buffer clickable."
:version "29.1"
:group 'dired
:type 'boolean)
(defcustom dired-initial-position-hook nil
"Hook used to position point in a new Dired listing display.
It is run by the function `dired-initial-position'."
:group 'dired
:type 'hook
:version "24.4")
(defcustom dired-dnd-protocol-alist
'(("^file:///" . dired-dnd-handle-local-file)
("^file://" . dired-dnd-handle-file)
("^file:" . dired-dnd-handle-local-file))
"The functions to call when a drop in `dired-mode' is made.
See `dnd-protocol-alist' for more information. When nil, behave
as in other buffers. Changing this option is effective only for
new Dired buffers."
:type '(choice (repeat (cons (regexp) (function)))
(const :tag "Behave as in other buffers" nil))
:version "22.1"
:group 'dired)
(defcustom dired-hide-details-hide-symlink-targets t
"Non-nil means `dired-hide-details-mode' hides symbolic link targets."
:type 'boolean
:version "24.4"
:group 'dired)
(defcustom dired-hide-details-hide-information-lines t
"Non-nil means `dired-hide-details-mode' hides all but header and file lines."
:type 'boolean
:version "24.4"
:group 'dired)
(defcustom dired-hide-details-hide-absolute-location nil
"Non-nil means `dired-hide-details-mode' hides directory absolute location."
:type 'boolean
:version "31.1"
:group 'dired)
(defcustom dired-always-read-filesystem nil
"Non-nil means revert buffers visiting files before searching them.
By default, commands like `dired-mark-files-containing-regexp' will
search any buffers visiting the marked files without reverting them,
even if they were changed on disk. When this option is non-nil, such
buffers are always reverted in a temporary buffer before searching
them: the search is performed on the temporary buffer, the original
buffer visiting the file is not modified."
:type 'boolean
:version "26.1"
:group 'dired)
(defcustom dired-mark-region 'file
"Defines what commands that mark files do with the active region.
When nil, marking commands don't operate on all files in the
active region. They process their prefix arguments as usual.
When the value of this option is non-nil, then all Dired commands
that mark or unmark files will operate on all files in the region
if the region is active in Transient Mark mode.
When `file', the region marking is based on the file name.
This means don't mark the file if the end of the region is
before the file name displayed on the Dired line, so the file name
is visually outside the region. This behavior is consistent with
marking files without the region using the key \\`m' that advances
point to the next line after marking the file. Thus the number
of keys used to mark files is the same as the number of keys
used to select the region, for example \\`M-2 m' marks 2 files, and
\\`C-SPC M-2 n m' marks 2 files, and \\`M-2 S-<down> m' marks 2 files.
When `line', the region marking is based on Dired lines,
so include the file into marking if the end of the region
is anywhere on its Dired line, except the beginning of the line."
:type '(choice
(const :tag "Don't mark files in active region" nil)
(const :tag "Exclude file name outside of region" file)
(const :tag "Include the file at region end line" line))
:group 'dired
:version "28.1")
(defcustom dired-kill-when-opening-new-dired-buffer nil
"If non-nil, kill the current buffer when selecting a new directory."
:type 'boolean
:group 'dired
:version "28.1")
(defcustom dired-guess-shell-case-fold-search t
"If non-nil, `dired-guess-shell-alist-default' and
`dired-guess-shell-alist-user' are matched case-insensitively."
:group 'dired-guess
:type 'boolean
:version "29.1")
(defcustom dired-guess-shell-alist-user nil
"User-defined alist of rules for suggested commands.
These rules take precedence over the predefined rules in the variables
`dired-guess-shell-alist-default' and `dired-guess-shell-alist-optional'
\(to which they are prepended).
Each element of this list looks like
(REGEXP COMMAND...)
COMMAND will be used if REGEXP matches the file to be processed.
If several files are to be processed, REGEXP has to match all the
files.
Each COMMAND can either be a string or a Lisp expression that evaluates
to a string. If this expression needs to consult the name of the file for
which the shell commands are being requested, it can access that file name
as the variable `file'.
If several COMMANDs are given, the first one will be the default
and the rest will be added temporarily to the history and can be retrieved
with `previous-history-element' (\\<minibuffer-mode-map>\\[previous-history-element]).
The variable `dired-guess-shell-case-fold-search' controls whether
REGEXP is matched case-sensitively."
:group 'dired-guess
:type '(alist :key-type regexp :value-type (repeat sexp))
:version "29.1")
(defcustom dired-guess-shell-gnutar
(catch 'found
(dolist (exe '("tar" "gtar"))
(if (with-temp-buffer
(ignore-errors (call-process exe nil t nil "--version"))
(and (re-search-backward "GNU tar" nil t) t))
(throw 'found exe))))
"If non-nil, name of GNU tar executable.
\(E.g., \"tar\" or \"gtar\"). The `z' switch will be used with it for
compressed or gzip'ed tar files. If you don't have GNU tar, set this
to nil: a pipe using `zcat' or `gunzip -c' will be used."
;; Changed from system-type test to testing --version output.
;; Maybe test --help for -z instead?
:group 'dired-guess
:type '(choice (const :tag "Not GNU tar" nil)
(string :tag "Command name"))
:version "29.1")
(defcustom dired-guess-shell-gzip-quiet t
"Non-nil says pass -q to gzip overriding verbose GZIP environment."
:group 'dired-guess
:type 'boolean
:version "29.1")
(defcustom dired-guess-shell-znew-switches nil
"If non-nil, then string of switches passed to `znew', example: \"-K\"."
:group 'dired-guess
:type '(choice (const :tag "None" nil)
(string :tag "Switches"))
:version "29.1")
(defcustom dired-movement-style nil
"Non-nil means point skips empty lines when moving in Dired buffers.
This affects only `dired-next-line', `dired-previous-line',
`dired-next-dirline', `dired-prev-dirline'.
Possible non-nil values:
* `cycle': when moving from the last/first visible line, cycle back
to the first/last visible line.
* `bounded': don't move up/down if the current line is the
first/last visible line.
* `cycle-files': like `cycle' but moves only over file lines.
* `bounded-files': like `bounded' but moves only over file lines.
Any other non-nil value is treated as `bounded'."
:type '(choice (const :tag "Move to any line" nil)
(const :tag "Cycle through non-empty lines" cycle)
(const :tag "Cycle through file lines" cycle-files)
(const :tag "Stop on last/first non-empty line" bounded)
(const :tag "Stop on last/first file line" bounded-files))
:group 'dired
:version "30.1")
(defcustom dired-hide-details-preserved-columns nil
"List of columns which are not hidden in `dired-hide-details-mode'."
:type '(repeat integer)
:group 'dired
:version "30.1")
(defcustom dired-filename-display-length nil
"If non-nil, restrict the display length of filenames.
If the value is the symbol `window', the right edge of current
window is used as the restriction. Otherwise, it should be an
integer representing the maximum filename length.
The middle part of filename whose length exceeds the restriction
is hidden by using the `invisible' property and an ellipsis is
displayed instead."
:type '(choice (const :tag "No restriction" nil)
(const :tag "Window" window)
(integer :tag "Integer"))
:group 'dired
:version "30.1")
;;; Internal variables
(defvar dired-marker-char ?* ; the answer is 42
;; so that you can write things like
;; (let ((dired-marker-char ?X))
;; ;; great code using X markers ...
;; )
;; For example, commands operating on two sets of files, A and B.
;; Or marking files with digits 0-9. This could implicate
;; concentric sets or an order for the marked files.
;; The code depends on dynamic scoping on the marker char.
"In Dired, the current mark character.
This is what the do-commands look for, and what the mark-commands store.")
(defvar dired-del-marker ?D
"Character used to flag files for deletion.")
(defvar dired-file-version-alist)
;;;###autoload
(defvar-local dired-directory nil
"The directory name or wildcard spec that this Dired directory lists.
Local to each Dired buffer. May be a list, in which case the car is the
directory name and the cdr is the list of files to mention.
The directory name must be absolute, but need not be fully expanded.")
;; Beware of "-l;reboot" etc. See bug#3230.
(defun dired-safe-switches-p (switches)
"Return non-nil if string SWITCHES does not look risky for Dired."
(or (not switches)
(and (stringp switches)
(< (length switches) 100) ; arbitrary
(string-match-p "\\` *-[- [:alnum:]]+\\'" switches))))
(defvar dired-actual-switches nil
"The value of `dired-listing-switches' used to make this buffer's text.")
(put 'dired-actual-switches 'safe-local-variable 'dired-safe-switches-p)
(defvar dired-re-inode-size "[0-9 \t]*[.,0-9]*[BkKMGTPEZYRQ]?[ \t]*"
"Regexp for optional initial inode and file size as made by `ls -i -s'.")
;; These regexps must be tested at beginning-of-line, but are also
;; used to search for next matches, so neither omitting "^" nor
;; replacing "^" by "\n" (to make it slightly faster) will work.
(defvar dired-re-mark "^[^ \n]")
;; "Regexp matching a marked line.
;; Important: the match ends just after the marker."
(defvar dired-re-maybe-mark "^. ")
;; The [^:] part after "d" and "l" is to avoid confusion with the
;; DOS/Windows-style drive letters in directory names, like in "d:/foo".
(defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d[^:]"))
(defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l[^:]"))
(defvar dired-re-special (concat dired-re-maybe-mark dired-re-inode-size
"[bcsp][^:]"))
(defvar dired-re-exe;; match ls permission string of an executable file
(mapconcat (lambda (x)
(concat dired-re-maybe-mark dired-re-inode-size x))
'("-[-r][-w][xs][-r][-w].[-r][-w]."
"-[-r][-w].[-r][-w][xs][-r][-w]."
"-[-r][-w].[-r][-w].[-r][-w][xst]")
"\\|"))
(defvar dired-re-perms "[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
(defvar dired-re-dot "^.* \\.\\.?/?$")
;; The subdirectory names in the next two lists are expanded.
(defvar-local dired-subdir-alist nil
"Alist of listed directories and their buffer positions.
Alist elements have the form (DIRNAME . STARTMARKER), where
DIRNAME is the absolute name of the directory and STARTMARKER is
a marker at the beginning of DIRNAME.
The order of elements is the reverse of the order in the buffer.
If no subdirectories are listed then the alist contains only one
element, for the listed directory.")
(defvar-local dired-switches-alist nil
"Keeps track of which switches to use for inserted subdirectories.
This is an alist of the form (SUBDIR . SWITCHES).")
(defvar dired-subdir-regexp "^. \\(.+\\)\\(:\\)\n"
"Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
Subexpression 1 is the subdirectory proper, no trailing colon.
The match starts at the beginning of the line and ends after the end
of the line.
Subexpression 2 must end right before the \\n.")
;;; Faces
(defgroup dired-faces nil
"Faces used by Dired."
:group 'dired
:group 'faces)
(defface dired-header
'((t (:inherit font-lock-type-face)))
"Face used for directory headers."
:group 'dired-faces
:version "22.1")
(defvar dired-header-face 'dired-header
"Face name used for directory headers.")
(defface dired-mark
'((t (:inherit font-lock-constant-face)))
"Face used for Dired marks."
:group 'dired-faces
:version "22.1")
(defvar dired-mark-face 'dired-mark
"Face name used for Dired marks.")
(defface dired-marked
'((t (:inherit warning)))
"Face used for marked files."
:group 'dired-faces
:version "22.1")
(defvar dired-marked-face 'dired-marked
"Face name used for marked files.")
(defface dired-flagged
'((t (:inherit error)))
"Face used for files flagged for deletion."
:group 'dired-faces
:version "22.1")
(defvar dired-flagged-face 'dired-flagged
"Face name used for files flagged for deletion.")
(defface dired-warning
;; Inherit from font-lock-warning-face since with min-colors 8
;; font-lock-comment-face is not colored any more.
'((t (:inherit font-lock-warning-face)))
"Face used to highlight a part of a buffer that needs user attention."
:group 'dired-faces
:version "22.1")
(defvar dired-warning-face 'dired-warning
"Face name used for a part of a buffer that needs user attention.")
(defface dired-perm-write
'((((type w32 pc)) :inherit default) ;; These default to rw-rw-rw.
;; Inherit from font-lock-comment-delimiter-face since with min-colors 8
;; font-lock-comment-face is not colored any more.
(t (:inherit font-lock-comment-delimiter-face)))
"Face used to highlight permissions of group- and world-writable files."
:group 'dired-faces
:version "22.2")
(defvar dired-perm-write-face 'dired-perm-write
"Face name used for permissions of group- and world-writable files.")
(defface dired-set-id
'((((type w32 pc)) :inherit default) ;; These default to rw-rw-rw.
(t (:inherit font-lock-warning-face)))
"Face used to highlight permissions of suid and guid files."
:group 'dired-faces
:version "27.1")
(defface dired-directory
'((t (:inherit font-lock-function-name-face)))
"Face used for subdirectories."
:group 'dired-faces
:version "22.1")
(defvar dired-directory-face 'dired-directory
"Face name used for subdirectories.")
(defface dired-symlink
'((t (:inherit font-lock-keyword-face)))
"Face used for symbolic links."
:group 'dired-faces
:version "22.1")
(defvar dired-symlink-face 'dired-symlink
"Face name used for symbolic links.")
(defface dired-broken-symlink
'((((class color))
:foreground "yellow1" :background "red1" :weight bold)
(t :weight bold :slant italic :underline t))
"Face used for broken symbolic links."
:group 'dired-faces
:version "28.1")
(defface dired-special
'((t (:inherit font-lock-variable-name-face)))
"Face used for sockets, pipes, block devices and char devices."
:group 'dired-faces
:version "27.1")
(defface dired-ignored
'((t (:inherit shadow)))
"Face used for files suffixed with `completion-ignored-extensions'."
:group 'dired-faces
:version "22.1")
(defvar dired-ignored-face 'dired-ignored
"Face name used for files suffixed with `completion-ignored-extensions'.")
;;; Font-lock
(defcustom dired-check-symlinks t
"Whether symlinks are checked for validity.
Set it to nil for remote directories, which suffer from a slow connection."
:type 'boolean
:group 'dired
:version "31.1")
(defvar dired-font-lock-keywords
(list
;;
;; Dired marks.
(list dired-re-mark '(0 dired-mark-face))
;;
;; We make heavy use of MATCH-ANCHORED, since the regexps don't identify the
;; file name itself. We search for Dired defined regexps, and then use the
;; Dired defined function `dired-move-to-filename' before searching for the
;; simple regexp ".+". It is that regexp which matches the file name.
;;
;; Marked files.
(list (concat "^[" (char-to-string dired-marker-char) "]")
'(".+" (dired-move-to-filename) nil (0 dired-marked-face)))
;;
;; Flagged files.
(list (concat "^[" (char-to-string dired-del-marker) "]")
'(".+" (dired-move-to-filename) nil (0 dired-flagged-face)))
;; People who are paranoid about security would consider this more
;; important than other things such as whether it is a directory.
;; But we don't want to encourage paranoia, so our default
;; should be what's most useful for non-paranoids. -- rms.
;;; ;;
;;; ;; Files that are group or world writable.
;;; (list (concat dired-re-maybe-mark dired-re-inode-size
;;; "\\([-d]\\(....w....\\|.......w.\\)\\)")
;;; '(1 dired-warning-face)
;;; '(".+" (dired-move-to-filename) nil (0 dired-warning-face)))
;; However, we don't need to highlight the file name, only the
;; permissions, to win generally. -- fx.
;; Fixme: we could also put text properties on the permission
;; fields with keymaps to frob the permissions, somewhat a la XEmacs.
(list (concat dired-re-maybe-mark dired-re-inode-size
"[-d]....\\(w\\)....") ; group writable
'(1 dired-perm-write-face))
(list (concat dired-re-maybe-mark dired-re-inode-size
"[-d].......\\(w\\).") ; world writable
'(1 dired-perm-write-face))
(list (concat dired-re-maybe-mark dired-re-inode-size
"[-d]..\\(s\\)......") ; suid
'(1 'dired-set-id))
(list (concat dired-re-maybe-mark dired-re-inode-size
"[-d].....\\([sS]\\)...") ; guid
'(1 'dired-set-id))
;;
;; Subdirectories.
(list dired-re-dir
'(".+" (dired-move-to-filename) nil (0 dired-directory-face)))
;;
;; Files suffixed with `completion-ignored-extensions'.
'(eval .
;; It is quicker to first find just an extension, then go back to the
;; start of that file name. So we do this complex MATCH-ANCHORED form.
(list (concat
"\\(" (regexp-opt completion-ignored-extensions)
"\\|#\\|\\.#.+\\)$")
'(".+" (dired-move-to-filename) nil (0 dired-ignored-face))))
;;
;; Files suffixed with `completion-ignored-extensions'
;; plus a character put in by -F.
'(eval .
(list (concat "\\(" (regexp-opt completion-ignored-extensions)
"\\|#\\|\\.#.+\\)[*=|]$")
'(".+" (progn
(end-of-line)
;; If the last character is not part of the filename,
;; move back to the start of the filename
;; so it can be fontified.
;; Otherwise, leave point at the end of the line;
;; that way, nothing is fontified.
(unless (get-text-property (1- (point)) 'mouse-face)
(dired-move-to-filename)))
nil (0 dired-ignored-face))))
;;
;; Broken Symbolic link.
(list dired-re-sym
(list (lambda (end)
(when (connection-local-value dired-check-symlinks)
(let* ((file (dired-file-name-at-point))
(truename (ignore-errors (file-truename file))))
;; either not existent target or circular link
(and (not (and truename (file-exists-p truename)))
(search-forward-regexp
"\\(.+\\) \\(->\\) ?\\(.+\\)" end t)))))
'(dired-move-to-filename)
nil
'(1 'dired-broken-symlink)
'(2 dired-symlink-face)
'(3 '(face dired-broken-symlink dired-symlink-filename t))))
;;
;; Symbolic link to a directory.
(list dired-re-sym
(list (lambda (end)
(when (connection-local-value dired-check-symlinks)
(when-let* ((file (dired-file-name-at-point))
(truename (ignore-errors (file-truename file))))
(and (file-directory-p truename)
(search-forward-regexp
"\\(.+-> ?\\)\\(.+\\)" end t)))))
'(dired-move-to-filename)
nil
'(1 dired-symlink-face)
'(2 `(face ,dired-directory-face dired-symlink-filename t))))
;;
;; Symbolic link to a non-directory. Or no check at all.
(list dired-re-sym
(list (lambda (end)
(if (not (connection-local-value dired-check-symlinks))
(search-forward-regexp
"\\(.+-> ?\\)\\(.+\\)" end t)
(when-let* ((file (dired-file-name-at-point)))
(let ((truename (ignore-errors (file-truename file))))
(and (or (not truename)
(not (file-directory-p truename)))
(search-forward-regexp
"\\(.+-> ?\\)\\(.+\\)" end t))))))
'(dired-move-to-filename)
nil
'(1 dired-symlink-face)
'(2 '(face default dired-symlink-filename t))))
;;
;; Sockets, pipes, block devices, char devices.
(list dired-re-special
'(".+" (dired-move-to-filename) nil (0 'dired-special)))
;;
;; Explicitly put the default face on file names ending in a colon to
;; avoid fontifying them as directory header.
(list (concat dired-re-maybe-mark dired-re-inode-size dired-re-perms ".*:$")
'(".+" (dired-move-to-filename) nil (0 'default)))
;;
;; Directory headers.
(list dired-subdir-regexp '(1 dired-header-face))
)
"Additional expressions to highlight in Dired mode.")
(defvar dnd-protocol-alist)
;;; Macros
;; Macros must be defined before they are used, for the byte compiler.
(defmacro dired-mark-if (predicate msg)
"Mark files for PREDICATE, according to `dired-marker-char'.
PREDICATE is evaluated on each line, with point at beginning of line.
MSG is a noun phrase for the type of files being marked.
It should end with a noun that can be pluralized by adding `s'.
In Transient Mark mode, if the mark is active, operate on the contents
of the region if `dired-mark-region' is non-nil. Otherwise, operate
on the whole buffer.
Return value is the number of files marked, or nil if none were marked."
`(let ((msg ,msg)
(inhibit-read-only t) count
(use-region-p (dired-mark--region-use-p))
(beg (dired-mark--region-beginning))
(end (dired-mark--region-end)))
(save-excursion
(setq count 0)
(when msg
(message "%s %ss%s%s..."
(cond ((eq dired-marker-char ?\s) "Unmarking")
((eq dired-del-marker dired-marker-char)
"Flagging")
(t "Marking"))
msg
(if (eq dired-del-marker dired-marker-char)
" for deletion"
"")
(if use-region-p
" in region"
"")))
(goto-char beg)
(while (< (point) end)
(when ,predicate
(unless (= (following-char) dired-marker-char)
(delete-char 1)
(insert dired-marker-char)
(setq count (1+ count))))
(forward-line 1))
(when msg (message "%s %s%s %s%s%s"
count
msg
(dired-plural-s count)
(if (eq dired-marker-char ?\s) "un" "")
(if (eq dired-marker-char dired-del-marker)
"flagged" "marked")
(if use-region-p
" in region"
""))))
(and (> count 0) count)))
(defmacro dired-map-over-marks (body arg &optional show-progress
distinguish-one-marked)
"Eval BODY with point on each marked line. Return a list of BODY's results.
If no marked file could be found, execute BODY on the current
line. ARG, if non-nil, specifies the files to use instead of the
marked files.
If ARG is an integer, use the next ARG (or previous -ARG, if
ARG<0) files. In that case, point is dragged along. This is so
that commands on the next ARG (instead of the marked) files can
be chained easily.
For any other non-nil value of ARG, use the current file.
If ARG is `marked', don't return the current file if nothing else
is marked.
If optional third arg SHOW-PROGRESS evaluates to non-nil,
redisplay the Dired buffer after each file is processed.
No guarantee is made about the position on the marked line.
BODY must ensure this itself if it depends on this.
Search starts at the beginning of the buffer, thus the car of the
list corresponds to the line nearest to the buffer's bottom.
This is also true for (positive and negative) integer values of
ARG.
BODY should not be too long as it is expanded four times.
If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one
marked file, return (t FILENAME) instead of (FILENAME)."
;;
;;Warning: BODY must not add new lines before point - this may cause an
;;endless loop.
;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
`(prog1
(inhibit-auto-revert
(let ((inhibit-read-only t)
case-fold-search found results)
(if (and ,arg (not (eq ,arg 'marked)))
(if (integerp ,arg)
(progn ;; no save-excursion, want to move point.
(dired-repeat-over-lines
,arg
(lambda ()
(if ,show-progress (sit-for 0))
(setq results (cons ,body results))))
(when (< ,arg 0)
(setq results (nreverse results)))
results)