-
Notifications
You must be signed in to change notification settings - Fork 15
/
sunrise-commander.el
3947 lines (3503 loc) · 158 KB
/
sunrise-commander.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
;;; sunrise-commander.el --- two-pane file manager for Emacs based on Dired and inspired by MC
;; Copyright (C) 2007-2011 José Alfredo Romero Latouche.
;; Author: José Alfredo Romero L. <[email protected]>
;; Štěpán Němec <[email protected]>
;; Maintainer: José Alfredo Romero L. <[email protected]>
;; Created: 24 Sep 2007
;; Version: 5
;; RCS Version: $Rev: 379 $
;; Keywords: files, dired, midnight commander, norton, orthodox
;; URL: http://www.emacswiki.org/emacs/sunrise-commander.el
;; Compatibility: GNU Emacs 22+
;; 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 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 de-
;; tails.
;; You should have received a copy of the GNU General Public License along with
;; this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Here is another two-pane mc emulation layer for Emacs. It's built on top of
;; Dired and takes advantage of all its features, offering at the same time the
;; double pane interface I'd been missing so badly since I started using regu-
;; larly Emacs (for everything!). I tried both Ilya Zakharevich's nc.el and
;; Kevin Burton's mc.el, but none of them was what I was looking for (though
;; mc.el was near the ideal).
;; A lot of this code was once adapted from Kevin's mc.el, but it has evolved
;; quite a bit since then. Another part (the code for file copying and renaming)
;; derives originally from the Dired extensions written by Kurt Nørmark for LAML
;; (http://www.cs.aau.dk/~normark/scheme/distribution/laml/).
;; I have added to the mix several useful functions:
;; * Sunrise is implemented as a derived major mode confined inside the pane
;; buffers, so its buffers and Dired ones can live together without easymenu or
;; viper to avoid key binding collisions.
;; * It automatically closes unused buffers and tries to never keep open more
;; than the one or two used to display the panes.
;; * Each pane has its own history ring: press M-y / M-u for moving backwards /
;; forwards in the history of directories.
;; * Press M-t to swap (transpose) the panes.
;; * Press C-= for "smart" file comparison using `ediff'. It compares together
;; the first two files marked on each pane or, if no files have been marked, it
;; as- sumes that the second pane contains a file with the same name as the
;; selected one and tries to compare these two. You can also mark whole lists of
;; files to be compared and then just press C-= for comparing the next pair.
;; * Press = for fast "smart" file comparison -- like above, but using regular
;; diff.
;; * Press C-M-= for directory comparison (by date / size / contents of files).
;; * Press C-c C-s to change the layout of the panes (horizontal/vertical/top)
;; * Press C-c / to interactively refine the contents of the current pane using
;; fuzzy (a.k.a. flex) matching, then:
;; - press Delete or Backspace to revert the buffer to its previous state
;; - press Return, C-n or C-p to exit and accept the current narrowed state
;; - press Esc or C-g to abort the operation and revert the buffer
;; - use ! to prefix characters that should NOT appear after a given position
;; Once narrowed and accepted, you can restore the original contents of the pane
;; by pressing g (revert-buffer).
;; * Press C-x C-q to put the current pane in Editable Dired mode (allows to
;; edit the pane as if it were a regular file -- press C-c C-c to commit your
;; changes to the filesystem, or C-c C-k to abort).
;; * Press y to recursively calculate the total size (in bytes) of all files and
;; directories currently selected/marked in the active pane.
;; * Sunrise VIRTUAL mode integrates dired-virtual mode to Sunrise, allowing to
;; capture find and locate results in regular files and to use them later as if
;; they were directories with all Dired and Sunrise operations at your
;; fingertips.
;; The results of the following operations are displayed in VIRTUAL mode:
;; - find-name-dired (press C-c C-n),
;; - find-grep-dired (press C-c C-g),
;; - find-dired (press C-c C-f),
;; - locate (press C-c C-l),
;; - list all recently visited files (press C-c C-r -- requires recentf),
;; - list all directories in active pane's history ring (press C-c C-d).
;; * Supports AVFS (http://www.inf.bme.hu/~mszeredi/avfs/) for transparent navi-
;; gation inside compressed archives (*.zip, *.tgz, *.tar.bz2, *.deb, etc. etc.)
;; You need to have AVFS with coda or fuse installed and running on your system
;; for this to work, though.
;; * Opening terminals directly from Sunrise:
;; - Press C-c C-t to inconditionally open a new terminal into the currently
;; selected directory in the active pane.
;; - Press C-c t to switch to the last opened terminal.
;; - Press C-c T to switch to the last opened terminal and change directory
;; to the one in the current directory.
;; * Terminal integration and Command line expansion: integrates tightly with
;; `eshell' or `term-mode' to allow interaction between terminal emulators in
;; line mode (C-c C-j) and the panes: the most important navigation commands
;; (up, down, mark, unmark, go to parent dir) can be executed on the active pane
;; directly from the terminal by pressing the usual keys with Meta: <M-up>,
;; <M-down>, etc. Additionally, the following substitutions are automagically
;; performed in `term-line-mode':
;; %f - expands to the currently selected file in the left pane
;; %F - expands to the currently selected file in the right pane
;; %m - expands to the list of paths of all marked files in the left pane
;; %M - expands to the list of paths of all marked files in the right pane
;; %n - expands to the list of names of all marked files in the left pane
;; %N - expands to the list of names of all marked files in the right pane
;; %d - expands to the current directory in the left pane
;; %D - expands to the current directory in the right pane
;; * Cloning of complete directory trees: press K to clone the selected files
;; and directories into the passive pane. Cloning is a more general operation
;; than copying, in which all directories are recursively created with the same
;; names and structures at the destination, while what happens to the files
;; within them depends on the option you choose:
;; - "(D)irectories only" ignores all files, copies only directories,
;; - "(C)opies" performs a regular recursive copy of all files and dirs,
;; - "(H)ardlinks" makes every new file a (hard) link to the original one
;; - "(S)ymlinks" creates absolute symbolic links for all files in the tree,
;; - "(R)elative symlinks” creates relative symbolic links.
;; * Passive navigation: the usual navigation keys (n, p, Return, U, ;) combined
;; with Meta allow to move across the passive pane without actually having to
;; switch to it.
;; * Synchronized navigation: press C-c C-z to enable / disable synchronized
;; navigation. In this mode, the passive navigation keys (M-n, M-p, M-Return,
;; etc.) operate on both panes simultaneously. I've found this quite useful for
;; comparing hierarchically small to medium-sized directory trees (for large to
;; very large directory trees one needs something on the lines of diff -r
;; though).
;; * Sticky search: press C-c s to launch an interactive search that will remain
;; active from directory to directory, until you hit a regular file or press C-g
;; to abort the operation.
;; * etc. ;-)
;; It doesn't even try to look like MC, so the help window is gone (you're in
;; Emacs, so you know your bindings, right?), though if you really miss it, just
;; get and install the sunrise-x-buttons extension.
;; It was written on GNU Emacs 23 on Linux, and tested on GNU Emacs 22 and 23
;; for Linux and on EmacsW32 (version 23) for Windows. I have also received
;; feedback from a user reporting it works OK on the Mac (GNU Emacs 22.2 on Mac
;; OS X Leopard). I *am* aware that there are several functions (including,
;; alas, file and directory comparison) that simply will not work on GNU Emacs
;; 21, but unfortunately I do not have the time to port them back. It doesn't
;; work either on XEmacs -- please drop me a line if you would like to help
;; porting it. All contributions and/or bug reports will be very welcome.
;; For more details on the file manager, extensions and cool tips & tricks visit
;; http://www.emacswiki.org/emacs/Sunrise_Commander
;;; Installation and Usage:
;; 1) Put this file somewhere in your Emacs `load-path'.
;; 2) Add a (require 'sunrise-commander) to your .emacs file.
;; 3) Choose some unused extension for files to be opened in Sunrise VIRTUAL
;; mode and add it to `auto-mode-alist', e.g. if you want to name your virtual
;; directories like *.svrm just add to your .emacs file a line like the
;; following:
;;
;; (add-to-list 'auto-mode-alist '("\\.srvm\\'" . sr-virtual-mode))
;; 4) Evaluate the new lines, or reload your .emacs file, or restart Emacs.
;; 5) Type M-x sunrise to invoke the Sunrise Commander (or much better: bind the
;; function to your favorite key combination). The command `sunrise-cd' invokes
;; Sunrise and automatically selects the current file wherever it is in the
;; filesystem. Type h at any moment for information on available key bindings.
;; 6) Type M-x customize-group <RET> sunrise <RET> to customize options, fonts
;; and colors (activate AVFS support here, too).
;; 7) Enjoy :)
;;; Code:
(require 'dired)
(require 'dired-x)
(require 'enriched)
(require 'find-dired)
(require 'font-lock)
(require 'sort)
(require 'term)
(eval-when-compile (require 'cl)
(require 'desktop)
(require 'dired-aux)
(require 'esh-mode)
(require 'recentf))
(defgroup sunrise nil
"The Sunrise Commander File Manager."
:group 'files)
(defcustom sr-show-file-attributes t
"Whether to initially display file attributes in Sunrise panes.
You can always toggle file attributes display pressing \\<sr-mode-map>\\[sr-toggle-attributes]."
:group 'sunrise
:type 'boolean)
(defcustom sr-show-hidden-files nil
"Whether to initially display hidden files in Sunrise panes.
You can always toggle hidden files display pressing \\<sr-mode-map>\\[dired-omit-mode].
You can also customize what files are considered hidden by setting
`dired-omit-files' and `dired-omit-extensions' in your .emacs file."
:group 'sunrise
:type 'boolean)
(defcustom sr-terminal-kill-buffer-on-exit t
"Whether to kill terminal buffers after their shell process ends."
:group 'sunrise
:type 'boolean)
(defcustom sr-terminal-program "eshell"
"The program to use for terminal emulation.
If this value is set to \"eshell\", the Emacs shell (`eshell')
will be used."
:group 'sunrise
:type 'string)
(defcustom sr-listing-switches "-al"
"Listing switches passed to `ls' when building Sunrise buffers.
\(Cf. `dired-listing-switches'.)
Most portable value: -al
Recommended value on GNU systems: \
--time-style=locale --group-directories-first -alDhgG"
:group 'sunrise
:type 'string)
(defcustom sr-virtual-listing-switches "-ald"
"Listing switches for building buffers in `sr-virtual-mode'.
Should not contain the -D option. See also `sr-listing-switches'."
:group 'sunrise
:type 'string)
(defcustom sr-avfs-root nil
"Root of the AVFS virtual filesystem used for navigating compressed archives.
Setting this value activates AVFS support."
:group 'sunrise
:type '(choice
(const :tag "AVFS support disabled" nil)
(directory :tag "AVFS root directory")))
(defcustom sr-avfs-handlers-alist '(("\\.[jwesh]ar$" . "#uzip/")
("\\.xpi$" . "#uzip/")
("\\.iso$" . "#iso9660/")
("\\.patch$" . "#/")
("." . "#/"))
"List of AVFS handlers to manage specific file extensions."
:group 'sunrise
:type 'alist)
(defcustom sr-md5-shell-command "md5sum %f | cut -d' ' -f1 2>/dev/null"
"Shell command to use for calculating MD5 sums for files.
Used when comparing directories using the ``(c)ontents'' option.
Use %f as a placeholder for the name of the file."
:group 'sunrise
:type 'string)
(defcustom sr-window-split-style 'horizontal
"The current window split configuration.
May be `horizontal', `vertical' or `top'."
:group 'sunrise
:type '(choice
(const horizontal)
(const vertical)
(const top)))
(defcustom sr-windows-locked t
"When non-nil, vertical size of the panes will remain constant."
:group 'sunrise
:type 'boolean)
(defcustom sr-history-length 20
"Number of entries to keep in each pane's history rings."
:group 'sunrise
:type 'integer)
(defcustom sr-fuzzy-negation-character ?!
"Character to use for negating patterns when fuzzy-narrowing a pane."
:group 'sunrise
:type '(choice
(const :tag "Fuzzy matching negation disabled" nil)
(character :tag "Fuzzy matching negation character" ?!)))
(defcustom sr-init-hook nil
"List of functions to be called before the Sunrise panes are displayed."
:group 'sunrise
:type 'hook
:options '(auto-insert))
(defcustom sr-start-hook nil
"List of functions to be called after the Sunrise panes are displayed."
:group 'sunrise
:type 'hook
:options '(auto-insert))
(defcustom sr-refresh-hook nil
"List of functions to be called every time a pane is refreshed."
:group 'sunrise
:type 'hook
:options '(auto-insert))
(defcustom sr-quit-hook nil
"List of functions to be called after the Sunrise panes are hidden."
:group 'sunrise
:type 'hook
:options '(auto-insert))
(defvar sr-restore-buffer nil
"Buffer to restore when Sunrise quits.")
(defvar sr-prior-window-configuration nil
"Window configuration before Sunrise was started.")
(defvar sr-running nil "True when Sunrise commander mode is running.")
(defvar sr-synchronized nil "True when synchronized navigation is on")
(defvar sr-current-window-overlay nil
"Holds the current overlay which marks the current Dired buffer.")
(defvar sr-clex-hotchar-overlay nil
"Overlay used to highlight the hot character (%) during CLEX operations.")
(defvar sr-left-directory "~/"
"Dired directory for the left window. See the variable `dired-directory'.")
(defvar sr-left-buffer nil
"Dired buffer for the left window.")
(defvar sr-left-window nil
"The left window of Dired.")
(defvar sr-right-directory "~/"
"Dired directory for the right window. See variable `dired-directory'.")
(defvar sr-right-buffer nil
"Dired buffer for the right window.")
(defvar sr-right-window nil
"The right window of Dired.")
(defvar sr-current-frame nil
"The frame Sunrise is active on (if any).")
(defvar sr-this-directory "~/"
"Dired directory in the active pane.
This isn't necessarily the same as `dired-directory'.")
(defvar sr-other-directory "~/"
"Dired directory in the passive pane.")
(defvar sr-selected-window 'left
"The window to select when Sunrise starts up.")
(defvar sr-selected-window-width nil
"The width the selected window should have on startup.")
(defvar sr-history-registry '((left)(right))
"Registry of visited directories for both panes.")
(defvar sr-ti-openterms nil
"Stack of currently open terminal buffers.")
(defvar sr-ediff-on nil
"Flag that indicates whether an `ediff' is being currently done.")
(defvar sr-clex-on nil
"Flag that indicates that a CLEX operation is taking place.")
(defvar sr-virtual-buffer nil
"Local flag that indicates the current buffer was originally in VIRTUAL mode.")
(defvar sr-dired-directory ""
"Directory inside which `sr-mode' is currently active.")
(defvar sr-start-message
"Been coding all night? Enjoy the Sunrise! (or press q to quit)"
"Message to display when Sunrise is started.")
(defvar sr-panes-height nil
"Current height of the pane windows.
Initial value is 2/3 the viewport height.")
(defvar sr-current-path-face 'sr-active-path-face
"Default face of the directory path (can be overridden buffer-locally).")
(defvar sr-desktop-save-handlers nil
"List of extension-defined handlers to save Sunrise buffers with desktop.")
(defvar sr-desktop-restore-handlers nil
"List of extension-defined handlers to restore Sunrise buffers from desktop.")
(defvar sr-backup-buffer nil
"Variable holding a buffer-local value of the backup buffer.")
(defvar sr-goto-dir-function nil
"Function to use to navigate to a given directory, or nil to do the default.
The function receives one argument DIR, which is the directory to go to.")
(defconst sr-side-lookup (list '(left . right) '(right . left))
"Trivial alist used by the Sunrise Commander to lookup its own passive side.")
(defface sr-active-path-face
'((((type tty) (class color) (min-colors 8))
:background "green" :foreground "yellow" :bold t)
(((type tty) (class mono)) :inverse-video t)
(t :background "#ace6ac" :foreground "yellow" :bold t :height 120))
"Face of the directory path in the active pane."
:group 'sunrise)
(defface sr-passive-path-face
'((((type tty) (class color) (min-colors 8) (background dark))
:background "black" :foreground "cyan")
(((type tty) (class color) (min-colors 8) (background light))
:background "white" :foreground "cyan")
(t :background "white" :foreground "lightgray" :bold t :height 120))
"Face of the directory path in the passive pane."
:group 'sunrise)
(defface sr-editing-path-face
'((t :background "red" :foreground "yellow" :bold t :height 120))
"Face of the directory path in the active pane while in editable pane mode."
:group 'sunrise)
(defface sr-highlight-path-face
'((t :background "yellow" :foreground "#ace6ac" :bold t :height 120))
"Face of the directory path on mouse hover."
:group 'sunrise)
(defface sr-broken-link-face
'((t :foreground "red" :italic t))
"Face to highlight broken symbolic links."
:group 'sunrise)
(defface sr-clex-hotchar-face
'((t :foreground "red" :bold t))
"Face of the hot character (%) in CLEX mode.
Indicates that a CLEX substitution may be about to happen."
:group 'sunrise)
;;; ============================================================================
;;; This is the core of Sunrise: the main idea is to apply `sr-mode' only inside
;;; Sunrise buffers while keeping all of `dired-mode' untouched.
(define-derived-mode sr-mode dired-mode "Sunrise Commander"
"Two-pane file manager for Emacs based on Dired and inspired by MC.
The following keybindings are available:
/, j .......... go to directory
p, n .......... move cursor up/down
M-p, M-n ...... move cursor up/down in passive pane
^, J .......... go to parent directory
M-^, M-J ...... go to parent directory in passive pane
Tab ........... switch to other pane
C-Tab.......... switch to viewer window
C-c Tab ....... switch to viewer window (console compatible)
RET, f ........ visit selected file/directory
M-RET, M-f .... visit selected file/directory in passive pane
C-c RET ....... visit selected in passive pane (console compatible)
b ............. visit selected file/directory in default browser
F ............. visit all marked files, each in its own window
C-u F ......... visit all marked files in the background
o,v ........... quick visit selected file (scroll with C-M-v, C-M-S-v)
C-u o, C-u v .. kill quick-visited buffer (restores normal scrolling)
X ............. execute selected file
C-u X.......... execute selected file with arguments
+ ............. create new directory
M-+ ........... create new empty file(s)
C ............. copy marked (or current) files and directories
R ............. rename marked (or current) files and directories
D ............. delete marked (or current) files and directories
S ............. soft-link selected file/directory to passive pane
Y ............. do relative soft-link of selected file in passive pane
H ............. hard-link selected file to passive pane
K ............. clone selected files and directories into passive pane
M-C ........... copy (using traditional dired-do-copy)
M-R ........... rename (using traditional dired-do-rename)
M-D ........... delete (using traditional dired-do-delete)
M-S............ soft-link (using traditional dired-do-symlink)
M-Y............ do relative soft-link (with traditional dired-do-relsymlink)
M-H............ hard-link selected file/directory (with dired-do-hardlink)
A ............. search marked files for regular expression
Q ............. perform query-replace-regexp on marked files
C-c s ......... start a \"sticky\" interactive search in the current pane
M-a ........... move to beginning of current directory
M-e ........... move to end of current directory
M-y ........... go to previous directory in history
M-u ........... go to next directory in history
C-M-y ......... go to previous directory in history on passive pane
C-M-u ......... go to next directory in history on passive pane
g, C-c C-c .... refresh pane
s ............. sort entries (by name, number, size, time or extension)
r ............. reverse the order of entries in the active pane (sticky)
C-o ........... show/hide hidden files (requires dired-omit-mode)
C-Backspace ... hide/show file attributes in pane
C-c Backspace . hide/show file attributes in pane (console compatible)
y ............. show file type / size of selected files and directories.
M-l ........... truncate/continue long lines in pane
C-c v ......... put current panel in VIRTUAL mode
C-c C-v ....... create new pure VIRTUAL buffer
C-c C-w ....... browse directory tree using w3m
M-t ........... transpose panes
M-o ........... synchronize panes
C-c C-s ....... change panes layout (vertical/horizontal/top-only)
[ ............. enlarges the right pane by 5 columns
] ............. enlarges the left pane by 5 columns
} ............. enlarges both panes vertically by 1 row
C-} ........... enlarges both panes vertically as much as it can
C-c } ......... enlarges both panes vertically as much as it can
{ ............. shrinks both panes vertically by 1 row
C-{ ........... shrinks both panes vertically as much as it can
C-c { ......... shrinks both panes vertically as much as it can
\\ ............. sets size of all windows back to «normal»
C-c C-z ....... enable/disable synchronized navigation
C-= ........... smart compare files (ediff)
C-c = ......... smart compare files (console compatible)
= ............. fast smart compare files (plain diff)
C-M-= ......... compare panes
C-x = ......... compare panes (console compatible)
C-c C-f ....... execute Find-dired in Sunrise VIRTUAL mode
C-c C-n ....... execute find-Name-dired in Sunrise VIRTUAL mode
C-c C-g ....... execute find-Grep-dired in Sunrise VIRTUAL mode
C-c C-l ....... execute Locate in Sunrise VIRTUAL mode
C-c C-r ....... browse list of Recently visited files (requires recentf)
C-c C-c ....... [after find, locate or recent] dismiss virtual buffer
C-c / ......... narrow the contents of the current pane using fuzzy matching
C-c b ......... partial Branch view of selected items in the current pane
C-c p ......... Prune paths matching regular expression from current pane
; ............. follow file (go to same directory as selected file)
M-; ........... follow file in passive pane
C-M-o ......... follow a projection of current directory in passive pane
C-> ........... save named checkpoint (a.k.a. \"bookmark panes\")
C-c > ......... save named checkpoint (console compatible)
C-. ........ restore named checkpoint
C-c . ........ restore named checkpoint
C-x C-q ....... put pane in Editable Dired mode (commit with C-c C-c)
@! ............ fast backup files (but not dirs!), each to [filename].bak
C-c t ......... open new terminal or switch to already open one
C-c T ......... open terminal AND/OR change directory to current
C-c C-t ....... open always a new terminal in current directory
C-c M-t ....... open a new terminal using an alternative shell program
q, C-x k ...... quit Sunrise Commander, restore previous window setup
M-q ........... quit Sunrise Commander, don't restore previous windows
Additionally, the following traditional commander-style keybindings are provided
\(these may be disabled by customizing the `sr-use-commander-keys' option):
F2 ............ go to directory
F3 ............ quick visit selected file
F4 ............ visit selected file
F5 ............ copy marked (or current) files and directories
F6 ............ rename marked (or current) files and directories
F7 ............ create new directory
F8 ............ delete marked (or current) files and directories
F10 ........... quit Sunrise Commander
C-F3 .......... sort contents of current pane by name
C-F4 .......... sort contents of current pane by extension
C-F5 .......... sort contents of current pane by time
C-F6 .......... sort contents of current pane by size
C-F7 .......... sort contents of current pane numerically
S-F7 .......... soft-link selected file/directory to passive pane
Insert ........ mark file
C-PgUp ........ go to parent directory
Any other dired keybinding (not overridden by any of the above) can be used in
Sunrise, like G for changing group, M for changing mode and so on.
Some more bindings are provided for terminals in line mode, most useful after
opening a terminal in the viewer window (with C-c t):
(these two are only for external shells - bash, ksh, etc. not for eshell)
C-c C-j ....... put terminal in line mode
C-c C-k ....... put terminal back in char mode
M-<up>, M-P ... move cursor up in active pane
M-<down>, M-N . move cursor down in active pane
M-Return ...... visit selected file/directory in active pane
M-J ........... go to parent directory in active pane
M-M ........... mark selected file/directory in active pane
M-Backspace ... unmark previous file/directory in active pane
M-U ........... remove all marks from active pane
C-Tab ......... switch focus to active pane
In a terminal in line mode the following substitutions are also performed
automatically:
%f - expands to the currently selected file in the left pane
%F - expands to the currently selected file in the right pane
%m - expands to the list of paths of all marked files in the left pane
%M - expands to the list of paths of all marked files in the right pane
%n - expands to the list of names of all marked files in the left pane
%N - expands to the list of names of all marked files in the right pane
%d - expands to the current directory in the left pane
%D - expands to the current directory in the right pane
%% - inserts a single % sign.
"
:group 'sunrise
(set-keymap-parent sr-mode-map dired-mode-map)
(sr-highlight)
(dired-omit-mode dired-omit-mode)
(make-local-variable 'dired-recursive-deletes)
(setq dired-recursive-deletes 'top)
(make-local-variable 'truncate-partial-width-windows)
(setq truncate-partial-width-windows (sr-truncate-v t))
(make-local-variable 'truncate-lines)
(setq truncate-lines nil)
(make-local-variable 'desktop-save-buffer)
(setq desktop-save-buffer 'sr-desktop-save-buffer)
(make-local-variable 'revert-buffer-function)
(setq revert-buffer-function 'sr-revert-buffer)
)
(define-derived-mode sr-virtual-mode dired-virtual-mode "Sunrise VIRTUAL"
"Sunrise Commander Virtual Mode. Useful for reusing find and locate results."
:group 'sunrise
(set-keymap-parent sr-virtual-mode-map sr-mode-map)
(sr-highlight)
(dired-omit-mode dired-omit-mode)
(enriched-mode -1)
(make-local-variable 'truncate-partial-width-windows)
(setq truncate-partial-width-windows (sr-truncate-v t))
(make-local-variable 'truncate-lines)
(setq truncate-lines nil)
(make-local-variable 'desktop-save-buffer)
(setq desktop-save-buffer 'sr-desktop-save-buffer)
(make-local-variable 'revert-buffer-function)
(setq revert-buffer-function 'sr-revert-buffer)
(define-key sr-virtual-mode-map "\C-c\C-c" 'sr-virtual-dismiss))
(defmacro sr-within (dir form)
"Evaluate FORM in Sunrise context."
`(unwind-protect
(progn
(setq sr-dired-directory
(file-name-as-directory (abbreviate-file-name dir)))
(ad-activate 'dired-find-buffer-nocreate)
,form)
(ad-deactivate 'dired-find-buffer-nocreate)
(setq sr-dired-directory "")))
(defmacro sr-save-aspect (&rest body)
"Restore omit mode, hidden attributes and highlighting after a directory transition."
`(let ((inhibit-read-only t)
(omit (or dired-omit-mode -1))
(hidden-attrs (not (null (get sr-selected-window 'hidden-attrs))))
(path-face sr-current-path-face))
(hl-line-mode 0)
,@body
(dired-omit-mode omit)
(if path-face
(set (make-local-variable 'sr-current-path-face) path-face))
(if (string= "NUMBER" (get sr-selected-window 'sorting-order))
(sr-sort-by-operation 'sr-numerical-sort-op))
(if (get sr-selected-window 'sorting-reverse)
(sr-reverse-pane))
(if hidden-attrs (sr-hide-attributes))
(sr-restore-point-if-same-buffer)))
(defmacro sr-alternate-buffer (form)
"Execute FORM in a new buffer, after killing the previous one."
`(let ((dispose nil))
(unless (or (not (or dired-directory (eq major-mode 'sr-tree-mode)))
(eq sr-left-buffer sr-right-buffer))
(setq dispose (current-buffer)))
,form
(setq sr-this-directory default-directory)
(sr-keep-buffer)
(sr-highlight)
(if (buffer-live-p dispose)
(with-current-buffer dispose
(bury-buffer)
(set-buffer-modified-p nil)
(unless (kill-buffer dispose)
(kill-local-variable 'sr-current-path-face))))))
(defmacro sr-in-other (form)
"Execute FORM in the context of the passive pane.
Helper macro for passive & synchronized navigation."
`(progn
(if sr-synchronized ,form)
(sr-change-window)
(condition-case description
,form
(error (message (cadr description))))
(sr-change-window)
(sr-highlight)))
(eval-and-compile
(defun sr-symbol (side type)
"Synthesize Sunrise symbols (`sr-left-buffer', `sr-right-window', etc.)."
(intern (concat "sr-" (symbol-name side) "-" (symbol-name type)))))
(defun sr-dired-mode ()
"Set Sunrise mode in every Dired buffer opened in Sunrise (called in a hook)."
(if (and sr-running
(sr-equal-dirs dired-directory default-directory)
(not (eq major-mode 'sr-mode)))
(let ((dired-listing-switches dired-listing-switches)
(sorting-options (or (get sr-selected-window 'sorting-options) "")))
(if (null (string-match "^/ftp:" default-directory))
(setq dired-listing-switches
(concat sr-listing-switches sorting-options)))
(sr-mode)
(dired-unadvertise dired-directory))))
(add-hook 'dired-before-readin-hook 'sr-dired-mode)
(defun sr-bookmark-jump ()
"Handle panes opened from bookmarks in Sunrise."
(when (and sr-running
(memq (selected-window) (list sr-left-window sr-right-window)))
(let ((last-buf (symbol-value (sr-symbol sr-selected-window 'buffer))))
(setq dired-omit-mode (with-current-buffer last-buf dired-omit-mode))
(setq sr-this-directory default-directory)
(if (sr-equal-dirs sr-this-directory sr-other-directory)
(sr-synchronize-panes t)
(revert-buffer))
(sr-keep-buffer)
(unless (memq last-buf (list (current-buffer) (sr-other 'buffer)))
(kill-buffer last-buf)))))
(add-hook 'bookmark-after-jump-hook 'sr-bookmark-jump)
(defun sr-virtualize-pane ()
"Put the current normal view in VIRTUAL mode."
(interactive)
(when (eq major-mode 'sr-mode)
(let ((focus (dired-get-filename 'verbatim t)))
(sr-virtual-mode)
(if focus (sr-focus-filename focus)))))
(defun sr-virtual-dismiss ()
"Restore normal pane view in Sunrise VIRTUAL mode."
(interactive)
(when (eq major-mode 'sr-virtual-mode)
(let ((focus (dired-get-filename 'verbatim t)))
(sr-process-kill)
(sr-save-aspect
(sr-alternate-buffer (sr-goto-dir sr-this-directory))
(if focus (sr-focus-filename focus))
(revert-buffer)))))
(defun sr-select-window (side)
"Select/highlight the given Sunrise window (right or left)."
(select-window (symbol-value (sr-symbol side 'window)))
(setq sr-selected-window side)
(setq sr-this-directory default-directory)
(sr-highlight))
(defun sr-viewer-window ()
"Return an active window that can be used as the viewer."
(if (or (memq major-mode '(sr-mode sr-virtual-mode sr-tree-mode))
(memq (current-buffer) (list sr-left-buffer sr-right-buffer)))
(let ((current-window (selected-window)) (target-window))
(dotimes (times 2)
(setq current-window (next-window current-window))
(unless (memq current-window (list sr-left-window sr-right-window))
(setq target-window current-window)))
target-window)
(selected-window)))
(defun sr-select-viewer-window (&optional force-setup)
"Select a window that is not a Sunrise pane.
If no suitable active window can be found and FORCE-SETUP is set,
calls the function `sr-setup-windows' and tries once again."
(interactive "p")
(let ((viewer (sr-viewer-window)))
(if viewer
(select-window viewer)
(when force-setup
(sr-setup-windows)
(select-window (sr-viewer-window))))))
(defun sr-backup-buffer ()
"Create a backup copy of the current buffer.
Used as a cache during revert operations."
(if (buffer-live-p sr-backup-buffer) (sr-kill-backup-buffer))
(let ((buf (current-buffer)))
(set (make-local-variable 'sr-backup-buffer)
(generate-new-buffer "*Sunrise Backup*"))
(with-current-buffer sr-backup-buffer
(insert-buffer-substring buf))
(run-hooks 'sr-refresh-hook)))
(defun sr-kill-backup-buffer ()
"Kill the backup buffer associated to the current one, if there is any."
(when (buffer-live-p sr-backup-buffer)
(kill-buffer sr-backup-buffer)
(setq sr-backup-buffer nil)))
(add-hook 'kill-buffer-hook 'sr-kill-backup-buffer)
(add-hook 'change-major-mode-hook 'sr-kill-backup-buffer)
(defun sr-insert-directory (file switches &optional wildcard full-directory-p)
(let ((beg (point)))
(insert-directory file switches wildcard full-directory-p)
(dired-align-file beg (point))
(save-excursion
(search-backward file)
(add-text-properties (point) (point-at-eol) '(dired-filename t)))))
(add-to-list 'enriched-translations '(dired-filename (t "x-dired-filename")))
(defun sr-enrich-buffer ()
"Activate `enriched-mode' before saving a Sunrise buffer to a file.
This is done so all its dired-filename attributes are kept in the file."
(if (memq major-mode '(sr-mode sr-virtual-mode))
(enriched-mode 1)))
(add-hook 'before-save-hook 'sr-enrich-buffer)
(defadvice dired-find-buffer-nocreate
(before sr-advice-findbuffer (dirname &optional mode))
"A hack to avoid some Dired mode quirks."
(if (sr-equal-dirs sr-dired-directory dirname)
(setq mode 'sr-mode)))
(defadvice dired-dwim-target-directory
(around sr-advice-dwim-target ())
"Tweak the target directory guessing mechanism."
(if sr-running
(setq ad-return-value sr-other-directory)
ad-do-it))
(ad-activate 'dired-dwim-target-directory)
(defadvice other-window
(around sr-advice-other-window (count &optional all-frames))
"Selects the correct (selected) pane when switching from other windows."
(let ((from-window (selected-window)))
ad-do-it
(when sr-running
(unless (member from-window (list sr-left-window sr-right-window))
(if (member (selected-window) (list sr-left-window sr-right-window))
(sr-select-window sr-selected-window))))))
(ad-activate 'other-window)
(defadvice use-hard-newlines
(around sr-advice-use-hard-newlines (&optional arg insert))
"Stop pestering me with questions whether I want hard lines, just guess."
(if (memq major-mode '(sr-mode sr-virtual-mode))
(let ((inhibit-read-only t))
(setq insert 'guess)
ad-do-it)
ad-do-it))
(ad-activate 'use-hard-newlines)
;;; ============================================================================
;;; Sunrise Commander keybindings:
(define-key sr-mode-map "\C-m" 'sr-advertised-find-file)
(define-key sr-mode-map "f" 'sr-advertised-find-file)
(define-key sr-mode-map "X" 'sr-advertised-execute-file)
(define-key sr-mode-map "o" 'sr-quick-view)
(define-key sr-mode-map "v" 'sr-quick-view)
(define-key sr-mode-map "/" 'sr-goto-dir)
(define-key sr-mode-map "j" 'sr-goto-dir)
(define-key sr-mode-map "^" 'sr-dired-prev-subdir)
(define-key sr-mode-map "J" 'sr-dired-prev-subdir)
(define-key sr-mode-map ";" 'sr-follow-file)
(define-key sr-mode-map "\M-t" 'sr-transpose-panes)
(define-key sr-mode-map "\M-o" 'sr-synchronize-panes)
(define-key sr-mode-map "\C-\M-o" 'sr-project-path)
(define-key sr-mode-map "\M-y" 'sr-history-prev)
(define-key sr-mode-map "\M-u" 'sr-history-next)
(define-key sr-mode-map "\C-c>" 'sr-checkpoint-save)
(define-key sr-mode-map "\C-c." 'sr-checkpoint-restore)
(define-key sr-mode-map "\C-c\C-z" 'sr-sync)
(define-key sr-mode-map "\C-c\C-c" 'revert-buffer)
(define-key sr-mode-map "\t" 'sr-change-window)
(define-key sr-mode-map "\C-c\t" 'sr-select-viewer-window)
(define-key sr-mode-map "\M-a" 'sr-beginning-of-buffer)
(define-key sr-mode-map "\M-e" 'sr-end-of-buffer)
(define-key sr-mode-map "\C-c\C-s" 'sr-split-toggle)
(define-key sr-mode-map "]" 'sr-enlarge-left-pane)
(define-key sr-mode-map "[" 'sr-enlarge-right-pane)
(define-key sr-mode-map "}" 'sr-enlarge-panes)
(define-key sr-mode-map "{" 'sr-shrink-panes)
(define-key sr-mode-map "\\" 'sr-lock-panes)
(define-key sr-mode-map "\C-c}" 'sr-max-lock-panes)
(define-key sr-mode-map "\C-c{" 'sr-min-lock-panes)
(define-key sr-mode-map "\C-o" 'dired-omit-mode)
(define-key sr-mode-map "b" 'sr-browse-file)
(define-key sr-mode-map "\C-c\C-w" 'sr-browse-pane)
(define-key sr-mode-map "\C-c\d" 'sr-toggle-attributes)
(define-key sr-mode-map "\M-l" 'sr-toggle-truncate-lines)
(define-key sr-mode-map "s" 'sr-interactive-sort)
(define-key sr-mode-map "r" 'sr-reverse-pane)
(define-key sr-mode-map "\C-e" 'sr-scroll-up)
(define-key sr-mode-map "\C-y" 'sr-scroll-down)
(define-key sr-mode-map " " 'sr-scroll-quick-view)
(define-key sr-mode-map "\M- " 'sr-scroll-quick-view-down)
(define-key sr-mode-map "C" 'sr-do-copy)
(define-key sr-mode-map "K" 'sr-do-clone)
(define-key sr-mode-map "R" 'sr-do-rename)
(define-key sr-mode-map "D" 'sr-do-delete)
(define-key sr-mode-map "x" 'sr-do-flagged-delete)
(define-key sr-mode-map "S" 'sr-do-symlink)
(define-key sr-mode-map "Y" 'sr-do-relsymlink)
(define-key sr-mode-map "H" 'sr-do-hardlink)
(define-key sr-mode-map "\M-C" 'dired-do-copy)
(define-key sr-mode-map "\M-R" 'dired-do-rename)
(define-key sr-mode-map "\M-D" 'dired-do-delete)
(define-key sr-mode-map "\M-S" 'dired-do-symlink)
(define-key sr-mode-map "\M-Y" 'dired-do-relsymlink)
(define-key sr-mode-map "\M-H" 'dired-do-hardlink)
(define-key sr-mode-map "\C-x\C-q" 'sr-editable-pane)
(define-key sr-mode-map "@" 'sr-fast-backup-files)
(define-key sr-mode-map "\M-+" 'sr-create-files)
(define-key sr-mode-map "=" 'sr-diff)
(define-key sr-mode-map "\C-c=" 'sr-ediff)
(define-key sr-mode-map "\C-x=" 'sr-compare-panes)
(define-key sr-mode-map "\C-c\C-f" 'sr-find)
(define-key sr-mode-map "\C-c\C-n" 'sr-find-name)
(define-key sr-mode-map "\C-c\C-g" 'sr-find-grep)
(define-key sr-mode-map "\C-cb" 'sr-flatten-branch)
(define-key sr-mode-map "\C-cp" 'sr-prune-paths)
(define-key sr-mode-map "\C-c\C-l" 'sr-locate)
(define-key sr-mode-map "\C-c/" 'sr-fuzzy-narrow)
(define-key sr-mode-map "\C-c\C-r" 'sr-recent-files)
(define-key sr-mode-map "\C-c\C-d" 'sr-recent-directories)
(define-key sr-mode-map "\C-cv" 'sr-virtualize-pane)
(define-key sr-mode-map "\C-c\C-v" 'sr-pure-virtual)
(define-key sr-mode-map "Q" 'sr-do-query-replace-regexp)
(define-key sr-mode-map "F" 'sr-do-find-marked-files)
(define-key sr-mode-map "A" 'sr-do-search)
(define-key sr-mode-map "\C-cs" 'sr-sticky-isearch-forward)
(define-key sr-mode-map "\C-cr" 'sr-sticky-isearch-backward)
(define-key sr-mode-map "\C-x\C-f" 'sr-find-file)
(define-key sr-mode-map "y" 'sr-show-files-info)
(define-key sr-mode-map "\M-n" 'sr-next-line-other)
(define-key sr-mode-map [M-down] 'sr-next-line-other)
(define-key sr-mode-map [A-down] 'sr-next-line-other)
(define-key sr-mode-map "\M-p" 'sr-prev-line-other)
(define-key sr-mode-map [M-up] 'sr-prev-line-other)
(define-key sr-mode-map [A-up] 'sr-prev-line-other)
(define-key sr-mode-map "\M-j" 'sr-goto-dir-other)
(define-key sr-mode-map "\M-\C-m" 'sr-advertised-find-file-other)
(define-key sr-mode-map "\M-f" 'sr-advertised-find-file-other)
(define-key sr-mode-map "\C-c\C-m" 'sr-advertised-find-file-other)
(define-key sr-mode-map "\M-^" 'sr-prev-subdir-other)
(define-key sr-mode-map "\M-J" 'sr-prev-subdir-other)
(define-key sr-mode-map "\M-U" 'sr-unmark-all-marks-other)
(define-key sr-mode-map "\M-;" 'sr-follow-file-other)
(define-key sr-mode-map "\C-\M-y" 'sr-history-prev-other)
(define-key sr-mode-map "\C-\M-u" 'sr-history-next-other)
(define-key sr-mode-map "\C-ct" 'sr-term)
(define-key sr-mode-map "\C-cT" 'sr-term-cd)
(define-key sr-mode-map "\C-c\C-t" 'sr-term-cd-newterm)
(define-key sr-mode-map "\C-c\M-t" 'sr-term-cd-program)
(define-key sr-mode-map "\C-c;" 'sr-follow-viewer)
(define-key sr-mode-map "q" 'sr-quit)
(define-key sr-mode-map "\C-xk" 'sr-quit)
(define-key sr-mode-map "\M-q" 'sunrise-cd)
(define-key sr-mode-map "h" 'sr-describe-mode)
(define-key sr-mode-map "?" 'sr-summary)
(define-key sr-mode-map "k" 'dired-do-kill-lines)
(define-key sr-mode-map [remap undo] 'sr-undo)
(define-key sr-mode-map [remap undo-only] 'sr-undo)