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 18:02:37 +0900 Message-ID: <8F6958D6-3E13-4C31-B1F8-AF10A8FC8FC6@gmail.com> References: <87vapij1l7.fsf@holos> <6870A2B6-F685-4955-9C0A-256601DB47BC@gmail.com> <51D5E92C-F125-4ADE-8C55-E3513C00ECDC@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1494061382 30500 195.159.176.226 (6 May 2017 09:03:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 6 May 2017 09:03:02 +0000 (UTC) Cc: Mark Oteiza , emacs-devel To: Tino Calancha Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 06 11:02:58 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 1d6vcA-0007oC-4u for ged-emacs-devel@m.gmane.org; Sat, 06 May 2017 11:02:58 +0200 Original-Received: from localhost ([::1]:50567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6vcE-0007BK-8N for ged-emacs-devel@m.gmane.org; Sat, 06 May 2017 05:03:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6vby-0007BD-5m for emacs-devel@gnu.org; Sat, 06 May 2017 05:02:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6vbv-0005WX-4A for emacs-devel@gnu.org; Sat, 06 May 2017 05:02:46 -0400 Original-Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:36183) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6vbu-0005W9-TX for emacs-devel@gnu.org; Sat, 06 May 2017 05:02:43 -0400 Original-Received: by mail-pg0-x244.google.com with SMTP id q4so363903pga.3 for ; Sat, 06 May 2017 02:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OBHSlMS5sc9Vr8PMud/ghYZkTnm/WqareKwyOk1b/io=; b=HrRaHBfzXNcYnnMeLls4Imx6EPu8qxAad8Y+tPUT1ZSNGceLJhW31T9w26WsN7SK6e YppUpdi/c9ZEESg4Jz0TWdANPFpZVx1Yp0aain19hYOyOTnW5Rly05VO1cRXek4/uh8e wJ3zxH75fO6yXvU33J8bhha7S4fZ27b7nxK+C41IGY8VPpyFto9VsxDyq5ISb2MOSr26 6V0Q/Ewg+/s0ZQzje6LqpEBU5M+d81CnHvqtO+Ka+Mq00uBFebJqm7LJbcJHY9elZ/nK xL0m0v5KVH7SK7fdQ0rfc3w7ZqtpeOLbjhFMD1N54zDFcLqHyRbyKnHRHdCWVFLKrHR9 vD/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OBHSlMS5sc9Vr8PMud/ghYZkTnm/WqareKwyOk1b/io=; b=PJFudQvYOLgjVWp69elpBRMjUEhlfrrIo2TbKshA6InGJGiOugdHco+fDFOy+Fr8ig f+SdEqgmDPMosoYWnrkELV2fg046AMutDSLL9/qR8j4HabsCh56hV+xxNYcZqm4axljG 9ZkO80Lx6bO0nHPPlyOe1qq6m7gidUqEWnGBe0PdnK8sgb1QBNLYRwI4Jq9QCwrykm0C /ai8YgiQjID5YhB0QiUZgJYASJrIWp/BGwcPvvu7GfYm4xxebsT3t4JhIbb52JkVsHu4 3S8Z2KqRefQZoFYPq249Ja/k2mupNul61LFQv40WeVVL1wyjlqWCD3KDeX5CZ4AdFrY9 CBFA== X-Gm-Message-State: AN3rC/4suxjsXVKbItSK5/I5tao97qdV2ym8ff+QBYFvvMwMXtAv2i61 bxtMqvTpjwARpg== X-Received: by 10.84.211.136 with SMTP id c8mr43553808pli.115.1494061360368; Sat, 06 May 2017 02:02:40 -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 u25sm7680734pfk.132.2017.05.06.02.02.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 May 2017 02:02:39 -0700 (PDT) In-Reply-To: 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::244 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:214608 Archived-At: > On May 6, 2017, at 13:29, Tino Calancha = wrote: >=20 > On Sat, 6 May 2017, Jean-Christophe Helary wrote: >=20 >>>> Basically everything in subr-x is either a macro or a defsubst, >>>>=20 >>>> As such, most uses of subr-x are done with (eval-when-compile = (require >>>> 'subr-x)). Won't the use of a global variable break these? >>>=20 >>> (defconst string-trim-default-regex "[ \t\n\r]+") >>> "The default value of the trimmed string for `string-trim'." >>>=20 >>> I have no idea what the effects would be. What would you suggest? Thank you Tino for the suggestion. > +(defsubst string-trim-left (string &optional regexp) > + "Trim STRING of leading whitespace matching REGEXP. > + > +REGEXP defaults to \"[ \t\n\r]+\"." > + (if (string-match (concat "\\`" (or regexp "[ \t\n\r]+")) string) > (replace-match "" t t string) > string)) What I did not like in the original design was that the default regexp = was hard-coded (besides for the fact that it did not allow for options). = I understand that your proposal *only* makes it the default, but I think = it would be more elegant to have the default extracted from the code and = visible to the user so as to allow for her to over-ride the default by = resetting the value. Isn't there a way to do that that would work with defsubst? Jean-Christophe=20=