From unknown Mon Jun 23 04:13:41 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#64126 <64126@debbugs.gnu.org> To: bug#64126 <64126@debbugs.gnu.org> Subject: Status: [PATCH] New command 'eww-copy-alternate-url' Reply-To: bug#64126 <64126@debbugs.gnu.org> Date: Mon, 23 Jun 2025 11:13:41 +0000 retitle 64126 [PATCH] New command 'eww-copy-alternate-url' reassign 64126 emacs submitter 64126 Eshel Yaron severity 64126 normal tag 64126 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 07:08:01 2023 Received: (at submit) by debbugs.gnu.org; 17 Jun 2023 11:08:01 +0000 Received: from localhost ([127.0.0.1]:50938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qATmi-00053J-KA for submit@debbugs.gnu.org; Sat, 17 Jun 2023 07:08:01 -0400 Received: from lists.gnu.org ([209.51.188.17]:47428) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qATmg-000539-AY for submit@debbugs.gnu.org; Sat, 17 Jun 2023 07:07:58 -0400 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 1qATmf-0007Te-PM for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:07:58 -0400 Received: from mail.eshelyaron.com ([107.175.124.16] helo=eshelyaron.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qATmd-000331-UB for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:07:57 -0400 From: Eshel Yaron DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1687000074; bh=82ylfLMAs67CI5Ti8t2L2I2PiqP3619DhfP4nBER9Dg=; h=From:To:Subject:Date:From; b=ukKs9OYZb8PGNTdmYl5CV9ekzZvGw3ZolZSM165nyTgY0+CgsK5JxyUB7+R+xuW/E No5wStcOuoKkY7dTrPZw+6APvszipOMphSHBAR4h5+6W8EdoExXIWtYtT6HpR1sMz6 lxqrpdW0psdcB6wERxnPIyEnfk2j8ermIVzBBzBKauCaVzJfOdBUTldN9+oImX0szX U6p/oZr7vUEiVIw0vED4Hwf2hhTMj+mu2jSizb1hhL0CJVTgFpWpUNu99Bb74Kox4b exWQNhLW20g+GGN6P4M7tc8lZVz5Csd62XGC6YeaZO2Qs5jCFMoCjfMpzhhWrgoNCp zvG+wmaXQgokA== To: bug-gnu-emacs@gnu.org Subject: [PATCH] New command 'eww-copy-alternate-url' Date: Sat, 17 Jun 2023 14:07:40 +0300 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=107.175.124.16; envelope-from=me@eshelyaron.com; helo=eshelyaron.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch This patch extends EWW with a command that grabs the URL of an alternate link of the current page, such as an RSS or Atom feed. In GNU Emacs 30.0.50 (build 5, x86_64-apple-darwin22.5.0, NS appkit-2299.60 Version 13.4 (Build 22F66)) of 2023-06-16 built on Dazzs-MBP Repository revision: 8657afac774f36777d0fdd368e0bec64beca22ae Repository branch: master Windowing system distributor 'Apple', version 10.3.2299 System Description: macOS 13.4 Configured using: 'configure 'CFLAGS=-g0 -O3' --with-native-compilation --with-json --with-imagemagick --with-tree-sitter --enable-link-time-optimization' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-New-command-eww-copy-alternate-url.patch >From 998f3048bd0a804b861140991e3c62cf3c42e9ed Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 17 Jun 2023 13:48:51 +0300 Subject: [PATCH] New command 'eww-copy-alternate-url' This adds a new command to EWW that copies an alternate link to the currently visited page into the kill ring. This is useful for subscribing to website feeds, etc.. * lisp/net/eww.el (eww--alternate-urls) (eww-read-alternate-url): New functions. (eww-copy-alternate-url): New command. (eww-mode-map): Bind it to 'A'. * doc/misc/eww.texi (Basics): Document it. * etc/NEWS: Announce it. --- doc/misc/eww.texi | 7 +++++ etc/NEWS | 5 ++++ lisp/net/eww.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index c02e9db11c9..2f2a1d7d405 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi @@ -115,6 +115,13 @@ Basics @kbd{w} calls @code{eww-copy-page-url}, which will copy the current page's URL to the kill ring instead. +@findex eww-copy-alternate-url +@kindex A + The @kbd{A} command (@code{eww-copy-alternate-url}) copies the URL +of an alternate link of the current page (such as an associated RSS +feed) into the kill ring. If the page specifies multiple alternate +links, this command prompt for one of them in the minibuffer. + @findex eww-open-in-new-buffer @kindex M-RET The @kbd{M-@key{RET}} command (@code{eww-open-in-new-buffer}) opens the diff --git a/etc/NEWS b/etc/NEWS index 61e6e161665..7c94c3efa89 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -253,6 +253,11 @@ The interactive minibuffer prompt when invoking 'eww' now provides completions from 'eww-suggest-uris'. 'eww-suggest-uris' now includes bookmark URIs. ++++ +*** New command 'eww-copy-alternate-url'. +It copies an alternate link to the page currently visited in EWW into +the kill ring. + ** go-ts-mode +++ diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 61f0f47373d..3ce9061ea7d 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1086,6 +1086,7 @@ eww-mode-map "&" #'eww-browse-with-external-browser "d" #'eww-download "w" #'eww-copy-page-url + "A" #'eww-copy-alternate-url "C" #'url-cookie-list "v" #'eww-view-source "R" #'eww-readable @@ -2576,4 +2577,78 @@ eww-bookmark-jump (provide 'eww) +;;; Alternate links (RSS and Atom feeds, etc.) + +(defun eww--alternate-urls (dom &optional base) + "Return an alist of alternate links in DOM. + +Each element is a list of the form (URL TYPE TITLE) where URL is +the href attribute of the link expanded relative to BASE, TYPE is +its type attribute, and TITLE is its title attribute. If any of +these attributes is absent, the corresponding element is nil." + (let ((alternates + (seq-filter + (lambda (attrs) (string= (alist-get 'rel attrs) + "alternate")) + (mapcar #'dom-attributes (dom-by-tag dom 'link))))) + (mapcar (lambda (alternate) + (list (url-expand-file-name (alist-get 'href alternate) + base) + (alist-get 'type alternate) + (alist-get 'title alternate))) + alternates))) + +(defun eww-read-alternate-url () + "Get the URL of an alternate link of this page. + +If there is just one alternate link, return it's URL. If there +are multiple alternate links, prompt for one in the minibuffer. +If there are none, return nil." + (when-let ((alternates (eww--alternate-urls + (plist-get eww-data :dom) + (plist-get eww-data :url)))) + (let ((max-length + (apply #'max + (mapcar #'length + (mapcar #'car alternates)))) + (max-title + (apply #'max + (mapcar #'length + (mapcar #'caddr alternates))))) + (if (cdr alternates) + (let ((completion-extra-properties + (list :annotation-function + (lambda (feed) + (let* ((attrs (alist-get feed + alternates + nil + nil + #'string=)) + (type (car attrs)) + (title (cadr attrs))) + (concat (when title + (concat (make-string + (1+ (- max-length + (length feed))) + ?\s) + title)) + (when type + (concat + (make-string + (1+ (- max-title + (length title))) + ?\s) + "[" type "]")))))))) + (completing-read "Alternate URL: " alternates nil t)) + (caar alternates))))) + +(defun eww-copy-alternate-url () + "Copy an alternate URL of the current page into the kill ring." + (interactive nil eww-mode) + (if-let ((url (eww-read-alternate-url))) + (progn + (kill-new url) + (message "Copied %s to kill ring" url)) + (user-error "No feeds found!"))) + ;;; eww.el ends here -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 09:07:18 2023 Received: (at 64126) by debbugs.gnu.org; 17 Jun 2023 13:07:18 +0000 Received: from localhost ([127.0.0.1]:51020 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAVeA-0002Oa-99 for submit@debbugs.gnu.org; Sat, 17 Jun 2023 09:07:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37946) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAVe6-0002O8-Bw for 64126@debbugs.gnu.org; Sat, 17 Jun 2023 09:07:16 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAVe0-0008Sb-Hc; Sat, 17 Jun 2023 09:07:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Ni87nxNZQ/ZxguRu2eTysiVG7nLJdL8M22QzHgafDk0=; b=aWZkxSMym1qB zpLEqbUK72ke+P3GrguKXVIOndM8sSisFPd13vtLFr2EDFLbaO4VEuf/5aQWz1QF19+VDy+GB2KX1 r2y9ycxY1u4qI3MwZB0mekHi75Tse+cnnkQeyRFHGp/6/EI7SQEwaYkFfe2vrCEaGtH0M2vnNv+Pv IPmB5/PfyL403JI8hNFUUKcclSuLNDf6eqdjr17sdbQK0ZZxzisgfJdPYq2VnUUfait/cNmRkKIZ5 UZe/C+bRCP4E2D0OpzMX4vQVHhcTujl0nF0CwjtC3m2IvK2v6gXRsjAR6XHaBmTCdATtxrchEtQAG E+AQYWJJFb79InCOPHWGFQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAVe0-0002pL-1Y; Sat, 17 Jun 2023 09:07:08 -0400 Date: Sat, 17 Jun 2023 16:07:07 +0300 Message-Id: <83a5wyqltw.fsf@gnu.org> From: Eli Zaretskii To: Eshel Yaron In-Reply-To: (bug-gnu-emacs@gnu.org) Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 64126 Cc: 64126@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Sat, 17 Jun 2023 14:07:40 +0300 > From: Eshel Yaron via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > This patch extends EWW with a command that grabs the URL of an alternate > link of the current page, such as an RSS or Atom feed. Thanks. > This adds a new command to EWW that copies an alternate link to the > currently visited page into the kill ring. This is useful for > subscribing to website feeds, etc.. ^^ Two periods, one of which is probably redunant. > +@findex eww-copy-alternate-url > +@kindex A > + The @kbd{A} command (@code{eww-copy-alternate-url}) copies the URL > +of an alternate link of the current page (such as an associated RSS > +feed) into the kill ring. If the page specifies multiple alternate > +links, this command prompt for one of them in the minibuffer. This doesn't say anything about what an "alternate link" could be, it just provides a single example. Since this is for the manual (as opposed to the doc string), there's no need to be so terse; we should instead explain more about what these alternate links are or could be, and give more than just a single example. Perhaps also tell how the alternate links are designated in HTML. > +*** New command 'eww-copy-alternate-url'. > +It copies an alternate link to the page currently visited in EWW into > +the kill ring. Searching the Internet for "alternate link" brings this: A type of hyperlink that gives alternate representations of the current document. Is this what is meant here? If so, why are you talking about RSS feeds? > +(defun eww-read-alternate-url () > + "Get the URL of an alternate link of this page. > + > +If there is just one alternate link, return it's URL. If there ^^^^ "its" > +are multiple alternate links, prompt for one in the minibuffer. I guess the prompt is with completion? If so, please mention that. > +(defun eww-copy-alternate-url () > + "Copy an alternate URL of the current page into the kill ring." This doc string says nothing at all about what an alternate link is. It should say at least something. > + (interactive nil eww-mode) > + (if-let ((url (eww-read-alternate-url))) > + (progn > + (kill-new url) > + (message "Copied %s to kill ring" url)) > + (user-error "No feeds found!"))) "No feeds"? Can the alternate link be something other than a feed? In any case, "No feeds found on this page!" is better, I think, as "No feeds!" is too general. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 10:08:31 2023 Received: (at 64126) by debbugs.gnu.org; 17 Jun 2023 14:08:31 +0000 Received: from localhost ([127.0.0.1]:52202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAWbP-0004L4-0j for submit@debbugs.gnu.org; Sat, 17 Jun 2023 10:08:31 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:46936 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAWbM-0004Ks-BR for 64126@debbugs.gnu.org; Sat, 17 Jun 2023 10:08:29 -0400 From: Eshel Yaron DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1687010907; bh=o3LCJbv+JaDgxgZuqfAfts/z/oddckxo1hXH/krVj0s=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=djCXGkZOQDfucWfAgbRLInltAXicP+U7lg/byn0QsgyRaWwcK73C58C8Q4odiET30 eoir04faEiOyqXC8TwETfWRnUtLMgbQqfun/0OZF55HHE8825hRDZiz/VuWD4dR3s5 3t5uLu4BsZeiyvBmAPEtzSaUFAMJxZd7BhKdeBg8Gb/7o4FqGdP6SUa2jbi+QkomHt NyoKedkzBYxge2fP9+nRDXk5Tvl579g9r6Gv9ZiljnRWyYpD1cp8eWE66MyVfYO89K CTMOp3XvDQHAHj2o9QsuRbznMIAknAwTitnDMueAI9c2z8sBSCP3BUWmPOJH7lCFOn Pern2o99mko/Q== To: Eli Zaretskii Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' In-Reply-To: <83a5wyqltw.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 17 Jun 2023 16:07:07 +0300") References: <83a5wyqltw.fsf@gnu.org> Date: Sat, 17 Jun 2023 17:08:24 +0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 64126 Cc: 64126@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Thanks for your comments, Eli, I'm attaching an updated patch below. Eli Zaretskii writes: >> This adds a new command to EWW that copies an alternate link to the >> currently visited page into the kill ring. This is useful for >> subscribing to website feeds, etc.. > ^^ > Two periods, one of which is probably redunant. > Fixed. >> +@findex eww-copy-alternate-url >> +@kindex A >> + The @kbd{A} command (@code{eww-copy-alternate-url}) copies the URL >> +of an alternate link of the current page (such as an associated RSS >> +feed) into the kill ring. If the page specifies multiple alternate >> +links, this command prompt for one of them in the minibuffer. > > This doesn't say anything about what an "alternate link" could be, it > just provides a single example. Since this is for the manual (as > opposed to the doc string), there's no need to be so terse; we should > instead explain more about what these alternate links are or could be, > and give more than just a single example. Perhaps also tell how the > alternate links are designated in HTML. > Alright, I wasn't sure how much to elaborate here, I've added more details in the updated patch. I hope I got the formatting right for referring to HTML elements, basically I tried to follow similar existing cases in eww.texi. >> +*** New command 'eww-copy-alternate-url'. >> +It copies an alternate link to the page currently visited in EWW into >> +the kill ring. > > Searching the Internet for "alternate link" brings this: > > A type of hyperlink that gives alternate representations of the > current document. > > Is this what is meant here? If so, why are you talking about RSS > feeds? > Yes, websites very often use these alternate links to point to their RSS/Atom feeds. Should I add a couple of words about that in the NEWS entry as well? For instance, https://www.gnu.org/ lists https://planet.gnu.org/rss20.xml as an alternate link (as well as translations of that webpage to other languages). There's more information about alternate links here https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel#alternate >> +(defun eww-read-alternate-url () >> + "Get the URL of an alternate link of this page. >> + >> +If there is just one alternate link, return it's URL. If there > ^^^^ > "its" > Thanks, fixed. >> +are multiple alternate links, prompt for one in the minibuffer. > > I guess the prompt is with completion? If so, please mention that. > Done. >> +(defun eww-copy-alternate-url () >> + "Copy an alternate URL of the current page into the kill ring." > > This doc string says nothing at all about what an alternate link is. > It should say at least something. > Sure, I've added a couple of words here as well. >> + (interactive nil eww-mode) >> + (if-let ((url (eww-read-alternate-url))) >> + (progn >> + (kill-new url) >> + (message "Copied %s to kill ring" url)) >> + (user-error "No feeds found!"))) > > "No feeds"? Can the alternate link be something other than a feed? > In any case, "No feeds found on this page!" is better, I think, as "No > feeds!" is too general. You're right, thanks, I've changed this to "No alternate links found on this page!". --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v2-0001-New-command-eww-copy-alternate-url.patch >From 70e10c40cf2319b316611c56be53a27b6e67cad5 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 17 Jun 2023 13:48:51 +0300 Subject: [PATCH v2] New command 'eww-copy-alternate-url' This adds a new command to EWW that copies an alternate link to the currently visited page into the kill ring. This is useful for subscribing to website feeds, etc. * lisp/net/eww.el (eww--alternate-urls) (eww-read-alternate-url): New functions. (eww-copy-alternate-url): New command. (eww-mode-map): Bind it to 'A'. * doc/misc/eww.texi (Basics): Document it. * etc/NEWS: Announce it. --- doc/misc/eww.texi | 15 +++++++++ etc/NEWS | 5 +++ lisp/net/eww.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index c02e9db11c9..cff48bd601e 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi @@ -115,6 +115,21 @@ Basics @kbd{w} calls @code{eww-copy-page-url}, which will copy the current page's URL to the kill ring instead. +@findex eww-copy-alternate-url +@kindex A + The @kbd{A} command (@code{eww-copy-alternate-url}) copies the URL +of an alternate link of the current page into the kill ring. If the +page specifies multiple alternate links, this command prompts for one +of them in the minibuffer, with completion. Alternate links are +references that an @acronym{HTML} page may include to point to other +documents that act as its alternative representations. Notably, +@acronym{HTML} pages can use alternate links to point to their +translated versions and to @acronym{RSS} feeds. Alternate links +appear in the @samp{} section of @acronym{HTML} pages as +@samp{} elements with @samp{rel} attribute equal to +@samp{``alternate''}, they are part of the page's metadata and are not +visible in its rendered content. + @findex eww-open-in-new-buffer @kindex M-RET The @kbd{M-@key{RET}} command (@code{eww-open-in-new-buffer}) opens the diff --git a/etc/NEWS b/etc/NEWS index 61e6e161665..7c94c3efa89 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -253,6 +253,11 @@ The interactive minibuffer prompt when invoking 'eww' now provides completions from 'eww-suggest-uris'. 'eww-suggest-uris' now includes bookmark URIs. ++++ +*** New command 'eww-copy-alternate-url'. +It copies an alternate link to the page currently visited in EWW into +the kill ring. + ** go-ts-mode +++ diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 61f0f47373d..6e8bb5961a0 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1086,6 +1086,7 @@ eww-mode-map "&" #'eww-browse-with-external-browser "d" #'eww-download "w" #'eww-copy-page-url + "A" #'eww-copy-alternate-url "C" #'url-cookie-list "v" #'eww-view-source "R" #'eww-readable @@ -2576,4 +2577,82 @@ eww-bookmark-jump (provide 'eww) +;;; Alternate links (RSS and Atom feeds, etc.) + +(defun eww--alternate-urls (dom &optional base) + "Return an alist of alternate links in DOM. + +Each element is a list of the form (URL TYPE TITLE) where URL is +the href attribute of the link expanded relative to BASE, TYPE is +its type attribute, and TITLE is its title attribute. If any of +these attributes is absent, the corresponding element is nil." + (let ((alternates + (seq-filter + (lambda (attrs) (string= (alist-get 'rel attrs) + "alternate")) + (mapcar #'dom-attributes (dom-by-tag dom 'link))))) + (mapcar (lambda (alternate) + (list (url-expand-file-name (alist-get 'href alternate) + base) + (alist-get 'type alternate) + (alist-get 'title alternate))) + alternates))) + +(defun eww-read-alternate-url () + "Get the URL of an alternate link of this page. + +If there is just one alternate link, return its URL. If there +are multiple alternate links, prompt for one in the minibuffer +with completion. If there are none, return nil." + (when-let ((alternates (eww--alternate-urls + (plist-get eww-data :dom) + (plist-get eww-data :url)))) + (let ((max-length + (apply #'max + (mapcar #'length + (mapcar #'car alternates)))) + (max-title + (apply #'max + (mapcar #'length + (mapcar #'caddr alternates))))) + (if (cdr alternates) + (let ((completion-extra-properties + (list :annotation-function + (lambda (feed) + (let* ((attrs (alist-get feed + alternates + nil + nil + #'string=)) + (type (car attrs)) + (title (cadr attrs))) + (concat (when title + (concat (make-string + (1+ (- max-length + (length feed))) + ?\s) + title)) + (when type + (concat + (make-string + (1+ (- max-title + (length title))) + ?\s) + "[" type "]")))))))) + (completing-read "Alternate URL: " alternates nil t)) + (caar alternates))))) + +(defun eww-copy-alternate-url () + "Copy an alternate URL of the current page into the kill ring. + +Alternate links are references that an HTML page may include to +point to its alternative representations, such as a translated +version or an RSS feed." + (interactive nil eww-mode) + (if-let ((url (eww-read-alternate-url))) + (progn + (kill-new url) + (message "Copied %s to kill ring" url)) + (user-error "No alternate links found on this page!"))) + ;;; eww.el ends here -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 13:08:39 2023 Received: (at 64126) by debbugs.gnu.org; 17 Jun 2023 17:08:39 +0000 Received: from localhost ([127.0.0.1]:52558 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAZPi-0002bo-E0 for submit@debbugs.gnu.org; Sat, 17 Jun 2023 13:08:38 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:60130 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAZPd-0002bc-Ft for 64126@debbugs.gnu.org; Sat, 17 Jun 2023 13:08:37 -0400 From: Eshel Yaron DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1687021713; bh=G8MDTh/+uCOvP1zgVIe3NWPjr1kiR+4J7RGZ4g/U9mM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=dXHK30knc8Rt6JmKZzI4vHmeIshlBJ3W1tVhILBgKmMGScFQWJW+V5z1Tiz/KFXwV BsA75iCsbybb5tOg5jGnylq1wHm5MuhMLYZsax7XrjauCNQ4dLdCe0rfmiYUa+FrmQ /39jdvioU/sbdZDla/UtoQxOI850+PI/DYm2oYCNb0mbOq+CtoeQoHkcXjXy4Zp1kZ rslxpaYXgWEAH9tYr/K5kVM8zu55Fp+SmRbQYcVRjJ+n3VEFyAOBOP1ykFTGbuadyA URqxPBDO9MDm0KgTj2oyulMW95ZyAnWippdVLxQyosCpkrzX1pdMAPjF/XRsyCBQ0M Fb9pOfAVISejA== To: 64126@debbugs.gnu.org Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' In-Reply-To: (Eshel Yaron via's message of "Sat, 17 Jun 2023 17:08:24 +0300") References: <83a5wyqltw.fsf@gnu.org> Date: Sat, 17 Jun 2023 20:08:26 +0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 64126 Cc: Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain I'm attaching yet another updated patch (v3), the difference compared to the former patch is that now the alignment of completion candidate annotations is based on `string-pixel-width` and `display` text properties instead of padding with spaces. This deals better with more exotic strings that may appear in the link's title (again gnu.org is a good example here, as there are alternate link titles in different languages). Still I wonder if there's a more principled way to align such annotations, any suggestions? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v3-0001-New-command-eww-copy-alternate-url.patch >From 2337ba007e2d0512b2a4445e6749ef51df343417 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 17 Jun 2023 13:48:51 +0300 Subject: [PATCH v3] New command 'eww-copy-alternate-url' This adds a new command to EWW that copies an alternate link to the currently visited page into the kill ring. This is useful for subscribing to website feeds, etc. * lisp/net/eww.el (eww--alternate-urls) (eww-read-alternate-url): New functions. (eww-copy-alternate-url): New command. (eww-mode-map): Bind it to 'A'. * doc/misc/eww.texi (Basics): Document it. * etc/NEWS: Announce it. --- doc/misc/eww.texi | 15 +++++++++ etc/NEWS | 5 +++ lisp/net/eww.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index c02e9db11c9..cff48bd601e 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi @@ -115,6 +115,21 @@ Basics @kbd{w} calls @code{eww-copy-page-url}, which will copy the current page's URL to the kill ring instead. +@findex eww-copy-alternate-url +@kindex A + The @kbd{A} command (@code{eww-copy-alternate-url}) copies the URL +of an alternate link of the current page into the kill ring. If the +page specifies multiple alternate links, this command prompts for one +of them in the minibuffer, with completion. Alternate links are +references that an @acronym{HTML} page may include to point to other +documents that act as its alternative representations. Notably, +@acronym{HTML} pages can use alternate links to point to their +translated versions and to @acronym{RSS} feeds. Alternate links +appear in the @samp{} section of @acronym{HTML} pages as +@samp{} elements with @samp{rel} attribute equal to +@samp{``alternate''}, they are part of the page's metadata and are not +visible in its rendered content. + @findex eww-open-in-new-buffer @kindex M-RET The @kbd{M-@key{RET}} command (@code{eww-open-in-new-buffer}) opens the diff --git a/etc/NEWS b/etc/NEWS index 61e6e161665..7c94c3efa89 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -253,6 +253,11 @@ The interactive minibuffer prompt when invoking 'eww' now provides completions from 'eww-suggest-uris'. 'eww-suggest-uris' now includes bookmark URIs. ++++ +*** New command 'eww-copy-alternate-url'. +It copies an alternate link to the page currently visited in EWW into +the kill ring. + ** go-ts-mode +++ diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 61f0f47373d..89f7ba37cc1 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1086,6 +1086,7 @@ eww-mode-map "&" #'eww-browse-with-external-browser "d" #'eww-download "w" #'eww-copy-page-url + "A" #'eww-copy-alternate-url "C" #'url-cookie-list "v" #'eww-view-source "R" #'eww-readable @@ -2576,4 +2577,82 @@ eww-bookmark-jump (provide 'eww) +;;; Alternate links (RSS and Atom feeds, etc.) + +(defun eww--alternate-urls (dom &optional base) + "Return an alist of alternate links in DOM. + +Each element is a list of the form (URL TYPE TITLE) where URL is +the href attribute of the link expanded relative to BASE, TYPE is +its type attribute, and TITLE is its title attribute. If any of +these attributes is absent, the corresponding element is nil." + (let ((alternates + (seq-filter + (lambda (attrs) (string= (alist-get 'rel attrs) + "alternate")) + (mapcar #'dom-attributes (dom-by-tag dom 'link))))) + (mapcar (lambda (alternate) + (list (url-expand-file-name (alist-get 'href alternate) + base) + (alist-get 'type alternate) + (alist-get 'title alternate))) + alternates))) + +(defun eww-read-alternate-url () + "Get the URL of an alternate link of this page. + +If there is just one alternate link, return its URL. If there +are multiple alternate links, prompt for one in the minibuffer +with completion. If there are none, return nil." + (when-let ((alternates (eww--alternate-urls + (plist-get eww-data :dom) + (plist-get eww-data :url)))) + (let ((url-max-width + (seq-max (mapcar #'string-pixel-width + (mapcar #'car alternates)))) + (title-max-width + (seq-max (mapcar #'string-pixel-width + (mapcar #'caddr alternates)))) + (sep-width (string-pixel-width " "))) + (if (cdr alternates) + (let ((completion-extra-properties + (list :annotation-function + (lambda (feed) + (let* ((attrs (alist-get feed + alternates + nil + nil + #'string=)) + (type (car attrs)) + (title (cadr attrs))) + (concat + (propertize " " 'display + `(space :align-to + (,(+ sep-width + url-max-width)))) + title + (when type + (concat + (propertize " " 'display + `(space :align-to + (,(+ (* 2 sep-width) + url-max-width + title-max-width)))) + "[" type "]")))))))) + (completing-read "Alternate URL: " alternates nil t)) + (caar alternates))))) + +(defun eww-copy-alternate-url () + "Copy an alternate URL of the current page into the kill ring. + +Alternate links are references that an HTML page may include to +point to its alternative representations, such as a translated +version or an RSS feed." + (interactive nil eww-mode) + (if-let ((url (eww-read-alternate-url))) + (progn + (kill-new url) + (message "Copied %s to kill ring" url)) + (user-error "No alternate links found on this page!"))) + ;;; eww.el ends here -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 21 02:01:24 2023 Received: (at submit) by debbugs.gnu.org; 21 Jun 2023 06:01:24 +0000 Received: from localhost ([127.0.0.1]:60279 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBquB-0006pn-Pt for submit@debbugs.gnu.org; Wed, 21 Jun 2023 02:01:24 -0400 Received: from lists.gnu.org ([209.51.188.17]:33454) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBquA-0006pf-2A for submit@debbugs.gnu.org; Wed, 21 Jun 2023 02:01:22 -0400 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 1qBqu1-0003bT-7n for bug-gnu-emacs@gnu.org; Wed, 21 Jun 2023 02:01:14 -0400 Received: from mail.eshelyaron.com ([107.175.124.16] helo=eshelyaron.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBqtz-0005CK-93; Wed, 21 Jun 2023 02:01:12 -0400 From: Eshel Yaron DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1687327268; bh=A3hf46JwDxvw+rOfjcnEI0Xr6Px+JrNeG4/cbV506IU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Odgyd6nVHMxLhIY/tGLxYh+39MGJlpz0jMr1kkp/3jJAoszqnvmR2x1fEGL4k/z6C hHhWH3H1u2EorkBuqK9/Ev41mNevvIuaEiBnnd6atd9VyTZaDx9eGRAwQ0RQqGUUpD 0/jB5xaz++/r+pIaJb3N9xDaCajJNrMeLkN3e4uqhgDgc7bo+sK+HuDFcn+GGyI1Z2 ID+KWzcYdVLVLnI4Y9oSP50w7t+1+4XgEBAY7Fq5AckB9lNAXWmYJBbiTaSBnW0t3/ sgMLnaBhalWT+CL+xFKVeHUvFAh0xqgYrvbEqk4BPDamvv9jfHoYQ1wGiDKIMat1H4 WLFogo6tL8elA== To: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' In-Reply-To: (Eshel Yaron via's message of "Sat, 17 Jun 2023 20:08:26 +0300") References: <83a5wyqltw.fsf@gnu.org> Date: Wed, 21 Jun 2023 09:01:03 +0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=107.175.124.16; envelope-from=me@eshelyaron.com; helo=eshelyaron.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: 64126@debbugs.gnu.org, Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Hi all, Any further comments about this addition? > I'm attaching yet another updated patch (v3), the difference compared to > the former patch is that now the alignment of completion candidate > annotations is based on `string-pixel-width` and `display` text > properties instead of padding with spaces. > > This deals better with more exotic strings that may appear in the link's > title (again gnu.org is a good example here, as there are alternate link > titles in different languages). Still I wonder if there's a more > principled way to align such annotations, any suggestions? > > From 2337ba007e2d0512b2a4445e6749ef51df343417 Mon Sep 17 00:00:00 2001 > From: Eshel Yaron > Date: Sat, 17 Jun 2023 13:48:51 +0300 > Subject: [PATCH v3] New command 'eww-copy-alternate-url' > > This adds a new command to EWW that copies an alternate link to the > currently visited page into the kill ring. This is useful for > subscribing to website feeds, etc. > > * lisp/net/eww.el (eww--alternate-urls) > (eww-read-alternate-url): New functions. > (eww-copy-alternate-url): New command. > (eww-mode-map): Bind it to 'A'. > > * doc/misc/eww.texi (Basics): Document it. > > * etc/NEWS: Announce it. > --- > doc/misc/eww.texi | 15 +++++++++ > etc/NEWS | 5 +++ > lisp/net/eww.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 99 insertions(+) > > diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi > index c02e9db11c9..cff48bd601e 100644 > --- a/doc/misc/eww.texi > +++ b/doc/misc/eww.texi > @@ -115,6 +115,21 @@ Basics > @kbd{w} calls @code{eww-copy-page-url}, which will copy the current > page's URL to the kill ring instead. > > +@findex eww-copy-alternate-url > +@kindex A > + The @kbd{A} command (@code{eww-copy-alternate-url}) copies the URL > +of an alternate link of the current page into the kill ring. If the > +page specifies multiple alternate links, this command prompts for one > +of them in the minibuffer, with completion. Alternate links are > +references that an @acronym{HTML} page may include to point to other > +documents that act as its alternative representations. Notably, > +@acronym{HTML} pages can use alternate links to point to their > +translated versions and to @acronym{RSS} feeds. Alternate links > +appear in the @samp{} section of @acronym{HTML} pages as > +@samp{} elements with @samp{rel} attribute equal to > +@samp{``alternate''}, they are part of the page's metadata and are not > +visible in its rendered content. > + > @findex eww-open-in-new-buffer > @kindex M-RET > The @kbd{M-@key{RET}} command (@code{eww-open-in-new-buffer}) opens the > diff --git a/etc/NEWS b/etc/NEWS > index 61e6e161665..7c94c3efa89 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -253,6 +253,11 @@ The interactive minibuffer prompt when invoking 'eww' now provides > completions from 'eww-suggest-uris'. 'eww-suggest-uris' now includes > bookmark URIs. > > ++++ > +*** New command 'eww-copy-alternate-url'. > +It copies an alternate link to the page currently visited in EWW into > +the kill ring. > + > ** go-ts-mode > > +++ > diff --git a/lisp/net/eww.el b/lisp/net/eww.el > index 61f0f47373d..89f7ba37cc1 100644 > --- a/lisp/net/eww.el > +++ b/lisp/net/eww.el > @@ -1086,6 +1086,7 @@ eww-mode-map > "&" #'eww-browse-with-external-browser > "d" #'eww-download > "w" #'eww-copy-page-url > + "A" #'eww-copy-alternate-url > "C" #'url-cookie-list > "v" #'eww-view-source > "R" #'eww-readable > @@ -2576,4 +2577,82 @@ eww-bookmark-jump > > (provide 'eww) > > +;;; Alternate links (RSS and Atom feeds, etc.) > + > +(defun eww--alternate-urls (dom &optional base) > + "Return an alist of alternate links in DOM. > + > +Each element is a list of the form (URL TYPE TITLE) where URL is > +the href attribute of the link expanded relative to BASE, TYPE is > +its type attribute, and TITLE is its title attribute. If any of > +these attributes is absent, the corresponding element is nil." > + (let ((alternates > + (seq-filter > + (lambda (attrs) (string= (alist-get 'rel attrs) > + "alternate")) > + (mapcar #'dom-attributes (dom-by-tag dom 'link))))) > + (mapcar (lambda (alternate) > + (list (url-expand-file-name (alist-get 'href alternate) > + base) > + (alist-get 'type alternate) > + (alist-get 'title alternate))) > + alternates))) > + > +(defun eww-read-alternate-url () > + "Get the URL of an alternate link of this page. > + > +If there is just one alternate link, return its URL. If there > +are multiple alternate links, prompt for one in the minibuffer > +with completion. If there are none, return nil." > + (when-let ((alternates (eww--alternate-urls > + (plist-get eww-data :dom) > + (plist-get eww-data :url)))) > + (let ((url-max-width > + (seq-max (mapcar #'string-pixel-width > + (mapcar #'car alternates)))) > + (title-max-width > + (seq-max (mapcar #'string-pixel-width > + (mapcar #'caddr alternates)))) > + (sep-width (string-pixel-width " "))) > + (if (cdr alternates) > + (let ((completion-extra-properties > + (list :annotation-function > + (lambda (feed) > + (let* ((attrs (alist-get feed > + alternates > + nil > + nil > + #'string=)) > + (type (car attrs)) > + (title (cadr attrs))) > + (concat > + (propertize " " 'display > + `(space :align-to > + (,(+ sep-width > + url-max-width)))) > + title > + (when type > + (concat > + (propertize " " 'display > + `(space :align-to > + (,(+ (* 2 sep-width) > + url-max-width > + title-max-width)))) > + "[" type "]")))))))) > + (completing-read "Alternate URL: " alternates nil t)) > + (caar alternates))))) > + > +(defun eww-copy-alternate-url () > + "Copy an alternate URL of the current page into the kill ring. > + > +Alternate links are references that an HTML page may include to > +point to its alternative representations, such as a translated > +version or an RSS feed." > + (interactive nil eww-mode) > + (if-let ((url (eww-read-alternate-url))) > + (progn > + (kill-new url) > + (message "Copied %s to kill ring" url)) > + (user-error "No alternate links found on this page!"))) > + > ;;; eww.el ends here -- Thanks, Eshel From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 21 07:00:26 2023 Received: (at 64126) by debbugs.gnu.org; 21 Jun 2023 11:00:26 +0000 Received: from localhost ([127.0.0.1]:60731 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBvZa-0000eO-E8 for submit@debbugs.gnu.org; Wed, 21 Jun 2023 07:00:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48930) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBvZY-0000e9-Gw for 64126@debbugs.gnu.org; Wed, 21 Jun 2023 07:00:25 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBvZT-0004B7-3h; Wed, 21 Jun 2023 07:00:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=WmqSG7UozYIfZrSvpwuVbr+/rXckurCyzFuxpRIGz+w=; b=OQzcTwTwl6I2 yWOu1px+DYEKoXcj68nUMTXfEPUPJgp7yoqaRNXQj3PqkmsSbSQsTG6c3Q5cj8yiqV9laHy5bi1zP eOHPKN9E3aLRKMopnb169WGsoaG99k0bkCWVmjX5U517W1qiH0IEpr1auW22iwEvsVq8nyRN/xYFg NI8nGV6z+Ii03xI2s1my5+guNZ7GzTQfAr2AopSjHoZ3dg6IKDWNB7c3b2qDXbWaM2siZHMKHKEsU Ft27bAa60zoUpcXQkdjICoRN24zT46zcyhtooFH5nynzvXk0ZWohP0rGS+MUVls/kP/Qg+Xts8tdm +0RnU9Uerj22S2CguKKvdA==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBvZR-0006WQ-8I; Wed, 21 Jun 2023 07:00:18 -0400 Date: Wed, 21 Jun 2023 14:00:21 +0300 Message-Id: <83fs6l5bcq.fsf@gnu.org> From: Eli Zaretskii To: Eshel Yaron In-Reply-To: (message from Eshel Yaron on Wed, 21 Jun 2023 09:01:03 +0300) Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' References: <83a5wyqltw.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 64126 Cc: 64126@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Eshel Yaron > Cc: 64126@debbugs.gnu.org, Eli Zaretskii > Date: Wed, 21 Jun 2023 09:01:03 +0300 > > Hi all, > Any further comments about this addition? Please allow more than just 3-4 days before pinging. This changeset is for master, not for the release branch, and it adds a new feature (i.e. is not a bugfix). Such changes are less urgent, and IME it is a good idea to let them be posted for at least a week before installing, to let enough people notice and comment if they want. (And in this case I didn't yet have time to review this final version myself.) TIA From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 21 08:02:18 2023 Received: (at 64126) by debbugs.gnu.org; 21 Jun 2023 12:02:18 +0000 Received: from localhost ([127.0.0.1]:60816 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBwXR-0004wc-RE for submit@debbugs.gnu.org; Wed, 21 Jun 2023 08:02:18 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:36624 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBwXQ-0004wU-Ce for 64126@debbugs.gnu.org; Wed, 21 Jun 2023 08:02:17 -0400 From: Eshel Yaron DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1687348935; bh=pbAhzx8YUJgMZ+uu6QTcVa4rAKwielNV92sp/EYNgYY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=jYCcEmPKnN7IWBHC1rCGAPt893ogV7c/ZTcZ0cdm57Mzj64rFMVYjWWqcAUPGgnWW oayLADDM7IaLTESWTaGGXshEfKqeFHZagHceXa3cvCz6rypo59JPF1CcEbvIP0Fn++ 9wlLoyEiaqpKSqU2EvDlQouDk3ge6dyRxMi2vELdgipWfkJvfWzBGDd4Ad3Qo9IuEJ 5F3owWYfJy650a1s7zH2nn5KJ4CyA9pwof+/1VCxjTuR57rGX65EsHHaaO18WLD+6X dbWcDiq07i2aAtXtwMA5XGCk4h3Jzq5JUJRHIwgo3Sulmis9In21LmRjdV0x9Ekg2k XI0tNu5SzNmvg== To: Eli Zaretskii Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' In-Reply-To: <83fs6l5bcq.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 21 Jun 2023 14:00:21 +0300") References: <83a5wyqltw.fsf@gnu.org> <83fs6l5bcq.fsf@gnu.org> Date: Wed, 21 Jun 2023 15:02:09 +0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 64126 Cc: 64126@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Eli Zaretskii writes: >> From: Eshel Yaron >> Cc: 64126@debbugs.gnu.org, Eli Zaretskii >> Date: Wed, 21 Jun 2023 09:01:03 +0300 >> >> Hi all, >> Any further comments about this addition? > > Please allow more than just 3-4 days before pinging. This changeset > is for master, not for the release branch, and it adds a new feature > (i.e. is not a bugfix). Such changes are less urgent, and IME it is a > good idea to let them be posted for at least a week before installing, > to let enough people notice and comment if they want. No problem, I'll keep that in mind. > (And in this case I didn't yet have time to review this final version > myself.) > > TIA Thanks, Eshel From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 21 10:04:13 2023 Received: (at 64126) by debbugs.gnu.org; 21 Jun 2023 14:04:13 +0000 Received: from localhost ([127.0.0.1]:33838 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qByRQ-00054A-Uo for submit@debbugs.gnu.org; Wed, 21 Jun 2023 10:04:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46608) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qByRP-00053x-9I for 64126@debbugs.gnu.org; Wed, 21 Jun 2023 10:04:11 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qByRJ-0006zD-2M; Wed, 21 Jun 2023 10:04:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=l+Hus/cDAWNkf4fk4alnJ858oS0QgWiknR+8eEnMzIM=; b=BVG7pCPzJLqJ 7+U04+PKJbbsI4zqWeHmKzVa0SG1VwdRWz23nRoJXPpD/GkOXA9B3LTCTQRQE7WMOCVX9GaHniZUW A6Cri7Vguyzz2dDLK+CzxHP19kwfyR6Yphc3Gst5JFVMPqiLPvKxTYSUymz5qc6vWJupA2Xn2VExK 2YrCZePuVtmSeiE0vXdfqqT5YugumFs62WkTz14+yOjsB2oZm6Qpj5cfG8sh64kd65ErbzQGUuq8K p2OKhodxlyBBBplFEvxIG8QhlRjI4TFnPLQxn2frs/oEVagmIT2Czh4Yzd61ToF16FdZZjBBwO7Gd hTVTVx7MqTPG43O+LHm99A==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qByRI-0006Zl-IQ; Wed, 21 Jun 2023 10:04:04 -0400 Date: Wed, 21 Jun 2023 17:04:14 +0300 Message-Id: <83r0q452u9.fsf@gnu.org> From: Eli Zaretskii To: Eshel Yaron In-Reply-To: (message from Eshel Yaron on Sat, 17 Jun 2023 17:08:24 +0300) Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' References: <83a5wyqltw.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 64126 Cc: 64126@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Eshel Yaron > Cc: 64126@debbugs.gnu.org > Date: Sat, 17 Jun 2023 17:08:24 +0300 > > >> +*** New command 'eww-copy-alternate-url'. > >> +It copies an alternate link to the page currently visited in EWW into > >> +the kill ring. > > > > Searching the Internet for "alternate link" brings this: > > > > A type of hyperlink that gives alternate representations of the > > current document. > > > > Is this what is meant here? If so, why are you talking about RSS > > feeds? > > > > Yes, websites very often use these alternate links to point to their > RSS/Atom feeds. Should I add a couple of words about that in the NEWS > entry as well? Yes, a few more words of explanation would be good there. From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 21 13:20:35 2023 Received: (at 64126) by debbugs.gnu.org; 21 Jun 2023 17:20:35 +0000 Received: from localhost ([127.0.0.1]:34184 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qC1VT-0005Rg-95 for submit@debbugs.gnu.org; Wed, 21 Jun 2023 13:20:35 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:57550 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qC1VQ-0005RV-BJ for 64126@debbugs.gnu.org; Wed, 21 Jun 2023 13:20:33 -0400 From: Eshel Yaron DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1687368031; bh=jgpdvTXDuigK0lzYxAzyHt5mXBfUEd6H0YNsI61sxdk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=eV6ZN3jO4O0XaRDZk3iAMIxF+Afl/BfuWRqPpBvEMfLm3onlqLLMPSCig2OxMiMMy NeC/jXPeU962CP3oOLYVN6IJe+B8F9htnOJGKVaE2bal5bdiM05hBEokkKfH+nXnB/ acAVzJLrSFr4l7hU1AL4+G8WrWDtDq1ipNF1nP5pBXhSti61IPsbHm0YK7UOvFRSjj odje7NsFVAh0jcx7VToroTKDV7F8TsS50CHjDXPdWtOajW+C+PTKyWmXKu6lYRJWuu 5l1rtV48CRUDXNIkrGBmTTa4n5gLxRYPDZaKDsu4wPE5MUDNNyhNPBTBt0pSmnm5I6 OCjqlCofqAXMw== To: Eli Zaretskii Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' In-Reply-To: <83r0q452u9.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 21 Jun 2023 17:04:14 +0300") References: <83a5wyqltw.fsf@gnu.org> <83r0q452u9.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Date: Wed, 21 Jun 2023 20:20:27 +0300 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 64126 Cc: 64126@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Eshel Yaron >> >> >> +*** New command 'eww-copy-alternate-url'. >> >> +It copies an alternate link to the page currently visited in EWW into >> >> +the kill ring. >> > >> > Searching the Internet for "alternate link" brings this: >> > >> > A type of hyperlink that gives alternate representations of the >> > current document. >> > >> > Is this what is meant here? If so, why are you talking about RSS >> > feeds? >> > >> >> Yes, websites very often use these alternate links to point to their >> RSS/Atom feeds. Should I add a couple of words about that in the NEWS >> entry as well? > > Yes, a few more words of explanation would be good there. Sure, I've added a few words about alternate links to the NEWS entry in the following (updated) patch: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v4-0001-New-command-eww-copy-alternate-url.patch >From 6f2de147056000d2007d7715f1f616ff6a37a508 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 17 Jun 2023 13:48:51 +0300 Subject: [PATCH v4] New command 'eww-copy-alternate-url' This adds a new command to EWW that copies an alternate link to the currently visited page into the kill ring. This is useful for subscribing to website feeds, etc. * lisp/net/eww.el (eww--alternate-urls) (eww-read-alternate-url): New functions. (eww-copy-alternate-url): New command. (eww-mode-map): Bind it to 'A'. * doc/misc/eww.texi (Basics): Document it. * etc/NEWS: Announce it. --- doc/misc/eww.texi | 15 +++++++++ etc/NEWS | 7 +++++ lisp/net/eww.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index c02e9db11c9..cff48bd601e 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi @@ -115,6 +115,21 @@ Basics @kbd{w} calls @code{eww-copy-page-url}, which will copy the current page's URL to the kill ring instead. +@findex eww-copy-alternate-url +@kindex A + The @kbd{A} command (@code{eww-copy-alternate-url}) copies the URL +of an alternate link of the current page into the kill ring. If the +page specifies multiple alternate links, this command prompts for one +of them in the minibuffer, with completion. Alternate links are +references that an @acronym{HTML} page may include to point to other +documents that act as its alternative representations. Notably, +@acronym{HTML} pages can use alternate links to point to their +translated versions and to @acronym{RSS} feeds. Alternate links +appear in the @samp{} section of @acronym{HTML} pages as +@samp{} elements with @samp{rel} attribute equal to +@samp{``alternate''}, they are part of the page's metadata and are not +visible in its rendered content. + @findex eww-open-in-new-buffer @kindex M-RET The @kbd{M-@key{RET}} command (@code{eww-open-in-new-buffer}) opens the diff --git a/etc/NEWS b/etc/NEWS index d703b7e77be..c2299c2998e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -258,6 +258,13 @@ The interactive minibuffer prompt when invoking 'eww' now provides completions from 'eww-suggest-uris'. 'eww-suggest-uris' now includes bookmark URIs. ++++ +*** New command 'eww-copy-alternate-url'. +It copies an alternate link to the page currently visited in EWW into +the kill ring. Alternate links are optional metadata that HTML pages +use for linking to their alternative representations, such as +translated versions or associated RSS feeds. + ** go-ts-mode +++ diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 61f0f47373d..89f7ba37cc1 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1086,6 +1086,7 @@ eww-mode-map "&" #'eww-browse-with-external-browser "d" #'eww-download "w" #'eww-copy-page-url + "A" #'eww-copy-alternate-url "C" #'url-cookie-list "v" #'eww-view-source "R" #'eww-readable @@ -2576,4 +2577,82 @@ eww-bookmark-jump (provide 'eww) +;;; Alternate links (RSS and Atom feeds, etc.) + +(defun eww--alternate-urls (dom &optional base) + "Return an alist of alternate links in DOM. + +Each element is a list of the form (URL TYPE TITLE) where URL is +the href attribute of the link expanded relative to BASE, TYPE is +its type attribute, and TITLE is its title attribute. If any of +these attributes is absent, the corresponding element is nil." + (let ((alternates + (seq-filter + (lambda (attrs) (string= (alist-get 'rel attrs) + "alternate")) + (mapcar #'dom-attributes (dom-by-tag dom 'link))))) + (mapcar (lambda (alternate) + (list (url-expand-file-name (alist-get 'href alternate) + base) + (alist-get 'type alternate) + (alist-get 'title alternate))) + alternates))) + +(defun eww-read-alternate-url () + "Get the URL of an alternate link of this page. + +If there is just one alternate link, return its URL. If there +are multiple alternate links, prompt for one in the minibuffer +with completion. If there are none, return nil." + (when-let ((alternates (eww--alternate-urls + (plist-get eww-data :dom) + (plist-get eww-data :url)))) + (let ((url-max-width + (seq-max (mapcar #'string-pixel-width + (mapcar #'car alternates)))) + (title-max-width + (seq-max (mapcar #'string-pixel-width + (mapcar #'caddr alternates)))) + (sep-width (string-pixel-width " "))) + (if (cdr alternates) + (let ((completion-extra-properties + (list :annotation-function + (lambda (feed) + (let* ((attrs (alist-get feed + alternates + nil + nil + #'string=)) + (type (car attrs)) + (title (cadr attrs))) + (concat + (propertize " " 'display + `(space :align-to + (,(+ sep-width + url-max-width)))) + title + (when type + (concat + (propertize " " 'display + `(space :align-to + (,(+ (* 2 sep-width) + url-max-width + title-max-width)))) + "[" type "]")))))))) + (completing-read "Alternate URL: " alternates nil t)) + (caar alternates))))) + +(defun eww-copy-alternate-url () + "Copy an alternate URL of the current page into the kill ring. + +Alternate links are references that an HTML page may include to +point to its alternative representations, such as a translated +version or an RSS feed." + (interactive nil eww-mode) + (if-let ((url (eww-read-alternate-url))) + (progn + (kill-new url) + (message "Copied %s to kill ring" url)) + (user-error "No alternate links found on this page!"))) + ;;; eww.el ends here -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 24 08:00:53 2023 Received: (at 64126-done) by debbugs.gnu.org; 24 Jun 2023 12:00:53 +0000 Received: from localhost ([127.0.0.1]:40015 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qD1wj-0005tY-5U for submit@debbugs.gnu.org; Sat, 24 Jun 2023 08:00:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qD1wg-0005tI-7o for 64126-done@debbugs.gnu.org; Sat, 24 Jun 2023 08:00:52 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qD1wa-0004WQ-Lr; Sat, 24 Jun 2023 08:00:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=WHNjdjJlKeNTWFyNtCqwKClRJ78gk6wrcP1jfjqd2AI=; b=Q44Oqg7ckMjX 3qa0orJPuij4LIkUMMwF4CWqPdEw4qhlAewPZOZrSoL7yZ8OGX4H49dXvhHOffPy16yJnGRnDp9Xb 4S+FYmc5+SmL4RKXJxM3gO0+icKrfE283vmiXaNBW+YLE2Okqt3Fo7VX77D2R/YgOJo60ciH7nR/O Wq5WOLF+TFDqKS/dYCIl73XvL5zGF5m21rd/3a2iFgFpPoC77MCrvEmurZ8O50XH3WxMzZOx/osL1 iXjyitBxYoCYzANX+sOE9mZoEXWnreBLLq6YtNldSPmj3i7Y4qP1W+tuar2EFaLRSMHKzHTaG+xyK y9Ilzkk0Y0py743VXyJSUA==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qD1wR-0008PU-1E; Sat, 24 Jun 2023 08:00:40 -0400 Date: Sat, 24 Jun 2023 15:00:51 +0300 Message-Id: <83mt0pysr0.fsf@gnu.org> From: Eli Zaretskii To: Eshel Yaron In-Reply-To: (message from Eshel Yaron on Wed, 21 Jun 2023 20:20:27 +0300) Subject: Re: bug#64126: [PATCH] New command 'eww-copy-alternate-url' References: <83a5wyqltw.fsf@gnu.org> <83r0q452u9.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 64126-done Cc: 64126-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Eshel Yaron > Cc: 64126@debbugs.gnu.org > Date: Wed, 21 Jun 2023 20:20:27 +0300 > > >> Yes, websites very often use these alternate links to point to their > >> RSS/Atom feeds. Should I add a couple of words about that in the NEWS > >> entry as well? > > > > Yes, a few more words of explanation would be good there. > > Sure, I've added a few words about alternate links to the NEWS entry in > the following (updated) patch: Thanks, installed (with a couple of minor fixes) on the master branch, and closing the bug. From unknown Mon Jun 23 04:13:41 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 23 Jul 2023 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator