unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#29513: 25.2; find-dired-centinel
@ 2017-12-01  0:50 Roland Winkler
  2017-12-01  7:48 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Roland Winkler @ 2017-12-01  0:50 UTC (permalink / raw)
  To: 29513


Following a discussion on help-gnu-emacs

https://lists.gnu.org/archive/html/help-gnu-emacs/2017-11/msg00415.html

I request to replace the function find-dired-sentinel by something
like the following that will sort the output of find
lexicographically.  I have tested that the function below works for me.
Yet there might be corner cases I do not know about where it might fail.

(defun find-dired-sentinel (proc state)
  "Sentinel for \\[find-dired] processes."
  (let ((buf (process-buffer proc)))
    (if (buffer-name buf)
	(with-current-buffer buf
	  (let ((inhibit-read-only t))
	    (save-excursion
              (save-restriction
                (widen)
                ;; `find-dired-filter' puts two whitespace characters
                ;; at the beginning of every line.
                (narrow-to-region (point) (- (point-max) 2))
                ;; Sort file names lexicographically.
                (sort-subr nil 'forward-line 'end-of-line
                           (lambda ()
                             (buffer-substring-no-properties
                              (next-single-property-change
                               (point) 'dired-filename)
                              (line-end-position))))
                (widen)
                (let ((point (point-max)))
                  (goto-char point)
                  (insert "\n  find "
                          (substring state 0 -1) ; omit \n at end of STATE.
                          " at " (substring (current-time-string) 0 19))
                  (dired-insert-set-properties point (point))))
              (setq mode-line-process
		    (format ":%s" (process-status proc)))
	      ;; Since the buffer and mode line will show that the
	      ;; process is dead, we can delete it now.  Otherwise it
	      ;; will stay around until M-x `list-processes'.
	      (delete-process proc)
	      (force-mode-line-update))))
	  (message "find-dired %s finished." buf))))




In GNU Emacs 25.2.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.18.9)
 of 2017-03-03 built on regnitz
Windowing system distributor 'The X.Org Foundation', version 11.0.11804000
System Description:	Ubuntu 16.04.3 LTS

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF
GSETTINGS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT
LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11

Important settings:
  value of $LC_COLLATE: C
  value of $LANG: en_US.utf8
  value of $XMODIFIERS: 
  locale-coding-system: utf-8-unix

Major mode: Dired





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01  0:50 bug#29513: 25.2; find-dired-centinel Roland Winkler
@ 2017-12-01  7:48 ` Eli Zaretskii
  2017-12-01 16:28   ` Roland Winkler
  2017-12-01  8:09 ` Michael Heerdegen
       [not found] ` <handler.29513.D29513.156028776529426.notifdone@debbugs.gnu.org>
  2 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2017-12-01  7:48 UTC (permalink / raw)
  To: Roland Winkler; +Cc: 29513

> Date: Thu, 30 Nov 2017 18:50:22 -0600
> From: "Roland Winkler" <winkler@gnu.org>
> 
> Following a discussion on help-gnu-emacs
> 
> https://lists.gnu.org/archive/html/help-gnu-emacs/2017-11/msg00415.html
> 
> I request to replace the function find-dired-sentinel by something
> like the following that will sort the output of find
> lexicographically.

Thanks.

IMO, if this is deemed a useful feature, it should be optional, as it
will cause files to move on display during the time the shell commands
is running, something that users might find annoying (I certainly
would).





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01  0:50 bug#29513: 25.2; find-dired-centinel Roland Winkler
  2017-12-01  7:48 ` Eli Zaretskii
@ 2017-12-01  8:09 ` Michael Heerdegen
  2017-12-01 15:26   ` Drew Adams
       [not found] ` <handler.29513.D29513.156028776529426.notifdone@debbugs.gnu.org>
  2 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2017-12-01  8:09 UTC (permalink / raw)
  To: Roland Winkler; +Cc: 29513

"Roland Winkler" <winkler@gnu.org> writes:

> Following a discussion on help-gnu-emacs
>
> https://lists.gnu.org/archive/html/help-gnu-emacs/2017-11/msg00415.html
>
> I request to replace the function find-dired-sentinel by something
> like the following that will sort the output of find
> lexicographically.

If we do this - wouldn't supporting other sort predicates also make
sense (e.g. sort by last change time)?


