all messages for Emacs-related lists mirrored at yhetil.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 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.