From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#64126: [PATCH] New command 'eww-copy-alternate-url' Date: Sat, 17 Jun 2023 14:07:40 +0300 Message-ID: Reply-To: Eshel Yaron 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="4840"; mail-complaints-to="usenet@ciao.gmane.io" To: 64126@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 17 13:08:20 2023 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 1qATn0-00014w-P1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Jun 2023 13:08:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qATmm-0007UN-53; Sat, 17 Jun 2023 07:08:04 -0400 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 1qATmk-0007Ty-9O for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:08:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qATmk-00033Z-0C for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qATmj-00053b-Po for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:08:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eshel Yaron Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Jun 2023 11:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64126 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.168700008119433 (code B ref -1); Sat, 17 Jun 2023 11:08:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Jun 2023 11:08:01 +0000 Original-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 Original-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 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 1qATmf-0007Te-PM for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:07:58 -0400 Original-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 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== 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-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:263524 Archived-At: --=-=-= 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 --=-=-=--