all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* split-string description in the ELR
@ 2017-05-01 15:38 Jean-Christophe Helary
  2017-05-01 16:20 ` Drew Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Christophe Helary @ 2017-05-01 15:38 UTC (permalink / raw)
  To: emacs-devel

Without Eli's comment I would never have thought of using split-string to trim a string. But even reading the reference did not make it's use super clear. In the description "trim" is just an option to trim the substrings resulting from splitting the string and it is not obvious that it can be used on it's own to trim a given string.

Could a small modification of the reference be in order to emphasize that use (with an example eventually) ?

Jean-Christophe 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: split-string description in the ELR
  2017-05-01 15:38 split-string description in the ELR Jean-Christophe Helary
@ 2017-05-01 16:20 ` Drew Adams
  2017-05-01 22:46   ` Jean-Christophe Helary
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2017-05-01 16:20 UTC (permalink / raw)
  To: Jean-Christophe Helary, emacs-devel

> Without Eli's comment I would never have thought of using split-string to
> trim a string. But even reading the reference did not make it's use super
> clear. In the description "trim" is just an option to trim the substrings
> resulting from splitting the string and it is not obvious that it can be
> used on it's own to trim a given string.
> 
> Could a small modification of the reference be in order to emphasize that
> use (with an example eventually) ?

Good idea.  Additionally, or instead, we could create a function
that is an alias and that has "trim" in the name.

----

FWIW, I define function `split-string-by-regexp' to do just
what vanilla `split-string' does, and I redefine `split-string'
to handle additional ways to specify the splitting.  The
redefined function does `split-string-by-regexp' by default.

Here are the signature and doc string of the redefined `split-string':

(split-string STRING &optional HOW OMIT-NULLS TRIM FLIP TEST)

 Split STRING into substrings.
 Arg HOW determines how splitting is done.  it is one of the following:
 * a regexp (a string) - see function `split-string-by-regexp'
 * a list whose first element is a text property (a symbol) and whose
   second element is the property value - see function
   `split-string-by-property'
 * a predicate that accepts a character as its first argument - see
   function `split-string-by-predicate'

 If optional arg OMIT-NULLS is t, then empty substrings are omitted
 from the returned list.  If nil, zero-length substrings are retained,
 which correctly parses CSV format, for example.

 If TRIM is non-nil, it should be a regular expression to match text to
 trim from the beginning and end of each substring.  If trimming makes
 a substring empty, it is treated according to OMIT-NULLS.

 Optional arg TEST is used only if HOW is a (PROPERTY VALUE) list, in
 which case it is passed to function `split-string-by-property' (which
 see).  Otherwise, it is ignored.

 Modifies the match data; use `save-match-data' if necessary.

Each of the HOW possibilities corresponds also to a separate
function:
 split-string-by-regexp
 split-string-by-property
 split-string-by-predicate

https://www.emacswiki.org/emacs/download/subr%2b.el



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: split-string description in the ELR
  2017-05-01 16:20 ` Drew Adams
@ 2017-05-01 22:46   ` Jean-Christophe Helary
  0 siblings, 0 replies; 3+ messages in thread
From: Jean-Christophe Helary @ 2017-05-01 22:46 UTC (permalink / raw)
  To: emacs-devel


> On May 2, 2017, at 1:20, Drew Adams <drew.adams@oracle.com> wrote:
> 
>> Without Eli's comment I would never have thought of using split-string to
>> trim a string. But even reading the reference did not make it's use super
>> clear. In the description "trim" is just an option to trim the substrings
>> resulting from splitting the string and it is not obvious that it can be
>> used on it's own to trim a given string.
>> 
>> Could a small modification of the reference be in order to emphasize that
>> use (with an example eventually) ?
> 
> Good idea.

Well, I'll try to propose something that puts a bit more emphasis on the "trim" part.

> Additionally, or instead, we could create a function
> that is an alias and that has "trim" in the name.

And I definitely leave that to you :)

Jean-Christophe 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-01 22:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-01 15:38 split-string description in the ELR Jean-Christophe Helary
2017-05-01 16:20 ` Drew Adams
2017-05-01 22:46   ` Jean-Christophe Helary

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.