unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55894: 26.3; [PATCH] `find-lisp.el' bugs
@ 2022-06-10 22:06 Drew Adams
  2022-06-11  6:01 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2022-06-10 22:06 UTC (permalink / raw)
  To: 55894

[-- Attachment #1: Type: text/plain, Size: 2653 bytes --]

`find-lisp.el' is an old file that doesn't seem to have gotten much
love.  It's apparently been updated just to change things like use of
(set (make-local-variable...)) to (setq-local...).

(I wasn't aware of this library till I saw a blog post by Micky Petersen:
https://www.masteringemacs.org/article/working-multiple-files-dired.)

The attached patch fixes a few bugs that prevent using it in some
important ways: (1) opening a Dired buffer that explicitly lists its
listed files or dirs (i.e. a snapshot Dired buffer, where DIRNAME is a
cons), (2) using its listing with a `dired-actual-switches' value that
contains switch `F', (3) properly handling a listed file or dir name
that starts with a space char.

[#1 is an important use case.  Because a `find' command (Lisp or not)
can take quite a while, it can be useful to make a snapshot of its
result, i.e., save the list of files and later restore a Dired buffer
for that explicit set of files, without rerunning `find'.  For that use
case, at least, these bugs need to be fixed.]

The patch does the following.  1-2 are improvements, 3-4 are bug fixes.

1. Add other-window versions of commands `find-lisp-find-dired' and
   `find-lisp-find-dired-subdirectories'.

   (Really, both command names should be shortened.  Really, most names
   in this library should be shortened/improved.  And really, the name
   `find-lisp-find-dired' is not good - besides a confusing combination
   of name components, it doesn't tell you that it's only about files,
   not files and dirs - its companion for listing only subdirs has that
   in its name.)

2. `find-lisp-find-dired-internal': Added optional arg OTHER-WINDOW.

3. `find-lisp-find-dired-insert-file':

   * Add a doc string.
   * Put text property `dired-filename' on the inserted file/dir name.
     (This fixes the mistreatment of file/dir names that start with a
     space char.)
   * Start with `dired-actual-switches', instead of just "".  In
     particular, this is to keep switch `F'.

4. `find-lisp-format': If `F' listing switch is present then append `/'
   to listed directories.

Attached is a patch against master today.

Other changes could also be made, both to clean up the code and to
improve the behavior.  But that will wait for someone else.



In GNU Emacs 26.3 (build 1, x86_64-w64-mingw32)
 of 2019-08-29
Repository revision: 96dd0196c28bc36779584e47fffcca433c9309cd
Windowing system distributor `Microsoft Corp.', version 10.0.19044
Configured using:
 `configure --without-dbus --host=x86_64-w64-mingw32
 --without-compress-install 'CFLAGS=-O2 -static -g3''


[-- Attachment #2: find-lisp-2022-06-10a.patch --]
[-- Type: application/octet-stream, Size: 5591 bytes --]

diff -u find-lisp.el find-lisp-PATCHED-2022-06-10a.el
--- find-lisp.el	2022-06-10 08:13:53.540137300 -0700
+++ find-lisp-PATCHED-2022-06-10a.el	2022-06-10 14:24:28.845259100 -0700
@@ -166,7 +166,7 @@
 
 ;;;###autoload
 (defun find-lisp-find-dired (dir regexp)
-  "Find files in DIR, matching REGEXP."
+  "Find, then dired, the files within DIR whose names match REGEXP."
   (interactive "DFind files in directory: \nsMatching regexp: ")
   (let ((find-lisp-regexp regexp))
     (find-lisp-find-dired-internal
@@ -175,34 +175,54 @@
      'find-lisp-default-directory-predicate
      "*Find Lisp Dired*")))
 
+(defun find-lisp-find-dired-other-window (dir regexp)
+  "Same as `find-lisp-find-dired', but use another window."
+  (interactive "DFind files in directory: \nsMatching regexp: ")
+  (let ((find-lisp-regexp regexp))
+    (find-lisp-find-dired-internal
+     dir
+     'find-lisp-default-file-predicate
+     'find-lisp-default-directory-predicate
+     "*Find Lisp Dired*"
+     'OTHER-WINDOW)))
+
 ;; Just the subdirectories
 ;;;###autoload
 (defun find-lisp-find-dired-subdirectories (dir)
   "Find all subdirectories of DIR."
-  (interactive "DFind subdirectories of directory: ")
+  (interactive "DDired descendent dirs of directory: ")
   (find-lisp-find-dired-internal
    dir
    'find-lisp-file-predicate-is-directory
    'find-lisp-default-directory-predicate
    "*Find Lisp Dired Subdirectories*"))
 
+;;;###autoload
+(defun find-lisp-find-dired-subdirs-other-window (dir)
+  "Same as `find-lisp-find-dired-subdirectories', but use another window."
+  (interactive "DDired descendent dirs of directory: ")
+  (find-lisp-find-dired-internal dir
+                                 'find-lisp-file-predicate-is-directory
+                                 'find-lisp-default-directory-predicate
+                                 "*Find Lisp Dired Subdirectories*"
+                                 'OTHER-WINDOW))
+
 ;; Most of this is lifted from find-dired.el
 ;;
 (defun find-lisp-find-dired-internal (dir file-predicate
-					  directory-predicate buffer-name)
-  "Run find (Lisp version) and go into Dired mode on a buffer of the output."
-  (let ((dired-buffers dired-buffers)
-	(regexp find-lisp-regexp))
-    ;; Expand DIR ("" means default-directory), and make sure it has a
-    ;; trailing slash.
+                                          directory-predicate buffer-name
+                                          &optional other-window)
+  "Run Lisp version of `find', then dired the result."
+  (let ((dired-buffers  dired-buffers)
+        (regexp         find-lisp-regexp))
+    ;; Expand DIR ("" means `default-directory'), ensuring a trailing slash.
     (setq dir (file-name-as-directory (expand-file-name dir)))
     ;; Check that it's really a directory.
     (or (file-directory-p dir)
 	(error "find-dired needs a directory: %s" dir))
-    (or
-     (and (buffer-name)
-	  (string= buffer-name (buffer-name)))
-	(switch-to-buffer (get-buffer-create buffer-name)))
+    (unless (and (buffer-name)  (string= buffer-name (buffer-name)))
+      (let ((buf  (get-buffer-create buffer-name)))
+        (if other-window (pop-to-buffer buf) (switch-to-buffer buf))))
     (widen)
     (kill-all-local-variables)
     (setq buffer-read-only nil)
@@ -278,10 +298,18 @@
   (revert-buffer))
 
 (defun find-lisp-find-dired-insert-file (file buffer)
+  "Insert line for FILE in BUFFER.
+FILE is a file or a directory name.
+If `dired-actual-switches' is non-nil in BUFFER then preserve it."
   (set-buffer buffer)
   (insert find-lisp-line-indent
-	  (find-lisp-format file (file-attributes file 'string) (list "")
-			  (current-time))))
+          (find-lisp-format
+           (propertize file 'dired-filename t) 
+           (file-attributes file 'string)
+           (or (and dired-actual-switches
+                    (split-string-and-unquote dired-actual-switches))
+               (list ""))
+           (current-time))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Lifted from ls-lisp. We don't want to require it, because that
@@ -289,15 +317,14 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun find-lisp-format (file-name file-attr switches now)
-  "Format one line of long ls output for file FILE-NAME.
+  "Format one line of long `ls' output for file or directory FILE-NAME.
 FILE-ATTR and FILE-SIZE give the file's attributes and size.
 SWITCHES and TIME-INDEX give the full switch list and time data."
   (let ((file-type (file-attribute-type file-attr)))
-    (concat (if (memq ?i switches)	; inode number
-		(format "%6d " (file-attribute-inode-number file-attr)))
-	    ;; nil is treated like "" in concat
-	    (if (memq ?s switches)	; size in K
-		(format "%4d " (1+ (/ (file-attribute-size file-attr) 1024))))
+    (concat (and (memq ?i switches)	; inode number
+		 (format "%6d " (file-attribute-inode-number file-attr)))
+	    (and (memq ?s switches)	; size in K
+		 (format "%4d " (1+ (/ (file-attribute-size file-attr) 1024))))
 	    (file-attribute-modes file-attr)
 	    (format " %3d %-8s %-8s %8d "
 		    (file-attribute-link-number file-attr)
@@ -314,9 +341,10 @@
 	    (find-lisp-format-time file-attr switches now)
 	    " "
 	    file-name
-	    (if (stringp file-type)	; is a symbolic link
-		(concat " -> " file-type)
-	      "")
+            (and (eq t file-type)  (memq ?F switches)
+                 "/")                  ; Add `/' for dir if `F' switch
+	    (and (stringp file-type)
+                 (concat " -> " file-type)) ; Add " -> " for symbolic link
 	    "\n")))
 
 (defun find-lisp-time-index (switches)

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

end of thread, other threads:[~2022-09-06 10:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 22:06 bug#55894: 26.3; [PATCH] `find-lisp.el' bugs Drew Adams
2022-06-11  6:01 ` Eli Zaretskii
2022-06-11 16:46   ` Drew Adams
2022-06-11 17:00     ` Eli Zaretskii
2022-06-11 17:47       ` Drew Adams
2022-06-17  9:38         ` Stefan Kangas
2022-06-17 14:57           ` Drew Adams
2022-09-06 10:54   ` Lars Ingebrigtsen

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).