* Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
@ 2017-05-02 9:34 Jean-Christophe Helary
2017-05-02 15:41 ` Clément Pit-Claudel
` (2 more replies)
0 siblings, 3 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-02 9:34 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
Following the discussion about how trimming in subr-x.el did not allow for non-default regex, I have this small modification to the 3 trimming functions found therein.
Basically:
1) I extracted the default regex and assigned it to string-trim-default-regex
2) I declared optional "trim-left" and "trim-right" arguments respectively for the string-trim-left and string-trim-right functions, and declared both optional for the general string-trim function
The documentation strings are pretty much taken from subr.el so maybe the wording is not the best.
Please advise.
Jean-Christophe
[-- Attachment #2: subr-x.el.diff --]
[-- Type: application/octet-stream, Size: 2083 bytes --]
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 440213eb38..188f314871 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -179,21 +179,36 @@ 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)
+(defconst string-trim-default-regex "[ \t\n\r]+")
+ "The default value of separators for `string-trim'."
+
+(defsubst string-trim-left (string &optional trim-left)
+ "Trim STRING of leading whitespace matching TRIM-LEFT.
+
+If TRIM-LEFT is non-nil, it should be a regular expression. If nil,
+it defaults to `string-trim-default-regex', normally \"[ \t\n\r]+\"."
+
+ (if (string-match (concat "\\`" (or trim-left string-trim-default-regex)) 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 trim-right)
+ "Trim STRING of trailing whitespace matching TRIM-RIGHT.
+
+If TRIM-RIGHT is non-nil, it should be a regular expression. If nil,
+it defaults to `string-trim-default-regex', normally \"[ \t\n\r]+\"."
+
+ (if (string-match (concat (or trim-right string-trim-default-regex) "\\'") 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 whitespace matching TRIM-LEFT and TRIM-RIGHT.
+
+If TRIM-LEFT and TRIM-RIGHT are non-nil, they should be a regular expression. If nil,
+they default to `string-trim-default-regex', normally \"[ \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."
^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-02 9:34 Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Jean-Christophe Helary
@ 2017-05-02 15:41 ` Clément Pit-Claudel
2017-05-02 22:35 ` Jean-Christophe Helary
2017-05-02 17:16 ` Eli Zaretskii
2017-05-02 23:11 ` Mark Oteiza
2 siblings, 1 reply; 73+ messages in thread
From: Clément Pit-Claudel @ 2017-05-02 15:41 UTC (permalink / raw)
To: Jean-Christophe Helary, emacs-devel
Looks good. The stirng could be called string-trim-regexp (no need for default), though, I think.
On 2017-05-02 05:34, Jean-Christophe Helary wrote:
> Following the discussion about how trimming in subr-x.el did not allow for non-default regex, I have this small modification to the 3 trimming functions found therein.
>
> Basically:
> 1) I extracted the default regex and assigned it to string-trim-default-regex
> 2) I declared optional "trim-left" and "trim-right" arguments respectively for the string-trim-left and string-trim-right functions, and declared both optional for the general string-trim function
>
> The documentation strings are pretty much taken from subr.el so maybe the wording is not the best.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-02 15:41 ` Clément Pit-Claudel
@ 2017-05-02 22:35 ` Jean-Christophe Helary
0 siblings, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-02 22:35 UTC (permalink / raw)
To: emacs-devel
> On May 3, 2017, at 0:41, Clément Pit-Claudel <cpitclaudel@gmail.com> wrote:
>
> Looks good. The stirng could be called string-trim-regexp (no need for default), though, I think.
I copied the name pattern from subr.el (split-string). I have no strong opinion about names but I thought it was good to keep some consistency between similar functions (although I understand that not all default values are named "default"...)
Jean-Christophe
>
> On 2017-05-02 05:34, Jean-Christophe Helary wrote:
>> Following the discussion about how trimming in subr-x.el did not allow for non-default regex, I have this small modification to the 3 trimming functions found therein.
>>
>> Basically:
>> 1) I extracted the default regex and assigned it to string-trim-default-regex
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-02 9:34 Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Jean-Christophe Helary
2017-05-02 15:41 ` Clément Pit-Claudel
@ 2017-05-02 17:16 ` Eli Zaretskii
2017-05-02 22:48 ` Jean-Christophe Helary
2017-05-02 23:11 ` Mark Oteiza
2 siblings, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-02 17:16 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: emacs-devel
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Tue, 2 May 2017 18:34:17 +0900
>
> Following the discussion about how trimming in subr-x.el did not allow for non-default regex, I have this small modification to the 3 trimming functions found therein.
>
> Basically:
> 1) I extracted the default regex and assigned it to string-trim-default-regex
> 2) I declared optional "trim-left" and "trim-right" arguments respectively for the string-trim-left and string-trim-right functions, and declared both optional for the general string-trim function
Thanks.
Do we really have use cases for string-trim where trim-left and
trim-right should be different? If not, let's give it only one
optional argument, not 2.
> +(defsubst string-trim-left (string &optional trim-left)
> + "Trim STRING of leading whitespace matching TRIM-LEFT.
Since TRIM-LEFT could be anything, the "whitespace" part is no longer
accurate. Suggest to use "delimiters" instead.
> +If TRIM-LEFT is non-nil, it should be a regular expression. If nil,
> +it defaults to `string-trim-default-regex', normally \"[ \t\n\r]+\"."
This is better worded like this:
TRIM-LEFT should be a regular expression, and defaults to
`string-trim-default-regex' if omitted or nil.
> +(defsubst string-trim-right (string &optional trim-right)
> + "Trim STRING of trailing whitespace matching TRIM-RIGHT.
> +
> +If TRIM-RIGHT is non-nil, it should be a regular expression. If nil,
> +it defaults to `string-trim-default-regex', normally \"[ \t\n\r]+\"."
Likewise.
> +(defsubst string-trim (string &optional trim-left trim-right)
> + "Trim STRING of leading and trailing whitespace matching TRIM-LEFT and TRIM-RIGHT.
Please make the first line shorter than 80 characters.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-02 17:16 ` Eli Zaretskii
@ 2017-05-02 22:48 ` Jean-Christophe Helary
0 siblings, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-02 22:48 UTC (permalink / raw)
To: emacs-devel
> On May 3, 2017, at 2:16, Eli Zaretskii <eliz@gnu.org> wrote:
>> 2) I declared optional "trim-left" and "trim-right" arguments respectively for the string-trim-left and string-trim-right functions, and declared both optional for the general string-trim function
>
> Do we really have use cases for string-trim where trim-left and
> trim-right should be different? If not, let's give it only one
> optional argument, not 2.
I have no clear use case because of my lack of programming experience, but I can see how TRIM-LEFT could be used to remove the beginning of a path and TRIM-RIGHT could be used to remove a file extension, for ex.
>> +(defsubst string-trim-left (string &optional trim-left)
>> + "Trim STRING of leading whitespace matching TRIM-LEFT.
>
> Since TRIM-LEFT could be anything, the "whitespace" part is no longer
> accurate. Suggest to use "delimiters" instead.
I overlooked that. In fact, since, as you correctly point out, a regex can be anything I think "characters" or "the string" is even better. It seems to me that "delimiter" fits better the concept of "splitting" than the concept of "trimming".
>> +If TRIM-LEFT is non-nil, it should be a regular expression. If nil,
>> +it defaults to `string-trim-default-regex', normally \"[ \t\n\r]+\"."
>
> This is better worded like this:
>
> TRIM-LEFT should be a regular expression, and defaults to
> `string-trim-default-regex' if omitted or nil.
Thank you. I tried to stick to the wording found in subr.el (split-string)... :-) I'll do as you suggest.
>> +(defsubst string-trim (string &optional trim-left trim-right)
>> + "Trim STRING of leading and trailing whitespace matching TRIM-LEFT and TRIM-RIGHT.
>
> Please make the first line shorter than 80 characters.
I overlooked that one. Sorry.
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-02 9:34 Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Jean-Christophe Helary
2017-05-02 15:41 ` Clément Pit-Claudel
2017-05-02 17:16 ` Eli Zaretskii
@ 2017-05-02 23:11 ` Mark Oteiza
2017-05-03 1:13 ` Jean-Christophe Helary
2 siblings, 1 reply; 73+ messages in thread
From: Mark Oteiza @ 2017-05-02 23:11 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: Eli Zaretskii, emacs-devel
Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
> Following the discussion about how trimming in subr-x.el did not allow
> for non-default regex, I have this small modification to the 3
> trimming functions found therein.
>
> Basically:
> 1) I extracted the default regex and assigned it to string-trim-default-regex
> 2) I declared optional "trim-left" and "trim-right" arguments
> respectively for the string-trim-left and string-trim-right functions,
> and declared both optional for the general string-trim function
>
> The documentation strings are pretty much taken from subr.el so maybe
> the wording is not the best.
>
> Please advise.
Basically everything in subr-x is either a macro or a defsubst, except
for read-multiple-choice (aside: why is this not in its own library?).
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?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-02 23:11 ` Mark Oteiza
@ 2017-05-03 1:13 ` Jean-Christophe Helary
2017-05-06 2:41 ` Jean-Christophe Helary
0 siblings, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-03 1:13 UTC (permalink / raw)
To: Mark Oteiza; +Cc: Eli Zaretskii, emacs-devel
> On May 3, 2017, at 8:11, Mark Oteiza <mvoteiza@udel.edu> wrote:
> Basically everything in subr-x is either a macro or a defsubst,
>
> 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?
(defconst string-trim-default-regex "[ \t\n\r]+")
"The default value of the trimmed string for `string-trim'."
I have no idea what the effects would be. What would you suggest?
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-03 1:13 ` Jean-Christophe Helary
@ 2017-05-06 2:41 ` Jean-Christophe Helary
2017-05-06 4:29 ` Tino Calancha
0 siblings, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-06 2:41 UTC (permalink / raw)
To: Mark Oteiza; +Cc: emacs-devel
Mark, do you have any suggestions regarding your remark?
Jean-Christophe
> On May 3, 2017, at 10:13, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
>
>
>> On May 3, 2017, at 8:11, Mark Oteiza <mvoteiza@udel.edu> wrote:
>
>> Basically everything in subr-x is either a macro or a defsubst,
>>
>> 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?
>
> (defconst string-trim-default-regex "[ \t\n\r]+")
> "The default value of the trimmed string for `string-trim'."
>
> I have no idea what the effects would be. What would you suggest?
>
> Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 2:41 ` Jean-Christophe Helary
@ 2017-05-06 4:29 ` Tino Calancha
2017-05-06 9:02 ` Jean-Christophe Helary
2017-05-06 9:12 ` Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Andreas Schwab
0 siblings, 2 replies; 73+ messages in thread
From: Tino Calancha @ 2017-05-06 4:29 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: Mark Oteiza, Tino Calancha, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 3376 bytes --]
On Sat, 6 May 2017, Jean-Christophe Helary wrote:
>>> Basically everything in subr-x is either a macro or a defsubst,
>>>
>>> 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?
>>
>> (defconst string-trim-default-regex "[ \t\n\r]+")
>> "The default value of the trimmed string for `string-trim'."
>>
>> I have no idea what the effects would be. What would you suggest?
Hi Jean-Christophe,
Mark is right. Your patch won't work in the following example:
Write a file '/tmp/test.el'
--8<-----------------------------cut here---------------start------------->8---
(eval-when-compile (require 'subr-x))
(defun test ()
(message
(string-trim " Hi! ")))
--8<-----------------------------cut here---------------end--------------->8---
M-! emacs -batch -eval '(byte-compile-file "/tmp/test.el")' && \
emacs -batch -l /tmp/test.elc -eval "(test)" RET
;; Signals error: Symbol’s value as variable is void: string-trim-default-regex
Instead, something as follows would work:
--8<-----------------------------cut here---------------start------------->8---
commit dc4d7fa64c5cf4f3c3fa04182da974f2d0bc6499
Author: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
Date: Sat May 6 13:24:03 2017 +0900
Allow trim strings of whitespaces with a general regexp
* lisp/emacs-lisp/subr-x.el (string-trim-left, string-trim-right):
Add optional arg REGEXP.
(string-trim): Add optional args TRIM-LEFT and TRIM-RIGHT.
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 440213eb38..5148e8b724 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -179,21 +179,29 @@ string-join
(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 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))
-(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 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))
-(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 whitespace matching TRIM-LEFT and TRIM-RIGHT.
+
+Both, TRIM-RIGHT and TRIM-LEFT 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."
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-05-05
Repository revision: 927dcbd2e6e0e53fcfb09296716e11c002ab1518
Cheers,
Tino
^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 4:29 ` Tino Calancha
@ 2017-05-06 9:02 ` Jean-Christophe Helary
2017-05-06 9:22 ` Eli Zaretskii
2017-05-06 16:30 ` Drew Adams
2017-05-06 9:12 ` Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Andreas Schwab
1 sibling, 2 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-06 9:02 UTC (permalink / raw)
To: Tino Calancha; +Cc: Mark Oteiza, emacs-devel
> On May 6, 2017, at 13:29, Tino Calancha <tino.calancha@gmail.com> wrote:
>
> On Sat, 6 May 2017, Jean-Christophe Helary wrote:
>
>>>> Basically everything in subr-x is either a macro or a defsubst,
>>>>
>>>> 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?
>>>
>>> (defconst string-trim-default-regex "[ \t\n\r]+")
>>> "The default value of the trimmed string for `string-trim'."
>>>
>>> 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
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 9:02 ` Jean-Christophe Helary
@ 2017-05-06 9:22 ` Eli Zaretskii
2017-05-06 10:33 ` Jean-Christophe Helary
2017-05-06 16:30 ` Drew Adams
1 sibling, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-06 9:22 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: mvoteiza, emacs-devel, tino.calancha
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Sat, 6 May 2017 18:02:37 +0900
> Cc: Mark Oteiza <mvoteiza@udel.edu>, emacs-devel <emacs-devel@gnu.org>
>
> > +(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.
Can you tell why you think that defconst is more elegant than a
hard-coded default? I think they are basically the same.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 9:22 ` Eli Zaretskii
@ 2017-05-06 10:33 ` Jean-Christophe Helary
2017-05-06 10:43 ` Eli Zaretskii
0 siblings, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-06 10:33 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: mvoteiza, emacs-devel, tino.calancha
> On May 6, 2017, at 18:22, Eli Zaretskii <eliz@gnu.org> wrote:
>> 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.
>
> Can you tell why you think that defconst is more elegant than a
> hard-coded default? I think they are basically the same.
I was confused by the fact that a const is, well, a constant and is not to be overridden by the user.
My original idea was to put the regexp into a variable that *can* eventually be overridden by a user preference.
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 10:33 ` Jean-Christophe Helary
@ 2017-05-06 10:43 ` Eli Zaretskii
2017-05-06 11:02 ` Jean-Christophe Helary
2017-05-06 11:06 ` Jean-Christophe Helary
0 siblings, 2 replies; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-06 10:43 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: mvoteiza, emacs-devel, tino.calancha
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Sat, 6 May 2017 19:33:10 +0900
> Cc: tino.calancha@gmail.com,
> mvoteiza@udel.edu,
> emacs-devel@gnu.org
>
> My original idea was to put the regexp into a variable that *can* eventually be overridden by a user preference.
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.
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.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 10:43 ` Eli Zaretskii
@ 2017-05-06 11:02 ` Jean-Christophe Helary
2017-05-06 13:05 ` Jean-Christophe Helary
2017-05-10 14:26 ` Jean-Christophe Helary
2017-05-06 11:06 ` Jean-Christophe Helary
1 sibling, 2 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-06 11:02 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: mvoteiza, emacs-devel, tino.calancha
Ok, I'm fine with that. Apologies for my lack of understanding of the issues.
Jean-Christophe
> On May 6, 2017, at 19:43, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
>> Date: Sat, 6 May 2017 19:33:10 +0900
>> Cc: tino.calancha@gmail.com,
>> mvoteiza@udel.edu,
>> emacs-devel@gnu.org
>>
>> My original idea was to put the regexp into a variable that *can* eventually be overridden by a user preference.
>
> 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.
>
> 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.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 11:02 ` Jean-Christophe Helary
@ 2017-05-06 13:05 ` Jean-Christophe Helary
2017-05-06 13:51 ` Tino Calancha
2017-05-06 17:51 ` Johan Bockgård
2017-05-10 14:26 ` Jean-Christophe Helary
1 sibling, 2 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-06 13:05 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: mvoteiza, emacs-devel, tino.calancha
[-- Attachment #1: Type: text/plain, Size: 417 bytes --]
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
===========================
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.
===========================
[-- Attachment #2: subr-x.el.diff --]
[-- Type: application/octet-stream, Size: 1614 bytes --]
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."
[-- Attachment #3: Type: text/plain, Size: 1120 bytes --]
> On May 6, 2017, at 20:02, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
>
> Ok, I'm fine with that. Apologies for my lack of understanding of the issues.
>
> Jean-Christophe
>
>> On May 6, 2017, at 19:43, Eli Zaretskii <eliz@gnu.org> wrote:
>>
>>> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
>>> Date: Sat, 6 May 2017 19:33:10 +0900
>>> Cc: tino.calancha@gmail.com,
>>> mvoteiza@udel.edu,
>>> emacs-devel@gnu.org
>>>
>>> My original idea was to put the regexp into a variable that *can* eventually be overridden by a user preference.
>>
>> 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.
>>
>> 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.
>
^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 13:05 ` Jean-Christophe Helary
@ 2017-05-06 13:51 ` Tino Calancha
2017-05-06 14:24 ` Eli Zaretskii
2017-05-06 17:51 ` Johan Bockgård
1 sibling, 1 reply; 73+ messages in thread
From: Tino Calancha @ 2017-05-06 13:51 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: mvoteiza, Eli Zaretskii, emacs-devel
Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
> 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
Thank you very much!
Some comments below.
===========================
>Add optional regexp for subr-x.el trimming functions
I would say something like:
Allow user regexp in string trimming functions.
>* lisp/emacs-lisp/subr-x.el (string-trim-left) (string-trim-right)
^^^
This must be:
* lisp/emacs-lisp/subr-x.el (string-trim-left, string-trim-right)
>(string-trim): add optional regexp that defaults on the original behavior.
^^^
Sentence must start in capital letter.
I would add a separated line for `string-trim', because there we add
two regexp's not just one.
So i would say something like:
===============================================================================
Allow user regexp in string trimming functions
* lisp/emacs-lisp/subr-x.el (string-trim-left) (string-trim-right):
Add optional arg REGEXP.
(string-trim): Add optional args REGEXP-BEG, REGEXP-END.
See discussion in:
https://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00047.html
===============================================================================
>-(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]+\"."
We don't need a empty line inside such short docstrings.
>-(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)
We must drop the empty line between the docstrings and the body of
`string-trim-left' and `string-trim-right'.
>-(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))
I feel like too much 'trim', 'left' and 'right' around. It's distracting.
I suggest something like:
(defsubst string-trim (string &optional regexp-beg regexp-end)
or
(defsubst string-trim (string &optional regexp-l regexp-r)
[Minor comment]
I find it more legible written as:
(string-trim-left
(string-trim-right string regexp-end)
regexp-beg)
than as:
(string-trim-left (string-trim-right string regexp-end) regexp-beg)
Cheers,
Tino
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 13:51 ` Tino Calancha
@ 2017-05-06 14:24 ` Eli Zaretskii
2017-05-07 2:25 ` Tino Calancha
0 siblings, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-06 14:24 UTC (permalink / raw)
To: Tino Calancha; +Cc: mvoteiza, jean.christophe.helary, emacs-devel
> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, mvoteiza@udel.edu, emacs-devel@gnu.org
> Date: Sat, 06 May 2017 22:51:26 +0900
>
> >Add optional regexp for subr-x.el trimming functions
> I would say something like:
> Allow user regexp in string trimming functions.
FWIW, I don't see much difference between these two. And the option
is not really for "users", it's for Lisp programs, right?
> >+(defsubst string-trim-left (string &optional regexp)
> >+ "Trim STRING of leading string matching REGEXP.
> >+
> >+REGEXP defaults to \"[ \\t\\n\\r]+\"."
> We don't need a empty line inside such short docstrings.
A matter of personal style, IMO.
> I feel like too much 'trim', 'left' and 'right' around. It's distracting.
> I suggest something like:
> (defsubst string-trim (string &optional regexp-beg regexp-end)
> or
> (defsubst string-trim (string &optional regexp-l regexp-r)
I wouldn't make comments like this so late in the review process.
> I find it more legible written as:
> (string-trim-left
> (string-trim-right string regexp-end)
> regexp-beg)
>
> than as:
> (string-trim-left (string-trim-right string regexp-end) regexp-beg)
Again, personal style issue, IMO.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 14:24 ` Eli Zaretskii
@ 2017-05-07 2:25 ` Tino Calancha
2017-05-07 2:43 ` Eli Zaretskii
0 siblings, 1 reply; 73+ messages in thread
From: Tino Calancha @ 2017-05-07 2:25 UTC (permalink / raw)
To: Eli Zaretskii
Cc: mvoteiza, jean.christophe.helary, Emacs developers, Tino Calancha
On Sat, 6 May 2017, Eli Zaretskii wrote:
>> From: Tino Calancha <tino.calancha@gmail.com>
>> Cc: Eli Zaretskii <eliz@gnu.org>, mvoteiza@udel.edu, emacs-devel@gnu.org
>> Date: Sat, 06 May 2017 22:51:26 +0900
>>
>>> Add optional regexp for subr-x.el trimming functions
>> I would say something like:
>> Allow user regexp in string trimming functions.
>
> FWIW, I don't see much difference between these two. And the option
> is not really for "users", it's for Lisp programs, right?
The latter try to summary the issue, that is 'what'. The former sounds
more like the implementation to fix the issue, i.e., 'how'.
>>> +(defsubst string-trim-left (string &optional regexp)
>>> + "Trim STRING of leading string matching REGEXP.
>>> +
>>> +REGEXP defaults to \"[ \\t\\n\\r]+\"."
>> We don't need a empty line inside such short docstrings.
>
> A matter of personal style, IMO.
Emacs might have a prefered style for this, and promote it.
>> I feel like too much 'trim', 'left' and 'right' around. It's distracting.
>> I suggest something like:
>> (defsubst string-trim (string &optional regexp-beg regexp-end)
>> or
>> (defsubst string-trim (string &optional regexp-l regexp-r)
>
> I wouldn't make comments like this so late in the review process.
It's just a rename of local variables. It's really a minor issue.
>> I find it more legible written as:
>> (string-trim-left
>> (string-trim-right string regexp-end)
>> regexp-beg)
>>
>> than as:
>> (string-trim-left (string-trim-right string regexp-end) regexp-beg)
>
> Again, personal style issue, IMO.
Just wondering what is your personal style here.
Emacs might have a prefered style for this as well. It's nicer to read
uniform style sources.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-07 2:25 ` Tino Calancha
@ 2017-05-07 2:43 ` Eli Zaretskii
2017-05-07 10:40 ` Tino Calancha
0 siblings, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-07 2:43 UTC (permalink / raw)
To: Tino Calancha; +Cc: mvoteiza, jean.christophe.helary, emacs-devel
> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Sun, 7 May 2017 11:25:41 +0900 (JST)
> cc: Tino Calancha <tino.calancha@gmail.com>, jean.christophe.helary@gmail.com,
> mvoteiza@udel.edu, Emacs developers <emacs-devel@gnu.org>
>
> >> I find it more legible written as:
> >> (string-trim-left
> >> (string-trim-right string regexp-end)
> >> regexp-beg)
> >>
> >> than as:
> >> (string-trim-left (string-trim-right string regexp-end) regexp-beg)
> >
> > Again, personal style issue, IMO.
> Just wondering what is your personal style here.
My personal style is to use the line as much as it allows me.
But I generally try not to impose my personal style on work done by
others. I think every one of us is entitled to have the code they
contributed keep their style.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-07 2:43 ` Eli Zaretskii
@ 2017-05-07 10:40 ` Tino Calancha
0 siblings, 0 replies; 73+ messages in thread
From: Tino Calancha @ 2017-05-07 10:40 UTC (permalink / raw)
To: Eli Zaretskii
Cc: mvoteiza, jean.christophe.helary, Emacs developers, Tino Calancha
On Sun, 7 May 2017, Eli Zaretskii wrote:
>> From: Tino Calancha <tino.calancha@gmail.com>
>> Date: Sun, 7 May 2017 11:25:41 +0900 (JST)
>> cc: Tino Calancha <tino.calancha@gmail.com>, jean.christophe.helary@gmail.com,
>> mvoteiza@udel.edu, Emacs developers <emacs-devel@gnu.org>
>>
>>>> I find it more legible written as:
>>>> (string-trim-left
>>>> (string-trim-right string regexp-end)
>>>> regexp-beg)
>>>>
>>>> than as:
>>>> (string-trim-left (string-trim-right string regexp-end) regexp-beg)
>>>
>>> Again, personal style issue, IMO.
>> Just wondering what is your personal style here.
>
> My personal style is to use the line as much as it allows me.
>
> But I generally try not to impose my personal style on work done by
> others. I think every one of us is entitled to have the code they
> contributed keep their style.
Thanks. No problem.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 13:05 ` Jean-Christophe Helary
2017-05-06 13:51 ` Tino Calancha
@ 2017-05-06 17:51 ` Johan Bockgård
2017-05-06 19:02 ` Eli Zaretskii
2017-05-07 13:48 ` Stefan Monnier
1 sibling, 2 replies; 73+ messages in thread
From: Johan Bockgård @ 2017-05-06 17:51 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: mvoteiza, Eli Zaretskii, tino.calancha, emacs-devel
Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
> -(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)
I think regexp should be surrounded by a grouping construct, like:
(concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
And similarly for string-trim-right.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 17:51 ` Johan Bockgård
@ 2017-05-06 19:02 ` Eli Zaretskii
2017-05-06 19:55 ` Johan Bockgård
2017-05-07 13:48 ` Stefan Monnier
1 sibling, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-06 19:02 UTC (permalink / raw)
To: Johan Bockgård
Cc: mvoteiza, jean.christophe.helary, tino.calancha, emacs-devel
> From: Johan Bockgård <bojohan@gnu.org>
> Cc: Eli Zaretskii <eliz@gnu.org>, mvoteiza@udel.edu, emacs-devel@gnu.org, tino.calancha@gmail.com
> Date: Sat, 06 May 2017 19:51:33 +0200
>
> > + (if (string-match (concat "\\`" (or regexp "[ \t\n\r]+")) string)
>
> I think regexp should be surrounded by a grouping construct, like:
>
> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
>
> And similarly for string-trim-right.
Rationale?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 19:02 ` Eli Zaretskii
@ 2017-05-06 19:55 ` Johan Bockgård
2017-05-06 20:03 ` Eli Zaretskii
2017-05-07 4:39 ` Jean-Christophe Helary
0 siblings, 2 replies; 73+ messages in thread
From: Johan Bockgård @ 2017-05-06 19:55 UTC (permalink / raw)
To: Eli Zaretskii
Cc: mvoteiza, jean.christophe.helary, emacs-devel, tino.calancha
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Johan Bockgård <bojohan@gnu.org>
>> Cc: Eli Zaretskii <eliz@gnu.org>, mvoteiza@udel.edu,
>> emacs-devel@gnu.org, tino.calancha@gmail.com
>> Date: Sat, 06 May 2017 19:51:33 +0200
>>
>> > + (if (string-match (concat "\\`" (or regexp "[ \t\n\r]+")) string)
>>
>> I think regexp should be surrounded by a grouping construct, like:
>>
>> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
>>
>> And similarly for string-trim-right.
>
> Rationale?
regexp can contain \|
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 19:55 ` Johan Bockgård
@ 2017-05-06 20:03 ` Eli Zaretskii
2017-05-07 16:23 ` Johan Bockgård
2017-05-08 2:40 ` Jean-Christophe Helary
2017-05-07 4:39 ` Jean-Christophe Helary
1 sibling, 2 replies; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-06 20:03 UTC (permalink / raw)
To: Johan Bockgård
Cc: mvoteiza, jean.christophe.helary, emacs-devel, tino.calancha
> From: Johan Bockgård <bojohan@gnu.org>
> Cc: mvoteiza@udel.edu, jean.christophe.helary@gmail.com, tino.calancha@gmail.com, emacs-devel@gnu.org
> Date: Sat, 06 May 2017 21:55:52 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> From: Johan Bockgård <bojohan@gnu.org>
> >> Cc: Eli Zaretskii <eliz@gnu.org>, mvoteiza@udel.edu,
> >> emacs-devel@gnu.org, tino.calancha@gmail.com
> >> Date: Sat, 06 May 2017 19:51:33 +0200
> >>
> >> > + (if (string-match (concat "\\`" (or regexp "[ \t\n\r]+")) string)
> >>
> >> I think regexp should be surrounded by a grouping construct, like:
> >>
> >> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
> >>
> >> And similarly for string-trim-right.
> >
> > Rationale?
>
> regexp can contain \|
Shouldn't such a regexp be surrounded by "\\(..\\)"?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 20:03 ` Eli Zaretskii
@ 2017-05-07 16:23 ` Johan Bockgård
2017-05-07 16:53 ` Eli Zaretskii
2017-05-08 2:40 ` Jean-Christophe Helary
1 sibling, 1 reply; 73+ messages in thread
From: Johan Bockgård @ 2017-05-07 16:23 UTC (permalink / raw)
To: Eli Zaretskii
Cc: mvoteiza, jean.christophe.helary, tino.calancha, emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Johan Bockgård <bojohan@gnu.org>
>> Cc: mvoteiza@udel.edu, jean.christophe.helary@gmail.com,
>> tino.calancha@gmail.com, emacs-devel@gnu.org
>> Date: Sat, 06 May 2017 21:55:52 +0200
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> From: Johan Bockgård <bojohan@gnu.org>
>> >> Cc: Eli Zaretskii <eliz@gnu.org>, mvoteiza@udel.edu,
>> >> emacs-devel@gnu.org, tino.calancha@gmail.com
>> >> Date: Sat, 06 May 2017 19:51:33 +0200
>> >>
>> >> > + (if (string-match (concat "\\`" (or regexp "[ \t\n\r]+")) string)
>> >>
>> >> I think regexp should be surrounded by a grouping construct, like:
>> >>
>> >> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
>> >>
>> >> And similarly for string-trim-right.
>> >
>> > Rationale?
>>
>> regexp can contain \|
>
> Shouldn't such a regexp be surrounded by "\\(..\\)"?
This code performs string concatenation on a perfectly valid regexp
provided by the caller. IMO, it is this code's responsibility that the
result is sensible after the concatenation.
Are you saying this should be the caller's duty?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-07 16:23 ` Johan Bockgård
@ 2017-05-07 16:53 ` Eli Zaretskii
2017-05-10 9:21 ` Yuri Khan
0 siblings, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-07 16:53 UTC (permalink / raw)
To: Johan Bockgård
Cc: mvoteiza, jean.christophe.helary, tino.calancha, emacs-devel
> From: Johan Bockgård <bojohan@gnu.org>
> Cc: mvoteiza@udel.edu, jean.christophe.helary@gmail.com, emacs-devel@gnu.org, tino.calancha@gmail.com
> Date: Sun, 07 May 2017 18:23:56 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> >> I think regexp should be surrounded by a grouping construct, like:
> >> >>
> >> >> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
> >> >>
> >> >> And similarly for string-trim-right.
> >> >
> >> > Rationale?
> >>
> >> regexp can contain \|
> >
> > Shouldn't such a regexp be surrounded by "\\(..\\)"?
>
> This code performs string concatenation on a perfectly valid regexp
> provided by the caller. IMO, it is this code's responsibility that the
> result is sensible after the concatenation.
>
> Are you saying this should be the caller's duty?
I'm _asking_ whether it should be the caller's duty.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-07 16:53 ` Eli Zaretskii
@ 2017-05-10 9:21 ` Yuri Khan
2017-05-10 11:15 ` Jean-Christophe Helary
2017-05-10 11:56 ` Stefan Monnier
0 siblings, 2 replies; 73+ messages in thread
From: Yuri Khan @ 2017-05-10 9:21 UTC (permalink / raw)
To: Eli Zaretskii
Cc: Mark Oteiza, jean.christophe.helary, Emacs developers,
Johan Bockgård, Tino Calancha
On Sun, May 7, 2017 at 11:53 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> >> >> I think regexp should be surrounded by a grouping construct, like:
>> >> >>
>> >> >> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
>
> I'm _asking_ whether it should be the caller's duty.
The issue is not unique to regular expressions. It is a poster example
for C preprocessor macros.
#define TWICE(x) 2 * x
vs
#define TWICE(x) (2 * (x))
The top example places the duty of correctly parenthesizing the macro
argument and the whole invocation on the caller. The bottom example
assumes that duty itself.
Pretty much every coding style guide resolves the issue in favor of
the latter. Meyers’ razor: [Make interfaces easy to use correctly and
hard to use incorrectly.][1]
(Also, pretty much every C++ coding style guide says “avoid
preprocessor macros; use language constructs that actually care for
syntax, such as functions and function templates”. In Elisp, the
closest although imperfect analogy would probably be (rx-to-string `(:
string-start (regexp ,regexp))), which does add a non-capturing group
where needed.)
[1]: http://www.aristeia.com/Papers/IEEE_Software_JulAug_2004_revised.htm
Now, the issue at hand is: Do we want to expose all the broken code
that is using the existing interface incorrectly, or do we keep
backward bug compatibility?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 9:21 ` Yuri Khan
@ 2017-05-10 11:15 ` Jean-Christophe Helary
2017-05-10 11:56 ` Stefan Monnier
1 sibling, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-10 11:15 UTC (permalink / raw)
To: Yuri Khan
Cc: Mark Oteiza, Eli Zaretskii, Emacs developers, Johan Bockgård,
Tino Calancha
> On May 10, 2017, at 18:21, Yuri Khan <yuri.v.khan@gmail.com> wrote:
>
> Now, the issue at hand is: Do we want to expose all the broken code
> that is using the existing interface incorrectly, or do we keep
> backward bug compatibility?
No, the issue at hand is, should my modifications to subr-x.el conform to the bugged but seemingly standard approach, or use a safer approach, *before* we consider the issue you mention :)
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 9:21 ` Yuri Khan
2017-05-10 11:15 ` Jean-Christophe Helary
@ 2017-05-10 11:56 ` Stefan Monnier
2017-05-10 12:21 ` Jean-Christophe Helary
1 sibling, 1 reply; 73+ messages in thread
From: Stefan Monnier @ 2017-05-10 11:56 UTC (permalink / raw)
To: emacs-devel
> #define TWICE(x) 2 * x
>
> vs
>
> #define TWICE(x) (2 * (x))
Exactly. And I can't believe we're discussing whether to keep the first
form or not.
Stefan
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 20:03 ` Eli Zaretskii
2017-05-07 16:23 ` Johan Bockgård
@ 2017-05-08 2:40 ` Jean-Christophe Helary
2017-05-08 14:28 ` Eli Zaretskii
1 sibling, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-08 2:40 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: mvoteiza, emacs-devel, Johan Bockgård, tino.calancha
I'm sorry, my only use for groupings was for recording a regexp and referring to it later, so I pretty sure I don't understand what you discuss here. But I'd like to...
> On May 7, 2017, at 5:03, Eli Zaretskii <eliz@gnu.org> wrote:
>
>>>> I think regexp should be surrounded by a grouping construct, like:
>>>>
>>>> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
>>>>
>>>> And similarly for string-trim-right.
>>>
>>> Rationale?
>>
>> regexp can contain \|
>
> Shouldn't such a regexp be surrounded by "\\(..\\)"?
So you both agree that the regexp should be surrounded by a grouping construct but you're arguing whether it should be a "normal" grouping or a shy grouping ?
Also,
>> This code performs string concatenation on a perfectly valid regexp
>> provided by the caller. IMO, it is this code's responsibility that the
>> result is sensible after the concatenation.
>>
>> Are you saying this should be the caller's duty?
>
> I'm _asking_ whether it should be the caller's duty.
How does that relate to the "shy" vs "non-shy" thing above?
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-08 2:40 ` Jean-Christophe Helary
@ 2017-05-08 14:28 ` Eli Zaretskii
2017-05-08 21:33 ` Jean-Christophe Helary
0 siblings, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-08 14:28 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: mvoteiza, emacs-devel, bojohan, tino.calancha
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Mon, 8 May 2017 11:40:33 +0900
> Cc: Johan Bockgård <bojohan@gnu.org>,
> mvoteiza@udel.edu,
> tino.calancha@gmail.com,
> emacs-devel@gnu.org
>
> >>>> I think regexp should be surrounded by a grouping construct, like:
> >>>>
> >>>> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
> >>>>
> >>>> And similarly for string-trim-right.
> >>>
> >>> Rationale?
> >>
> >> regexp can contain \|
> >
> > Shouldn't such a regexp be surrounded by "\\(..\\)"?
>
> So you both agree that the regexp should be surrounded by a grouping construct but you're arguing whether it should be a "normal" grouping or a shy grouping ?
No, the issue is whether the function should enclose the argument in a
grouping constructs of any kind, or should this be the caller's
responsibility when the regexp includes \|.
> > I'm _asking_ whether it should be the caller's duty.
>
> How does that relate to the "shy" vs "non-shy" thing above?
It doesn't.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-08 14:28 ` Eli Zaretskii
@ 2017-05-08 21:33 ` Jean-Christophe Helary
2017-05-08 22:45 ` Johan Bockgård
0 siblings, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-08 21:33 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: mvoteiza, emacs-devel, bojohan, tino.calancha
> No, the issue is whether the function should enclose the argument in a
> grouping constructs of any kind, or should this be the caller's
> responsibility when the regexp includes \|.
(split-string) in subr.el (line 3808) doesn't use grouping constructs so why do something different than what's already the norm in an official emacs lisp file? Doesn't that settle the issue?
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-08 21:33 ` Jean-Christophe Helary
@ 2017-05-08 22:45 ` Johan Bockgård
2017-05-08 23:15 ` Jean-Christophe Helary
0 siblings, 1 reply; 73+ messages in thread
From: Johan Bockgård @ 2017-05-08 22:45 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: mvoteiza, Eli Zaretskii, tino.calancha, emacs-devel
Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
>> No, the issue is whether the function should enclose the argument in a
>> grouping constructs of any kind, or should this be the caller's
>> responsibility when the regexp includes \|.
>
> (split-string) in subr.el (line 3808) doesn't use grouping constructs
> so why do something different than what's already the norm in an
> official emacs lisp file? Doesn't that settle the issue?
To me, that's nothing other than a bug:
(split-string "abc, ;def g,hi" nil nil "[,;]")
=>
("abc" "def" "g,hi")
;; Should be equivalent!
(split-string "abc, ;def g,hi" nil nil ",\\|;")
=>
("abc" "def" "g") ; BUG
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-08 22:45 ` Johan Bockgård
@ 2017-05-08 23:15 ` Jean-Christophe Helary
2017-05-09 12:05 ` Michael Heerdegen
0 siblings, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-08 23:15 UTC (permalink / raw)
To: Johan Bockgård; +Cc: mvoteiza, Eli Zaretskii, tino.calancha, emacs-devel
> On May 9, 2017, at 7:45, Johan Bockgård <bojohan@gnu.org> wrote:
>
> Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
>
>>> No, the issue is whether the function should enclose the argument in a
>>> grouping constructs of any kind, or should this be the caller's
>>> responsibility when the regexp includes \|.
>>
>> (split-string) in subr.el (line 3808) doesn't use grouping constructs
>> so why do something different than what's already the norm in an
>> official emacs lisp file? Doesn't that settle the issue?
>
> To me, that's nothing other than a bug:
>
> (split-string "abc, ;def g,hi" nil nil "[,;]")
> =>
> ("abc" "def" "g,hi")
>
> ;; Should be equivalent!
> (split-string "abc, ;def g,hi" nil nil ",\\|;")
> =>
> ("abc" "def" "g") ; BUG
Ok, and the way to get your result is:
(split-string "abc, ;def g,hi" nil nil "\\(,\\|;\\)")
which means that Emacs thinks it is the caller's duty to provide the grouping construct, which also happens to be ugly, and non-intuitive since ",\\|;" is an otherwise valid regexp...
So, how do we go about that? Do we report a bug? Or do we find a good reason for that to happen and modify the documentation for split-string ?
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-08 23:15 ` Jean-Christophe Helary
@ 2017-05-09 12:05 ` Michael Heerdegen
2017-05-09 13:09 ` Jean-Christophe Helary
2017-05-09 15:23 ` Eli Zaretskii
0 siblings, 2 replies; 73+ messages in thread
From: Michael Heerdegen @ 2017-05-09 12:05 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: mvoteiza, Eli Zaretskii, emacs-devel, Johan Bockgård,
tino.calancha
Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
> > (split-string "abc, ;def g,hi" nil nil ",\\|;")
> > =>
> > ("abc" "def" "g") ; BUG
>
> Ok, and the way to get your result is:
>
> (split-string "abc, ;def g,hi" nil nil "\\(,\\|;\\)")
>
> which means that Emacs thinks it is the caller's duty to provide the
> grouping construct, which also happens to be ugly, and non-intuitive
> since ",\\|;" is an otherwise valid regexp...
>
> So, how do we go about that? Do we report a bug? Or do we find a good
> reason for that to happen and modify the documentation for
> split-string ?
I'm curious what could be reasons not to fix this (in the code).
Allowing only a subset of possible regexps would be quite strange.
Would there be any advantages?
Michael.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 12:05 ` Michael Heerdegen
@ 2017-05-09 13:09 ` Jean-Christophe Helary
2017-05-09 14:05 ` Michael Heerdegen
2017-05-10 9:30 ` Michael Heerdegen
2017-05-09 15:23 ` Eli Zaretskii
1 sibling, 2 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-09 13:09 UTC (permalink / raw)
To: Michael Heerdegen
Cc: mvoteiza, Eli Zaretskii, emacs-devel, Johan Bockgård,
tino.calancha
> On May 9, 2017, at 21:05, Michael Heerdegen <michael_heerdegen@web.de> wrote:
>
> Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
>
>>> (split-string "abc, ;def g,hi" nil nil ",\\|;")
>>> =>
>>> ("abc" "def" "g") ; BUG
>>
>> Ok, and the way to get your result is:
>>
>> (split-string "abc, ;def g,hi" nil nil "\\(,\\|;\\)")
>>
>> which means that Emacs thinks it is the caller's duty to provide the
>> grouping construct, which also happens to be ugly, and non-intuitive
>> since ",\\|;" is an otherwise valid regexp...
>>
>> So, how do we go about that? Do we report a bug? Or do we find a good
>> reason for that to happen and modify the documentation for
>> split-string ?
>
> I'm curious what could be reasons not to fix this (in the code).
Because split-string is used all over the place in Emacs and we'd have to check that the fix is not breaking some code somewhere in ways that we can't always guess?
> Allowing only a subset of possible regexps would be quite strange.
Not if you document the strangeness.
> Would there be any advantages?
Not having to modify a lot of other places in the Emacs code.
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 13:09 ` Jean-Christophe Helary
@ 2017-05-09 14:05 ` Michael Heerdegen
2017-05-10 9:30 ` Michael Heerdegen
1 sibling, 0 replies; 73+ messages in thread
From: Michael Heerdegen @ 2017-05-09 14:05 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: mvoteiza, Eli Zaretskii, emacs-devel, Johan Bockgård,
tino.calancha
Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
> > I'm curious what could be reasons not to fix this (in the code).
>
> Because split-string is used all over the place in Emacs and we'd have
> to check that the fix is not breaking some code somewhere in ways that
> we can't always guess?
I see.
OTOH we would probably also fix a lot of use cases that were broken
until now, unrecognized, in subtle ways. Also in code outside of the
Emacs repository.
> > Allowing only a subset of possible regexps would be quite strange.
>
> Not if you document the strangeness.
Per definitionem. In the long term, it might still be less work to fix
it.
Michael.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 13:09 ` Jean-Christophe Helary
2017-05-09 14:05 ` Michael Heerdegen
@ 2017-05-10 9:30 ` Michael Heerdegen
2017-05-10 11:11 ` Jean-Christophe Helary
1 sibling, 1 reply; 73+ messages in thread
From: Michael Heerdegen @ 2017-05-10 9:30 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: mvoteiza, Eli Zaretskii, tino.calancha, Johan Bockgård,
emacs-devel
Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
> Not if you document the strangeness.
BTW, if you really do this (I hope you don't), note that the strangeness
would also have to be documented for variables that are used at that
argument position of `split-string'. An example is `crm-separator' in
crm.el.
Michael.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 9:30 ` Michael Heerdegen
@ 2017-05-10 11:11 ` Jean-Christophe Helary
0 siblings, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-10 11:11 UTC (permalink / raw)
To: Michael Heerdegen
Cc: mvoteiza, Eli Zaretskii, tino.calancha, Johan Bockgård,
emacs-devel
> On May 10, 2017, at 18:30, Michael Heerdegen <michael_heerdegen@web.de> wrote:
>
> Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
>
>> Not if you document the strangeness.
>
> BTW, if you really do this (I hope you don't), note that the strangeness
> would also have to be documented for variables that are used at that
> argument position of `split-string'. An example is `crm-separator' in
> crm.el.
*I* won't :) But I'd expect somebody to report Johan's bug and the bug to be fixed in a way or another (either fix the documentation or fix the code). But that's something that's totally beyond what I'm able to do.
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 12:05 ` Michael Heerdegen
2017-05-09 13:09 ` Jean-Christophe Helary
@ 2017-05-09 15:23 ` Eli Zaretskii
2017-05-09 15:33 ` Jean-Christophe Helary
1 sibling, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-09 15:23 UTC (permalink / raw)
To: Michael Heerdegen
Cc: mvoteiza, jean.christophe.helary, emacs-devel, bojohan,
tino.calancha
> From: Michael Heerdegen <michael_heerdegen@web.de>
> Cc: Johan Bockgård <bojohan@gnu.org>, mvoteiza@udel.edu,
> Eli Zaretskii <eliz@gnu.org>, tino.calancha@gmail.com,
> emacs-devel@gnu.org
> Date: Tue, 09 May 2017 14:05:13 +0200
>
> Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
>
> > > (split-string "abc, ;def g,hi" nil nil ",\\|;")
> > > =>
> > > ("abc" "def" "g") ; BUG
> >
> > Ok, and the way to get your result is:
> >
> > (split-string "abc, ;def g,hi" nil nil "\\(,\\|;\\)")
> >
> > which means that Emacs thinks it is the caller's duty to provide the
> > grouping construct, which also happens to be ugly, and non-intuitive
> > since ",\\|;" is an otherwise valid regexp...
> >
> > So, how do we go about that? Do we report a bug? Or do we find a good
> > reason for that to happen and modify the documentation for
> > split-string ?
>
> I'm curious what could be reasons not to fix this (in the code).
> Allowing only a subset of possible regexps would be quite strange.
> Would there be any advantages?
How about if we proceed with the change in string-trim, and file a
separate bug against both it and split-string, for such regexps?
These seem to be largely unrelated issues, and it's a pity to block
Jean-Christophe's changes due to that.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 15:23 ` Eli Zaretskii
@ 2017-05-09 15:33 ` Jean-Christophe Helary
2017-05-09 16:21 ` Eli Zaretskii
2017-05-09 16:37 ` Andreas Schwab
0 siblings, 2 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-09 15:33 UTC (permalink / raw)
To: Eli Zaretskii
Cc: Michael Heerdegen, Mark Oteiza, emacs-devel, Johan Bockgård,
tino.calancha
> On May 10, 2017, at 0:23, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Michael Heerdegen <michael_heerdegen@web.de>
>> Cc: Johan Bockgård <bojohan@gnu.org>, mvoteiza@udel.edu,
>> Eli Zaretskii <eliz@gnu.org>, tino.calancha@gmail.com,
>> emacs-devel@gnu.org
>> Date: Tue, 09 May 2017 14:05:13 +0200
>>
>> Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:
>>
>>>> (split-string "abc, ;def g,hi" nil nil ",\\|;")
>>>> =>
>>>> ("abc" "def" "g") ; BUG
>>>
>>> Ok, and the way to get your result is:
>>>
>>> (split-string "abc, ;def g,hi" nil nil "\\(,\\|;\\)")
>>>
>>> which means that Emacs thinks it is the caller's duty to provide the
>>> grouping construct, which also happens to be ugly, and non-intuitive
>>> since ",\\|;" is an otherwise valid regexp...
>>>
>>> So, how do we go about that? Do we report a bug? Or do we find a good
>>> reason for that to happen and modify the documentation for
>>> split-string ?
>>
>> I'm curious what could be reasons not to fix this (in the code).
>> Allowing only a subset of possible regexps would be quite strange.
>> Would there be any advantages?
>
> How about if we proceed with the change in string-trim, and file a
> separate bug against both it and split-string, for such regexps?
> These seem to be largely unrelated issues, and it's a pity to block
> Jean-Christophe's changes due to that.
Ok, so we agree that we don't add \\( \\) to the regexp and that we expect the caller to send a correct regexp as is the case for split-string, is that correct ?
(But I'm also glad the discussion that started with a trivial modification to ns-win.el triggered all that *and* that I understood what was at stake :-)
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 15:33 ` Jean-Christophe Helary
@ 2017-05-09 16:21 ` Eli Zaretskii
2017-05-09 23:03 ` Jean-Christophe Helary
2017-05-09 16:37 ` Andreas Schwab
1 sibling, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-09 16:21 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: michael_heerdegen, mvoteiza, emacs-devel, bojohan, tino.calancha
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Wed, 10 May 2017 00:33:47 +0900
> Cc: Michael Heerdegen <michael_heerdegen@web.de>,
> Johan Bockgård <bojohan@gnu.org>,
> Mark Oteiza <mvoteiza@udel.edu>,
> tino.calancha@gmail.com,
> emacs-devel@gnu.org
>
> > How about if we proceed with the change in string-trim, and file a
> > separate bug against both it and split-string, for such regexps?
> > These seem to be largely unrelated issues, and it's a pity to block
> > Jean-Christophe's changes due to that.
>
> Ok, so we agree that we don't add \\( \\) to the regexp and that we expect the caller to send a correct regexp as is the case for split-string, is that correct ?
_I_ obviously agree, and so do you, but I'd like to hear from others
as well.
Thanks.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 16:21 ` Eli Zaretskii
@ 2017-05-09 23:03 ` Jean-Christophe Helary
2017-05-10 0:45 ` Stefan Monnier
0 siblings, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-09 23:03 UTC (permalink / raw)
To: monnier, Johan Bockgård
Cc: Michael Heerdegen, Mark Oteiza, Eli Zaretskii, emacs-devel,
Tino Calancha
> On May 10, 2017, at 1:21, Eli Zaretskii <eliz@gnu.org> wrote:
>
>>> How about if we proceed with the change in string-trim, and file a
>>> separate bug against both it and split-string, for such regexps?
>>> These seem to be largely unrelated issues, and it's a pity to block
>>> Jean-Christophe's changes due to that.
>>
>> Ok, so we agree that we don't add \\( \\) to the regexp and that we expect the caller to send a correct regexp as is the case for split-string, is that correct ?
>
> _I_ obviously agree, and so do you, but I'd like to hear from others as well.
Johan, Stephan what's your take on this?
Since what I propose is consistant with the existing code, not agreeing with that means *first* finding the bug that Johan mentioned (which is not directly related to my modification), starting a review process of the whole code base that uses subr.el/split-string (and maybe other places where that regexp bug happens), fixing the code to ensure some kind of backward compatibility, etc. and *then* applying my change to subr-x...
While we could first change subr-x (string-trim...) so that they behave similarly to split-string and then start the bug hunting...
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 23:03 ` Jean-Christophe Helary
@ 2017-05-10 0:45 ` Stefan Monnier
2017-05-10 2:44 ` Eli Zaretskii
2017-05-10 3:49 ` Jean-Christophe Helary
0 siblings, 2 replies; 73+ messages in thread
From: Stefan Monnier @ 2017-05-10 0:45 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: Tino Calancha, Michael Heerdegen, Johan Bockgård,
emacs-devel, Mark Oteiza, Eli Zaretskii
> Since what I propose is consistant with the existing code, not agreeing with
> that means *first* finding the bug that Johan mentioned (which is not
> directly related to my modification), starting a review process of the whole
> code base that uses subr.el/split-string (and maybe other places where that
> regexp bug happens), fixing the code to ensure some kind of backward
> compatibility, etc. and *then* applying my change to subr-x...
I'm pretty sure surrounding the regexp in \(?:..\) will break no code at
all. To me it's an absolute no-brainer that doesn't even merit any discussion.
Stefan
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 0:45 ` Stefan Monnier
@ 2017-05-10 2:44 ` Eli Zaretskii
2017-05-10 3:09 ` Stefan Monnier
2017-05-10 3:49 ` Jean-Christophe Helary
1 sibling, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-10 2:44 UTC (permalink / raw)
To: Stefan Monnier
Cc: tino.calancha, michael_heerdegen, jean.christophe.helary, bojohan,
emacs-devel, mvoteiza
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Johan Bockgård <bojohan@gnu.org>, Michael
> Heerdegen <michael_heerdegen@web.de>, Eli Zaretskii <eliz@gnu.org>, Mark
> Oteiza <mvoteiza@udel.edu>, Tino Calancha <tino.calancha@gmail.com>,
> emacs-devel <emacs-devel@gnu.org>
> Date: Tue, 09 May 2017 20:45:14 -0400
>
> I'm pretty sure surrounding the regexp in \(?:..\) will break no code at
> all. To me it's an absolute no-brainer that doesn't even merit any discussion.
What about the same issue in split-string?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 0:45 ` Stefan Monnier
2017-05-10 2:44 ` Eli Zaretskii
@ 2017-05-10 3:49 ` Jean-Christophe Helary
2017-05-10 11:55 ` Stefan Monnier
1 sibling, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-10 3:49 UTC (permalink / raw)
To: Stefan Monnier
Cc: Tino Calancha, Michael Heerdegen, Johan Bockgård,
emacs-devel, Mark Oteiza, Eli Zaretskii
> On May 10, 2017, at 9:45, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
>> Since what I propose is consistant with the existing code, not agreeing with
>> that means *first* finding the bug that Johan mentioned (which is not
>> directly related to my modification), starting a review process of the whole
>> code base that uses subr.el/split-string (and maybe other places where that
>> regexp bug happens), fixing the code to ensure some kind of backward
>> compatibility, etc. and *then* applying my change to subr-x...
>
> I'm pretty sure surrounding the regexp in \(?:..\) will break no code at
> all. To me it's an absolute no-brainer that doesn't even merit any discussion.
That does not seem to be the case. Johan has identified a case where a regexp that uses \| does not produce the same result as the "trim" argument of split-string whether it uses \( \) or not.
So there is the possibility that code that use the "trim" argument will produce an unexpected result if split-string is modified.
I am not talking about subr-x.el, it is an addition that is backward compatible since the new argument is optional.
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 3:49 ` Jean-Christophe Helary
@ 2017-05-10 11:55 ` Stefan Monnier
0 siblings, 0 replies; 73+ messages in thread
From: Stefan Monnier @ 2017-05-10 11:55 UTC (permalink / raw)
To: emacs-devel
>> I'm pretty sure surrounding the regexp in \(?:..\) will break no code
>> at all. To me it's an absolute no-brainer that doesn't even merit
>> any discussion.
> That does not seem to be the case. Johan has identified a case
> where a regexp that uses \| does not produce the same result as the "trim"
> argument of split-string whether it uses \( \) or not.
Of course it doesn't behave the same (otherwise, why bother changing
it): "I'm pretty sure surrounding the regexp in \(?:..\) will break no
code at all" doesn't mean that such code can't exist, but that I expect
such code not to exist in the wild (or if it exists, it *suffers* from
the current behavior rather than benefitting from it).
Stefan
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 15:33 ` Jean-Christophe Helary
2017-05-09 16:21 ` Eli Zaretskii
@ 2017-05-09 16:37 ` Andreas Schwab
2017-05-10 2:29 ` Eli Zaretskii
1 sibling, 1 reply; 73+ messages in thread
From: Andreas Schwab @ 2017-05-09 16:37 UTC (permalink / raw)
To: Jean-Christophe Helary
Cc: tino.calancha, Michael Heerdegen, Johan Bockgård,
emacs-devel, Mark Oteiza, Eli Zaretskii
On Mai 10 2017, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
> Ok, so we agree that we don't add \\( \\) to the regexp and that we expect the caller to send a correct regexp as is the case for split-string, is that correct ?
If you want to modify a regexp you need to make sure to preserve its
semantics.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-09 16:37 ` Andreas Schwab
@ 2017-05-10 2:29 ` Eli Zaretskii
2017-05-10 7:45 ` Andreas Schwab
0 siblings, 1 reply; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-10 2:29 UTC (permalink / raw)
To: Andreas Schwab
Cc: tino.calancha, michael_heerdegen, jean.christophe.helary, bojohan,
emacs-devel, mvoteiza
> From: Andreas Schwab <schwab@suse.de>
> Cc: Eli Zaretskii <eliz@gnu.org>, Michael Heerdegen
> <michael_heerdegen@web.de>, Mark Oteiza <mvoteiza@udel.edu>,
> emacs-devel@gnu.org, Johan Bockgård <bojohan@gnu.org>,
> tino.calancha@gmail.com
> Date: Tue, 09 May 2017 18:37:47 +0200
>
> > Ok, so we agree that we don't add \\( \\) to the regexp and that we expect the caller to send a correct regexp as is the case for split-string, is that correct ?
>
> If you want to modify a regexp you need to make sure to preserve its
> semantics.
Can you give an example of a regexp whose semantics might change by
adding \\(..\\)?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 2:29 ` Eli Zaretskii
@ 2017-05-10 7:45 ` Andreas Schwab
2017-05-10 11:07 ` Jean-Christophe Helary
0 siblings, 1 reply; 73+ messages in thread
From: Andreas Schwab @ 2017-05-10 7:45 UTC (permalink / raw)
To: Eli Zaretskii
Cc: tino.calancha, michael_heerdegen, jean.christophe.helary, bojohan,
emacs-devel, mvoteiza
On Mai 10 2017, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Andreas Schwab <schwab@suse.de>
>> Cc: Eli Zaretskii <eliz@gnu.org>, Michael Heerdegen
>> <michael_heerdegen@web.de>, Mark Oteiza <mvoteiza@udel.edu>,
>> emacs-devel@gnu.org, Johan Bockgård <bojohan@gnu.org>,
>> tino.calancha@gmail.com
>> Date: Tue, 09 May 2017 18:37:47 +0200
>>
>> > Ok, so we agree that we don't add \\( \\) to the regexp and that we expect the caller to send a correct regexp as is the case for split-string, is that correct ?
>>
>> If you want to modify a regexp you need to make sure to preserve its
>> semantics.
>
> Can you give an example of a regexp whose semantics might change by
> adding \\(..\\)?
If you have any backrefs, their numbers change.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 7:45 ` Andreas Schwab
@ 2017-05-10 11:07 ` Jean-Christophe Helary
0 siblings, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-10 11:07 UTC (permalink / raw)
To: Andreas Schwab
Cc: tino.calancha, michael_heerdegen, bojohan, emacs-devel, mvoteiza,
Eli Zaretskii
> On May 10, 2017, at 16:45, Andreas Schwab <schwab@suse.de> wrote:
>
>> Can you give an example of a regexp whose semantics might change by
>> adding \\(..\\)?
>
> If you have any backrefs, their numbers change.
I think Eli meant using \(?:
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 19:55 ` Johan Bockgård
2017-05-06 20:03 ` Eli Zaretskii
@ 2017-05-07 4:39 ` Jean-Christophe Helary
2017-05-07 14:49 ` Eli Zaretskii
1 sibling, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-07 4:39 UTC (permalink / raw)
To: Johan Bockgård; +Cc: mvoteiza, Eli Zaretskii, emacs-devel, tino.calancha
Any conclusion on that point?
Jean-Christophe
> On May 7, 2017, at 4:55, Johan Bockgård <bojohan@gnu.org> wrote:
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
>>>> + (if (string-match (concat "\\`" (or regexp "[ \t\n\r]+")) string)
>>>
>>> I think regexp should be surrounded by a grouping construct, like:
>>>
>>> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
>>>
>>> And similarly for string-trim-right.
>>
>> Rationale?
>
> regexp can contain \|
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 17:51 ` Johan Bockgård
2017-05-06 19:02 ` Eli Zaretskii
@ 2017-05-07 13:48 ` Stefan Monnier
1 sibling, 0 replies; 73+ messages in thread
From: Stefan Monnier @ 2017-05-07 13:48 UTC (permalink / raw)
To: emacs-devel
> I think regexp should be surrounded by a grouping construct, like:
>
> (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)")
>
> And similarly for string-trim-right.
Indeed, thanks,
Stefan
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 11:02 ` Jean-Christophe Helary
2017-05-06 13:05 ` Jean-Christophe Helary
@ 2017-05-10 14:26 ` Jean-Christophe Helary
2017-05-13 13:36 ` bug#26908: Fwd: " Jean-Christophe Helary
1 sibling, 1 reply; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-10 14:26 UTC (permalink / raw)
To: Emacs developers
[-- Attachment #1: Type: text/plain, Size: 439 bytes --]
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
===========================
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.
===========================
[-- Attachment #2: subr-x.el.diff --]
[-- Type: application/octet-stream, Size: 1625 bytes --]
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."
[-- Attachment #3: Type: text/plain, Size: 1120 bytes --]
> On May 6, 2017, at 20:02, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
>
> Ok, I'm fine with that. Apologies for my lack of understanding of the issues.
>
> Jean-Christophe
>
>> On May 6, 2017, at 19:43, Eli Zaretskii <eliz@gnu.org> wrote:
>>
>>> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
>>> Date: Sat, 6 May 2017 19:33:10 +0900
>>> Cc: tino.calancha@gmail.com,
>>> mvoteiza@udel.edu,
>>> emacs-devel@gnu.org
>>>
>>> My original idea was to put the regexp into a variable that *can* eventually be overridden by a user preference.
>>
>> 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.
>>
>> 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.
>
^ permalink raw reply related [flat|nested] 73+ messages in thread
* bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-10 14:26 ` Jean-Christophe Helary
@ 2017-05-13 13:36 ` Jean-Christophe Helary
2017-05-16 22:21 ` Jean-Christophe Helary
` (2 more replies)
0 siblings, 3 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-13 13:36 UTC (permalink / raw)
To: 26908
[-- Attachment #1: Type: text/plain, Size: 883 bytes --]
Since nobody reacted in the last 3 days, I guess that means there is nothing to change, so I'm sending the patch here.
Jean-Christophe
> Begin forwarded message:
>
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Subject: Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
> Date: May 10, 2017 23:26:04 GMT+9
> To: Emacs developers <emacs-devel@gnu.org>
>
> 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
>
>
> ===========================
> 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.
> ===========================
>
>
>
[-- Attachment #2.1: Type: text/html, Size: 3045 bytes --]
[-- Attachment #2.2: subr-x.el.diff --]
[-- Type: application/octet-stream, Size: 1625 bytes --]
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."
[-- Attachment #2.3: Type: text/html, Size: 343 bytes --]
^ permalink raw reply related [flat|nested] 73+ messages in thread
* Re: bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-13 13:36 ` bug#26908: Fwd: " Jean-Christophe Helary
@ 2017-05-16 22:21 ` Jean-Christophe Helary
2017-05-17 2:26 ` Eli Zaretskii
2017-05-17 2:26 ` Eli Zaretskii
2017-05-16 22:21 ` Jean-Christophe Helary
2017-05-19 11:30 ` Eli Zaretskii
2 siblings, 2 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-16 22:21 UTC (permalink / raw)
To: 26908; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]
Nobody is interested in checking/commiting that ? If it's something I should not have touched in the first place, please somebody tell me to drop it...
Jean-Christophe
> On May 13, 2017, at 22:36, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
>
> Since nobody reacted in the last 3 days, I guess that means there is nothing to change, so I'm sending the patch here.
>
> Jean-Christophe
>
>> Begin forwarded message:
>>
>> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com <mailto:jean.christophe.helary@gmail.com>>
>> Subject: Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
>> Date: May 10, 2017 23:26:04 GMT+9
>> To: Emacs developers <emacs-devel@gnu.org <mailto:emacs-devel@gnu.org>>
>>
>> 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
>>
>>
>> ===========================
>> 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.
>> ===========================
>>
>>
> <subr-x.el.diff>
>>
[-- Attachment #2: Type: text/html, Size: 4126 bytes --]
^ permalink raw reply [flat|nested] 73+ messages in thread
* bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-16 22:21 ` Jean-Christophe Helary
@ 2017-05-17 2:26 ` Eli Zaretskii
2017-05-17 2:26 ` Eli Zaretskii
1 sibling, 0 replies; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-17 2:26 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: 26908, emacs-devel
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Wed, 17 May 2017 07:21:19 +0900
> Cc: emacs-devel <emacs-devel@gnu.org>
>
> Nobody is interested in checking/commiting that ?
I usually wait for a week at least, to let people comment. So please
be a bit more patient.
Thanks for working on this.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-16 22:21 ` Jean-Christophe Helary
2017-05-17 2:26 ` Eli Zaretskii
@ 2017-05-17 2:26 ` Eli Zaretskii
2017-05-17 3:41 ` Jean-Christophe Helary
2017-05-17 3:41 ` Jean-Christophe Helary
1 sibling, 2 replies; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-17 2:26 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: 26908, emacs-devel
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Wed, 17 May 2017 07:21:19 +0900
> Cc: emacs-devel <emacs-devel@gnu.org>
>
> Nobody is interested in checking/commiting that ?
I usually wait for a week at least, to let people comment. So please
be a bit more patient.
Thanks for working on this.
^ permalink raw reply [flat|nested] 73+ messages in thread
* bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-17 2:26 ` Eli Zaretskii
@ 2017-05-17 3:41 ` Jean-Christophe Helary
2017-05-17 3:41 ` Jean-Christophe Helary
1 sibling, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-17 3:41 UTC (permalink / raw)
To: 26908; +Cc: emacs-devel
Thank you Eli. I was not aware of the procedure. I have no problem waiting :)
JC
> On May 17, 2017, at 11:26, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
>> Date: Wed, 17 May 2017 07:21:19 +0900
>> Cc: emacs-devel <emacs-devel@gnu.org>
>>
>> Nobody is interested in checking/commiting that ?
>
> I usually wait for a week at least, to let people comment. So please
> be a bit more patient.
>
> Thanks for working on this.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-17 2:26 ` Eli Zaretskii
2017-05-17 3:41 ` Jean-Christophe Helary
@ 2017-05-17 3:41 ` Jean-Christophe Helary
1 sibling, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-17 3:41 UTC (permalink / raw)
To: 26908; +Cc: emacs-devel
Thank you Eli. I was not aware of the procedure. I have no problem waiting :)
JC
> On May 17, 2017, at 11:26, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
>> Date: Wed, 17 May 2017 07:21:19 +0900
>> Cc: emacs-devel <emacs-devel@gnu.org>
>>
>> Nobody is interested in checking/commiting that ?
>
> I usually wait for a week at least, to let people comment. So please
> be a bit more patient.
>
> Thanks for working on this.
^ permalink raw reply [flat|nested] 73+ messages in thread
* bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-13 13:36 ` bug#26908: Fwd: " Jean-Christophe Helary
2017-05-16 22:21 ` Jean-Christophe Helary
@ 2017-05-16 22:21 ` Jean-Christophe Helary
2017-05-19 11:30 ` Eli Zaretskii
2 siblings, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-16 22:21 UTC (permalink / raw)
To: 26908; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]
Nobody is interested in checking/commiting that ? If it's something I should not have touched in the first place, please somebody tell me to drop it...
Jean-Christophe
> On May 13, 2017, at 22:36, Jean-Christophe Helary <jean.christophe.helary@gmail.com> wrote:
>
> Since nobody reacted in the last 3 days, I guess that means there is nothing to change, so I'm sending the patch here.
>
> Jean-Christophe
>
>> Begin forwarded message:
>>
>> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com <mailto:jean.christophe.helary@gmail.com>>
>> Subject: Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
>> Date: May 10, 2017 23:26:04 GMT+9
>> To: Emacs developers <emacs-devel@gnu.org <mailto:emacs-devel@gnu.org>>
>>
>> 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
>>
>>
>> ===========================
>> 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.
>> ===========================
>>
>>
> <subr-x.el.diff>
>>
[-- Attachment #2: Type: text/html, Size: 4126 bytes --]
^ permalink raw reply [flat|nested] 73+ messages in thread
* bug#26908: Fwd: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-13 13:36 ` bug#26908: Fwd: " Jean-Christophe Helary
2017-05-16 22:21 ` Jean-Christophe Helary
2017-05-16 22:21 ` Jean-Christophe Helary
@ 2017-05-19 11:30 ` Eli Zaretskii
2 siblings, 0 replies; 73+ messages in thread
From: Eli Zaretskii @ 2017-05-19 11:30 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: 26908-done
> From: Jean-Christophe Helary <jean.christophe.helary@gmail.com>
> Date: Sat, 13 May 2017 22:36:11 +0900
>
> Since nobody reacted in the last 3 days, I guess that means there is nothing to change, so I'm sending the patch here.
Thanks, pushed.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 10:43 ` Eli Zaretskii
2017-05-06 11:02 ` Jean-Christophe Helary
@ 2017-05-06 11:06 ` Jean-Christophe Helary
1 sibling, 0 replies; 73+ messages in thread
From: Jean-Christophe Helary @ 2017-05-06 11:06 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: mvoteiza, emacs-devel, tino.calancha
>> My original idea was to put the regexp into a variable that *can* eventually be overridden by a user preference.
>
> 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.
By the way, the idea I had was like what we have in Applescript for the split function.
AS provides the system with a default list of splitters and the user can locally change it for specific purposes and then revert it to it's original value.
In AS, this is used very frequently.
Jean-Christophe
^ permalink raw reply [flat|nested] 73+ messages in thread
* RE: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 9:02 ` Jean-Christophe Helary
2017-05-06 9:22 ` Eli Zaretskii
@ 2017-05-06 16:30 ` Drew Adams
2017-05-06 17:44 ` Stefan Monnier
1 sibling, 1 reply; 73+ messages in thread
From: Drew Adams @ 2017-05-06 16:30 UTC (permalink / raw)
To: Jean-Christophe Helary, Tino Calancha; +Cc: Mark Oteiza, emacs-devel
> > +(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))
>
> Isn't there a way to do [...] that would work with defsubst?
IMHO, *none* of the defsubsts in subr-x.el should be there.
They should all be defuns. (Currently, even their names are
inconsistent, some with `--' to indicate internal, most not.)
The code will be byte-compiled. I see zero reason why these
functions should be defsubsts. Instead of using a boatload
of defsubsts willy nilly, any defsubsts we put in the code
should be _strongly_ justified. I don't see any justification
for these defsubsts.
It's not just because `defsubst' still exists that we should
use it casually (or even use it at all). It is a precambrian
vestige, with little or no real use case.
Just one opinion.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 16:30 ` Drew Adams
@ 2017-05-06 17:44 ` Stefan Monnier
2017-05-06 18:07 ` subr-x.el code and defsubst [was: Trimming strings, /.../subr-x.el modification] Drew Adams
0 siblings, 1 reply; 73+ messages in thread
From: Stefan Monnier @ 2017-05-06 17:44 UTC (permalink / raw)
To: emacs-devel
> The code will be byte-compiled. I see zero reason why these
> functions should be defsubsts.
The reason, AFAIC is the following: subr-x holds functions which we
haven't committed to adding to core. We exceptionally allow them to
not use a prefix but in return we only use subr-x while compiling (since
it's fundamentally not namespace-clean and we don't want to impose those
non-clean names upon the unsuspecting user).
Stefan
^ permalink raw reply [flat|nested] 73+ messages in thread
* subr-x.el code and defsubst [was: Trimming strings, /.../subr-x.el modification]
2017-05-06 17:44 ` Stefan Monnier
@ 2017-05-06 18:07 ` Drew Adams
2017-05-14 22:45 ` Tianxiang Xiong
0 siblings, 1 reply; 73+ messages in thread
From: Drew Adams @ 2017-05-06 18:07 UTC (permalink / raw)
To: Stefan Monnier, emacs-devel
> > The code will be byte-compiled. I see zero reason why these
> > functions should be defsubsts.
>
> The reason, AFAIC is the following: subr-x holds functions which we
> haven't committed to adding to core. We exceptionally allow them to
> not use a prefix but in return we only use subr-x while compiling (since
> it's fundamentally not namespace-clean and we don't want to impose those
> non-clean names upon the unsuspecting user).
OK. Not a great reason, IMO, but I understand now, at least.
I don't think that reason is obvious. Please consider adding a
GIANT comment in subr-x.el to explain this exceptional treatment.
This existing comment, which is all there is, does not cover it, IMO:
;; Less commonly used functions that complement basic APIs, often
;; implemented in C code (like hash-tables and strings), and are
;; not eligible for inclusion in subr.el.
;; Do not document these functions in the lispref.
;; http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01006.html
And why is it that this library has still not been "committed to
core"? (And isn't that what GNU ELPA is for?)
Beyond that, this approach of not bothering with name prefixes,
byte-compiling separately, etc. seems really weird (fragile, error
prone). Why such an exception? Is this really the best way to
handle code that you consider "experimental" or "less commonly used"
or code "that complements basic APIs"?
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: subr-x.el code and defsubst [was: Trimming strings, /.../subr-x.el modification]
2017-05-06 18:07 ` subr-x.el code and defsubst [was: Trimming strings, /.../subr-x.el modification] Drew Adams
@ 2017-05-14 22:45 ` Tianxiang Xiong
2017-05-15 1:11 ` Drew Adams
0 siblings, 1 reply; 73+ messages in thread
From: Tianxiang Xiong @ 2017-05-14 22:45 UTC (permalink / raw)
To: Drew Adams; +Cc: Stefan Monnier, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 2378 bytes --]
I also don't understand why `subr-x.el` exists.
First of all, why not put `string-*` functions in a `string.el`? It's
surprising that no such file exists at the moment.
Secondly, why are these functions considered "experimental"? If a package
depends on a function in `subr-x` that is later removed, is it any less
inconvenient for the package author than if `subr-x` was *not* experimental?
No. Empirically, the `string-*` and `thread-*` functions see a lot of use
in the wild, so (re)moving them at this point would cause quite an uproar.
If functions need to considered experimental, at least put them in the
"right" place--e.g. `string-empty-p` in `string.el`. That way, even if the
function's implementation needed to be modified, package authors won't need
to `require` a different package. Organization matters.
On Sat, May 6, 2017 at 11:07 AM, Drew Adams <drew.adams@oracle.com> wrote:
> > > The code will be byte-compiled. I see zero reason why these
> > > functions should be defsubsts.
> >
> > The reason, AFAIC is the following: subr-x holds functions which we
> > haven't committed to adding to core. We exceptionally allow them to
> > not use a prefix but in return we only use subr-x while compiling (since
> > it's fundamentally not namespace-clean and we don't want to impose those
> > non-clean names upon the unsuspecting user).
>
> OK. Not a great reason, IMO, but I understand now, at least.
>
> I don't think that reason is obvious. Please consider adding a
> GIANT comment in subr-x.el to explain this exceptional treatment.
>
> This existing comment, which is all there is, does not cover it, IMO:
>
> ;; Less commonly used functions that complement basic APIs, often
> ;; implemented in C code (like hash-tables and strings), and are
> ;; not eligible for inclusion in subr.el.
>
> ;; Do not document these functions in the lispref.
> ;; http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01006.html
>
> And why is it that this library has still not been "committed to
> core"? (And isn't that what GNU ELPA is for?)
>
> Beyond that, this approach of not bothering with name prefixes,
> byte-compiling separately, etc. seems really weird (fragile, error
> prone). Why such an exception? Is this really the best way to
> handle code that you consider "experimental" or "less commonly used"
> or code "that complements basic APIs"?
>
>
[-- Attachment #2: Type: text/html, Size: 3129 bytes --]
^ permalink raw reply [flat|nested] 73+ messages in thread
* RE: subr-x.el code and defsubst [was: Trimming strings, /.../subr-x.el modification]
2017-05-14 22:45 ` Tianxiang Xiong
@ 2017-05-15 1:11 ` Drew Adams
0 siblings, 0 replies; 73+ messages in thread
From: Drew Adams @ 2017-05-15 1:11 UTC (permalink / raw)
To: Tianxiang Xiong; +Cc: Stefan Monnier, Emacs developers
> I also don't understand why `subr-x.el` exists.
>
> First of all, why not put `string-*` functions in a `string.el`?
> It's surprising that no such file exists at the moment.
>
> Secondly, why are these functions considered "experimental"?
> If a package depends on a function in `subr-x` that is later
> removed, is it any less inconvenient for the package author
> than if `subr-x` was not experimental? No. Empirically, the
> `string-*` and `thread-*` functions see a lot of use in the
> wild, so (re)moving them at this point would cause quite an
> uproar.
>
> If functions need to considered experimental, at least put
> them in the "right" place--e.g. `string-empty-p` in `string.el`.
> That way, even if the function's implementation needed to
> be modified, package authors won't need to `require` a
> different package. Organization matters.
FWIW, I agree.
Perhaps it's not a coincidence that this policy/approach was
accompanied in time by the introduction (or perhaps increase)
of the use of "*--*" names for "internal" Lisp constructs.
Similarly misguided, I think.
If you really feel the need for a "purgatory" or "lab" for
code that you don't yet feel confident about or haven't yet
consecrated as official or backed by commitment, code that
you consider experimental or internal so that you can feel
more freedom to modify it without worrying about users, at
least stick it in GNU ELPA, please.
^ permalink raw reply [flat|nested] 73+ messages in thread
* Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
2017-05-06 4:29 ` Tino Calancha
2017-05-06 9:02 ` Jean-Christophe Helary
@ 2017-05-06 9:12 ` Andreas Schwab
2017-05-06 10:31 ` Tino Calancha
1 sibling, 1 reply; 73+ messages in thread
From: Andreas Schwab @ 2017-05-06 9:12 UTC (permalink / raw)
To: Tino Calancha; +Cc: Mark Oteiza, Jean-Christophe Helary, emacs-devel
On Mai 06 2017, Tino Calancha <tino.calancha@gmail.com> wrote:
> +(defsubst string-trim-left (string &optional regexp)
> + "Trim STRING of leading whitespace matching REGEXP.
> +
> +REGEXP defaults to \"[ \t\n\r]+\"."
You need to quote the backslashes in the string.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 73+ messages in thread
end of thread, other threads:[~2017-05-19 11:30 UTC | newest]
Thread overview: 73+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-02 9:34 Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Jean-Christophe Helary
2017-05-02 15:41 ` Clément Pit-Claudel
2017-05-02 22:35 ` Jean-Christophe Helary
2017-05-02 17:16 ` Eli Zaretskii
2017-05-02 22:48 ` Jean-Christophe Helary
2017-05-02 23:11 ` Mark Oteiza
2017-05-03 1:13 ` Jean-Christophe Helary
2017-05-06 2:41 ` Jean-Christophe Helary
2017-05-06 4:29 ` Tino Calancha
2017-05-06 9:02 ` Jean-Christophe Helary
2017-05-06 9:22 ` Eli Zaretskii
2017-05-06 10:33 ` Jean-Christophe Helary
2017-05-06 10:43 ` Eli Zaretskii
2017-05-06 11:02 ` Jean-Christophe Helary
2017-05-06 13:05 ` Jean-Christophe Helary
2017-05-06 13:51 ` Tino Calancha
2017-05-06 14:24 ` Eli Zaretskii
2017-05-07 2:25 ` Tino Calancha
2017-05-07 2:43 ` Eli Zaretskii
2017-05-07 10:40 ` Tino Calancha
2017-05-06 17:51 ` Johan Bockgård
2017-05-06 19:02 ` Eli Zaretskii
2017-05-06 19:55 ` Johan Bockgård
2017-05-06 20:03 ` Eli Zaretskii
2017-05-07 16:23 ` Johan Bockgård
2017-05-07 16:53 ` Eli Zaretskii
2017-05-10 9:21 ` Yuri Khan
2017-05-10 11:15 ` Jean-Christophe Helary
2017-05-10 11:56 ` Stefan Monnier
2017-05-10 12:21 ` Jean-Christophe Helary
2017-05-08 2:40 ` Jean-Christophe Helary
2017-05-08 14:28 ` Eli Zaretskii
2017-05-08 21:33 ` Jean-Christophe Helary
2017-05-08 22:45 ` Johan Bockgård
2017-05-08 23:15 ` Jean-Christophe Helary
2017-05-09 12:05 ` Michael Heerdegen
2017-05-09 13:09 ` Jean-Christophe Helary
2017-05-09 14:05 ` Michael Heerdegen
2017-05-10 9:30 ` Michael Heerdegen
2017-05-10 11:11 ` Jean-Christophe Helary
2017-05-09 15:23 ` Eli Zaretskii
2017-05-09 15:33 ` Jean-Christophe Helary
2017-05-09 16:21 ` Eli Zaretskii
2017-05-09 23:03 ` Jean-Christophe Helary
2017-05-10 0:45 ` Stefan Monnier
2017-05-10 2:44 ` Eli Zaretskii
2017-05-10 3:09 ` Stefan Monnier
2017-05-10 3:49 ` Jean-Christophe Helary
2017-05-10 11:55 ` Stefan Monnier
2017-05-09 16:37 ` Andreas Schwab
2017-05-10 2:29 ` Eli Zaretskii
2017-05-10 7:45 ` Andreas Schwab
2017-05-10 11:07 ` Jean-Christophe Helary
2017-05-07 4:39 ` Jean-Christophe Helary
2017-05-07 14:49 ` Eli Zaretskii
2017-05-07 13:48 ` Stefan Monnier
2017-05-10 14:26 ` Jean-Christophe Helary
2017-05-13 13:36 ` bug#26908: Fwd: " Jean-Christophe Helary
2017-05-16 22:21 ` Jean-Christophe Helary
2017-05-17 2:26 ` Eli Zaretskii
2017-05-17 2:26 ` Eli Zaretskii
2017-05-17 3:41 ` Jean-Christophe Helary
2017-05-17 3:41 ` Jean-Christophe Helary
2017-05-16 22:21 ` Jean-Christophe Helary
2017-05-19 11:30 ` Eli Zaretskii
2017-05-06 11:06 ` Jean-Christophe Helary
2017-05-06 16:30 ` Drew Adams
2017-05-06 17:44 ` Stefan Monnier
2017-05-06 18:07 ` subr-x.el code and defsubst [was: Trimming strings, /.../subr-x.el modification] Drew Adams
2017-05-14 22:45 ` Tianxiang Xiong
2017-05-15 1:11 ` Drew Adams
2017-05-06 9:12 ` Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Andreas Schwab
2017-05-06 10:31 ` Tino Calancha
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.