Adding an `or condition without changing code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding an `or condition without changing code

Tim Johnson-2
Using emacs 26.1 on ubuntu

I'm implementing dired-single-buffer

The function of the same name has the following `let initialization

(let ((name (or default-dirname (dired-get-filename nil t)))) ;;
default-dirname is an optional argument to dired-single-buffer

The two conditions to `or are not sufficient if I call
dired-single-buffer from an unvisited buffer. The result is that `name
is nil and a string-p, nil error is thrown.

A simple hack is to add a third condition to `or

(let ((name (or default-dirname (dired-get-filename nil t) "~/")))  ;;
fall-back to /home/user

But, it IS a hack and means I have altered some good citizen's code.

How can that be resolved? Might the solution be a customization of dired?

 From the documentation of dired-get-filename I don't grok a solution....

thanks

--

Tim
tj49.com


Reply | Threaded
Open this post in threaded view
|

Re: Adding an `or condition without changing code

Stefan Monnier
> I'm implementing dired-single-buffer
>
> The function of the same name has the following `let initialization
>
> (let ((name (or default-dirname (dired-get-filename nil t)))) ;;
>  default-dirname is an optional argument to dired-single-buffer
>
> The two conditions to `or are not sufficient if I call dired-single-buffer
> from an unvisited buffer. The result is that `name is nil and a string-p,
> nil error is thrown.
>
> A simple hack is to add a third condition to `or
>
> (let ((name (or default-dirname (dired-get-filename nil t) "~/")))  ;;
>  fall-back to /home/user

I guess using `default-directory` rather than "~" would be more
generally useful.

> But, it IS a hack and means I have altered some good citizen's code.

Indeed.  Luckily Emacs does make it possible to do that.

> How can that be resolved? Might the solution be a customization of dired?

I think it should be considered as a bug in `dired-single-buffer`.

> From the documentation of dired-get-filename I don't grok a solution....

You can only meaningfully use `dired-get-filename` inside
a dired buffer, so the problem is in that function.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Adding an `or condition without changing code

Tim Johnson-2
On 1/13/20 5:37 AM, Stefan Monnier wrote:

>> I'm implementing dired-single-buffer
>>
>> The function of the same name has the following `let initialization
>>
>> (let ((name (or default-dirname (dired-get-filename nil t)))) ;;
>>   default-dirname is an optional argument to dired-single-buffer
>>
>> The two conditions to `or are not sufficient if I call dired-single-buffer
>> from an unvisited buffer. The result is that `name is nil and a string-p,
>> nil error is thrown.
>>
>> A simple hack is to add a third condition to `or
>>
>> (let ((name (or default-dirname (dired-get-filename nil t) "~/")))  ;;
>>   fall-back to /home/user
> I guess using `default-directory` rather than "~" would be more
> generally useful.
>
>> But, it IS a hack and means I have altered some good citizen's code.
> Indeed.  Luckily Emacs does make it possible to do that.
>
>> How can that be resolved? Might the solution be a customization of dired?
> I think it should be considered as a bug in `dired-single-buffer`.
>
>>  From the documentation of dired-get-filename I don't grok a solution....
> You can only meaningfully use `dired-get-filename` inside
> a dired buffer, so the problem is in that function.

Thanks for those insights. I'm going with Drew Adams' dired+ instead.

dired+ easily takes care of multiple buffer issues.

cheers

--
Tim
tj49.com