[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: some dired questions

From: William Xu
Subject: Re: some dired questions
Date: Wed, 13 Jun 2007 12:35:54 +0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

Fabian Braennstroem <address@hidden> 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
       ":$" "" (cadr
                 (shell-command-to-string "dircolors")

;; colored by file extensions
(setq xwl-dircolors-extensions
        "=[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
            (0 (ansi-color-get-face ,(xwl-dircolors-get-escape-seq "ex")))))

   ;; colorful by extensions
   ,@(mapcar (lambda (ext)
               `(,(format ".*\\.%s$" ext)
                  (0 (ansi-color-get-face ,(xwl-dircolors-get-escape-seq 

   ;; 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
                    ;; 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)
             nil (0 dired-ignored-face))))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]