comparison lisp/gnus/nneething.el @ 110:fe104dbd9147 r20-1b7

Import from CVS: tag r20-1b7
author cvs
date Mon, 13 Aug 2007 09:19:45 +0200
parents 360340f9fd5f
children 48d667d6f17f
comparison
equal deleted inserted replaced
109:e183fc049578 110:fe104dbd9147
186 (concat (file-name-as-directory nneething-map-file-directory) 186 (concat (file-name-as-directory nneething-map-file-directory)
187 nneething-group nneething-map-file)) 187 nneething-group nneething-map-file))
188 188
189 (defun nneething-create-mapping () 189 (defun nneething-create-mapping ()
190 ;; Read nneething-active and nneething-map. 190 ;; Read nneething-active and nneething-map.
191 (let ((map-file (nneething-map-file)) 191 (when (file-exists-p nneething-directory)
192 (files (directory-files nneething-directory)) 192 (let ((map-file (nneething-map-file))
193 touched map-files) 193 (files (directory-files nneething-directory))
194 (when (file-exists-p map-file) 194 touched map-files)
195 (ignore-errors 195 (when (file-exists-p map-file)
196 (load map-file nil t t))) 196 (ignore-errors
197 (unless nneething-active 197 (load map-file nil t t)))
198 (setq nneething-active (cons 1 0))) 198 (unless nneething-active
199 ;; Old nneething had a different map format. 199 (setq nneething-active (cons 1 0)))
200 (when (and (cdar nneething-map) 200 ;; Old nneething had a different map format.
201 (atom (cdar nneething-map))) 201 (when (and (cdar nneething-map)
202 (setq nneething-map 202 (atom (cdar nneething-map)))
203 (mapcar (lambda (n) 203 (setq nneething-map
204 (list (cdr n) (car n) 204 (mapcar (lambda (n)
205 (nth 5 (file-attributes 205 (list (cdr n) (car n)
206 (nneething-file-name (car n)))))) 206 (nth 5 (file-attributes
207 nneething-map))) 207 (nneething-file-name (car n))))))
208 ;; Remove files matching the exclusion regexp. 208 nneething-map)))
209 (when nneething-exclude-files 209 ;; Remove files matching the exclusion regexp.
210 (let ((f files) 210 (when nneething-exclude-files
211 (let ((f files)
212 prev)
213 (while f
214 (if (string-match nneething-exclude-files (car f))
215 (if prev (setcdr prev (cdr f))
216 (setq files (cdr files)))
217 (setq prev f))
218 (setq f (cdr f)))))
219 ;; Remove deleted files from the map.
220 (let ((map nneething-map)
211 prev) 221 prev)
212 (while f 222 (while map
213 (if (string-match nneething-exclude-files (car f)) 223 (if (and (member (cadar map) files)
214 (if prev (setcdr prev (cdr f)) 224 ;; We also remove files that have changed mod times.
215 (setq files (cdr files))) 225 (equal (nth 5 (file-attributes
216 (setq prev f)) 226 (nneething-file-name (cadar map))))
217 (setq f (cdr f))))) 227 (caddar map)))
218 ;; Remove deleted files from the map. 228 (progn
219 (let ((map nneething-map) 229 (push (cadar map) map-files)
220 prev) 230 (setq prev map))
221 (while map 231 (setq touched t)
222 (if (and (member (cadar map) files) 232 (if prev
223 ;; We also remove files that have changed mod times. 233 (setcdr prev (cdr map))
224 (equal (nth 5 (file-attributes 234 (setq nneething-map (cdr nneething-map))))
225 (nneething-file-name (cadar map)))) 235 (setq map (cdr map))))
226 (caddar map))) 236 ;; Find all new files and enter them into the map.
227 (progn 237 (while files
228 (push (cadar map) map-files) 238 (unless (member (car files) map-files)
229 (setq prev map)) 239 ;; This file is not in the map, so we enter it.
230 (setq touched t) 240 (setq touched t)
231 (if prev 241 (setcdr nneething-active (1+ (cdr nneething-active)))
232 (setcdr prev (cdr map)) 242 (push (list (cdr nneething-active) (car files)
233 (setq nneething-map (cdr nneething-map)))) 243 (nth 5 (file-attributes
234 (setq map (cdr map)))) 244 (nneething-file-name (car files)))))
235 ;; Find all new files and enter them into the map. 245 nneething-map))
236 (while files 246 (setq files (cdr files)))
237 (unless (member (car files) map-files) 247 (when (and touched
238 ;; This file is not in the map, so we enter it. 248 (not nneething-read-only))
239 (setq touched t) 249 (nnheader-temp-write map-file
240 (setcdr nneething-active (1+ (cdr nneething-active))) 250 (insert "(setq nneething-map '")
241 (push (list (cdr nneething-active) (car files) 251 (gnus-prin1 nneething-map)
242 (nth 5 (file-attributes 252 (insert ")\n(setq nneething-active '")
243 (nneething-file-name (car files))))) 253 (gnus-prin1 nneething-active)
244 nneething-map)) 254 (insert ")\n"))))))
245 (setq files (cdr files)))
246 (when (and touched
247 (not nneething-read-only))
248 (nnheader-temp-write map-file
249 (insert "(setq nneething-map '")
250 (gnus-prin1 nneething-map)
251 (insert ")\n(setq nneething-active '")
252 (gnus-prin1 nneething-active)
253 (insert ")\n")))))
254 255
255 (defun nneething-insert-head (file) 256 (defun nneething-insert-head (file)
256 "Insert the head of FILE." 257 "Insert the head of FILE."
257 (when (nneething-get-head file) 258 (when (nneething-get-head file)
258 (insert-buffer-substring nneething-work-buffer) 259 (insert-buffer-substring nneething-work-buffer)