annotate lisp/efs/dired-sex.el @ 189:489f57a838ef r20-3b21

Import from CVS: tag r20-3b21
author cvs
date Mon, 13 Aug 2007 09:57:07 +0200
parents 9f59509498e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;; File: dired-sex.el
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 22
diff changeset
4 ;; Dired Version: #Revision: 7.9 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;; Description: Marking files according to sexpressions. Sorry.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; Created: Wed Sep 14 01:30:43 1994 by sandy on ibm550
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 (provide 'dired-sex)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 (require 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 (defvar dired-sexpr-history-symbol nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 "History of sexpr used to mark files in dired.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 ;;; Marking files according to sexpr's
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 (defmacro dired-parse-ls ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 ;; Sets vars
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 ;; inode s mode nlink uid gid size time name sym
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 ;; (probably let-bound in caller) according to current file line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 ;; Returns t for succes, nil if this is no file line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 ;; Upon success, all variables are set, either to nil or the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 ;; appropriate value, so they need not be initialized.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 ;; Moves point within the current line to the end of the file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 '(let ((bol (progn (beginning-of-line) (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 (eol (save-excursion (skip-chars-forward "^\n\r") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 (if (re-search-forward dired-re-month-and-time eol t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 (let ((mode-len 10) ; length of mode string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 (tstart (progn (goto-char (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 (skip-chars-forward " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 (fstart (match-end 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 (goto-char (1+ bol))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 (skip-chars-forward " \t")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 ;; This subdir had better have been created with the current
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 ;; setting of actual switches. Otherwise, we can't parse.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 ((and (or (memq ?k dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 (memq ?s dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 (memq ?i dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 (setq pos (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 (skip-chars-forward "0-9")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 (if (setq inode (and (/= pos (point)) (string-to-int
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 pos (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (skip-chars-forward " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 (setq pos (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 (skip-chars-forward "0-9")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (setq s (and (/= pos (point)) (string-to-int
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 pos (point))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 (setq s nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 ((or (memq ?s dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 (memq ?k dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 (setq pos (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 (skip-chars-forward "0-9")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (setq s (and (/= pos (point)) (string-to-int
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 pos (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 inode nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 ((memq ?i dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (setq pos (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (skip-chars-forward "0-9")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (setq inode (and (/= pos (point)) (string-to-int
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 pos (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 s nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 (setq s nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 inode nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (skip-chars-forward " 0-9") ; in case of junk
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 (setq mode (buffer-substring (point) (+ mode-len (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (forward-char mode-len)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (setq nlink (read (current-buffer)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 (or (integerp nlink) (setq nlink nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (setq uid (buffer-substring (point) (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (skip-chars-forward "^ ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 (goto-char tstart)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 (skip-chars-backward " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (setq pos (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (skip-chars-backward "0-9")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (if (= pos (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (setq size nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (setq size (string-to-int (buffer-substring (point) pos))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (skip-chars-backward " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 ;; if no gid is displayed, gid will be set to uid
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 ;; but user will then not reference it anyway in PREDICATE.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (setq gid (buffer-substring (point) (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 (skip-chars-backward "^ ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 time (buffer-substring tstart
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 (goto-char fstart)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 (skip-chars-backward " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 name (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 fstart
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (or (dired-move-to-end-of-filename t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 sym (and (looking-at "[/*@#=|]? -> ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 (buffer-substring (match-end 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 eol)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 t)))) ; return t if parsing was a success
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (defun dired-mark-sexp (predicate &optional unflag-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 "Mark files for which PREDICATE returns non-nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 With a prefix arg, unflag those files instead.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 PREDICATE is a lisp expression that can refer to the following symbols:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 inode [integer] the inode of the file (only for ls -i output)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 s [integer] the size of the file for ls -s output
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 (ususally in blocks or, with -k, in KByte)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 mode [string] file permission bits, e.g. \"-rw-r--r--\"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 nlink [integer] number of links to file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 uid [string] owner
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 gid [string] group (If the gid is not displayed by ls,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 this will still be set (to the same as uid))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 size [integer] file size in bytes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 time [string] the time that ls displays, e.g. \"Feb 12 14:17\"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 name [string] the name of the file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 sym [string] if file is a symbolic link, the linked-to name, else nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 For example, use
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (equal 0 size)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 to mark all zero length files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 ;; Using sym="" instead of nil avoids the trap of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 ;; (string-match "foo" sym) into which a user would soon fall.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 ;; No! Want to be able look for symlinks pointing to the empty string.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 ;; Can happen. Also, then I can do an (if sym ...) structure. --sandy
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 ;; Give `equal' instead of `=' in the example, as this works on
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 ;; integers and strings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 (read
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 (dired-read-with-history "Mark if (lisp expr): " nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 'dired-sexpr-history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 (message "%s" predicate)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 inode s mode nlink uid gid size time name sym)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 (dired-mark-if (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (and (dired-parse-ls)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 (eval predicate)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 (format "'%s file" predicate)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 ;;; end of dired-sex.el