all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 74781@debbugs.gnu.org
Cc: mail@daniel-mendler.de, rpluim@gmail.com
Subject: bug#74781: [PATCH] Add `browse-url-qutebrowser'
Date: Wed, 11 Dec 2024 16:14:24 +0200	[thread overview]
Message-ID: <87r06etigv.fsf@thaodan.de> (raw)
In-Reply-To: <87a5d2wl9p.fsf@daniel-mendler.de> (Daniel Mendler via's message of "Wed, 11 Dec 2024 11:45:38 +0100")

Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> Robert Pluim <rpluim@gmail.com> writes:
>
>>>>>>> On Wed, 11 Dec 2024 10:07:08 +0100, Daniel Mendler <mail@daniel-mendler.de> said:
>> The emacs help system applies heuristics which are not always
>> accurate, and donʼt always return an answer, hence the version tags.
>
> Thanks, I added the version tags. See the updated patch.
>
>>     >> We have `xdg-runtime-dir' in xdg.el
>>
>>     Daniel> The goal was to avoid loading `xdg.el' unnecessarily for this trivial
>>     Daniel> function, which is just a wrapper around `getenv'. Do you suggest to use
>>     Daniel> `declare-function' and require xdg inside `browse-url-qutebrowser-send'?
>>
>> That would work.
>
> I would be pragmatic and keep the (getenv "XDG_RUNTIME_DIR"), instead
> of replacing it by this:
>
> (declare-function xdg-runtime-dir "xdg")
> (require 'xdg)

These are only required because you load a new dependency.
Further these functions can take care of later eventualities if needed,
e.g. such as handling when a xdg variable isn't set.
Also using these functions makes the code easier to read as you can
follow the code down further to the documentation.

> (xdg-runtime-dir)
>
> Daniel
>
> From 753ee0b033a34a556cdef8c7d2009b423e115fb0 Mon Sep 17 00:00:00 2001
> From: Daniel Mendler <mail@daniel-mendler.de>
> Date: Wed, 11 Dec 2024 07:36:16 +0100
> Subject: [PATCH] Add `browse-url-qutebrowser'
>
> The browser launcher supports the NEW-WINDOW argument and
> `browse-url-qutebrowser-new-window-is-tab' to open tabs.
> Furthermore opening new URLs is speed up via Unix socket IPC if
> available.
>
> * lisp/net/browse-url.el (browse-url-qutebrowser-send): Function
> to send command to Qutebrowser via IPC.
> (browse-url-qutebrowser): New browser launcher.  Use
> `browse-url-qutebrowser-send'.
> (browse-url-qutebrowser-program, browse-url-qutebrowser-arguments,
> browse-url-qutebrowser-new-window-is-tab): New customizables.
> ---
>  lisp/net/browse-url.el | 71 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 71 insertions(+)
>
> diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
> index 8ec025d017b..0533810dae2 100644
> --- a/lisp/net/browse-url.el
> +++ b/lisp/net/browse-url.el
> @@ -342,6 +342,16 @@ browse-url-epiphany-startup-arguments
>  `browse-url' is loaded."
>    :type '(repeat (string :tag "Argument")))
>  
> +(defcustom browse-url-qutebrowser-program "qutebrowser"
> +  "The name by which to invoke Qutebrowser."
> +  :type 'string
> +  :version "31.1")
> +
> +(defcustom browse-url-qutebrowser-arguments nil
> +  "A list of strings to pass to Qutebrowser when it starts up."
> +  :type '(repeat (string :tag "Argument"))
> +  :version "31.1")
> +
>  (defcustom browse-url-webpositive-program "WebPositive"
>    "The name by which to invoke WebPositive."
>    :type 'string
> @@ -387,6 +397,13 @@ browse-url-epiphany-new-window-is-tab
>  `browse-url-epiphany' is asked to open it in a new window."
>    :type 'boolean)
>  
> +(defcustom browse-url-qutebrowser-new-window-is-tab nil
> +  "Whether to open up new windows in a tab or a new window.
> +If non-nil, then open the URL in a new tab rather than a new window if
> +`browse-url-qutebrowser' is asked to open it in a new window."
> +  :type 'boolean
> +  :version "31.1")
> +
>  (defcustom browse-url-new-window-flag nil
>    "Non-nil means always open a new browser window with appropriate browsers.
>  Passing an interactive argument to \\[browse-url], or specific browser
> @@ -1294,6 +1311,60 @@ browse-url-epiphany-sentinel
>  	       browse-url-epiphany-program
>  	       (append browse-url-epiphany-startup-arguments (list url))))))
>  
> +(defun browse-url-qutebrowser-send (cmd)
> +  "Send CMD to Qutebrowser via IPC."
> +  (let* ((dir (getenv "XDG_RUNTIME_DIR"))
> +         (sock (and dir (expand-file-name
> +                         (format "qutebrowser/ipc-%s" (md5 (user-login-name)))
> +                         dir))))
> +    (unless (file-exists-p sock)
> +      (error "No Qutebrowser IPC socket found"))
> +    (let ((proc
> +           (make-network-process
> +            :name "qutebrowser"
> +            :family 'local
> +            :service sock
> +            :coding 'utf-8)))
> +      (unwind-protect
> +          (process-send-string
> +           proc
> +           (concat
> +            (json-serialize `( :args [,cmd]
> +                               :target_arg :null
> +                               :protocol_version 1))
> +            "\n"))
> +        (delete-process proc)))))
> +
> +(defun browse-url-qutebrowser (url &optional new-window)
> +  "Ask the Qutebrowser WWW browser to load URL.
> +Default to the URL around or before point.
> +
> +When called interactively, if variable `browse-url-new-window-flag' is
> +non-nil, load the document in a new Qutebrowser window, otherwise use a
> +random existing one.  A non-nil interactive prefix argument reverses
> +the effect of `browse-url-new-window-flag'.
> +
> +If `browse-url-qutebrowser-new-window-is-tab' is non-nil, then whenever a
> +document would otherwise be loaded in a new window, it is loaded in a
> +new tab in an existing window instead.
> +
> +When called non-interactively, optional second argument NEW-WINDOW is
> +used instead of `browse-url-new-window-flag'."
> +  (interactive (browse-url-interactive-arg "URL: "))
> +  (let ((cmd (concat ":open "
> +                     (and (browse-url-maybe-new-window new-window)
> +                          (if browse-url-qutebrowser-new-window-is-tab
> +                              "-t " "-w "))
> +                     (browse-url-encode-url url))))
> +    (condition-case nil
> +        (browse-url-qutebrowser-send cmd)
> +      (error
> +       (apply #'start-process (concat "qutebrowser " url) nil
> +              browse-url-qutebrowser-program
> +              (append browse-url-qutebrowser-arguments (list cmd)))))))
> +
> +(function-put 'browse-url-qutebrowser 'browse-url-browser-kind 'external)
> +
>  (defvar url-handler-regexp)
>  
>  ;;;###autoload





  reply	other threads:[~2024-12-11 14:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-11  7:04 bug#74781: [PATCH] Add `browse-url-qutebrowser' Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11  8:27 ` Robert Pluim
2024-12-11  9:07   ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11  9:58     ` Robert Pluim
2024-12-11 10:45       ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11 14:14         ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-12-11 14:38           ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11 16:16             ` Eli Zaretskii
2024-12-11 15:32         ` Eli Zaretskii
2024-12-11 15:36           ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11 14:40 ` Eli Zaretskii
2024-12-11 15:12   ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11 15:44     ` Robert Pluim
2024-12-11 15:54       ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11 16:54     ` Eli Zaretskii
2024-12-14 12:50 ` bug#74781: Status: " Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r06etigv.fsf@thaodan.de \
    --to=bug-gnu-emacs@gnu.org \
    --cc=74781@debbugs.gnu.org \
    --cc=bjorn.bidar@thaodan.de \
    --cc=mail@daniel-mendler.de \
    --cc=rpluim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.