From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: William Xu Newsgroups: gmane.emacs.help Subject: Re: some dired questions Date: Wed, 13 Jun 2007 12:35:54 +0800 Organization: the Church of Emacs Message-ID: <87vedsjwt1.fsf@www.williamxu.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1181710052 24968 80.91.229.12 (13 Jun 2007 04:47:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 13 Jun 2007 04:47:32 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 13 06:47:30 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HyKlV-00021L-B9 for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jun 2007 06:47:29 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HyKlU-0000xS-Sx for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jun 2007 00:47:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HyKlG-0000xN-66 for help-gnu-emacs@gnu.org; Wed, 13 Jun 2007 00:47:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HyKlE-0000xB-BL for help-gnu-emacs@gnu.org; Wed, 13 Jun 2007 00:47:13 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HyKlE-0000x8-7j for help-gnu-emacs@gnu.org; Wed, 13 Jun 2007 00:47:12 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HyKlD-0005lZ-IP for help-gnu-emacs@gnu.org; Wed, 13 Jun 2007 00:47:11 -0400 Original-Received: from root by ciao.gmane.org with local (Exim 4.43) id 1HyKj8-00007p-0F for help-gnu-emacs@gnu.org; Wed, 13 Jun 2007 06:45:02 +0200 Original-Received: from 203.86.61.139 ([203.86.61.139]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Jun 2007 06:45:01 +0200 Original-Received: from william.xwl by 203.86.61.139 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Jun 2007 06:45:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 126 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 203.86.61.139 User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:vdtk0NenhB010iDtXWjdm/arubo= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:44987 Archived-At: Fabian Braennstroem writes: I was looking for a way to adjust dired's coloring to the terminal colors provided by '.dircolors'. I saw 'dircolors.el', but it does not seem to be helpful for dired's mode!? You can modify `dired-font-lock-keywords'. Try my setup: ;; apply shell's color scheme to dired ;; ----------------------------------- (setq xwl-dircolors-string (replace-regexp-in-string ":$" "" (cadr (split-string (shell-command-to-string "dircolors") "'")))) ;; colored by file extensions (setq xwl-dircolors-extensions (split-string (replace-regexp-in-string "=[0-9;]+\\|\\*\\." "" (replace-regexp-in-string "^[^*]*" "" xwl-dircolors-string)) ":")) (defun xwl-dircolors-get-escape-seq (regexp) "Get escape-seq by matching REGEXP against `xwl-dircolors-string'. e.g., (xwl-dircolors-get-escape-seq \"*.gz\") => \"01;31\"" (string-match (concat regexp "=\\([^:]+\\):") xwl-dircolors-string) (match-string 1 xwl-dircolors-string)) (setq dired-font-lock-keywords `( ;; ;; Directory headers. ,(list dired-subdir-regexp '(1 dired-header-face)) ;; ;; Dired marks. ,(list dired-re-mark '(0 dired-mark-face)) ;; ;; We make heavy use of MATCH-ANCHORED, since the regexps don't identify the ;; file name itself. We search for Dired defined regexps, and then use the ;; Dired defined function `dired-move-to-filename' before searching for the ;; simple regexp ".+". It is that regexp which matches the file name. ;; ;; Marked files. ,(list (concat "^[" (char-to-string dired-marker-char) "]") '(".+" (dired-move-to-filename) nil (0 dired-marked-face))) ;; ;; Flagged files. ,(list (concat "^[" (char-to-string dired-del-marker) "]") '(".+" (dired-move-to-filename) nil (0 dired-flagged-face))) ;; People who are paranoid about security would consider this more ;; important than other things such as whether it is a directory. ;; But we don't want to encourage paranoia, so our default ;; should be what's most useful for non-paranoids. -- rms. ;;; ;; ;;; ;; Files that are group or world writable. ;;; (list (concat dired-re-maybe-mark dired-re-inode-size ;;; "\\([-d]\\(....w....\\|.......w.\\)\\)") ;;; '(1 dired-warning-face) ;;; '(".+" (dired-move-to-filename) nil (0 dired-warning-face))) ;; However, we don't need to highlight the file name, only the ;; permissions, to win generally. -- fx. ;; Fixme: we could also put text properties on the permission ;; fields with keymaps to frob the permissions, somewhat a la XEmacs. ,(list (concat dired-re-maybe-mark dired-re-inode-size "[-d]....\\(w\\)....") ; group writable '(1 dired-warning-face)) ,(list (concat dired-re-maybe-mark dired-re-inode-size "[-d].......\\(w\\).") ; world writable '(1 dired-warning-face)) ;; ;; Subdirectories. ,(list dired-re-dir '(".+" (dired-move-to-filename) nil (0 dired-directory-face))) ;; ;; Symbolic links. ,(list dired-re-sym '(".+" (dired-move-to-filename) nil (0 dired-symlink-face))) ;; executables ,(list dired-re-exe `(".+" (dired-move-to-filename) nil (0 (ansi-color-get-face ,(xwl-dircolors-get-escape-seq "ex"))))) ;; colorful by extensions ,@(mapcar (lambda (ext) `(,(format ".*\\.%s$" ext) (".+" (dired-move-to-filename) nil (0 (ansi-color-get-face ,(xwl-dircolors-get-escape-seq ext)))))) xwl-dircolors-extensions) ;; ;; Files suffixed with `completion-ignored-extensions'. (eval . ;; It is quicker to first find just an extension, then go back to the ;; start of that file name. So we do this complex MATCH-ANCHORED form. (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$") '(".+" (dired-move-to-filename) nil (0 dired-ignored-face)))) ;; ;; Files suffixed with `completion-ignored-extensions' ;; plus a character put in by -F. (eval . (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)[*=|]$") '(".+" (progn (end-of-line) ;; If the last character is not part of the filename, ;; move back to the start of the filename ;; so it can be fontified. ;; Otherwise, leave point at the end of the line; ;; that way, nothing is fontified. (unless (get-text-property (1- (point)) 'mouse-face) (dired-move-to-filename))) nil (0 dired-ignored-face)))))) -- William