Created
July 20, 2018 12:11
-
-
Save yqrashawn/fef5909650cd40253f3b6551e2b2ccbe to your computer and use it in GitHub Desktop.
diff between find-dired (emacs 5498acb https://github.com/emacs-mirror/emacs/blob/5498acb5a2b4a19060d17c0e2ce0aec36ee684f9/lisp/find-dired.el#L129) and fd-dired (e7091c8 https://github.com/yqrashawn/fd-dired/blob/master/fd-dired.el#L42)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 20-195405.el 2018-07-20 20:00:48.000000000 +0800 | |
+++ 20-195454.el 2018-07-20 19:55:04.000000000 +0800 | |
@@ -1,63 +1,62 @@ | |
-(defun find-dired (dir args) | |
- "Run `find' and go into Dired mode on a buffer of the output. | |
+(defun fd-dired (dir args) | |
+ "Run `fd' and go into Dired mode on a buffer of the output. | |
The command run (after changing into DIR) is essentially | |
- find . \\( ARGS \\) -ls | |
+ fd . ARGS -ls | |
-except that the car of the variable `find-ls-option' specifies what to | |
+except that the car of the variable `fd-dired-ls-option' specifies what to | |
use in place of \"-ls\" as the final argument." | |
- (interactive (list (read-directory-name "Run find in directory: " nil "" t) | |
- (read-string "Run find (with args): " find-args | |
- '(find-args-history . 1)))) | |
+ (interactive (list (and current-prefix-arg (read-directory-name "Run fd in directory: " nil "" t)) | |
+ (read-string "Run fd (with args): " fd-dired-input-fd-args | |
+ '(fd-dired-args-history . 1)))) | |
(let ((dired-buffers dired-buffers)) | |
;; Expand DIR ("" means default-directory), and make sure it has a | |
;; trailing slash. | |
- (setq dir (file-name-as-directory (expand-file-name dir))) | |
+ (setq dir (file-name-as-directory (expand-file-name (or dir default-directory)))) | |
;; Check that it's really a directory. | |
(or (file-directory-p dir) | |
- (error "find-dired needs a directory: %s" dir)) | |
- (switch-to-buffer (get-buffer-create "*Find*")) | |
+ (error "Fd-dired needs a directory: %s" dir)) | |
+ (switch-to-buffer (get-buffer-create "*Fd*")) | |
- ;; See if there's still a `find' running, and offer to kill | |
+ ;; See if there's still a `fd' running, and offer to kill | |
;; it first, if it is. | |
- (let ((find (get-buffer-process (current-buffer)))) | |
- (when find | |
- (if (or (not (eq (process-status find) 'run)) | |
- (yes-or-no-p | |
- (format-message "A `find' process is running; kill it? "))) | |
- (condition-case nil | |
- (progn | |
- (interrupt-process find) | |
- (sit-for 1) | |
- (delete-process find)) | |
- (error nil)) | |
- (error "Cannot have two processes in `%s' at once" (buffer-name))))) | |
+ (let ((fd (get-buffer-process (current-buffer)))) | |
+ (when fd | |
+ (if (or (not (eq (process-status fd) 'run)) | |
+ (yes-or-no-p | |
+ (format-message "A `fd' process is running; kill it? "))) | |
+ (condition-case nil | |
+ (progn | |
+ (interrupt-process fd) | |
+ (sit-for 1) | |
+ (delete-process fd)) | |
+ (error nil)) | |
+ (error "Cannot have two processes in `%s' at once" (buffer-name))))) | |
(widen) | |
(kill-all-local-variables) | |
(setq buffer-read-only nil) | |
(erase-buffer) | |
(setq default-directory dir | |
- find-args args ; save for next interactive call | |
- args (concat find-program " . " | |
- (if (string= args "") | |
- "" | |
- (concat | |
- (shell-quote-argument "(") | |
- " " args " " | |
- (shell-quote-argument ")") | |
- " ")) | |
- (if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|+\\)\\'" | |
- (car find-ls-option)) | |
- (format "%s %s %s" | |
- (match-string 1 (car find-ls-option)) | |
- (shell-quote-argument "{}") | |
- find-exec-terminator) | |
- (car find-ls-option)))) | |
+ fd-dired-input-fd-args args ; save for next interactive call | |
+ args (concat fd-dired-program " " fd-dired-pre-fd-args | |
+ ;; " . " | |
+ (if (string= args "") | |
+ "" | |
+ (concat | |
+ " " args " " | |
+ " ")) | |
+ (if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|+\\)\\'" | |
+ (car fd-dired-ls-option)) | |
+ (format "%s %s %s" | |
+ (match-string 1 (car fd-dired-ls-option)) | |
+ (shell-quote-argument "{}") | |
+ find-exec-terminator) | |
+ (car fd-dired-ls-option)))) | |
;; Start the find process. | |
(shell-command (concat args "&") (current-buffer)) | |
;; The next statement will bomb in classic dired (no optional arg allowed) | |
- (dired-mode dir (cdr find-ls-option)) | |
+ (dired-mode dir (cdr fd-dired-ls-option)) | |
(let ((map (make-sparse-keymap))) | |
(set-keymap-parent map (current-local-map)) | |
(define-key map "\C-c\C-k" 'kill-find) | |
@@ -65,17 +64,17 @@ | |
(make-local-variable 'dired-sort-inhibit) | |
(setq dired-sort-inhibit t) | |
(set (make-local-variable 'revert-buffer-function) | |
- `(lambda (ignore-auto noconfirm) | |
- (find-dired ,dir ,find-args))) | |
+ `(lambda (ignore-auto noconfirm) | |
+ (fd-dired ,dir ,fd-dired-input-fd-args))) | |
;; Set subdir-alist so that Tree Dired will work: | |
(if (fboundp 'dired-simple-subdir-alist) | |
- ;; will work even with nested dired format (dired-nstd.el,v 1.15 | |
- ;; and later) | |
- (dired-simple-subdir-alist) | |
+ ;; will work even with nested dired format (dired-nstd.el,v 1.15 | |
+ ;; and later) | |
+ (dired-simple-subdir-alist) | |
;; else we have an ancient tree dired (or classic dired, where | |
;; this does no harm) | |
(set (make-local-variable 'dired-subdir-alist) | |
- (list (cons default-directory (point-min-marker))))) | |
+ (list (cons default-directory (point-min-marker))))) | |
(set (make-local-variable 'dired-subdir-switches) find-ls-subdir-switches) | |
(setq buffer-read-only nil) | |
;; Subdir headlerline must come first because the first marker in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment