[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification

From: Jean-Christophe Helary
Subject: Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification
Date: Sat, 6 May 2017 18:02:37 +0900

> On May 6, 2017, at 13:29, Tino Calancha <address@hidden> 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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]