From 0cc17047a75e6d88a58e80135942665be92724c1 Mon Sep 17 00:00:00 2001 From: findidiot Date: Wed, 25 Dec 2024 09:46:41 +0800 Subject: [PATCH] dired*-use-ls-dired --- config/autoloads.el | 2 -- config/boot.el | 2 ++ config/direds.el | 44 ++++++++++++++----------------------- config/on-dired-autoload.el | 3 +++ 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/config/autoloads.el b/config/autoloads.el index f89b63ec..42aa13f9 100644 --- a/config/autoloads.el +++ b/config/autoloads.el @@ -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!)) diff --git a/config/boot.el b/config/boot.el index 46fd0f97..f6a30aae 100644 --- a/config/boot.el +++ b/config/boot.el @@ -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/ diff --git a/config/direds.el b/config/direds.el index f956c90e..e3471b01 100644 --- a/config/direds.el +++ b/config/direds.el @@ -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) diff --git a/config/on-dired-autoload.el b/config/on-dired-autoload.el index 8b7f58fc..e516a6ce 100644 --- a/config/on-dired-autoload.el +++ b/config/on-dired-autoload.el @@ -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