From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Bj=C3=B6rn?= Bidar via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74781: [PATCH] Add `browse-url-qutebrowser' Date: Wed, 11 Dec 2024 16:14:24 +0200 Message-ID: <87r06etigv.fsf@thaodan.de> References: <87msh21z0i.fsf@daniel-mendler.de> <87ed2e8vzv.fsf@gmail.com> <87jzc61tc3.fsf@daniel-mendler.de> <87a5d28rsp.fsf@gmail.com> <87a5d2wl9p.fsf@daniel-mendler.de> Reply-To: =?UTF-8?Q?Bj=C3=B6rn?= Bidar Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22676"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: mail@daniel-mendler.de, rpluim@gmail.com To: 74781@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 11 15:15:26 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tLNUs-0005i7-4Z for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 11 Dec 2024 15:15:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLNUY-0008FX-0d; Wed, 11 Dec 2024 09:15:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLNUU-0008EP-Ua for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 09:15:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLNUU-00070G-Lv for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 09:15:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=C/dj5S3iMl7AIEtne1nOuT3GJn+nllLC2uhvVQxB5Kc=; b=b8M+/I1Xo+VZYetopHY+Zea8xjZ5f3PNEI+krAs09QvQkm95BYAOIrK8b3cGinU3gKKtguqtYUeuPbrPViDHoo6S5WvPdq/SBSMSPt4zFoYRVHr0IonVJV3ZI1655abHcvCox9NV6e2Lrcmmifz9blW50nDvYpCOZ2f6hJB+aFOrsfOahiMrdQsHkc+e3JJ14OkQwwzliZC6TzEyoeWRpdQQQDbdgrg4dptKq9gsz8WVqSJVwhdCz0dZoe1JBhmkv8qvKtT0tBUROFszE0jF0n1pvsI3lhX3Bz0UENbSIvtlZNyAX5FzLUpzIB4pna3FhX7LqfzJRKjh5RRdhhsu4g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLNUU-0002Cx-Ej for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 09:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Bj=C3=B6rn?= Bidar Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Dec 2024 14:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74781 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: Daniel Mendler , Robert Pluim , 74781@debbugs.gnu.org Original-Received: via spool by 74781-submit@debbugs.gnu.org id=B74781.17339264748384 (code B ref 74781); Wed, 11 Dec 2024 14:15:02 +0000 Original-Received: (at 74781) by debbugs.gnu.org; 11 Dec 2024 14:14:34 +0000 Original-Received: from localhost ([127.0.0.1]:33632 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLNU1-0002B9-LB for submit@debbugs.gnu.org; Wed, 11 Dec 2024 09:14:34 -0500 Original-Received: from thaodan.de ([185.216.177.71]:51496) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLNTu-0002AZ-Ou for 74781@debbugs.gnu.org; Wed, 11 Dec 2024 09:14:28 -0500 Original-Received: from NordStern (unknown [185.252.118.71]) by thaodan.de (Postfix) with ESMTPSA id 562DBD00055; Wed, 11 Dec 2024 16:14:25 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thaodan.de; s=mail; t=1733926465; bh=vuf/i3zAyw4nh1Kq5VploU6a51AhBQWAWVTsYB4m9W0=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=AYeBAjJFHl+o8vFPJWBTbPGJFmHdsWYxuWf6q1WUmrEsNfGkw6CV7UqiTnq4KHRHk Hvehh9FFs8ReBR3vERPLVA66Yi1K5NchWOFWhyGkgu8yOPqZxggl854ocu746sftz+ Dh9gI+45/SXAKt/o0f9JEhK3xPExGFOtfii22SmHmM7xhKl5WXhZ+SW/ajlpWqRTfc veV3LugdE79C5EOtp1yLMc9Aur6yvumhEnWYh90YKRo0sAitf9tIpbNyx/DTSh/anb BMvV06fTg3dPIuH6IU7zeJKe8YHJrzZ0UDhdClyp1PhT6Mm5qQKO0fwj/EWNyb5hi/ FDn9hVRBo/+25WDjqYA7zXrtHLvHvwhaeQHIUQdELaZJiBWBWgR3ytU2FtozUU18V8 LBtMqgx04+B3CCYIyIzKX4Xtx0xmlW60fRMZxRcYt/VulOPwmr3X5s24Ow9WDgPnYA 67EBqz5c4Y2us2iQdijmgi17E8bvZNh48ldrWNojTzkfZo3C+mDlBQQu7nyIJrcSt+ Y2KvZvw9OJQ18tAJV4H9VbG6keoWv6eT5KD9L5CME9xi4UCNnU26HlRdqTytFyXqC0 Jwek5CHSyqrrtS2DoksnsVKgfhAHS7AinZ+D3V3JWplLUOtCNqoJi4n+p56RNEIfHR o2pybPhy142PFsWtIcCh4rpU= In-Reply-To: <87a5d2wl9p.fsf@daniel-mendler.de> (Daniel Mendler via's message of "Wed, 11 Dec 2024 11:45:38 +0100") Autocrypt: addr=bjorn.bidar@thaodan.de; prefer-encrypt=nopreference; keydata= mDMEZNfpPhYJKwYBBAHaRw8BAQdACBEmr+0xwIIHZfIDlZmm7sa+lHHSb0g9FZrN6qE6ru60JUJq w7ZybiBCaWRhciA8Ympvcm4uYmlkYXJAdGhhb2Rhbi5kZT6IlgQTFgoAPgIbAwULCQgHAgIiAgYV CgkICwIEFgIDAQIeBwIXgBYhBFHxdut1RzAepymoq1wbdKFlHF9oBQJk1/YmAhkBAAoJEFwbdKFl HF9oB9cBAJoIIGQKXm4cpap+Flxc/EGnYl0123lcEyzuduqvlDT0AQC3OlFKm/OiqJ8IMTrzJRZ8 phFssTkSrrFXnM2jm5PYDoiTBBMWCgA7FiEEUfF263VHMB6nKairXBt0oWUcX2gFAmTX6T4CGwMF CwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQXBt0oWUcX2hbCQEAtru7kvM8hi8zo6z9ux2h K+B5xViKuo7Z8K3IXuK5ugwA+wUfKzomzdBPhfxDsqLcEziGRxoyx0Q3ld9aermBUccHtBxCasO2 cm4gQmlkYXIgPG1lQHRoYW9kYW4uZGU+iJMEExYKADsCGwMFCwkIBwICIgIGFQoJCAsCBBYCAwEC HgcCF4AWIQRR8XbrdUcwHqcpqKtcG3ShZRxfaAUCZNf2FQAKCRBcG3ShZRxfaCzSAP4hZ7cSp0YN XYpcjHdsySh2MuBhhoPeLGXs+2kSiqBiOwD/TP8AgPEg/R+SI9GI9on7fBJJ0mp2IT8kZ2rhDOjg gA6IkwQTFgoAOxYhBFHxdut1RzAepymoq1wbdKFlH X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296827 Archived-At: Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > Robert Pluim writes: > >>>>>>> On Wed, 11 Dec 2024 10:07:08 +0100, Daniel Mendler said: >> The emacs help system applies heuristics which are not always >> accurate, and don=CA=BCt 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 thi= s trivial >> Daniel> function, which is just a wrapper around `getenv'. Do you su= ggest to use >> Daniel> `declare-function' and require xdg inside `browse-url-qutebr= owser-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 > 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"))) >=20=20 > +(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) >=20=20 > +(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 brows= ers. > 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)))))) >=20=20 > +(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-n= ame))) > + 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) >=20=20 > ;;;###autoload