From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Oleh Krehel Newsgroups: gmane.emacs.devel Subject: Latest commit to dired-aux; maybe add string-multi-replace? Date: Mon, 29 Aug 2016 10:44:43 +0200 Message-ID: <87poosj75w.fsf@oremacs.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1472460314 2423 195.159.176.226 (29 Aug 2016 08:45:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Aug 2016 08:45:14 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 29 10:45:07 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1beIBi-000827-Oe for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 10:45:02 +0200 Original-Received: from localhost ([::1]:42337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beIBg-0004KN-3K for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 04:45:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beIBa-0004KF-CZ for emacs-devel@gnu.org; Mon, 29 Aug 2016 04:44:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beIBW-0007Rw-5W for emacs-devel@gnu.org; Mon, 29 Aug 2016 04:44:53 -0400 Original-Received: from mail-wm0-f53.google.com ([74.125.82.53]:36155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beIBV-0007RN-Vz for emacs-devel@gnu.org; Mon, 29 Aug 2016 04:44:50 -0400 Original-Received: by mail-wm0-f53.google.com with SMTP id q128so68711882wma.1 for ; Mon, 29 Aug 2016 01:44:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=yYcpGcN/+sDMnIzpG/MeWqOjgDnJ7eG8hoGfuCtGM0o=; b=cZOs94szqEcsUx6RgrXXu3p7URCH0IN8SUF/PZ4NGrwxfn5EdyyhYtJfyguRvmMk2C 7jWY8G5sUxJKo+RWLKbiumENNBp2IXaav9tNFJX0D+lhphNbClA38HkKq9D+zYuJA2aC RVzfeTqK2FinDN/c7l07N1t1rm3MgFEyji37LaxaxxCl46fJJ7I0Mu8wo+ts9DbYQabT +VzMTqWHbN8GfJT8SVKVAnzPrg6RQfkD/IpBu6a922DYx4/nwWBdvY3dfcUqUSzpBZou Qov/G5q9J/nzeq7hM5i2SYbWiY8zt9mjvc+T9osS4ftqp2NfseU0A14orqF8bG8T3mZv e4Xg== X-Gm-Message-State: AE9vXwPUrPV+GYYP4Ak7j3J3NM1zin/fKUbXogHH0Z1maa508nUgQIJ2RYTpT5AI+uH0AA== X-Received: by 10.28.35.86 with SMTP id j83mr9036738wmj.18.1472460288366; Mon, 29 Aug 2016 01:44:48 -0700 (PDT) Original-Received: from firefly (mail2.sioux.nl. [213.126.128.209]) by smtp.gmail.com with ESMTPSA id g7sm33265449wjx.10.2016.08.29.01.44.47 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 29 Aug 2016 01:44:47 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.53 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206861 Archived-At: 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