all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: lux <lx@shellcodes.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 60562@debbugs.gnu.org, Robert Pluim <rpluim@gmail.com>
Subject: bug#60562: [PATCH] Fix split-string error if there is a space in the filename.
Date: Sat, 7 Jan 2023 22:52:09 +0800	[thread overview]
Message-ID: <tencent_A3E447C2C7838339C766546B5A6B9AEE2409@qq.com> (raw)
In-Reply-To: <834jt2u1yh.fsf@gnu.org>

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

On Sat, 07 Jan 2023 11:29:58 +0200
Eli Zaretskii <eliz@gnu.org> wrote:

> > Cc: 60562@debbugs.gnu.org
> > From: Robert Pluim <rpluim@gmail.com>
> > Date: Fri, 06 Jan 2023 10:48:43 +0100
> >   
> > >>>>> On Thu, 5 Jan 2023 06:56:05 +0800, lux <lx@shellcodes.org>
> > >>>>> said:  
> >   
> >     lux> * lisp/htmlfontify.el (hfy-list-files): Specify separator
> >     lux> (\n\r). ---
> >     lux>  lisp/htmlfontify.el | 5 +++--
> >     lux>  1 file changed, 3 insertions(+), 2 deletions(-)  
> >   
> >     lux> diff --git a/lisp/htmlfontify.el b/lisp/htmlfontify.el
> >     lux> index c989a12d205..be020b6b1c5 100644
> >     lux> --- a/lisp/htmlfontify.el
> >     lux> +++ b/lisp/htmlfontify.el
> >     lux> @@ -1826,8 +1826,9 @@ hfy-list-files
> >     lux>    ;;(message "hfy-list-files");;DBUG
> >     lux>    ;; FIXME: this changes the dir of the current buffer.
> >     lux> Is that right?? (cd directory)
> >     lux> -  (mapcar (lambda (F) (if (string-match "^./\\(.*\\)" F)
> >     lux> (match-string 1 F) F))
> >     lux> -          (split-string (shell-command-to-string
> >     lux> hfy-find-cmd))) )
> >     lux> +  (remove-if #'string-empty-p
> >     lux> +             (mapcar (lambda (F) (if (string-match
> >     lux> "^./\\(.*\\)" F) (match-string 1 F) F))
> >     lux> +                     (split-string
> >     lux> (shell-command-to-string hfy-find-cmd) "[\n\r]+")) ))  
> > 
> > You can avoid the issue (and improve portability) by using
> > `directory-files-recursively' instead of `find'  
> 
> Right.  Would you like to rewrite the patch using
> directory-files-recursively?
>

I try rewrite the patch using  directory-files-recursively.


[-- Attachment #2: 0001-Replace-hfy-find-cmd-with-directory-files-recursivel.patch --]
[-- Type: text/x-patch, Size: 1880 bytes --]

From 1e00b856ca423bb7e4491b9999cd3de80223d0bd Mon Sep 17 00:00:00 2001
From: Xi Lu <lx@shellcodes.org>
Date: Sat, 7 Jan 2023 22:46:40 +0800
Subject: [PATCH] Replace `hfy-find-cmd' with `directory-files-recursively'.

---
 lisp/htmlfontify.el | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/lisp/htmlfontify.el b/lisp/htmlfontify.el
index c989a12d205..0746b5e3a36 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
@@ -1823,11 +1826,12 @@ htmlfontify-buffer
 (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 "." ".*")))
 
 ;; strip the filename off, return a directory name
 ;; not a particularly thorough implementation, but it will be
-- 
2.39.0


  parent reply	other threads:[~2023-01-07 14:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04 22:56 bug#60562: [PATCH] Fix split-string error if there is a space in the filename lux
2023-01-06  9:48 ` Robert Pluim
2023-01-07  9:29   ` Eli Zaretskii
2023-01-07 11:16     ` Robert Pluim
2023-01-07 11:37       ` Eli Zaretskii
2023-01-07 13:56         ` Eli Zaretskii
2023-01-07 14:52     ` lux [this message]
2023-01-07 23:00       ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-08  7:23         ` lux
2023-01-09 14:28           ` Robert Pluim
2023-01-09 14:55             ` lux
2023-01-14  9:12           ` Eli Zaretskii
2023-01-07  9:42   ` lux
2023-01-07 10:48     ` Eli Zaretskii
2023-01-15 12:33       ` Andy Moreton
2023-01-15 14:07         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_A3E447C2C7838339C766546B5A6B9AEE2409@qq.com \
    --to=lx@shellcodes.org \
    --cc=60562@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rpluim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.