Mercurial > emacs
comparison lisp/dired.el @ 47507:d03e0c2bb52c
(dired-font-lock-keywords): Use regexp-opt.
(dired-move-to-filename): Better message when we fail to find the file.
(dired-sort-toggle): Minor optimization.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 16 Sep 2002 17:13:16 +0000 |
parents | ca99f74a4b9d |
children | c361d424aee2 |
comparison
equal
deleted
inserted
replaced
47506:7281e0917f10 | 47507:d03e0c2bb52c |
---|---|
190 :group 'dired | 190 :group 'dired |
191 :type 'hook) | 191 :type 'hook) |
192 ;; Note this can't simply be run inside function `dired-ls' as the hook | 192 ;; Note this can't simply be run inside function `dired-ls' as the hook |
193 ;; functions probably depend on the dired-subdir-alist to be OK. | 193 ;; functions probably depend on the dired-subdir-alist to be OK. |
194 | 194 |
195 ;;; Internal variables | 195 ;; Internal variables |
196 | 196 |
197 (defvar dired-marker-char ?* ; the answer is 42 | 197 (defvar dired-marker-char ?* ; the answer is 42 |
198 ;; so that you can write things like | 198 ;; so that you can write things like |
199 ;; (let ((dired-marker-char ?X)) | 199 ;; (let ((dired-marker-char ?X)) |
200 ;; ;; great code using X markers ... | 200 ;; ;; great code using X markers ... |
302 (list dired-re-sym | 302 (list dired-re-sym |
303 '(".+" (dired-move-to-filename) nil (0 font-lock-keyword-face))) | 303 '(".+" (dired-move-to-filename) nil (0 font-lock-keyword-face))) |
304 ;; | 304 ;; |
305 ;; Files suffixed with `completion-ignored-extensions'. | 305 ;; Files suffixed with `completion-ignored-extensions'. |
306 '(eval . | 306 '(eval . |
307 (let ((extensions (mapcar 'regexp-quote completion-ignored-extensions))) | 307 ;; It is quicker to first find just an extension, then go back to the |
308 ;; It is quicker to first find just an extension, then go back to the | 308 ;; start of that file name. So we do this complex MATCH-ANCHORED form. |
309 ;; start of that file name. So we do this complex MATCH-ANCHORED form. | 309 (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$") |
310 (list (concat "\\(" (mapconcat 'identity extensions "\\|") "\\|#\\)$") | 310 '(".+" (dired-move-to-filename) nil (0 font-lock-string-face))))) |
311 '(".+" (dired-move-to-filename) nil (0 font-lock-string-face)))))) | |
312 "Additional expressions to highlight in Dired mode.") | 311 "Additional expressions to highlight in Dired mode.") |
313 | 312 |
314 ;;; Macros must be defined before they are used, for the byte compiler. | 313 ;;; Macros must be defined before they are used, for the byte compiler. |
315 | 314 |
316 ;; Mark all files for which CONDITION evals to non-nil. | 315 ;; Mark all files for which CONDITION evals to non-nil. |
1447 ;; Using read to unquote is much faster than substituting | 1446 ;; Using read to unquote is much faster than substituting |
1448 ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop. | 1447 ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop. |
1449 (setq file | 1448 (setq file |
1450 (read | 1449 (read |
1451 (concat "\"" | 1450 (concat "\"" |
1452 ;; some ls -b don't escape quotes, argh! | 1451 ;; Some ls -b don't escape quotes, argh! |
1453 ;; This is not needed for GNU ls, though. | 1452 ;; This is not needed for GNU ls, though. |
1454 (or (dired-string-replace-match | 1453 (or (dired-string-replace-match |
1455 "\\([^\\]\\|\\`\\)\"" file "\\1\\\\\"" nil t) | 1454 "\\([^\\]\\|\\`\\)\"" file "\\1\\\\\"" nil t) |
1456 file) | 1455 file) |
1457 "\""))))) | 1456 "\""))))) |
1582 | 1581 |
1583 ;; Move to first char of filename on this line. | 1582 ;; Move to first char of filename on this line. |
1584 ;; Returns position (point) or nil if no filename on this line." | 1583 ;; Returns position (point) or nil if no filename on this line." |
1585 (defun dired-move-to-filename (&optional raise-error eol) | 1584 (defun dired-move-to-filename (&optional raise-error eol) |
1586 ;; This is the UNIX version. | 1585 ;; This is the UNIX version. |
1587 (or eol (setq eol (progn (end-of-line) (point)))) | 1586 (or eol (setq eol (line-end-position))) |
1588 (beginning-of-line) | 1587 (beginning-of-line) |
1589 ;; First try assuming `ls --dired' was used. | 1588 ;; First try assuming `ls --dired' was used. |
1590 (let ((change (next-single-property-change (point) 'dired-filename | 1589 (let ((change (next-single-property-change (point) 'dired-filename nil eol))) |
1591 nil eol))) | 1590 (cond |
1592 (if (and change (< change eol)) | 1591 ((and change (< change eol)) |
1593 (goto-char change) | 1592 (goto-char change)) |
1594 (if (re-search-forward dired-move-to-filename-regexp eol t) | 1593 ((re-search-forward dired-move-to-filename-regexp eol t) |
1595 (goto-char (match-end 0)) | 1594 (goto-char (match-end 0))) |
1596 (if raise-error | 1595 ((re-search-forward dired-permission-flags-regexp eol t) |
1597 (error "No file on this line")))))) | 1596 ;; Ha! There *is* a file. Our regexp-from-hell just failed to find it. |
1597 (funcall (if raise-error 'error 'message) | |
1598 "Unrecognized line! Check dired-move-to-filename-regexp")) | |
1599 (raise-error | |
1600 (error "No file on this line"))))) | |
1598 | 1601 |
1599 (defun dired-move-to-end-of-filename (&optional no-error) | 1602 (defun dired-move-to-end-of-filename (&optional no-error) |
1600 ;; Assumes point is at beginning of filename, | 1603 ;; Assumes point is at beginning of filename, |
1601 ;; thus the rwx bit re-search-backward below will succeed in *this* | 1604 ;; thus the rwx bit re-search-backward below will succeed in *this* |
1602 ;; line if at all. So, it should be called only after | 1605 ;; line if at all. So, it should be called only after |
2242 Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress', | 2245 Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress', |
2243 `copy', `delete', `hardlink', `load', `move', `print', `shell', `symlink' and | 2246 `copy', `delete', `hardlink', `load', `move', `print', `shell', `symlink' and |
2244 `uncompress'.") | 2247 `uncompress'.") |
2245 | 2248 |
2246 (defun dired-mark-pop-up (bufname op-symbol files function &rest args) | 2249 (defun dired-mark-pop-up (bufname op-symbol files function &rest args) |
2247 "Args BUFNAME OP-SYMBOL FILES FUNCTION &rest ARGS. | 2250 "Return FUNCTION's result on ARGS after popping up a window |
2248 Return FUNCTION's result on ARGS after popping up a window (in a buffer | 2251 \(in a buffer named BUFNAME, nil gives \" *Marked Files*\") showing the marked |
2249 named BUFNAME, nil gives \" *Marked Files*\") showing the marked | |
2250 files. Uses function `dired-pop-to-buffer' to do that. | 2252 files. Uses function `dired-pop-to-buffer' to do that. |
2251 FUNCTION should not manipulate files. | 2253 FUNCTION should not manipulate files. |
2252 It should only read input (an argument or confirmation). | 2254 It should only read input (an argument or confirmation). |
2253 The window is not shown if there is just one file or | 2255 The window is not shown if there is just one file or |
2254 OP-SYMBOL is a member of the list in `dired-no-confirm'. | 2256 OP-SYMBOL is a member of the list in `dired-no-confirm'. |
2747 (setq dired-actual-switches | 2749 (setq dired-actual-switches |
2748 (let (case-fold-search) | 2750 (let (case-fold-search) |
2749 (if (string-match " " dired-actual-switches) | 2751 (if (string-match " " dired-actual-switches) |
2750 ;; New toggle scheme: add/remove a trailing " -t" | 2752 ;; New toggle scheme: add/remove a trailing " -t" |
2751 (if (string-match " -t\\'" dired-actual-switches) | 2753 (if (string-match " -t\\'" dired-actual-switches) |
2752 (dired-replace-in-string " -t\\'" "" dired-actual-switches) | 2754 (substring dired-actual-switches 0 (match-beginning 0)) |
2753 (concat dired-actual-switches " -t")) | 2755 (concat dired-actual-switches " -t")) |
2754 ;; old toggle scheme: look for some 't' switch and add/remove it | 2756 ;; old toggle scheme: look for some 't' switch and add/remove it |
2755 (concat | 2757 (concat |
2756 "-l" | 2758 "-l" |
2757 (dired-replace-in-string (concat "[-lt" | 2759 (dired-replace-in-string (concat "[-lt" |