From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: Re: Latest commit to dired-aux; maybe add string-multi-replace? Date: Mon, 29 Aug 2016 21:16:49 +0900 (JST) Message-ID: References: <87poosj75w.fsf@oremacs.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1472474007 11548 195.159.176.226 (29 Aug 2016 12:33:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Aug 2016 12:33:27 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: tino.calancha@gmail.com, Emacs developers To: Oleh Krehel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 29 14:33:19 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 1beLkZ-00025L-Da for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 14:33:15 +0200 Original-Received: from localhost ([::1]:43262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beLkW-0008Fh-Tz for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 08:33:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beLVn-0002bZ-Aw for emacs-devel@gnu.org; Mon, 29 Aug 2016 08:18:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beLVi-0006tf-AI for emacs-devel@gnu.org; Mon, 29 Aug 2016 08:17:58 -0400 Original-Received: from mail-pf0-f172.google.com ([209.85.192.172]:35216) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beLVi-0006tY-4E for emacs-devel@gnu.org; Mon, 29 Aug 2016 08:17:54 -0400 Original-Received: by mail-pf0-f172.google.com with SMTP id x72so51726374pfd.2 for ; Mon, 29 Aug 2016 05:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=5dSSK6OHf+KpoZ5ZEuBaIqIQCn+auDuB1jhv66hCCC8=; b=X4yLJQOT5jF37WyVed8qp+S09+toiMWnQIO7apby9896Pajyo/4NcqCN7BJ1Wa3Boz urqyxVXXx/MqcZuA5kHtoXnlPTUQ4vat8BTHzrVKqdaayXnPqiMh3r5peUSfElhzwuOD fmvj4Dpf1GWK7q73pK1ZWipt7ZMuAhGbR7qK+vzWSmzeb7xOIFCS7V8qmaGRVFw5mhJx +KqQaY50bfA0XctD32uZC2UxYXEKwaHes86Zyze9mrfI/mcI87yaqFl/cdY2vT2+p6UQ mFG7Xn7EjPxeKte6DVRQ4RiQcb3B/KsX1RuNQHjIRsPl0tvQx5kO9+BTi/6hhfS9yJqA 995Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=5dSSK6OHf+KpoZ5ZEuBaIqIQCn+auDuB1jhv66hCCC8=; b=YC6MlnyZlDVReK8cxUnVe4METYeUJ5zi5rLGInL6z5f6kHXKhRtZjjobbaar9XgmA9 GxQhQavXKaoJaT8a9pNSBq8m16AZxV+Od0G7EYqA6SyRZhYKaubKdJrP4mbiLwIWcSfU XxL9RyYnok5F9AkxYe5/J94Kdz2W2ag1jvndZCwZIN9vuu46MNicsJQq5TtnnA2PxaJj ia5t6fdp1Kut/nx0Bt+QKdg5AFRFDrrmUBQK+ylW4o9DduN3YR4Wt/OUionc/BUnHy/r zISeWNaEaaqU7q+IEkKs/7D2thGIUV1UWx32yHsoGxY6Owrmqfd4M3a6rlcH7K14Vf5v jERA== X-Gm-Message-State: AE9vXwPhtKL/NTbZzszVt0FoSqErPL4vi7a9Q7NydpMDVcYZUHh3v+zEcYCM72S/PzLmFQ== X-Received: by 10.98.12.18 with SMTP id u18mr32015165pfi.89.1472473013519; Mon, 29 Aug 2016 05:16:53 -0700 (PDT) Original-Received: from calancha-pc (69.191.218.133.dy.bbexcite.jp. [133.218.191.69]) by smtp.gmail.com with ESMTPSA id f12sm49048898pfj.31.2016.08.29.05.16.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Aug 2016 05:16:52 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <87poosj75w.fsf@oremacs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.172 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:206866 Archived-At: On Mon, 29 Aug 2016, Oleh Krehel wrote: > In which file would the new function belong? I guess this should go to subr.el (or subr-x.el). In that case you should use: (car (cddr pat)) instead of (caddr pat) > Any further comments? I would mention in the doc string that the returned string is actually a copy of STR. I would also mention the order of the replacements: only in case this doesn't result obvious, but i guess it should be obvious. How about passing the patterns just as a list of strings as follows?: (defun string-multi-replace (str &rest patterns) "Replace PATTERNS in STR. Return a new string containing the replacements. PATTERNS is a list of patterns (FROM TO LITERAL ...). Replace patterns calling `replace-regexp-in-string' sequencially starting from (car PATTERNS)." (let (pat from to literal) (unless (zerop (% (length patterns) 3)) (error "Length of patterns should be a multiple of 3")) (while (setq pat patterns) (setq from (car pat) to (cadr pat) literal (car (cddr pat)) str (replace-regexp-in-string from to str nil literal) patterns (nthcdr 3 patterns))) str)) (string-multi-replace "tar -c %i | xz -c9 > %o" "%o" (shell-quote-argument "foo bar.tar.gz") t "%i" (shell-quote-argument "foo bar") t) ;; => "tar -c foo\\ bar | xz -c9 > foo\\ bar.tar.gz"