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 08:04:29 +0100 Message-ID: <87msh21z0i.fsf@daniel-mendler.de> 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="35172"; mail-complaints-to="usenet@ciao.gmane.io" 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 08:05:27 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 1tLGmk-00091v-Nz for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 11 Dec 2024 08:05:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLGmQ-00022R-08; Wed, 11 Dec 2024 02:05: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 1tLGmN-000212-0e for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 02:05:04 -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 1tLGmM-0004B3-NM for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 02:05: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:From:To:Subject; bh=b1jV1Ge5YnZQDx5vTZR98aLn2ryZHXev5HSWMHLVlYk=; b=rFMVjlVXVEzcsptHsC3iEVoauXH/jiZJJmOKt87xX2P1tNzfJSki37O4sffLuAvm5mvMtQOczoxW9UgW/46nDGppeiwWTrcYcK6GkptjgUnZV3oMUab+VAR11MP0TDxeQlroEYUPZLRvq3RrgtfVdwC+9dLTPTaDHvFtLntrVL6BE7YvfUN67gdPGRIYPODNHU12x70iwXJYk+nH8s0NXepPoBvSGsJS/b4nZsn2/r4j+T/4S7S1iD4/Du6CiMEhc/1jIXnRZZpWsNa3dICPHWM2TkWXl/EK/PgBhZ16LvAF+lAvHG7kxlZl9Jz696mArq53xRmmSQD0+zbkQ9o7Ew==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLGmL-0000ax-WD for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 02:05: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 07:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74781 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17339006892257 (code B ref -1); Wed, 11 Dec 2024 07:05:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Dec 2024 07:04:49 +0000 Original-Received: from localhost ([127.0.0.1]:60913 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLGm6-0000aF-5i for submit@debbugs.gnu.org; Wed, 11 Dec 2024 02:04:49 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:58386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLGm3-0000a4-2U for submit@debbugs.gnu.org; Wed, 11 Dec 2024 02:04:44 -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 1tLGm0-00020G-NY for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 02:04:41 -0500 Original-Received: from server.qxqx.de ([2a01:4f8:c012:9177::1] helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLGlv-00048o-TY for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 02:04:37 -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: Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=b1jV1Ge5YnZQDx5vTZR98aLn2ryZHXev5HSWMHLVlYk=; b=tE3YVdpcXG5eN5wc+XlM/J20UT XkqyjXQhn4pLVV4az7giKtReCRSwjhVVBK190a8SeXyj1lWhJjbJ44R3tizD/dP71mid2nPc26ki+ 3yvdg4P4dUHOKc4blDogMxp+COlwrBD9rJJv07xL3o1zq82GhrxO0XuPkONtEyMIt2H4=; Received-SPF: pass client-ip=2a01:4f8:c012:9177::1; envelope-from=mail@daniel-mendler.de; helo=mail.qxqx.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:296803 Archived-At: --=-=-= Content-Type: text/plain Tags: patch 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. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-browse-url-qutebrowser.patch >From ea24ef81a4a8551a8212582a65dd4aa685c9c648 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 | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 8ec025d017b..3b6833715f4 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -342,6 +342,14 @@ 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) + +(defcustom browse-url-qutebrowser-arguments nil + "A list of strings to pass to Qutebrowser when it starts up." + :type '(repeat (string :tag "Argument"))) + (defcustom browse-url-webpositive-program "WebPositive" "The name by which to invoke WebPositive." :type 'string @@ -387,6 +395,12 @@ 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) + (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 +1308,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 -- 2.45.2 --=-=-=--