Reformat with dash library to make code more readable
Using the anaphoric macros from the dash library allows the banner code to be smaller and I feel more readable. Yes, I could have run the `ls` command into another buffer and copied it, I have bigger plans for displaying my directory listing.
This commit is contained in:
parent
d5e30ec98f
commit
b399c30bb6
1 changed files with 18 additions and 20 deletions
|
@ -563,7 +563,7 @@ The [[http://projects.ryuslash.org/eshell-fringe-status/][eshell-fringe-status]]
|
||||||
:hook (eshell-mode . eshell-fringe-status-mode))
|
:hook (eshell-mode . eshell-fringe-status-mode))
|
||||||
#+end_src
|
#+end_src
|
||||||
** Opening Banner
|
** Opening Banner
|
||||||
Whenever I open a shell, I instinctively type =ls= … so why not do that automatically?
|
Whenever I open a shell, I instinctively type =ls= … so why not do that automatically? The [[elisp:(describe-variable 'eshell-banner-message)][eshell-banner-message]] variable, while normally a string, can be a /form/ (an s-expression) that calls a function, so I made a customized =ls= that can be attractive:
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defun ha-eshell-banner ()
|
(defun ha-eshell-banner ()
|
||||||
"Return a string containing the files in the current directory."
|
"Return a string containing the files in the current directory."
|
||||||
|
@ -573,34 +573,32 @@ Whenever I open a shell, I instinctively type =ls= … so why not do that automa
|
||||||
(not "~")
|
(not "~")
|
||||||
string-end))
|
string-end))
|
||||||
(files (directory-files default-directory nil non-hidden))
|
(files (directory-files default-directory nil non-hidden))
|
||||||
(longest (reduce (lambda (longest file) (max longest (length file)))
|
(longest (--reduce-from (max acc (length it)) 1 files))
|
||||||
files :initial-value 1))
|
|
||||||
(padded (format "%%-%ds " longest))
|
(padded (format "%%-%ds " longest))
|
||||||
(width (window-total-width))
|
(width (window-total-width))
|
||||||
(columns (/ width (+ longest 3))))
|
(columns (/ width (+ longest 3))))
|
||||||
|
|
||||||
(cl-flet* ((process-file
|
(cl-flet* ((process-file
|
||||||
(file)
|
(file)
|
||||||
(let ((image-rx (rx "." (or "png" "jpg" "jpeg" "tif" "wav") string-end))
|
(let ((impor-rx (rx string-start "README"))
|
||||||
|
(image-rx (rx "." (or "png" "jpg" "jpeg" "tif" "wav") string-end))
|
||||||
(code-rx (rx "." (or "el" "py" "rb") string-end))
|
(code-rx (rx "." (or "el" "py" "rb") string-end))
|
||||||
(docs-rx (rx "." (or "org" "md") string-end)))
|
(docs-rx (rx "." (or "org" "md") string-end)))
|
||||||
(format padded (cond
|
(format padded (cond
|
||||||
((string-match image-rx file) (propertize file 'face '(:foreground "light pink")))
|
((string-match impor-rx file)
|
||||||
((string-match code-rx file) (propertize file 'face '(:foreground "DarkSeaGreen1")))
|
(propertize file 'face '(:foreground "gold")))
|
||||||
((file-directory-p file) (propertize file 'face '(:foreground "SteelBlue")))
|
((string-match image-rx file)
|
||||||
(t file)))))
|
(propertize file 'face '(:foreground "light pink")))
|
||||||
;; This nasty little function was an attempt to make
|
((string-match code-rx file)
|
||||||
;; things readable, but who would have thunk that
|
(propertize file 'face '(:foreground "DarkSeaGreen1")))
|
||||||
;; `mapconcat' couldn't access a symbol reference to a
|
((file-directory-p file)
|
||||||
;; function created by `cl-flet*'!?
|
(propertize file 'face 'eshell-ls-directory))
|
||||||
(process-files
|
(t
|
||||||
(table)
|
file)))))
|
||||||
(mapconcat (lambda (line) (mapconcat
|
|
||||||
(lambda (file) (process-file file))
|
(process-lines (files) (s-join "• " (--map (process-file it) files)))
|
||||||
line
|
|
||||||
"• "))
|
(process-files (table) (s-join "\n" (--map (process-lines it) table))))
|
||||||
table
|
|
||||||
"\n")))
|
|
||||||
|
|
||||||
(concat (process-files (seq-partition files columns)) "\n\n"))))
|
(concat (process-files (seq-partition files columns)) "\n\n"))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
Loading…
Reference in a new issue