Fuco1 / dired-hacks

Collection of useful dired additions
GNU General Public License v3.0
880 stars 77 forks source link

Not seeing anything when I M-x dired-rainbow ... #148

Open godfrey-cw opened 5 years ago

godfrey-cw commented 5 years ago

Installed dired-rainbow via MELPA with the package manager, along with most of the other dired-hacks packages. All the others are working fine but when I hit M-x dired-rainbow-define or M-x describe-function ENTER dired-rainbow-define I'm not getting anything. When I use dired-rainbow in my init it doesn't run to completion.

Anyway, it seems like my emacs isn't finding the dired-rainbow functions. Any help in this matter would be appreciated!

dieggsy commented 5 years ago

@godfrey-cw could you show the relevant part of your config pertaining to dired-rainbow ?

Fuco1 commented 5 years ago

The functions are not interactive so you won't be able to run them with M-x.

Fuco1 commented 5 years ago

This is an example from my config

(use-package dired-rainbow
  :config
  (progn
    (dired-rainbow-define html "#4e9a06" ("htm" "html" "xhtml"))
    (dired-rainbow-define xml "#b4fa70" ("xml" "xsd" "xsl" "xslt" "wsdl"))

    (dired-rainbow-define document font-lock-function-name-face ("doc" "docx" "odt" "pdb" "pdf" "ps" "rtf" "djvu" "epub"))
    (dired-rainbow-define excel "#3465a4" ("xlsx"))
    (dired-rainbow-define media "#ce5c00" my-dired-media-files-extensions)
    (dired-rainbow-define image "#ff4b4b" ("jpg" "png" "jpeg" "gif"))

    (dired-rainbow-define log "#c17d11" ("log"))
    (dired-rainbow-define sourcefile "#fcaf3e" ("py" "c" "cc" "h" "java" "pl" "rb" "R" "php"))

    (dired-rainbow-define executable "#8cc4ff" ("exe" "msi"))
    (dired-rainbow-define compressed "#ad7fa8" ("zip" "bz2" "tgz" "txz" "gz" "xz" "z" "Z" "jar" "war" "ear" "rar" "sar" "xpi" "apk" "xz" "tar"))
    (dired-rainbow-define packaged "#e6a8df" ("deb" "rpm"))
    (dired-rainbow-define encrypted "LightBlue" ("gpg" "pgp"))

    (dired-rainbow-define-chmod executable-unix "Green" "-.*x.*")
    ))
godfrey-cw commented 5 years ago

Awesome, many thanks that's very helpful. I just basically copy-pasted from the readme, and was adding stuff like

(defconst my-dired-media-files-extensions
  '("mp3" "mp4" "MP3" "MP4" "avi" "mpg" "flv" "ogg")
  "Media files.")
(dired-rainbow-define media "#ce5c00" my-dired-media-files-extensions)

But without any use-package or :config. Sorry, still kind of an emacs newbie here!

UPDATE: The example you just posted works great -- in my newbie fashion I'll just cautiously tweak that. Thanks for all the dired-hacks!

godfrey-cw commented 5 years ago