Michael.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01  8:09 ` Michael Heerdegen
@ 2017-12-01 15:26   ` Drew Adams
  2017-12-01 17:48     ` Roland Winkler
  0 siblings, 1 reply; 15+ messages in thread
From: Drew Adams @ 2017-12-01 15:26 UTC (permalink / raw)
  To: Michael Heerdegen, Roland Winkler; +Cc: 29513

> If we do this - wouldn't supporting other sort predicates also make
> sense (e.g. sort by last change time)?

My thought exactly.  Pretty much anywhere we sort stuff
it makes sense to ask ourselves whether it might be
good to let users specify the sort predicate/order.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01  7:48 ` Eli Zaretskii
@ 2017-12-01 16:28   ` Roland Winkler
  2017-12-01 19:38     ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Winkler @ 2017-12-01 16:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 29513

On Fri Dec 1 2017 Eli Zaretskii wrote:
> IMO, if this is deemed a useful feature, it should be optional, as it
> will cause files to move on display during the time the shell commands
> is running, something that users might find annoying (I certainly
> would).

In my code, nothing happens while the shell command is running.  The
sorting happens only once when find has finished its job.  But it
would certainly be fine with me to have a user option such as
find-dired-sort for enabling / disabling this feature.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01 15:26   ` Drew Adams
@ 2017-12-01 17:48     ` Roland Winkler
  2017-12-01 20:04       ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Winkler @ 2017-12-01 17:48 UTC (permalink / raw)
  To: Drew Adams; +Cc: Michael Heerdegen, 29513

On Fri Dec 1 2017 Drew Adams wrote:
> > If we do this - wouldn't supporting other sort predicates also make
> > sense (e.g. sort by last change time)?
> 
> My thought exactly.  Pretty much anywhere we sort stuff
> it makes sense to ask ourselves whether it might be
> good to let users specify the sort predicate/order.

Fine with me, I'd be happy to be able to use such a feature.
The only question is how to achieve that.  The point is that (as far
as I understand these things) something like dired-sort-toggle-or-edit
ultimately relies on the shell command ls to sort its output.

Sorting the output of find by predicates such as last change time
requires to parse its output more carefully.  I believe that
currently dired's parsing capabilities are restricted to identifying
the file name, and my patch for find-dired-sentinel relies on that.

In other words, other predicates require somewhat more work than my
patch.

(All this reminds me of when I wrote proced.el years ago.  Initially
this code relied on the shell command ps that comes with zillions of
flavors on different OSs, which made the code rather fragile.
Things got much cleaner when Eli wrote the built-ins
list-system-processes and process-attributes (thank you Eli!!).  But
I expect that we do not want to re-invent the shell command find for
Emacs.  -- Phrased differently: I do not know how many flavors of
find we may have to cover to sort its output by predicates such as
last change time.)





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01 16:28   ` Roland Winkler
@ 2017-12-01 19:38     ` Eli Zaretskii
  2017-12-01 20:05       ` Roland Winkler
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2017-12-01 19:38 UTC (permalink / raw)
  To: Roland Winkler; +Cc: 29513

> Date: Fri, 1 Dec 2017 10:28:02 -0600
> From: "Roland Winkler" <winkler@gnu.org>
> Cc: 29513@debbugs.gnu.org
> 
> On Fri Dec 1 2017 Eli Zaretskii wrote:
> > IMO, if this is deemed a useful feature, it should be optional, as it
> > will cause files to move on display during the time the shell commands
> > is running, something that users might find annoying (I certainly
> > would).
> 
> In my code, nothing happens while the shell command is running.  The
> sorting happens only once when find has finished its job.  But it
> would certainly be fine with me to have a user option such as
> find-dired-sort for enabling / disabling this feature.

Maybe we should simply provide a defcustom, which is a function called
by the sentinel.  Then users could customize what happens after the
files are all collected, be it sort the results or anything else.  The
advantage will be that we won't need to support every possible tweak
of post-processing in core.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01 17:48     ` Roland Winkler
@ 2017-12-01 20:04       ` Eli Zaretskii
  2017-12-01 20:16         ` Roland Winkler
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2017-12-01 20:04 UTC (permalink / raw)
  To: Roland Winkler; +Cc: michael_heerdegen, 29513

> Date: Fri, 1 Dec 2017 11:48:34 -0600
> From: "Roland Winkler" <winkler@gnu.org>
> Cc: Michael Heerdegen <michael_heerdegen@web.de>, 29513@debbugs.gnu.org
> 
> I expect that we do not want to re-invent the shell command find for
> Emacs.

We already have, actually: see find-lisp.el.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01 19:38     ` Eli Zaretskii
@ 2017-12-01 20:05       ` Roland Winkler
  2019-06-11 21:15         ` Roland Winkler
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Winkler @ 2017-12-01 20:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 29513

On Fri Dec 1 2017 Eli Zaretskii wrote:
> Maybe we should simply provide a defcustom, which is a function called
> by the sentinel.  Then users could customize what happens after the
> files are all collected, be it sort the results or anything else.  The
> advantage will be that we won't need to support every possible tweak
> of post-processing in core.

Again: fine with me.  This could be done such that the *Find* buffer
is narrowed to the portion containing the output of the shell
command (as in my patch).  Also, as a further option (or default
value of the defcustom) we could provide a function that sorts by
file name (thus providing a real-world example of how this new
defcustom can be used).





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01 20:04       ` Eli Zaretskii
@ 2017-12-01 20:16         ` Roland Winkler
  2017-12-01 20:27           ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Winkler @ 2017-12-01 20:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: michael_heerdegen, 29513

> > I expect that we do not want to re-invent the shell command find for
> > Emacs.
> 
> We already have, actually: see find-lisp.el.

Interesting, I did not know that.  It seems, though, that the
statement in find-lisp.el

  This is a very generalized form of find.

