EWW: Fallback to next numerical URL
parent
8ee705b1de
commit
082656530a
|
@ -218,4 +218,11 @@
|
|||
(evil-define-key '(normal motion) emms-browser-mode-map (kbd "<return>") 'ambrevar/emms-browser-add-tracks-and-maybe-play))))
|
||||
(add-hook 'evil-collection-setup-hook 'ambrevar/evil-emms)
|
||||
|
||||
;; EWW
|
||||
(defun ambrevar/evil-eww (mode _mode-keymaps &rest _rest)
|
||||
(when (eq mode 'eww)
|
||||
(evil-define-key 'normal eww-mode-map "[" 'ambrevar/eww-previous-url)
|
||||
(evil-define-key 'normal eww-mode-map "]" 'ambrevar/eww-next-url)))
|
||||
(add-hook 'evil-collection-setup-hook 'ambrevar/evil-eww)
|
||||
|
||||
(provide 'init-evil)
|
||||
|
|
|
@ -3,6 +3,38 @@
|
|||
(setq eww-bookmarks-directory "~/personal/bookmarks"
|
||||
eww-download-directory "~/temp")
|
||||
|
||||
(defun ambrevar/eww-next-url (&optional backward)
|
||||
"Like `eww-next-url' but if no next URL is found, go to next URL numerically.
|
||||
The URL index is the last number after the last '/'."
|
||||
(interactive)
|
||||
(condition-case nil
|
||||
(if backward
|
||||
(eww-previous-url)
|
||||
(eww-next-url))
|
||||
(user-error
|
||||
(when (eq major-mode 'eww-mode)
|
||||
(require 'rx)
|
||||
(let* ((url (plist-get eww-data :url))
|
||||
(re (rx (group (one-or-more digit))
|
||||
(zero-or-more (not (any "/")))
|
||||
line-end)))
|
||||
(if (and (string-match re url)
|
||||
(or (not backward)
|
||||
(> (string-to-number (match-string 1 url)) 0)))
|
||||
(eww
|
||||
(replace-regexp-in-string
|
||||
re
|
||||
(format (format "%%0.%dd" (length (match-string 1 url))) ; In case matched number is zero-padded.
|
||||
(funcall (if backward '1- '1+) (string-to-number (match-string 1 url))))
|
||||
url nil nil 1))
|
||||
(message "No index in URL.")))))))
|
||||
|
||||
(defun ambrevar/eww-previous-url ()
|
||||
"Like `eww-previous-url' but if no next URL is found, go to next URL numerically.
|
||||
The URL index is the last number after the last '/'."
|
||||
(interactive)
|
||||
(ambrevar/eww-next-url 'backward))
|
||||
|
||||
(defun ambrevar/eww-switch-back ()
|
||||
"Switch to the *eww* buffer."
|
||||
(interactive)
|
||||
|
|
Loading…
Reference in New Issue