From: Yuchen Pei <hi@ypei.me>
To: 50497@debbugs.gnu.org
Subject: bug#50497: [PATCH] Adding eww-{next,previous,up,top}-path.
Date: Fri, 10 Sep 2021 13:05:45 +1000 [thread overview]
Message-ID: <87lf45xh86.fsf@ypei.me> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 714 bytes --]
I often find myself wanting to navigate paginated web pages
(e.g. <https://media.libreplanet.org/videos?page=4>), or to go up
or all the way up when visiting a web page, which is why I added
these functions to my eww.
Does this change make sense? If so I will amend the patch to
include tests, doc and bug number.
Note that there seem to be currently no tests for eww, so I will
need to create a new file.
BTW a newbie question: CONTRIBUTE mentions the commit message
should include bug number, but when I send a patch like this a bug
number is only generated afterwards. Does this mean I should
report a bug, wait for the item to be created in debbugs, before
sending a patch for the bug?
Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Add-eww-next-previous-up-top-path.patch --]
[-- Type: text/x-patch, Size: 3054 bytes --]
From 8abc291f6fb9bd85c51fd1b0b7f6dce044b231a5 Mon Sep 17 00:00:00 2001
From: Yuchen Pei <hi@ypei.me>
Date: Fri, 10 Sep 2021 12:41:49 +1000
Subject: [PATCH] Add eww-{next,previous,up,top}-path.
Similar to eww-{next,previous,up,top}-url, but working based on the
url path rather than the rel attribute.
* lisp/net/eww.el (eww-next-path, eww-previous-path, eww-up-path,
eww-top-path).
* doc/misc/eww.texi TODO.
* test/lisp/net/eww-tests.el TODO.
---
lisp/net/eww.el | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 90301e92ac..ded01f97e8 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -974,6 +974,10 @@ eww-mode-map
(define-key map "p" 'eww-previous-url)
(define-key map "u" 'eww-up-url)
(define-key map "t" 'eww-top-url)
+ (define-key map "N" 'eww-next-path)
+ (define-key map "P" 'eww-previous-path)
+ (define-key map "U" 'eww-up-path)
+ (define-key map "T" 'eww-top-path)
(define-key map "&" 'eww-browse-with-external-browser)
(define-key map "d" 'eww-download)
(define-key map "w" 'eww-copy-page-url)
@@ -1194,6 +1198,50 @@ eww-top-url
(eww-browse-url (shr-expand-url best-url (plist-get eww-data :url)))
(user-error "No `top' for this page"))))
+(defun eww-next-path ()
+ "Go to the `next' page according to the url path.
+The url of the `next' page is generated by incrementing the last
+number in the path."
+ (interactive)
+ (let ((url (plist-get eww-data :url)))
+ (when (string-match "^\\(.*?\\)\\([0-9]+\\)\\(.*\\)$" url)
+ (eww (concat
+ (match-string 1 url)
+ (number-to-string
+ (1+ (string-to-number (match-string 2 url))))
+ (match-string 3 url))))))
+
+(defun eww-previous-path ()
+ "Go to the `previous' page according to the url path.
+The url of the `previous' page is generated by decrementing the
+last integer in the path."
+ (interactive)
+ (let ((url (plist-get eww-data :url)))
+ (when (string-match "^\\(.*\\)\\([0-9]+\\)\\(.*\\)$" url)
+ (eww (concat
+ (match-string 1 url)
+ (number-to-string
+ (1- (string-to-number (match-string 2 url))))
+ (match-string 3 url))))))
+
+(defun eww-up-path ()
+ "Go to the `parent' page according to the url path.
+The url of the `parent' page is generated by removing the last
+segment delimited by a forward slash."
+ (interactive)
+ (let ((url (plist-get eww-data :url)))
+ (when (and (string-match "^\\(.*//.*/\\)[^/]+\\(/\\)?$" url)
+ (match-string 1 url))
+ (eww (match-string 1 url)))))
+
+(defun eww-top-path ()
+ "Go to the domain."
+ (interactive)
+ (let ((url (plist-get eww-data :url)))
+ (when (and (string-match "^\\(.*//.*?/\\).*$" url)
+ (match-string 1 url))
+ (eww (match-string 1 url)))))
+
(defun eww-reload (&optional local encode)
"Reload the current page.
If LOCAL is non-nil (interactively, the command was invoked with
--
2.33.0
[-- Attachment #1.3: Type: text/plain, Size: 131 bytes --]
--
Best,
Yuchen
PGP Key: 47F9 D050 1E11 8879 9040 4941 2126 7E93 EF86 DFD0
<https://ypei.me/assets/ypei-pubkey.txt>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 243 bytes --]
next reply other threads:[~2021-09-10 3:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-10 3:05 Yuchen Pei [this message]
2021-09-10 6:43 ` bug#50497: [PATCH] Adding eww-{next,previous,up,top}-path Juri Linkov
2021-09-10 6:57 ` Yuchen Pei
2021-09-10 11:28 ` Lars Ingebrigtsen
2021-09-10 12:50 ` Yuchen Pei
2021-09-11 12:22 ` Lars Ingebrigtsen
2021-11-06 0:29 ` Lars Ingebrigtsen
2021-09-10 16:10 ` Juri Linkov
2021-09-11 12:18 ` Lars Ingebrigtsen
2021-09-11 19:01 ` Juri Linkov
2021-09-13 8:03 ` Lars Ingebrigtsen
2021-09-13 8:25 ` Juri Linkov
2021-09-13 17:51 ` Juri Linkov
2021-09-14 11:04 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lf45xh86.fsf@ypei.me \
--to=hi@ypei.me \
--cc=50497@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.