FWIW I just spent 20 minutes tweaking your example into a pseudo-port of LS_COLORS (didn't actually figure out how to turn ls colors into hex, just used inspection of my terminal and Tailwind CSS colors to find approximations. I skipped extensions I had never heard of and amalgamated where it made sense to me (e.g. grouping xlsx and csv ...). It'd be cool if someone did a better port of an extensive LS_COLORS setup than this, but I'm content with the below.

(use-package dired-rainbow
  :config
  (progn
    (dired-rainbow-define html "#eb5286" ("css" "less" "sass" "scss" "htm" "html" "jhtm" "mht" "eml" "mustache" "xhtml"))
    (dired-rainbow-define xml "#f2d024" ("xml" "xsd" "xsl" "xslt" "wsdl" "bib" "json" "msg" "pgn" "rss" "yaml" "yml" "rdata"))
    (dired-rainbow-define document "#9561e2" ("docm" "doc" "docx" "odb" "odt" "pdb" "pdf" "ps" "rtf" "djvu" "epub" "odp" "ppt" "pptx"))
    (dired-rainbow-define markdown "#ffed4a" ("org" "etx" "info" "markdown" "md" "mkd" "nfo" "pod" "rst" "tex" "textfile" "txt"))
    (dired-rainbow-define database "#6574cd" ("xlsx" "xls" "csv" "accdb" "db" "mdb" "sqlite" "nc"))
    (dired-rainbow-define media "#de751f" ("mp3" "mp4" "MP3" "MP4" "avi" "mpeg" "mpg" "flv" "ogg" "mov" "mid" "midi" "wav" "aiff" "flac"))
    (dired-rainbow-define image "#f66d9b" ("tiff" "tif" "cdr" "gif" "ico" "jpeg" "jpg" "png" "psd" "eps" "svg"))
    (dired-rainbow-define log "#c17d11" ("log"))
    (dired-rainbow-define shell "#f6993f" ("awk" "bash" "bat" "sed" "sh" "zsh" "vim"))
    (dired-rainbow-define interpreted "#38c172" ("py" "ipynb" "rb" "pl" "t" "msql" "mysql" "pgsql" "sql" "r" "clj" "cljs" "scala" "js"))
    (dired-rainbow-define compiled "#4dc0b5" ("asm" "cl" "lisp" "el" "c" "h" "c++" "h++" "hpp" "hxx" "m" "cc" "cs" "cp" "cpp" "go" "f" "for" "ftn" "f90" "f95" "f03" "f08" "s" "rs" "hi" "hs" "pyc" ".java"))
    (dired-rainbow-define executable "#8cc4ff" ("exe" "msi"))
    (dired-rainbow-define compressed "#51d88a" ("7z" "zip" "bz2" "tgz" "txz" "gz" "xz" "z" "Z" "jar" "war" "ear" "rar" "sar" "xpi" "apk" "xz" "tar"))
    (dired-rainbow-define packaged "#faad63" ("deb" "rpm" "apk" "jad" "jar" "cab" "pak" "pk3" "vdf" "vpk" "bsp"))
    (dired-rainbow-define encrypted "#ffed4a" ("gpg" "pgp" "asc" "bfe" "enc" "signature" "sig" "p12" "pem"))
    (dired-rainbow-define fonts "#6cb2eb" ("afm" "fon" "fnt" "pfb" "pfm" "ttf" "otf"))
    (dired-rainbow-define partition "#e3342f" ("dmg" "iso" "bin" "nrg" "qcow" "toast" "vcd" "vmdk" "bak"))
    (dired-rainbow-define vc "#0074d9" ("git" "gitignore" "gitattributes" "gitmodules"))
    (dired-rainbow-define-chmod executable-unix "#38c172" "-.*x.*")
    ))

Not sure if you'd consider including this (or a better version of this) as a "dired-rainbow starter kit," for lazy people like myself who would be fine just copy-pasting something into their .emacs.

Fuco1 commented 5 years ago

The last number of the triplet maps through this: https://jonasjacek.github.io/colors/

The ;1 part marks bold.

This is indeed pretty cool, maybe a simple sed/awk script could turn LS_COLORS into the lisp equivalent.

Either way your example can be included in the readme for sure. PR welcome!

EDIT: also unrelated, but Algebraic geometry is awesome! My 3rd year thesis was on the Nullstellensatz... a pretty unusual proof through some more obscure theorems. Sadly I only really got into it my last year :/ I was more into CT nonsense due to my compsci origins :D

publicimageltd commented 3 years ago

I just want to remark that for me, dired-rainbow also never worked. Accidentally, I found out that the cause was a wrong regexp in dired-hacks-datetime-regexp.

The original value was:

"\\sw\\sw\\sw....\\(?:[0-9][0-9]:[0-9][0-9]\\|.[0-9]\\{4\\}\\)"

I changed it to:

"\\sw\\sw\\sw.\\(?:[0-9][0-9]:[0-9][0-9]\\|[0-9]\\{4\\}\\)"

Now everything works fine. So basically, I now wrap all definitions in init.el within a let-statement:

  (let ((dired-hacks-datetime-regexp
    "\\sw\\sw\\sw.\\(?:[0-9][0-9]:[0-9][0-9]\\|[0-9]\\{4\\}\\)"))
    (dired-rainbow-define-chmod directory "#6cb2eb" "d.*")
    .... etc ....
   )

I have no clue why this change is necessary. Looking at the regexps, it's something with the spaces between the dates and the rights. I pass no unconventional switches to ls, however, so I think it might be some change of the behavior of \sw (syntax table or whatever). I leave finding the cause to the experts; just wanted to point out that this helps.

Fuco1 commented 3 years ago

These outputs can also depend on the platform and versions of many other packages/commands. Maybe we can come up with a regexp that works for everything out of the box.

publicimageltd commented 3 years ago

I'd be happy to help if you have any idea which parameters or programs could be relevant.

For a starter, maybe it would be enough to just replace the three dots ... with a simple .*?. The result is:

"\\sw\\sw\\sw.*?\\(?:[0-9][0-9]:[0-9][0-9]\\|[0-9]\\{4\\}\\)"

Works for me right now, and would also cover the case where the original regexp applied.

Fuco1 commented 3 years ago

Yes I think that would be reasonable. I'll try it also and we'll see.

jpdur7729 commented 3 years ago

dired-rainbow does not work for me... Within dired the faces used are still the dired-faces when any (C-u C-x =). I tried the trick suggested above but did not work either for me. I am on w10 with Emacs 27.1.

Any Idea of how to sort out the issue.... I have attached below a quick snapshot of what I can see.

image

legends2k commented 2 years ago

@Fuco1 I'm on Emacs 28.2 (Windows 11), I'm not able to get it to work either. Here's my configuration:

(use-package dired-rainbow
  :ensure t
  :after dired
  :config
    (dired-rainbow-define markdown "#ffed4a" ("org" "etx" "info" "markdown" "md" "mkd" "nfo" "pod" "rst" "tex" "adoc"
                                              "textfile" "txt"))
    (dired-rainbow-define compiled "#4dc0b5" ("asm" "cl" "m" "mm" "lisp" "el" "c" "h" "c++" "h++" "hpp" "hxx" "m" "cc"
                                              "cs" "cp" "cpp" "go" "f" "rs" "hi" "hs" "pyc" ".java"))
)

I only see directories with a different colour and nothing more. Any way I can debug this? Help on dired-rainbow-ext-to-face variable shows

(
(("org" "etx" "info" "markdown" "md" "mkd" "nfo" "pod" "rst" "tex" "adoc" "textfile" "txt")
  dired-rainbow-markdown-face "\\.\\(?:adoc\\|etx\\|info\\|m\\(?:arkdown\\|k?d\\)\\|nfo\\|org\\|pod\\|rst\\|t\\(?:ex\\(?:tfile\\)?\\|xt\\)\\)")
(("asm" "cl" "m" "mm" "lisp" "el" "c" "h" "c++" "h++" "hpp" "hxx" "m" "cc" "cs" "cp" "cpp" "go" "f" "rs" "hi" "hs" "pyc" ".java")
  dired-rainbow-compiled-face "\\.\\(?:\\.java\\|asm\\|c\\(?:\\+\\+\\|pp\\|[clps]\\)\\|el\\|go\\|h\\(?:\\+\\+\\|pp\\|xx\\|[is]\\)\\|lisp\\|mm\\|pyc\\|rs\\|[cfhm]\\)")
)
legends2k commented 2 years ago

Got it working!

(setq dired-hacks-datetime-regexp "\\(?:[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]\\|[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)")

works as my dired buffers show date and time as DD-MM hh:mm or YYYY-MM-DD.

Fuco1 commented 1 year ago

@purcell has a diredfl package https://github.com/purcell/diredfl which also adds a lot of dired fontifications. For those who have issues with the dates you can also steal the regexp from there :grin:

purcell commented 1 year ago

Yeah, extracted from dired+ and independently updated a few times since.

groskwik commented 12 months ago

Got it working!

(setq dired-hacks-datetime-regexp "\\(?:[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]\\|[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)")

works as my dired buffers show date and time as DD-MM hh:mm or YYYY-MM-DD.

Thanks so much !!! my config was only working on my mcbook but failed on linux and PC at work. This simple line fixed the issue.

emilsenan commented 9 months ago

@Fuco1 Hi, is dired-rainbow still supposed to work with latest emacs? Faces based on file extension are actually not added, checked with (C-u C-x =).

sven765 commented 8 months ago

The datetime regexp tip helped me too! Thanks!

My dired shows datetime as "8. Mär 20:06" or "27. Feb 2023" for examples, so this regexp helped me:

(setq dired-hacks-datetime-regexp "\\(?:[0-9]\\| \\)[0-9]. \\w\\w\\w \\(?:[0-9][0-9]:[0-9][0-9]\\|[0-9][0-9][0-9][0-9] \\)")