From: Oleh Krehel <oleh@oremacs.com>
To: emacs-devel@gnu.org
Subject: Latest commit to dired-aux; maybe add string-multi-replace?
Date: Mon, 29 Aug 2016 10:44:43 +0200 [thread overview]
Message-ID: <87poosj75w.fsf@oremacs.com> (raw)
Hi all,
I just fixed the `dired-do-compress' command to work with files and
directories that have spaces in them.
After the fix, I saw this pattern repeat:
(dired-shell-command
(replace-regexp-in-string
"%o" (shell-quote-argument out-name)
(replace-regexp-in-string
"%i" (shell-quote-argument (file-name-nondirectory file))
(cadr suffix)
nil t)
nil t))
I've seen the pattern of nested `replace-regexp-in-string' quite a few
times before. It doesn't look great.
I propose the following API:
(defun string-multi-replace (str &rest patterns)
"Return STR after replacing PATTERNS in it.
PATTERNS is a list of (FROM TO LITERAL)."
(let (pat from to literal)
(while (setq pat (pop patterns))
(setq from (car pat))
(setq to (cadr pat))
(setq literal (caddr pat))
(setq str (replace-regexp-in-string from to str nil literal)))
str))
(string-multi-replace
"tar -c %i | xz -c9 > %o"
(list "%o" (shell-quote-argument "foo bar.tar.gz") t)
(list "%i" (shell-quote-argument "foo bar") t))
;; => "tar -c foo\\ bar | xz -c9 > foo\\ bar.tar.gz"
Would this be OK? In which file would the new function belong? Any
further comments?
regards,
Oleh
next reply other threads:[~2016-08-29 8:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-29 8:44 Oleh Krehel [this message]
2016-08-29 11:52 ` Latest commit to dired-aux; maybe add string-multi-replace? Noam Postavsky
2016-08-29 12:04 ` Oleh Krehel
2016-08-29 12:16 ` Tino Calancha
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87poosj75w.fsf@oremacs.com \
--to=oleh@oremacs.com \
--cc=emacs-devel@gnu.org \
/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 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).