is not quite accurate.  The power of the shell command find (at
least: the GNU version, which is the only one I know) lies in its
many bells and whistles, whereas find-lisp provides only a subset of
these features.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01 20:16         ` Roland Winkler
@ 2017-12-01 20:27           ` Eli Zaretskii
  0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2017-12-01 20:27 UTC (permalink / raw)
  To: Roland Winkler; +Cc: michael_heerdegen, 29513

> Date: Fri, 1 Dec 2017 14:16:09 -0600
> From: "Roland Winkler" <winkler@gnu.org>
> Cc: drew.adams@oracle.com,
>     michael_heerdegen@web.de,
>     29513@debbugs.gnu.org
> 
> The power of the shell command find (at least: the GNU version,
> which is the only one I know) lies in its many bells and whistles,
> whereas find-lisp provides only a subset of these features.

I'm sure patches to extend its functionality will be most welcome.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2017-12-01 20:05       ` Roland Winkler
@ 2019-06-11 21:15         ` Roland Winkler
  0 siblings, 0 replies; 15+ messages in thread
From: Roland Winkler @ 2019-06-11 21:15 UTC (permalink / raw)
  To: 29513-done

On Fri Dec 1 2017 Roland Winkler wrote:
> On Fri Dec 1 2017 Eli Zaretskii wrote:
> > Maybe we should simply provide a defcustom, which is a function called
> > by the sentinel.  Then users could customize what happens after the
> > files are all collected, be it sort the results or anything else.  The
> > advantage will be that we won't need to support every possible tweak
> > of post-processing in core.
> 
> Again: fine with me.  This could be done such that the *Find* buffer
> is narrowed to the portion containing the output of the shell
> command (as in my patch).  Also, as a further option (or default
> value of the defcustom) we could provide a function that sorts by
> file name (thus providing a real-world example of how this new
> defcustom can be used).

See commit 249902d5ad5d3ae3e25323c23a2f442913729ceb.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
       [not found] ` <handler.29513.D29513.156028776529426.notifdone@debbugs.gnu.org>
@ 2019-06-11 22:21   ` Noam Postavsky
  2019-06-12  3:25     ` Roland Winkler
  0 siblings, 1 reply; 15+ messages in thread
From: Noam Postavsky @ 2019-06-11 22:21 UTC (permalink / raw)
  To: Roland Winkler, 29513

> See commit 249902d5ad5d3ae3e25323c23a2f442913729ceb.

> +(defcustom find-dired-refine-function #'find-dired-sort-by-filename
> +  "If non-nil, a function for refining the *Find* buffer of `find-dired'.

> +                (when (boundp 'find-dired-refine-function)

I think you meant just

    (when find-dired-refine-function

(boundp 'find-dired-refine-function) is always going to be true.

Although you could just drop the "If non-nil" and conditional
altogether: the feature can already be disabled by setting to #'ignore.






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2019-06-11 22:21   ` Noam Postavsky
@ 2019-06-12  3:25     ` Roland Winkler
  2019-06-12 10:35       ` Noam Postavsky
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Winkler @ 2019-06-12  3:25 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 29513

On Tue Jun 11 2019 Noam Postavsky wrote:
> > +(defcustom find-dired-refine-function #'find-dired-sort-by-filename
> > +  "If non-nil, a function for refining the *Find* buffer of `find-dired'.
> 
> I think you meant just
> 
>     (when find-dired-refine-function

Sure, thanks, I should read my doc string.

> Although you could just drop the "If non-nil" and conditional
> altogether: the feature can already be disabled by setting to #'ignore.

Does it make a difference?





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#29513: 25.2; find-dired-centinel
  2019-06-12  3:25     ` Roland Winkler
@ 2019-06-12 10:35       ` Noam Postavsky
  0 siblings, 0 replies; 15+ messages in thread
From: Noam Postavsky @ 2019-06-12 10:35 UTC (permalink / raw)
  To: Roland Winkler; +Cc: 29513

"Roland Winkler" <winkler@gnu.org> writes:

>> Although you could just drop the "If non-nil" and conditional
>> altogether: the feature can already be disabled by setting to #'ignore.
>
> Does it make a difference?

It makes things just a tiny bit simpler.  Plus, if you really want to
allow nil, you also need to update the defcustom :type field.






^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-06-12 10:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-01  0:50 bug#29513: 25.2; find-dired-centinel Roland Winkler
2017-12-01  7:48 ` Eli Zaretskii
2017-12-01 16:28   ` Roland Winkler
2017-12-01 19:38     ` Eli Zaretskii
2017-12-01 20:05       ` Roland Winkler
2019-06-11 21:15         ` Roland Winkler
2017-12-01  8:09 ` Michael Heerdegen
2017-12-01 15:26   ` Drew Adams
2017-12-01 17:48     ` Roland Winkler
2017-12-01 20:04       ` Eli Zaretskii
2017-12-01 20:16         ` Roland Winkler
2017-12-01 20:27           ` Eli Zaretskii
     [not found] ` <handler.29513.D29513.156028776529426.notifdone@debbugs.gnu.org>
2019-06-11 22:21   ` Noam Postavsky
2019-06-12  3:25     ` Roland Winkler
2019-06-12 10:35       ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).