From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Mendler 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:12:23 +0100 Message-ID: <87pllyuuco.fsf@daniel-mendler.de> References: <87msh21z0i.fsf@daniel-mendler.de> <865xnq4720.fsf@gnu.org> Reply-To: Daniel Mendler Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31980"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74781@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 11 16:15:15 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 1tLOQk-00089K-9I for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 11 Dec 2024 16:15:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLOQb-0007nI-KD; Wed, 11 Dec 2024 10: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 1tLOQY-0007lW-L5 for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 10: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 1tLOQY-0007GA-Bz for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 10: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=Rm7bLEX081TD9JNoEibke5Bz/i90ZIjbSQxbgMc+W4U=; b=Z6SZKrJeVF59unz+sLEgLIIOmtT3HCORgwte0OMfuLjk2vFsPKtM9A+W2quj4P//qD+NFxTujv7jJAXxX6OAxstdv6LJZ12eeRVmoaORfwQAmeuUSRJduoLNkD/+FZ+wLCMuTdHRKTnV5Yd/2Xfib7Pc8SFdyAp3wB3PKkQPzYodKoZ5VnyrBzCSDIuoGXoSw/g23wDaeDDLAX/oBUcua8ZfpJUIKfFAsz25ycbyH8a5uF5GKBHjeMjaeyVn/9F4up0Rswlo4twYKmILABqH2osRfNG6/6kj8U7BxBRGA/oTZtlG7Uu2XKCiCZiwm6gUTGRIuckNNfLlntMRWsHPhw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLOQY-0006Ju-5j for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 10:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Dec 2024 15: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 Original-Received: via spool by 74781-submit@debbugs.gnu.org id=B74781.173393008524238 (code B ref 74781); Wed, 11 Dec 2024 15:15:02 +0000 Original-Received: (at 74781) by debbugs.gnu.org; 11 Dec 2024 15:14:45 +0000 Original-Received: from localhost ([127.0.0.1]:35694 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLOQG-0006Ir-Ig for submit@debbugs.gnu.org; Wed, 11 Dec 2024 10:14:45 -0500 Original-Received: from server.qxqx.de ([49.12.34.165]:50615 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLOQD-0006IW-Rd for 74781@debbugs.gnu.org; Wed, 11 Dec 2024 10:14:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=daniel-mendler.de; s=key; h=Content-Type:MIME-Version:Message-ID:Date: References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Rm7bLEX081TD9JNoEibke5Bz/i90ZIjbSQxbgMc+W4U=; b=q7wySJrlDF8o6XGgM7UuW+zYmD +hv80UBh4TIqyPtdRkm7dlKHgdTVBNuW1XHIyhFcnCNEgovZcdkEQsnVEKOnbXFgh4WzVoLIa4Os+ lDtXwygFS276+iLLrZat0mTC+C+i61JnRQw5oI08WkOt3ttsf5s9/b7P4FGpNoiVrZBc=; In-Reply-To: <865xnq4720.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 11 Dec 2024 16:40:07 +0200") 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:296834 Archived-At: --=-=-= Content-Type: text/plain Hello Eli, thanks. I added the version tags, the NEWS entry, improved the docstrings and use `xdg-runtime-dir' now. See the updated patch attached to this mail. >> + (sock (and dir (expand-file-name >> + (format "qutebrowser/ipc-%s" (md5 (user-login-name))) >> + dir)))) > > I think Qutebrowser is available on Windows, where we don't (yet) > support local sockets. So I think there should be some kind of test > for running on Windows, and falling back to alternatives. On Windows, the socket won't be there, and the new Qutebrowser window will be opened by the newly executed Qutebrowser process via `call-process'. This will work but is unfortunately slower. Daniel --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-browse-url-qutebrowser.patch >From c5286d132bb1afa6078b45e0f7df9ecdecf104ce 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 sped 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. (browse-url-mozilla-new-window-is-tab) (browse-url-firefox-new-window-is-tab) (browse-url-epiphany-new-window-is-tab): Improve docstrings. * etc/NEWS: Announce the change. --- etc/NEWS | 6 +++ lisp/net/browse-url.el | 93 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 043e55edf3e..add18c68d4e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -296,6 +296,12 @@ modal editing packages. * Changes in Specialized Modes and Packages in Emacs 31.1 +** Browse URL + +*** New function 'browse-url-qutebrowser' for the Qutebrowser. +For better integration with the Qutebrowser, set +'browse-url(-secondary)-browser-function' to 'browse-url-qutebrowser'. + ** CL-Lib +++ *** 'cl-labels' now also accepts (FUNC EXP) bindings, like 'cl-flet'. diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 8ec025d017b..e96a24d3ff1 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -140,6 +140,7 @@ ;;; Code: (require 'url) +(require 'xdg) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variables @@ -342,6 +343,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 @@ -360,33 +371,45 @@ browse-url-gnome-moz-arguments (make-obsolete-variable 'browse-url-gnome-moz-arguments nil "25.1") (defcustom browse-url-mozilla-new-window-is-tab nil - "Whether to open up new windows in a tab or a new window. + "Whether to open up new Mozilla 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-mozilla' is asked to open it in a new window." +`browse-url-mozilla' is asked to open it in a new window via the +NEW-WINDOW argument." :type 'boolean) (make-obsolete-variable 'browse-url-mozilla-new-window-is-tab nil "29.1") (defcustom browse-url-firefox-new-window-is-tab nil - "Whether to open up new windows in a tab or a new window. + "Whether to open up new Firefox 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-firefox' is asked to open it in a new window." +`browse-url-firefox' is asked to open it in a new window via the +NEW-WINDOW argument." :type 'boolean) (defcustom browse-url-conkeror-new-window-is-buffer nil - "Whether to open up new windows in a buffer or a new window. + "Whether to open up new Conkeror windows in a buffer or a new window. If non-nil, then open the URL in a new buffer rather than a new window if -`browse-url-conkeror' is asked to open it in a new window." +`browse-url-conkeror' is asked to open it in a new window via the +NEW-WINDOW argument." :version "25.1" :type 'boolean) (make-obsolete-variable 'browse-url-conkeror-new-window-is-buffer nil "28.1") (defcustom browse-url-epiphany-new-window-is-tab nil - "Whether to open up new windows in a tab or a new window. + "Whether to open up new Epiphany 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-epiphany' is asked to open it in a new window." +`browse-url-epiphany' is asked to open it in a new window via the +NEW-WINDOW argument." :type 'boolean) +(defcustom browse-url-qutebrowser-new-window-is-tab nil + "Whether to open up new Qutebrowser 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 via the +NEW-WINDOW argument." + :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 +1317,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 (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 -- 2.45.2 --=-=-=--