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

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

bug#69098: [PATCH] Add new command 'browse-url-here'


From: Philip Kaludercic
Subject: bug#69098: [PATCH] Add new command 'browse-url-here'
Date: Sun, 18 Feb 2024 12:36:00 +0000

Felician Nemeth <felician.nemeth@gmail.com> writes:

>>> Philip Kaludercic <philipk@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@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





reply via email to

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