emacs-devel
[Top][All Lists]
Advanced

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

Re: master 4f1a5e4: Add `file-name-set-extension'


From: Michael Albinus
Subject: Re: master 4f1a5e4: Add `file-name-set-extension'
Date: Sat, 19 Jun 2021 14:09:14 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Lars Ingebrigtsen <larsi@gnus.org> writes:

Hi Lars,

>> +(defun file-name-with-extension (filename extension)
>> +  "Set the EXTENSION of a FILENAME.
>> +Consolidates leading/trailing dots so that either `foo' or `.foo'
>> +can be passed as an EXTENSION.
>> +
>> +See also `file-name-sans-extension'."
>> +  (let* ((patt "[ .]+")
>> +         (file (string-trim-right filename patt))
>> +         (extn (string-trim-left extension patt)))
>> +    (cond ((string-empty-p file) (error "Malformed filename: %s" filename))
>> +          ((string-empty-p extn) (error "Malformed extension: %s" 
>> extension))
>> + ((directory-name-p file) (error "Filename is a directory: %s"
>> filename))
>> +          (t (concat (file-name-sans-extension file) "." extn)))))
>
> Is this really a well-defined function?  It strips spaces from the
> start of the extension?
>
> (file-name-with-extension "foo.bar" "  zot ")
> => "foo.zot "
>
> That seems pretty peculiar and is not documented.  And also:
>
> (file-name-with-extension "foo.bar.." "  zot ")
> => "foo.zot "

This was discussed on emacs-devel, see thread starting with
<https://lists.gnu.org/archive/html/emacs-devel/2021-05/msg01162.html>.

Anyway, I've made an error in commit, failing to use Colin as author. So
I have reverted the patch; when this discussion here has finished I'm
ready to reapply this (or a modified version of) this patch.

Best regards, Michael.



reply via email to

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