emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] lisp/files.el: Add `file-name-set-extension`


From: Stefan Monnier
Subject: Re: [PATCH] lisp/files.el: Add `file-name-set-extension`
Date: Tue, 25 May 2021 16:25:38 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> +  (when (and filename extension)
> +    (let* ((patt "[ \t\n\r.]+") ; Inspired by `string-trim'.
> +           (filename (string-trim-right filename patt))
> +           (extension (string-trim-left extension patt)))
> +      (unless (or (string-empty-p filename)
> +                  (string-empty-p extension))
> +        (concat (file-name-sans-extension filename) "." extension)))))

Why do you trim [ \t\n\r.]+ from the end of the filename and the
beginning of the extension?

I can see why you'd want to remove a single "." at the beginning of
`extension`, so as to allow extension to come with or without a leading
".", but the rest seems rather surprising because such characters in my
experience almost never show up in such a circumstance (which means
that if they do, it's either on purpose and we should preserve it, or
it's an error "upstream" and we should try and help expose the error
rather than silently try to cover it).


        Stefan




reply via email to

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