bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#28258: 26.0.50; [PATCH] Let file-name-base succeed when buffer-file-


From: Philipp Stephani
Subject: bug#28258: 26.0.50; [PATCH] Let file-name-base succeed when buffer-file-name is nil
Date: Mon, 18 Sep 2017 17:12:36 +0000



Glenn Morris <address@hidden> schrieb am Di., 29. Aug. 2017 um 19:03 Uhr:
Mohammed Sadiq wrote:

>> IIUC: file-name-base currently errors when called with no applicable
>> file name, and you want it to instead return nil? This seems rather
>> unusual for an Emacs file-related function. I would have thought this
>> unlikely to be applied, but maybe you could explain why you want it?
>
> The signature of `file-name-base' is (file-name-base &optional FILENAME).
> That is, the FILENAME argument is optional. So I believe it shouldn't
> be an error to not give the optional argument. And so calling the function
> in a buffer with no file associated shouldn't be an error. I'm not sure
> if my assertion is right.

Thanks for explaining. I don't think I agree, but then the fact that the
argument is optional and defaults to buffer-file-name also seems
atypical to me (eg I don't think any other file-name- functions behaves
like that). Let's wait and see if anyone else feels strongly one way or
the other.




Changing from raising an error to returning nil is a breaking change: callers currently can rely on the return value being never nil, and can rely on errors being raised. Changing this would break these assumptions.
Even ignoring that, I think raising an error is the right thing to do: unless given a filename, the function can't fulfil its promise, and raising an error is the most appropriate reaction to this. (There are already way too many Elisp functions that silently ignore errorneous situations.)
I do agree that the calling convention of `file-name-base' is odd. How about making the argument mandatory (initially only by changing the advertised calling convention and the docstring)?

reply via email to

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