unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Latest commit to dired-aux; maybe add string-multi-replace?
@ 2016-08-29  8:44 Oleh Krehel
  2016-08-29 11:52 ` Noam Postavsky
  2016-08-29 12:16 ` Tino Calancha
  0 siblings, 2 replies; 4+ messages in thread
From: Oleh Krehel @ 2016-08-29  8:44 UTC (permalink / raw)
  To: emacs-devel

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
    
    



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

end of thread, other threads:[~2016-08-29 12:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-29  8:44 Latest commit to dired-aux; maybe add string-multi-replace? Oleh Krehel
2016-08-29 11:52 ` Noam Postavsky
2016-08-29 12:04   ` Oleh Krehel
2016-08-29 12:16 ` Tino Calancha

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