Skip to content

Commit

Permalink
dired*-use-ls-dired
Browse files Browse the repository at this point in the history
  • Loading branch information
junjiemars committed Dec 25, 2024
1 parent 52e47a4 commit 0cc1704
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
2 changes: 0 additions & 2 deletions config/autoloads.el
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@
;; after-init
(defun on-autoloads! ()
"Autoload after init."
;; preferred coding system
(prefer-coding-system 'utf-8)
(self-graphic-init!)
(when-fn% self-shell-read! nil (self-shell-read!))
(when-fn% self-socks-init! nil (self-socks-init!))
Expand Down
2 changes: 2 additions & 0 deletions config/boot.el
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ No matter the declaration order, the executing order is:

;; disable `package' at startup
(when-package% (setq package-enable-at-startup nil))
;; preferred coding system
(prefer-coding-system 'utf-8)
;; make `v-home' .exec/
(v-home! ".exec/")
;; make `v-home' private/
Expand Down
44 changes: 17 additions & 27 deletions config/direds.el
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,27 @@
(let ((interprogram-paste-function nil))
(dired-copy-filename-as-kill arg)))

(defun dired*-use-ls-dired ()
;; prefer GNU's ls (--dired option) on Windows or Darwin. on
;; Windows: `dired-mode' does not display executable flag in file
;; mode,see `dired-use-ls-dired' and `ido-dired' for more defails
(if% (executable-find* "ls")
(if% (zerop (car (shell-command* "ls" "--dired")))
;; on Drawin: the builtin `ls' does not support --dired option
(setq% dired-use-ls-dired t dired)
(setq% dired-use-ls-dired nil dired)
(setq% ls-lisp-use-insert-directory-program t ls-lisp))
(setq% dired-use-ls-dired nil dired)
(setq% ls-lisp-use-insert-directory-program nil ls-lisp)))

(defun on-dired-init! ()
"On \\=`dired\\=' initialization."
(when-platform% windows-nt
;; prefer GNU find on Windows, such for `find-dired' or `find-name-dired'.
(let ((find (executable-find%
"find"
(lambda (bin)
(let ((ver (shell-command* bin "--version")))
(and (zerop (car ver))
(string-match "^find (GNU findutils)"
(cdr ver))))))))
(when find
(windows-nt-env-path+ (file-name-directory find)))))
;; prefer GNU's ls (--dired option) on Windows or Darwin. on
;; Windows: `dired-mode' does not display executable flag in file
;; mode,see `dired-use-ls-dired' and `ido-dired' for more defails
(when% (executable-find*
"ls"
(lambda (bin)
(let ((home (shell-command* bin (emacs-home%))))
(zerop (car home)))))
;; on Drawin: the builtin ls does not support --dired option
(setq% dired-use-ls-dired
(executable-find%
"ls"
(lambda (bin)
(let ((dired (shell-command* bin "--dired")))
(zerop (car dired)))))
dired)
;; using `insert-directory-program'
(setq% ls-lisp-use-insert-directory-program t ls-lisp))
(when% (let ((ver (shell-command* "find" "--version")))
(and (zerop (car ver))
(string-match "^find (GNU findutils)" (cdr ver))))
(windows-nt-env-path+ (file-name-directory (executable-find* "find")))))
;; keys
(define-key dired-mode-map "b" #'dired*-hexl-find-file)
(define-key dired-mode-map "B" #'dired*-browse-file)
Expand Down
3 changes: 3 additions & 0 deletions config/on-dired-autoload.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
(autoload 'on-dired-init! (v-home%> "config/direds"))
(autoload 'on-dired-aux-init! (v-home%> "config/direds"))
(autoload 'on-arc-mode-init! (v-home%> "config/direds"))
(autoload 'dired*-use-ls-dired (v-home%> "config/direds"))

(add-hook 'dired-load-hook #'dired*-use-ls-dired)

;;; `dired' after load
(with-eval-after-load 'dired
Expand Down

0 comments on commit 0cc1704

Please sign in to comment.