GNU bug report logs - #69098
[PATCH] Add new command 'browse-url-here'

Previous Next

Package: emacs;

Reported by: Philip Kaludercic <philipk <at> posteo.net>

Date: Tue, 13 Feb 2024 10:11:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 69098 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#69098; Package emacs. (Tue, 13 Feb 2024 10:11:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philip Kaludercic <philipk <at> posteo.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 13 Feb 2024 10:11:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Add new command 'browse-url-here'
Date: Tue, 13 Feb 2024 10:09:50 +0000
[Message part 1 (text/plain, inline)]
The idea is to have a command that can be used to open a file or
directory using something outside Emacs.

I find this useful, but it might be that there are edge-cases that I am
not considering that don't pop up on my system.

[0001-Add-new-command-'browse-url-here'.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69098; Package emacs. (Tue, 13 Feb 2024 12:00:02 GMT) Full text and rfc822 format available.

Message #8 received at 69098 <at> debbugs.gnu.org (full text, mbox):

From: Felician Nemeth <felician.nemeth <at> gmail.com>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 69098 <at> debbugs.gnu.org
Subject: Re: bug#69098: [PATCH] Add new command 'browse-url-here'
Date: Tue, 13 Feb 2024 12:57:57 +0100
Philip Kaludercic <philipk <at> posteo.net> writes:

> The idea is to have a command that can be used to open a file or
> directory using something outside Emacs.
>
> I find this useful, but it might be that there are edge-cases that I am
> not considering that don't pop up on my system.

Shouldn't it do something when the buffer is modified?

> +(defun browse-url-here (arg)

Since browse-url-of-buffer does something similar, the name could be
more descriptive.   Maybe browse-url-of-buffer-external?  

> +  "Open current file or directory with external tools.
> +With prefix argument ARG, open the current `default-directory' instead
> +of the buffer of the current file."

"the file of the current buffer."

> +  (interactive "P")
> +  (let ((browse-url-default-handlers '()))

This is strange.  There are other ways to use an external browser-kind.
Maybe you could use browse-url-secondary-browser-function, which is
"usually an external browser".

> +    (browse-url-of-file
> +     (expand-file-name
> +      (or (and arg ".")
> +          (and (derived-mode-p 'dired-mode)
> +               (dired-get-filename))
> +          buffer-file-name ".")))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69098; Package emacs. (Wed, 14 Feb 2024 17:13:02 GMT) Full text and rfc822 format available.

Message #11 received at 69098 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Felician Nemeth <felician.nemeth <at> gmail.com>
Cc: 69098 <at> debbugs.gnu.org
Subject: Re: bug#69098: [PATCH] Add new command 'browse-url-here'
Date: Wed, 14 Feb 2024 17:11:35 +0000
[Message part 1 (text/plain, inline)]
Felician Nemeth <felician.nemeth <at> gmail.com> writes:

> Philip Kaludercic <philipk <at> posteo.net> writes:
>
>> The idea is to have a command that can be used to open a file or
>> directory using something outside Emacs.
>>
>> I find this useful, but it might be that there are edge-cases that I am
>> not considering that don't pop up on my system.
>
> Shouldn't it do something when the buffer is modified?

A warning is generated by `browse-url-of-file'.

>> +(defun browse-url-here (arg)
>
> Since browse-url-of-buffer does something similar, the name could be
> more descriptive.   Maybe browse-url-of-buffer-external?  

I like that name, used it.

>> +  "Open current file or directory with external tools.
>> +With prefix argument ARG, open the current `default-directory' instead
>> +of the buffer of the current file."
>
> "the file of the current buffer."

Done, thanks.

>> +  (interactive "P")
>> +  (let ((browse-url-default-handlers '()))
>
> This is strange.  There are other ways to use an external browser-kind.
> Maybe you could use browse-url-secondary-browser-function, which is
> "usually an external browser".

The thing is if `browse-url-default-handlers' includes

  (browse-url--non-html-file-url-p . browse-url-emacs)

then this catches all the requests and the file is always opened in
Emacs.  In this patch I try to only filter out these entries that would
open the file in Emacs:

[0001-Add-new-command-browse-url-of-buffer-external.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69098; Package emacs. (Sun, 18 Feb 2024 08:43:02 GMT) Full text and rfc822 format available.

Message #14 received at 69098 <at> debbugs.gnu.org (full text, mbox):

From: Felician Nemeth <felician.nemeth <at> gmail.com>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 69098 <at> debbugs.gnu.org
Subject: Re: bug#69098: [PATCH] Add new command 'browse-url-here'
Date: Sun, 18 Feb 2024 09:41:15 +0100
[Message part 1 (text/plain, inline)]
>> Philip Kaludercic <philipk <at> posteo.net> writes:
>>
>>> The idea is to have a command that can be used to open a file or
>>> directory using something outside Emacs.
>>>
>>> I find this useful, but it might be that there are edge-cases that I am
>>> not considering that don't pop up on my system.

Now I think the attached patch is more inline with the philosophy of
browse-url than the previous patches of this thread.

However, this patch might not be necessary.  You can open a file with
C-x C-j W or in the secondary browser with C-x C-j C-u W.  This seems
cumbersome, but C-x C-j (dired-jump) quickly becomes second nature.  And
to open the directory of file: C-x C-j C-x C-j C-u W, which once again
seems frightening, but can be entered quickly without thinking.

[0001-Allow-browse-url-commands-to-invoke-secondary-browse.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69098; Package emacs. (Sun, 18 Feb 2024 12:37:02 GMT) Full text and rfc822 format available.

Message #17 received at 69098 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Felician Nemeth <felician.nemeth <at> gmail.com>
Cc: 69098 <at> debbugs.gnu.org
Subject: Re: bug#69098: [PATCH] Add new command 'browse-url-here'
Date: Sun, 18 Feb 2024 12:36:00 +0000
Felician Nemeth <felician.nemeth <at> gmail.com> writes:

>>> Philip Kaludercic <philipk <at> posteo.net> writes:
>>>
>>>> The idea is to have a command that can be used to open a file or
>>>> directory using something outside Emacs.
>>>>
>>>> I find this useful, but it might be that there are edge-cases that I am
>>>> not considering that don't pop up on my system.
>
> Now I think the attached patch is more inline with the philosophy of
> browse-url than the previous patches of this thread.
>
> However, this patch might not be necessary.  You can open a file with
> C-x C-j W or in the secondary browser with C-x C-j C-u W.  This seems
> cumbersome, but C-x C-j (dired-jump) quickly becomes second nature.  And
> to open the directory of file: C-x C-j C-x C-j C-u W, which once again
> seems frightening, but can be entered quickly without thinking.
>
> From a5227603c87ae899a6ccf7e581b80a0f6b816946 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= <felician.nemeth <at> gmail.com>
> Date: Sun, 18 Feb 2024 09:22:30 +0100
> Subject: [PATCH] Allow browse-url commands to invoke secondary browser
>
> * lisp/net/browse-url.el (browse-url-of-file)
> (browse-url-of-buffer): Use 'browse-url-secondary-browser-function'
> if the new argument 'secondary' is non-nil or when invoked with a
> prefix arg.
> ---
>  lisp/net/browse-url.el | 25 +++++++++++++++++--------
>  1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
> index 74740af3bd6..4c4c79a80da 100644
> --- a/lisp/net/browse-url.el
> +++ b/lisp/net/browse-url.el
> @@ -728,13 +728,16 @@ browse-url-maybe-new-window
>  ;; Browse current buffer
>  
>  ;;;###autoload
> -(defun browse-url-of-file (&optional file)
> +(defun browse-url-of-file (&optional file secondary)
>    "Use a web browser to display FILE.
>  Display the current buffer's file if FILE is nil or if called
>  interactively.  Turn the filename into a URL with function
>  `browse-url-file-url'.  Pass the URL to a browser using the
> -`browse-url' function then run `browse-url-of-file-hook'."
> -  (interactive)
> +`browse-url' function then run `browse-url-of-file-hook'.
> +
> +With a prefix argument, or when SECONDARY is non-nil, use
> +`browse-url-secondary-browser-function' instead."
> +  (interactive (list nil current-prefix-arg))

This would lack the convince feature of being able to also quickly open
the current directory, which is what I used the prefix argument for.

>    (or file
>        (setq file (buffer-file-name))
>        (error "Current buffer has no file"))
> @@ -748,7 +751,10 @@ browse-url-of-file
>               (not browse-url-temp-file-name))
>      (setq browse-url-temp-file-name (file-local-copy file)
>            file browse-url-temp-file-name))
> -  (browse-url (browse-url-file-url file))
> +  (let ((url (browse-url-file-url file)))
> +    (if secondary
> +      (funcall browse-url-secondary-browser-function url)
> +    (browse-url url)))
>    (run-hooks 'browse-url-of-file-hook))
>  
>  (defun browse-url--file-name-coding-system ()
> @@ -789,14 +795,17 @@ browse-url-file-url
>    file)
>  
>  ;;;###autoload
> -(defun browse-url-of-buffer (&optional buffer)
> +(defun browse-url-of-buffer (&optional buffer secondary)
>    "Use a web browser to display BUFFER.
>  See `browse-url' for details.
>  
>  Display the current buffer if BUFFER is nil.  Display only the
>  currently visible part of BUFFER (from a temporary file) if buffer is
> -narrowed."
> -  (interactive)
> +narrowed.
> +
> +With a prefix argument, or when SECONDARY is non-nil, use
> +`browse-url-secondary-browser-function' instead."
> +  (interactive (list nil current-prefix-arg))
>    (save-excursion
>      (and buffer (set-buffer buffer))
>      (let ((file-name
> @@ -816,7 +825,7 @@ browse-url-of-buffer
>  		  nil ".html"))))
>  	(setq file-name browse-url-temp-file-name)
>  	(write-region (point-min) (point-max) file-name nil 'no-message))
> -      (browse-url-of-file file-name))))
> +      (browse-url-of-file file-name secondary))))
>  
>  (defun browse-url-delete-temp-file (&optional temp-file-name)
>    "Delete `browse-url-temp-file-name' from the file system.

-- 
Philip Kaludercic




This bug report was last modified 76 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.