diff options
| author | Chong Yidong | 2012-11-18 13:38:13 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-11-18 13:38:13 +0800 |
| commit | 6a3dd257cf7437865caeb43173800e92abd8bf88 (patch) | |
| tree | a6fa1cee780fdb751f1b77fb01c35d97fe5d8867 /lisp | |
| parent | eef97f35c8d8a6983e30462d16b0c01297325b94 (diff) | |
| download | emacs-6a3dd257cf7437865caeb43173800e92abd8bf88.tar.gz emacs-6a3dd257cf7437865caeb43173800e92abd8bf88.zip | |
Avoid using "X" interactive flag in filecache.el.
* filecache.el (file-cache--read-list): New function.
(file-cache-add-directory-list, file-cache-add-file-list)
(file-cache-delete-file-list, file-cache-delete-directory-list):
Use it to read a list of files or directories.
(file-cache-add-file, file-cache-add-directory)
(file-cache-delete-file-list, file-cache-delete-file-regexp)
(file-cache-delete-directory): Print an message.
Fixes: debbugs:12846
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/filecache.el | 138 |
2 files changed, 94 insertions, 54 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fdcde1dde0f..ca65e431964 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2012-11-18 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * filecache.el (file-cache--read-list): New function. | ||
| 4 | (file-cache-add-directory-list, file-cache-add-file-list) | ||
| 5 | (file-cache-delete-file-list, file-cache-delete-directory-list): | ||
| 6 | Use it to read a list of files or directories (Bug#12846). | ||
| 7 | (file-cache-add-file, file-cache-add-directory) | ||
| 8 | (file-cache-delete-file-list, file-cache-delete-file-regexp) | ||
| 9 | (file-cache-delete-directory): Print an message. | ||
| 10 | |||
| 1 | 2012-11-18 Jay Belanger <jay.p.belanger@gmail.com> | 11 | 2012-11-18 Jay Belanger <jay.p.belanger@gmail.com> |
| 2 | 12 | ||
| 3 | * calc/calc-forms.el (math-date-to-dt): Use integer date when | 13 | * calc/calc-forms.el (math-date-to-dt): Use integer date when |
diff --git a/lisp/filecache.el b/lisp/filecache.el index f868ef5e275..bc77c24fe63 100644 --- a/lisp/filecache.el +++ b/lisp/filecache.el | |||
| @@ -267,44 +267,63 @@ files of names DIRNAME1/FILENAME, DIRNAME2/FILENAME, ...") | |||
| 267 | ;; Functions to add files to the cache | 267 | ;; Functions to add files to the cache |
| 268 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 268 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 269 | 269 | ||
| 270 | (defun file-cache--read-list (file op-prompt) | ||
| 271 | (let* ((fun (if file 'read-file-name 'read-directory-name)) | ||
| 272 | (type (if file "file" "directory")) | ||
| 273 | (prompt-1 (concat op-prompt " " type ": ")) | ||
| 274 | (prompt-2 (concat op-prompt " another " type "?")) | ||
| 275 | (continue t) | ||
| 276 | result) | ||
| 277 | (while continue | ||
| 278 | (push (funcall fun prompt-1 nil nil t) result) | ||
| 279 | (setq continue (y-or-n-p prompt-2))) | ||
| 280 | (nreverse result))) | ||
| 281 | |||
| 270 | ;;;###autoload | 282 | ;;;###autoload |
| 271 | (defun file-cache-add-directory (directory &optional regexp) | 283 | (defun file-cache-add-directory (directory &optional regexp) |
| 272 | "Add DIRECTORY to the file cache. | 284 | "Add all files in DIRECTORY to the file cache. |
| 273 | If the optional REGEXP argument is non-nil, only files which match it will | 285 | If called from Lisp with a non-nil REGEXP argument is non-nil, |
| 274 | be added to the cache." | 286 | only add files whose names match REGEXP." |
| 275 | (interactive "DAdd files from directory: ") | 287 | (interactive (list (read-directory-name "Add files from directory: " |
| 288 | nil nil t) | ||
| 289 | nil)) | ||
| 276 | ;; Not an error, because otherwise we can't use load-paths that | 290 | ;; Not an error, because otherwise we can't use load-paths that |
| 277 | ;; contain non-existent directories. | 291 | ;; contain non-existent directories. |
| 278 | (if (not (file-accessible-directory-p directory)) | 292 | (when (file-accessible-directory-p directory) |
| 279 | (message "Directory %s does not exist" directory) | ||
| 280 | (let* ((dir (expand-file-name directory)) | 293 | (let* ((dir (expand-file-name directory)) |
| 281 | (dir-files (directory-files dir t regexp))) | 294 | (dir-files (directory-files dir t regexp))) |
| 282 | ;; Filter out files we don't want to see | 295 | ;; Filter out files we don't want to see |
| 283 | (dolist (file dir-files) | 296 | (dolist (file dir-files) |
| 284 | (if (file-directory-p file) | 297 | (if (file-directory-p file) |
| 285 | (setq dir-files (delq file dir-files)) | 298 | (setq dir-files (delq file dir-files)) |
| 286 | (dolist (regexp file-cache-filter-regexps) | 299 | (dolist (regexp file-cache-filter-regexps) |
| 287 | (if (string-match regexp file) | 300 | (if (string-match regexp file) |
| 288 | (setq dir-files (delq file dir-files)))))) | 301 | (setq dir-files (delq file dir-files)))))) |
| 289 | (file-cache-add-file-list dir-files)))) | 302 | (file-cache-add-file-list dir-files)))) |
| 290 | 303 | ||
| 291 | ;;;###autoload | 304 | ;;;###autoload |
| 292 | (defun file-cache-add-directory-list (directory-list &optional regexp) | 305 | (defun file-cache-add-directory-list (directories &optional regexp) |
| 293 | "Add DIRECTORY-LIST (a list of directory names) to the file cache. | 306 | "Add DIRECTORIES (a list of directory names) to the file cache. |
| 307 | If called interactively, read the directory names one by one. | ||
| 294 | If the optional REGEXP argument is non-nil, only files which match it | 308 | If the optional REGEXP argument is non-nil, only files which match it |
| 295 | will be added to the cache. Note that the REGEXP is applied to the | 309 | will be added to the cache. Note that the REGEXP is applied to the |
| 296 | files in each directory, not to the directory list itself." | 310 | files in each directory, not to the directory list itself." |
| 297 | (interactive "XAdd files from directory list: ") | 311 | (interactive (list (file-cache--read-list nil "Add"))) |
| 298 | (mapcar | 312 | (dolist (dir directories) |
| 299 | (lambda (dir) (file-cache-add-directory dir regexp)) | 313 | (file-cache-add-directory dir regexp)) |
| 300 | directory-list)) | 314 | (let ((n (length directories))) |
| 301 | 315 | (message "Filecache: cached file names from %d director%s." | |
| 302 | (defun file-cache-add-file-list (file-list) | 316 | n (if (= n 1) "y" "ies")))) |
| 303 | "Add FILE-LIST (a list of file names) to the file cache. | 317 | |
| 304 | Interactively, FILE-LIST is read as a Lisp expression, which | 318 | (defun file-cache-add-file-list (files) |
| 305 | should evaluate to the desired list of file names." | 319 | "Add FILES (a list of file names) to the file cache. |
| 306 | (interactive "XFile List: ") | 320 | If called interactively, read the file names one by one." |
| 307 | (mapcar 'file-cache-add-file file-list)) | 321 | (interactive (list (file-cache--read-list t "Add"))) |
| 322 | (dolist (f files) | ||
| 323 | (file-cache-add-file f)) | ||
| 324 | (let ((n (length files))) | ||
| 325 | (message "Filecache: cached %d file name%s." | ||
| 326 | n (if (= n 1) "" "s")))) | ||
| 308 | 327 | ||
| 309 | ;; Workhorse function | 328 | ;; Workhorse function |
| 310 | 329 | ||
| @@ -319,15 +338,18 @@ should evaluate to the desired list of file names." | |||
| 319 | (dir-name (file-name-directory file)) | 338 | (dir-name (file-name-directory file)) |
| 320 | (the-entry (assoc-string file-name file-cache-alist | 339 | (the-entry (assoc-string file-name file-cache-alist |
| 321 | file-cache-ignore-case))) | 340 | file-cache-ignore-case))) |
| 322 | ;; Does the entry exist already? | 341 | (cond ((null the-entry) |
| 323 | (if the-entry | 342 | ;; If the entry wasn't in the cache, add it. |
| 324 | (unless (or (and (stringp (cdr the-entry)) | 343 | (push (list file-name dir-name) file-cache-alist) |
| 325 | (string= dir-name (cdr the-entry))) | 344 | (if (called-interactively-p 'interactive) |
| 326 | (and (listp (cdr the-entry)) | 345 | (message "Filecache: cached file name %s." file))) |
| 327 | (member dir-name (cdr the-entry)))) | 346 | ((not (member dir-name (cdr the-entry))) |
| 328 | (setcdr the-entry (cons dir-name (cdr the-entry)))) | 347 | (setcdr the-entry (cons dir-name (cdr the-entry))) |
| 329 | ;; If not, add it to the cache | 348 | (if (called-interactively-p 'interactive) |
| 330 | (push (list file-name dir-name) file-cache-alist)))) | 349 | (message "Filecache: cached file name %s." file))) |
| 350 | (t | ||
| 351 | (if (called-interactively-p 'interactive) | ||
| 352 | (message "Filecache: %s is already cached." file)))))) | ||
| 331 | 353 | ||
| 332 | ;;;###autoload | 354 | ;;;###autoload |
| 333 | (defun file-cache-add-directory-using-find (directory) | 355 | (defun file-cache-add-directory-using-find (directory) |
| @@ -413,17 +435,26 @@ or the optional REGEXP argument." | |||
| 413 | 435 | ||
| 414 | ;; This clears *all* files with the given name | 436 | ;; This clears *all* files with the given name |
| 415 | (defun file-cache-delete-file (file) | 437 | (defun file-cache-delete-file (file) |
| 416 | "Delete FILE from the file cache." | 438 | "Delete FILE (a relative file name) from the file cache. |
| 439 | Return nil if FILE was not in the file cache, non-nil otherwise." | ||
| 417 | (interactive | 440 | (interactive |
| 418 | (list (completing-read "Delete file from cache: " file-cache-alist))) | 441 | (list (completing-read "Delete file from cache: " file-cache-alist))) |
| 419 | (setq file-cache-alist | 442 | (let ((elt (assoc-string file file-cache-alist file-cache-ignore-case))) |
| 420 | (delq (assoc-string file file-cache-alist file-cache-ignore-case) | 443 | (setq file-cache-alist (delq elt file-cache-alist)) |
| 421 | file-cache-alist))) | 444 | elt)) |
| 422 | 445 | ||
| 423 | (defun file-cache-delete-file-list (file-list) | 446 | (defun file-cache-delete-file-list (files &optional message) |
| 424 | "Delete FILE-LIST (a list of files) from the file cache." | 447 | "Delete FILES (a list of files) from the file cache. |
| 425 | (interactive "XFile List: ") | 448 | If called interactively, read the file names one by one. |
| 426 | (mapcar 'file-cache-delete-file file-list)) | 449 | If MESSAGE is non-nil, or if called interactively, print a |
| 450 | message reporting the number of file names deleted." | ||
| 451 | (interactive (list (file-cache--read-list t "Uncache") t)) | ||
| 452 | (let ((n 0)) | ||
| 453 | (dolist (f files) | ||
| 454 | (if (file-cache-delete-file f) | ||
| 455 | (setq n (1+ n)))) | ||
| 456 | (message "Filecache: uncached %d file name%s." | ||
| 457 | n (if (= n 1) "" "s")))) | ||
| 427 | 458 | ||
| 428 | (defun file-cache-delete-file-regexp (regexp) | 459 | (defun file-cache-delete-file-regexp (regexp) |
| 429 | "Delete files matching REGEXP from the file cache." | 460 | "Delete files matching REGEXP from the file cache." |
| @@ -432,21 +463,18 @@ or the optional REGEXP argument." | |||
| 432 | (dolist (elt file-cache-alist) | 463 | (dolist (elt file-cache-alist) |
| 433 | (and (string-match regexp (car elt)) | 464 | (and (string-match regexp (car elt)) |
| 434 | (push (car elt) delete-list))) | 465 | (push (car elt) delete-list))) |
| 435 | (file-cache-delete-file-list delete-list) | 466 | (file-cache-delete-file-list delete-list))) |
| 436 | (message "Filecache: deleted %d files from file cache" | ||
| 437 | (length delete-list)))) | ||
| 438 | 467 | ||
| 439 | (defun file-cache-delete-directory (directory) | 468 | (defun file-cache-delete-directory (directory) |
| 440 | "Delete DIRECTORY from the file cache." | 469 | "Delete DIRECTORY from the file cache." |
| 441 | (interactive "DDelete directory from file cache: ") | 470 | (interactive "DDelete directory from file cache: ") |
| 442 | (let ((dir (expand-file-name directory)) | 471 | (let ((dir (expand-file-name directory)) |
| 443 | (result 0)) | 472 | (n 0)) |
| 444 | (dolist (entry file-cache-alist) | 473 | (dolist (entry file-cache-alist) |
| 445 | (if (file-cache-do-delete-directory dir entry) | 474 | (if (file-cache-do-delete-directory dir entry) |
| 446 | (setq result (1+ result)))) | 475 | (setq n (1+ n)))) |
| 447 | (if (zerop result) | 476 | (message "Filecache: uncached %d file name%s." |
| 448 | (error "Filecache: no entries containing %s found in cache" directory) | 477 | n (if (= n 1) "" "s")))) |
| 449 | (message "Filecache: deleted %d entries" result)))) | ||
| 450 | 478 | ||
| 451 | (defun file-cache-do-delete-directory (dir entry) | 479 | (defun file-cache-do-delete-directory (dir entry) |
| 452 | (let ((directory-list (cdr entry)) | 480 | (let ((directory-list (cdr entry)) |
| @@ -457,10 +485,12 @@ or the optional REGEXP argument." | |||
| 457 | (delq entry file-cache-alist)) | 485 | (delq entry file-cache-alist)) |
| 458 | (setcdr entry (delete directory directory-list)))))) | 486 | (setcdr entry (delete directory directory-list)))))) |
| 459 | 487 | ||
| 460 | (defun file-cache-delete-directory-list (directory-list) | 488 | (defun file-cache-delete-directory-list (directories) |
| 461 | "Delete DIRECTORY-LIST (a list of directories) from the file cache." | 489 | "Delete DIRECTORIES (a list of directory names) from the file cache. |
| 462 | (interactive "XDirectory List: ") | 490 | If called interactively, read the directory names one by one." |
| 463 | (mapcar 'file-cache-delete-directory directory-list)) | 491 | (interactive (list (file-cache--read-list nil "Uncache"))) |
| 492 | (dolist (d directories) | ||
| 493 | (file-cache-delete-directory d))) | ||
| 464 | 494 | ||
| 465 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 495 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 466 | ;; Utility functions | 496 | ;; Utility functions |