aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2019-06-11 16:04:45 -0500
committerRoland Winkler2019-06-11 16:04:45 -0500
commit249902d5ad5d3ae3e25323c23a2f442913729ceb (patch)
tree6c7d0266b15120ff4e8cac4edfa8775f62292477
parente92dac3434d30b870461898a336854879620f400 (diff)
downloademacs-249902d5ad5d3ae3e25323c23a2f442913729ceb.tar.gz
emacs-249902d5ad5d3ae3e25323c23a2f442913729ceb.zip
Allow refining the *Find* buffer of find-dired. (Bug#29513)
* find-dired.el (find-dired-refine-function): New user variable. (find-dired-sentinel): Use it. Simplify. (find-dired-sort-by-filename): New function.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/find-dired.el55
2 files changed, 44 insertions, 16 deletions
diff --git a/etc/NEWS b/etc/NEWS
index c9da98b0adc..6efa7642f85 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -580,6 +580,11 @@ remapped to these, respectively.
580+++ 580+++
581*** New command 'dired-create-empty-file'. 581*** New command 'dired-create-empty-file'.
582 582
583** Find-Dired
584
585*** New customizable variable 'find-dired-refine-function'.
586The default value is 'find-dired-sort-by-filename'.
587
583** Change Logs and VC 588** Change Logs and VC
584 589
585*** Recording ChangeLog entries doesn't require an actual file. 590*** Recording ChangeLog entries doesn't require an actual file.
diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index ef137be9bbf..6e5abe2f134 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -117,6 +117,14 @@ find also ignores case. Otherwise, -name is used."
117 :group 'find-dired 117 :group 'find-dired
118 :version "22.2") 118 :version "22.2")
119 119
120(defcustom find-dired-refine-function #'find-dired-sort-by-filename
121 "If non-nil, a function for refining the *Find* buffer of `find-dired'.
122This function takes no arguments. The *Find* buffer is narrowed to the
123output of `find' (one file per line) when this function is called."
124 :version "27.1"
125 :group 'find-dired
126 :type 'function)
127
120(defvar find-args nil 128(defvar find-args nil
121 "Last arguments given to `find' by \\[find-dired].") 129 "Last arguments given to `find' by \\[find-dired].")
122 130
@@ -334,28 +342,43 @@ specifies what to use in place of \"-ls\" as the final argument."
334 (delete-process proc)))) 342 (delete-process proc))))
335 343
336(defun find-dired-sentinel (proc state) 344(defun find-dired-sentinel (proc state)
337 ;; Sentinel for \\[find-dired] processes. 345 "Sentinel for \\[find-dired] processes."
338 (let ((buf (process-buffer proc)) 346 (let ((buf (process-buffer proc)))
339 (inhibit-read-only t))
340 (if (buffer-name buf) 347 (if (buffer-name buf)
341 (with-current-buffer buf 348 (with-current-buffer buf
342 (let ((buffer-read-only nil)) 349 (let ((inhibit-read-only t))
343 (save-excursion 350 (save-excursion
344 (goto-char (point-max)) 351 (save-restriction
345 (let ((point (point))) 352 (widen)
346 (insert "\n find " state) 353 (when (boundp 'find-dired-refine-function)
347 (forward-char -1) ;Back up before \n at end of STATE. 354 ;; `find-dired-filter' puts two whitespace characters
348 (insert " at " (substring (current-time-string) 0 19)) 355 ;; at the beginning of every line.
349 (dired-insert-set-properties point (point))) 356 (narrow-to-region (point) (- (point-max) 2))
350 (setq mode-line-process 357 (funcall find-dired-refine-function)
351 (concat ":" 358 (widen))
352 (symbol-name (process-status proc)))) 359 (let ((point (point-max)))
360 (goto-char point)
361 (insert "\n find "
362 (substring state 0 -1) ; omit \n at end of STATE.
363 " at " (substring (current-time-string) 0 19))
364 (dired-insert-set-properties point (point))))
365 (setq mode-line-process
366 (format ":%s" (process-status proc)))
353 ;; Since the buffer and mode line will show that the 367 ;; Since the buffer and mode line will show that the
354 ;; process is dead, we can delete it now. Otherwise it 368 ;; process is dead, we can delete it now. Otherwise it
355 ;; will stay around until M-x list-processes. 369 ;; will stay around until M-x `list-processes'.
356 (delete-process proc) 370 (delete-process proc)
357 (force-mode-line-update))) 371 (force-mode-line-update))))
358 (message "find-dired %s finished." (current-buffer)))))) 372 (message "find-dired %s finished." buf))))
373
374(defun find-dired-sort-by-filename ()
375 "Sort entries in *Find* buffer by file name lexicographically."
376 (sort-subr nil 'forward-line 'end-of-line
377 (lambda ()
378 (buffer-substring-no-properties
379 (next-single-property-change
380 (point) 'dired-filename)
381 (line-end-position)))))
359 382
360 383
361(provide 'find-dired) 384(provide 'find-dired)