Subject: Re: bug#60562: [PATCH] Fix split-string error if there is a space in the filename.

From: lux <[email-masked]>
Date: Sun, 8 Jan 2023 15:23:45 +0800

On Sat, 07 Jan 2023 17:00:02 -0600
Ruijie Yu <[email-masked]> wrote:

> Hi,
> 
> >-(defcustom hfy-find-cmd
> >-  "find . -type f \\! -name \\*~ \\! -name \\*.flc \\! -path
> >\\*/CVS/\\*"
> >-  "Find command used to harvest a list of files to attempt to
> >fontify."
> >-  :tag   "find-command"
> >-  :type  '(string))
> >+(defcustom hfy-exclude-file-rules
> >+  '("\\.flc$"
> >+    "/CVS/.*"
> >+    ".*~"
> >+    "\\.git/.*")
> >+  "Define some regular expressions to exclude files"
> >+  :tag "exclude-rules"
> >+  :type '(list string))  
> 
> For the third entry, shouldn't it be ".*~$" instead, to indicate that
> "~" is the last character?
> 
> For the fourth entry, currently it would match against the file name
> "ROOT/hello.git/foo".  In addition, for git submodules, ".git" is a
> regular file instead of a directory.  Maybe something like this is
> what you want:
> 
>     (rx "/.git" (opt "/" (0+ any)) line-end)
> 
> or in raw regexp: "/\\.git\\(?:/.*\\)?$"
> 
> Also, in this change, we are dropping the requirement that the found
> file are actually files, whereas we used to say "-type f".  Is this
> change fine?
> 
> > (defun hfy-list-files (directory)
> >   "Return a list of files under DIRECTORY.
> > Strips any leading \"./\" from each filename."
> >-  ;;(message "hfy-list-files");;DBUG
> >+  ;;(message "hfy-list-files");;DEBUG
> >   ;; FIXME: this changes the dir of the current buffer.  Is that
> > right?? (cd directory)
> >-  (mapcar (lambda (F) (if (string-match "^./\\(.*\\)" F)
> >(match-string 1 F) F))
> >-          (split-string (shell-command-to-string hfy-find-cmd))) )
> >+  (remove-if (lambda (f) (seq-some (lambda (r)
> >+                                     (string-match r f))
> >hfy-exclude-file-rules))
> >+             (directory-files-recursively "." ".*")))  
> 
> We should change `remove-if' into `cl-remove-if' because both "cl.el"
> and the alias `remove-if' are deprecated.
> 

Thank you, I updated the patch file.
>From 58fcb50eae760a6565e1703dfb8cea46a4ee5843 Mon Sep 17 00:00:00 2001
From: Xi Lu <[email-masked]>
Date: Sat, 7 Jan 2023 22:46:40 +0800
Subject: [PATCH] Replace `hfy-find-cmd' with `directory-files-recursively'.

---
 lisp/htmlfontify.el | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lisp/htmlfontify.el b/lisp/htmlfontify.el
index c989a12d205..f05bc4e1e35 100644
--- a/lisp/htmlfontify.el
+++ b/lisp/htmlfontify.el
@@ -372,11 +372,14 @@ hfy-istext-command
   :tag   "istext-command"
   :type  '(string))
 
-(defcustom hfy-find-cmd
-  "find . -type f \\! -name \\*~ \\! -name \\*.flc \\! -path \\*/CVS/\\*"
-  "Find command used to harvest a list of files to attempt to fontify."
-  :tag   "find-command"
-  :type  '(string))
+(defcustom hfy-exclude-file-rules
+  '("\\.flc$"
+    "/CVS/.*"
+    ".*~$"
+    "/\\.git\\(?:/.*\\)?$")
+  "Define some regular expressions to exclude files"
+  :tag "exclude-rules"
+  :type '(list string))
 
 (defcustom hfy-display-class nil
   "Display class to use to determine which display class to use when
@@ -1826,8 +1829,12 @@ hfy-list-files
   ;;(message "hfy-list-files");;DBUG
   ;; FIXME: this changes the dir of the current buffer.  Is that right??
   (cd directory)
-  (mapcar (lambda (F) (if (string-match "^./\\(.*\\)" F) (match-string 1 F) F))
-          (split-string (shell-command-to-string hfy-find-cmd))) )
+  (cl-remove-if (lambda (f)
+                  (or (null (file-regular-p f))
+                      (seq-some (lambda (r)
+                                  (string-match r f))
+                                hfy-exclude-file-rules)))
+                (directory-files-recursively "." ".*" nil t)))
 
 ;; strip the filename off, return a directory name
 ;; not a particularly thorough implementation, but it will be
-- 
2.39.0