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: Wed, 10 May 2017 23:26:04 +0900 Message-ID: <98EBD2BF-A0ED-4726-9EDA-380058B517F0@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=_6C795F35-E5AB-49DA-B8E3-6FAB4B97D3CF" X-Trace: blaine.gmane.org 1494426384 30813 195.159.176.226 (10 May 2017 14:26:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 10 May 2017 14:26:24 +0000 (UTC) To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 10 16:26:20 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 1d8SZE-0007oH-9M for ged-emacs-devel@m.gmane.org; Wed, 10 May 2017 16:26:16 +0200 Original-Received: from localhost ([::1]:43046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8SZJ-0007KL-SM for ged-emacs-devel@m.gmane.org; Wed, 10 May 2017 10:26:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8SZB-0007JL-0R for emacs-devel@gnu.org; Wed, 10 May 2017 10:26:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8SZ7-0008UT-37 for emacs-devel@gnu.org; Wed, 10 May 2017 10:26:13 -0400 Original-Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]:33650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d8SZ6-0008U8-TR for emacs-devel@gnu.org; Wed, 10 May 2017 10:26:09 -0400 Original-Received: by mail-pg0-x22e.google.com with SMTP id u187so17507298pgb.0 for ; Wed, 10 May 2017 07:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=3UpcXM3HSaHagOU0Gx1acd+yoQf5bOhglRj3tmRfiac=; b=ri11hfxy9yBdrJH6/43d2vFuDItL//Y45OA64JAdPkViJc1tcdsQ4h9UVui6xEcU5Y l3/VxbSp34UKh+m2CM3tMN5M2zPzIH8FzKr6415KpPiA80kuxBGKiST7K8xoapwb8pYh M0evAFFkWCZqRNCvoiX2vkslkp4MywgK8fq+4N2JY0L1eE7UkUOUEWO4E/S6dLuKuyvb p0cKpI0ZacbY0CPaluTb3QfqKyTP3AhGOEDqew7/WxcSJs6Jrb8tJl9veJ+kGxQDflDI wq6fSqfrKG2ZFQYlVpZsvKplxuBXqFb04ViYyylpN0j4ybKTPU2F1nZ/wko1Y1cBhvvc KefA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=3UpcXM3HSaHagOU0Gx1acd+yoQf5bOhglRj3tmRfiac=; b=kd24vjfYATCjEt5gMaWzQl6j95qMc5xinarsySipOIcScgA7+IywzDBoCZl6u2edeE +g97TDyjcYDtwttCZWltG0AvDR0iJq6wgNH07I325uiphe6JXvMHOpbpbCVkYX2iYpf1 J/xPM4JcDcls0v5xajF0zcooUiwdb2VUp5ZIznh9Y+hoXMrWAVXYQvhdizLwCNefRdqR EcQ4JYaRgYoZbAb/PPr5pGgijZ8raLEzbmN94AuNPiRKPOYG5lwBLsa48x9ENAi45x1X 1THRMiBNCzTKYic1XouQeZJ/5oq2jTi8jTJS3+KRMq96VbW05inaDz/M0MhM+o5tFCDI ralw== X-Gm-Message-State: AODbwcBTcl18UmgRhsU1PAUXQAyZRk6KfPSuP/quGSCLb5vgqb3/j/DY HpMxaTqaKZPqYUeKWtg= X-Received: by 10.84.231.136 with SMTP id g8mr8584841plk.12.1494426367473; Wed, 10 May 2017 07:26:07 -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 h89sm6650706pfh.45.2017.05.10.07.26.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 May 2017 07:26:06 -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::22e 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:214762 Archived-At: --Apple-Mail=_6C795F35-E5AB-49DA-B8E3-6FAB4B97D3CF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hopefully last fixes. I've added the \\(?: ... \\) parens to make sure we capture any = potential issue with \|. Is there anything else I've missed ? 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 regexps for subr-x.el trimming functions * lisp/emacs-lisp/subr-x.el (string-trim-left, string-trim-right, = string-trim): add optional regexps that default 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=_6C795F35-E5AB-49DA-B8E3-6FAB4B97D3CF 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..ded231c475 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -179,21 +179,27 @@ 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=_6C795F35-E5AB-49DA-B8E3-6FAB4B97D3CF 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=_6C795F35-E5AB-49DA-B8E3-6FAB4B97D3CF--