help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: some dired questions


From: Fabian Braennstroem
Subject: Re: some dired questions
Date: Wed, 13 Jun 2007 20:34:05 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1.3) Gecko/20070326 Thunderbird/2.0.0.0 Mnenhy/0.7.5.0

Hi William,

it works nice! Thanks!

William Xu schrieb am 06/13/2007 04:35 AM:
> 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))))))
> 
> 

Regards!
Fabian


reply via email to

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