202 |
|
|
203 |
;; Fixme: This should use mailcap. |
;; Fixme: This should use mailcap. |
204 |
(defcustom dired-view-command-alist |
(defcustom dired-view-command-alist |
205 |
'(("[.]\\(ps\\|ps_pages\\|eps\\)\\'" . "gv -spartan -color -watch %s") |
'(("\\.\\(ps\\|ps_pages\\|eps\\)\\'" . "gv %s") |
206 |
("[.]pdf\\'" . "xpdf %s") |
("\\.pdf\\'" . "xpdf %s") |
207 |
("[.]\\(jpe?g\\|gif\\|png\\)\\'" . "eog %s") |
;; ("\\.pod\\'" . "perldoc %s") |
208 |
("[.]dvi\\'" . "xdvi -sidemargin 0.5 -topmargin 1 %s")) |
("\\.\\(jpe?g\\|gif\\|png\\)\\'" . "eog %s") |
209 |
|
("\\.dvi\\'" . "xdvi %s")) |
210 |
"Alist specifying how to view special types of files. |
"Alist specifying how to view special types of files. |
211 |
Each element has the form (REGEXP . SHELL-COMMAND). |
Each element has the form (REGEXP . SHELL-COMMAND). |
212 |
When the file name matches REGEXP, `dired-view-file' |
When the file name matches REGEXP, `dired-view-file' |
798 |
(dired-insert-directory dir dired-actual-switches |
(dired-insert-directory dir dired-actual-switches |
799 |
file-list (not file-list) t))))) |
file-list (not file-list) t))))) |
800 |
|
|
801 |
|
(defun dired-align-file (beg end) |
802 |
|
"Align the fields of a file to the ones of surrounding lines. |
803 |
|
BEG..END is the line where the file info is located." |
804 |
|
;; Some versions of ls try to adjust the size of each field so as to just |
805 |
|
;; hold the largest element ("largest" in the current invocation, of |
806 |
|
;; course). So when a single line is output, the size of each field is |
807 |
|
;; just big enough for that one output. Thus when dired refreshes one |
808 |
|
;; line, the alignment if this line w.r.t the rest is messed up because |
809 |
|
;; the fields of that one line will generally be smaller. |
810 |
|
;; |
811 |
|
;; To work around this problem, we here add spaces to try and re-align the |
812 |
|
;; fields as needed. Since this is purely aesthetic, it is of utmost |
813 |
|
;; importance that it doesn't mess up anything like |
814 |
|
;; `dired-move-to-filename'. To this end, we limit ourselves to adding |
815 |
|
;; spaces only, and to only add them at places where there was already at |
816 |
|
;; least one space. This way, as long as `dired-move-to-filename-regexp' |
817 |
|
;; always matches spaces with "*" or "+", we know we haven't made anything |
818 |
|
;; worse. There is one spot where the exact number of spaces is |
819 |
|
;; important, which is just before the actual filename, so we refrain from |
820 |
|
;; adding spaces there (and within the filename as well, of course). |
821 |
|
(save-excursion |
822 |
|
(let (file file-col other other-col) |
823 |
|
;; Check the there is indeed a file, and that there is anoter adjacent |
824 |
|
;; file with which to align, and that additional spaces are needed to |
825 |
|
;; align the filenames. |
826 |
|
(when (and (setq file (progn (goto-char beg) |
827 |
|
(dired-move-to-filename nil end))) |
828 |
|
(setq file-col (current-column)) |
829 |
|
(setq other |
830 |
|
(or (and (goto-char beg) |
831 |
|
(zerop (forward-line -1)) |
832 |
|
(dired-move-to-filename)) |
833 |
|
(and (goto-char beg) |
834 |
|
(zerop (forward-line 1)) |
835 |
|
(dired-move-to-filename)))) |
836 |
|
(setq other-col (current-column)) |
837 |
|
(/= file other) |
838 |
|
;; Make sure there is some work left to do. |
839 |
|
(> other-col file-col)) |
840 |
|
;; If we've only looked at the line above, check to see if the line |
841 |
|
;; below exists as well and if so, align with the shorter one. |
842 |
|
(when (and (< other file) |
843 |
|
(goto-char beg) |
844 |
|
(zerop (forward-line 1)) |
845 |
|
(dired-move-to-filename)) |
846 |
|
(let ((alt-col (current-column))) |
847 |
|
(when (< alt-col other-col) |
848 |
|
(setq other-col alt-col) |
849 |
|
(setq other (point))))) |
850 |
|
;; Keep positions uptodate when we insert stuff. |
851 |
|
(if (> other file) (setq other (copy-marker other))) |
852 |
|
(setq file (copy-marker file)) |
853 |
|
;; Main loop. |
854 |
|
(goto-char beg) |
855 |
|
(while (and (> other-col file-col) |
856 |
|
(skip-chars-forward "^ ") |
857 |
|
;; Skip the spaces, and make sure there's at least one. |
858 |
|
(> (skip-chars-forward " ") 0) |
859 |
|
;; Don't touch anything just before (and after) the |
860 |
|
;; beginning of the filename. |
861 |
|
(> file (point))) |
862 |
|
;; We're now just in front of a field, with a space behind us. |
863 |
|
(let* ((curcol (current-column)) |
864 |
|
;; Nums are right-aligned. |
865 |
|
(num-align (looking-at "[0-9]")) |
866 |
|
;; Let's look at the other line, in the same column: we |
867 |
|
;; should be either near the end of the previous field, or |
868 |
|
;; in the space between that field and the next. |
869 |
|
;; [ Of course, it's also possible that we're already within |
870 |
|
;; the next field or even past it, but that's unlikely since |
871 |
|
;; other-col > file-col. ] |
872 |
|
;; Let's find the distance to the alignment-point (either |
873 |
|
;; the beginning or the end of the next field, depending on |
874 |
|
;; whether this field is left or right aligned). |
875 |
|
(align-pt-offset |
876 |
|
(save-excursion |
877 |
|
(goto-char other) |
878 |
|
(move-to-column curcol) |
879 |
|
(when (looking-at |
880 |
|
(concat |
881 |
|
(if (eq (char-before) ?\ ) " *" "[^ ]* *") |
882 |
|
(if num-align "[0-9][^ ]*"))) |
883 |
|
(- (match-end 0) (match-beginning 0))))) |
884 |
|
;; Now, the number of spaces to insert is align-pt-offset |
885 |
|
;; minus the distance to the equivalent point on the |
886 |
|
;; current line. |
887 |
|
(spaces |
888 |
|
(if (not num-align) |
889 |
|
align-pt-offset |
890 |
|
(and align-pt-offset |
891 |
|
(save-excursion |
892 |
|
(skip-chars-forward "^ ") |
893 |
|
(- align-pt-offset (- (current-column) curcol))))))) |
894 |
|
(when (and spaces (> spaces 0)) |
895 |
|
(setq file-col (+ spaces file-col)) |
896 |
|
(if (> file-col other-col) |
897 |
|
(setq spaces (- spaces (- file-col other-col)))) |
898 |
|
(insert-char ?\s spaces) |
899 |
|
;; Let's just make really sure we did not mess up. |
900 |
|
(unless (save-excursion |
901 |
|
(equal (dired-move-to-filename) (marker-position file))) |
902 |
|
;; Damn! We messed up: let's revert the change. |
903 |
|
(delete-char (- spaces)))))) |
904 |
|
(set-marker file nil))))) |
905 |
|
|
906 |
|
|
907 |
(defun dired-insert-directory (dir switches &optional file-list wildcard hdr) |
(defun dired-insert-directory (dir switches &optional file-list wildcard hdr) |
908 |
"Insert a directory listing of DIR, Dired style. |
"Insert a directory listing of DIR, Dired style. |
909 |
Use SWITCHES to make the listings. |
Use SWITCHES to make the listings. |
922 |
;; with the new value of dired-move-to-filename-regexp. |
;; with the new value of dired-move-to-filename-regexp. |
923 |
(if file-list |
(if file-list |
924 |
(dolist (f file-list) |
(dolist (f file-list) |
925 |
(insert-directory f switches nil nil)) |
(let ((beg (point))) |
926 |
|
(insert-directory f switches nil nil) |
927 |
|
;; Re-align fields, if necessary. |
928 |
|
(dired-align-file beg (point)))) |
929 |
(insert-directory dir switches wildcard (not wildcard))) |
(insert-directory dir switches wildcard (not wildcard))) |
930 |
;; Quote certain characters, unless ls quoted them for us. |
;; Quote certain characters, unless ls quoted them for us. |
931 |
(if (not (string-match "b" dired-actual-switches)) |
(if (not (string-match "b" dired-actual-switches)) |
1872 |
;; Move to first char of filename on this line. |
;; Move to first char of filename on this line. |
1873 |
;; Returns position (point) or nil if no filename on this line." |
;; Returns position (point) or nil if no filename on this line." |
1874 |
(defun dired-move-to-filename (&optional raise-error eol) |
(defun dired-move-to-filename (&optional raise-error eol) |
1875 |
|
"Move to the beginning of the filename on the current line. |
1876 |
|
Return the position of the beginning of the filename, or nil if none found." |
1877 |
;; This is the UNIX version. |
;; This is the UNIX version. |
1878 |
(or eol (setq eol (line-end-position))) |
(or eol (setq eol (line-end-position))) |
1879 |
(beginning-of-line) |
(beginning-of-line) |
1886 |
(goto-char (match-end 0))) |
(goto-char (match-end 0))) |
1887 |
((re-search-forward dired-permission-flags-regexp eol t) |
((re-search-forward dired-permission-flags-regexp eol t) |
1888 |
;; Ha! There *is* a file. Our regexp-from-hell just failed to find it. |
;; Ha! There *is* a file. Our regexp-from-hell just failed to find it. |
1889 |
(funcall (if raise-error 'error 'message) |
(if raise-error |
1890 |
"Unrecognized line! Check dired-move-to-filename-regexp")) |
(error "Unrecognized line! Check dired-move-to-filename-regexp")) |
1891 |
|
(beginning-of-line) |
1892 |
|
nil) |
1893 |
(raise-error |
(raise-error |
1894 |
(error "No file on this line"))))) |
(error "No file on this line"))))) |
1895 |
|
|
1932 |
(or no-error (error "No file on this line")))) |
(or no-error (error "No file on this line")))) |
1933 |
;; Move point to end of name: |
;; Move point to end of name: |
1934 |
(if symlink |
(if symlink |
1935 |
(if (search-forward " ->" eol t) |
(if (search-forward " -> " eol t) |
1936 |
(progn |
(progn |
1937 |
(forward-char -3) |
(forward-char -4) |
1938 |
(and used-F |
(and used-F |
1939 |
dired-ls-F-marks-symlinks |
dired-ls-F-marks-symlinks |
1940 |
(eq (preceding-char) ?@) ;; did ls really mark the link? |
(eq (preceding-char) ?@) ;; did ls really mark the link? |
1999 |
;; As a side effect, killed dired buffers for DIR are removed from |
;; As a side effect, killed dired buffers for DIR are removed from |
2000 |
;; dired-buffers. |
;; dired-buffers. |
2001 |
(setq dir (file-name-as-directory dir)) |
(setq dir (file-name-as-directory dir)) |
2002 |
(let ((alist dired-buffers) result elt buf pattern) |
(let ((alist dired-buffers) result elt buf) |
2003 |
(while alist |
(while alist |
2004 |
(setq elt (car alist) |
(setq elt (car alist) |
2005 |
buf (cdr elt)) |
buf (cdr elt)) |