From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jean-Christophe Helary Newsgroups: gmane.emacs.devel Subject: Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Date: Sat, 6 May 2017 22:05:06 +0900 Message-ID: <3D0BA0E6-02E2-4E90-8A59-121065547E1C@gmail.com> References: <87vapij1l7.fsf@holos> <6870A2B6-F685-4955-9C0A-256601DB47BC@gmail.com> <51D5E92C-F125-4ADE-8C55-E3513C00ECDC@gmail.com> <8F6958D6-3E13-4C31-B1F8-AF10A8FC8FC6@gmail.com> <838tmafigi.fsf@gnu.org> <7C79DA34-96F2-4D9F-9E9C-01574AE00F12@gmail.com> <8360hefepp.fsf@gnu.org> <0E129E02-FA64-4664-825B-8854A66CA9C6@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_BFD4188F-5CD4-426D-AC5F-39D38D9073A4" X-Trace: blaine.gmane.org 1494075930 23215 195.159.176.226 (6 May 2017 13:05:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 6 May 2017 13:05:30 +0000 (UTC) Cc: mvoteiza@udel.edu, emacs-devel@gnu.org, tino.calancha@gmail.com To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 06 15:05:23 2017 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 1d6zOi-0005pM-1A for ged-emacs-devel@m.gmane.org; Sat, 06 May 2017 15:05:20 +0200 Original-Received: from localhost ([::1]:51440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6zOl-000258-Uc for ged-emacs-devel@m.gmane.org; Sat, 06 May 2017 09:05:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6zOf-000252-BM for emacs-devel@gnu.org; Sat, 06 May 2017 09:05:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6zOe-0003nR-Cm for emacs-devel@gnu.org; Sat, 06 May 2017 09:05:17 -0400 Original-Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:34106) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6zOa-0003lU-KC; Sat, 06 May 2017 09:05:12 -0400 Original-Received: by mail-pg0-x243.google.com with SMTP id u187so4232912pgb.1; Sat, 06 May 2017 06:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=OYimT2bM6whL+wpueqniABSPbN5V6y+FMx8I76FYgjg=; b=YASTt0rlD5BVed639Eme+zNnHsOuXt6iLeX2cnCmg3vjk33XiHvUiUl5y0Ok+bASkT 0zPVYLv+NDDwYKIxXVCG7bTQ6sz/zg2KbECIIaLtTdef/B22ErKBD4OosbaHbZFrh7QR +ueVsEbEaziN5S75kYf9p78qmNfuMmARxqkvl0XDC9ESc1sTpsnGQJIREHqQJ0fIkbLb 8jAIvnhcSJUlfUUQsGVXrEQ2JyOYxiVGHnqNqJK6D4BGGWglpdB/4+HI3L/kqCBaIKaA b/QP2YA9mnin6afiT0L7Na2qnyA/bGoKF6//uCUr+2yu4gPJ0EfIfnjWEr6RLxhUJrcn EU0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=OYimT2bM6whL+wpueqniABSPbN5V6y+FMx8I76FYgjg=; b=TF9IE5BNwkjkEXJWNdIYMQPrXndG2e1ZetzvbnMYB2tBftIdEG2XYfM/lDrdX32LFT Irk67T+G1jsb78HZjM2fEy1Cs8HCqay+aJ3p1PUU2qDkBCfCIVLgsd9YAL55LypHpqJo pptlL+GCEHW5NhbI0ASXQbxIIrYi/uTMpWDjnLj5KjFArkC8sUVgw9Zu1/UbhgEVDRQo 9hb1ybtotnSaQn76willflvLBIr2W1z8JA7bY3LvTYiLH2me1NU4dVDqo/1CZDacDxvd dKYwXQmHe1h4n2+WbhrlaqUMlmWiF0Ye8rVgurox6siDt57oKoD1Hnu1whBq0+th8Gvu nrtA== X-Gm-Message-State: AN3rC/7dSHHuvzI8fL/8WMNLdRbLDOvvShnUAtzvmgir1llnXWwtiDdx ik1wpXmhr4FSBA== X-Received: by 10.84.128.66 with SMTP id 60mr72546750pla.167.1494075911534; Sat, 06 May 2017 06:05:11 -0700 (PDT) Original-Received: from [192.168.24.54] (pl25298.ag0304.nttpc.ne.jp. [133.232.153.210]) by smtp.gmail.com with ESMTPSA id y78sm15070296pff.107.2017.05.06.06.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 May 2017 06:05:09 -0700 (PDT) In-Reply-To: <0E129E02-FA64-4664-825B-8854A66CA9C6@gmail.com> X-Mailer: Apple Mail (2.3273) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 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:214621 Archived-At: --Apple-Mail=_BFD4188F-5CD4-426D-AC5F-39D38D9073A4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Ok, I think I have something clean. (btw, I'm done with the copyleft paperwork) Here is the diff, and a potential log message. Jean-Christophe=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Add optional regexp for subr-x.el trimming functions * lisp/emacs-lisp/subr-x.el (string-trim-left) (string-trim-right) = (string-trim): add optional regexp that defaults on the original = behavior. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D --Apple-Mail=_BFD4188F-5CD4-426D-AC5F-39D38D9073A4 Content-Disposition: attachment; filename=subr-x.el.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="subr-x.el.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 440213eb38..40fe78c104 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -179,21 +179,30 @@ VARLIST can just be a plain tuple. (define-obsolete-function-alias 'string-reverse 'reverse "25.1") -(defsubst string-trim-left (string) - "Remove leading whitespace from STRING." - (if (string-match "\\`[ \t\n\r]+" string) +(defsubst string-trim-left (string &optional regexp) + "Trim STRING of leading string matching REGEXP. + +REGEXP defaults to \"[ \\t\\n\\r]+\"." + + (if (string-match (concat "\\`" (or regexp "[ \t\n\r]+")) string) (replace-match "" t t string) string)) -(defsubst string-trim-right (string) - "Remove trailing whitespace from STRING." - (if (string-match "[ \t\n\r]+\\'" string) +(defsubst string-trim-right (string &optional regexp) + "Trim STRING of trailing string matching REGEXP. + +REGEXP defaults to \"[ \\t\\n\\r]+\"." + + (if (string-match (concat (or regexp "[ \t\n\r]+") "\\'") string) (replace-match "" t t string) string)) -(defsubst string-trim (string) - "Remove leading and trailing whitespace from STRING." - (string-trim-left (string-trim-right string))) +(defsubst string-trim (string &optional trim-left trim-right) + "Trim STRING of leading and trailing strings matching TRIM-LEFT and TRIM-RIGHT. + +TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"." + + (string-trim-left (string-trim-right string trim-right) trim-left)) (defsubst string-blank-p (string) "Check whether STRING is either empty or only whitespace." --Apple-Mail=_BFD4188F-5CD4-426D-AC5F-39D38D9073A4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On May 6, 2017, at 20:02, Jean-Christophe Helary = wrote: >=20 > Ok, I'm fine with that. Apologies for my lack of understanding of the = issues. >=20 > Jean-Christophe >=20 >> On May 6, 2017, at 19:43, Eli Zaretskii wrote: >>=20 >>> From: Jean-Christophe Helary >>> Date: Sat, 6 May 2017 19:33:10 +0900 >>> Cc: tino.calancha@gmail.com, >>> mvoteiza@udel.edu, >>> emacs-devel@gnu.org >>>=20 >>> My original idea was to put the regexp into a variable that *can* = eventually be overridden by a user preference. >>=20 >> Does this really have legitimate use cases? We are talking about a >> very low-level function; overriding its default definition of >> whitespace by a user option would affect every single use of this >> function, and will most probably disrupt some code which uses it. >>=20 >> I think having a way for overriding the default programmatically >> should be good enough, at least for now. Let's not provide a >> defcustom unless and until we have use cases for that which we want = to >> support. >=20 --Apple-Mail=_BFD4188F-5CD4-426D-AC5F-39D38D9073A4--