[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dired needs a hide backups toggle
From: |
thi |
Subject: |
Re: dired needs a hide backups toggle |
Date: |
24 Feb 2001 15:08:01 -0800 |
see below for `M-x dired-wipe'. munge to taste.
thi
__________________________________
;;; ID: dired-wipe.el,v 1.18 2000/12/21 20:34:32 ttn Rel
;;;
;;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Thien-Thi Nguyen
;;; This file is part of ttn's personal elisp library, released under GNU
;;; GPL with ABSOLUTELY NO WARRANTY. See the file COPYING for details.
;;; Description: In dired, remove lines of certain type.
(defvar dired-wipe-types ; todo: use defcustom
(append
'(("unseeables" . "--- ")
("read-only" . "^....-")
("version control" . ",v\\>")
("compiled elisp" . "\\.elc\\>")
;; Add new wipe types here.
)
(let (ret)
(mapcar (lambda (pair)
(let ((key (symbol-name (cdr pair)))
(val (car pair)))
(let ((lookup (assoc key ret)))
(if lookup
(setcdr lookup (cons val (cdr lookup)))
(setq ret (cons (list key val) ret))))))
(remove-if-not (lambda (item)
(and (consp item)
(not (consp (cdr item)))))
auto-mode-alist))
(flet ((munge (s)
(while (string-match "\\\\[`]" s)
(setq s (concat
(substring s 0 (match-beginning 0))
(substring s (match-end 0)))))
(while (string-match "\\\\[']" s)
(setq s (concat
(substring s 0 (match-beginning 0))
"$"
(substring s (match-end 0)))))
s))
(mapcar (lambda (pair)
(cons (car pair)
(if (= 1 (length (cdr pair)))
(munge (cadr pair))
(mapconcat (lambda (s)
(concat "\\(" (munge s) "\\)"))
(cdr pair)
"\\|"))))
ret)))))
;;;###autoload
(defun dired-wipe (type)
"In dired, don't bother with certain TYPEs of files/directories."
(interactive (list (completing-read "Type: " dired-wipe-types nil 1)))
(let ((wt dired-wipe-types))
(when (string= "" type)
(let ((new (read-string "Regexp: "))
(name (read-string "Name (or blank for temporary): ")))
(if (string= "" name)
(setq wt (cons (cons type new) wt))
(setq type name
dired-wipe-types (cons (cons type new) dired-wipe-types)
wt dired-wipe-types))))
(let ((re (cdr (assoc type wt))))
(save-excursion
(goto-char (point-min))
(dired-goto-next-nontrivial-file)
(let (buffer-read-only)
(delete-matching-lines re))))))
(provide 'dired-wipe)
;;; dired-wipe.el,v1.18 ends here