all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: William Xu <william.xwl@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: some dired questions
Date: Wed, 13 Jun 2007 12:35:54 +0800	[thread overview]
Message-ID: <87vedsjwt1.fsf@www.williamxu.com> (raw)
In-Reply-To: f4mrbo$1tm$1@tamarack.fernuni-hagen.de

Fabian Braennstroem <f.braennstroem@gmx.de> 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

  reply	other threads:[~2007-06-13  4:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-12 21:22 some dired questions Fabian Braennstroem
2007-06-13  4:35 ` William Xu [this message]
     [not found] ` <mailman.2074.1181710035.32220.help-gnu-emacs@gnu.org>
2007-06-13 20:34   ` Fabian Braennstroem

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vedsjwt1.fsf@www.williamxu.com \
    --to=william.xwl@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.