diff --git a/.emacs.d/lisp/init-evil.el b/.emacs.d/lisp/init-evil.el index 31b773b2..21a605c3 100644 --- a/.emacs.d/lisp/init-evil.el +++ b/.emacs.d/lisp/init-evil.el @@ -218,4 +218,11 @@ (evil-define-key '(normal motion) emms-browser-mode-map (kbd "") '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) diff --git a/.emacs.d/lisp/init-eww.el b/.emacs.d/lisp/init-eww.el index 1360437f..821cce1f 100644 --- a/.emacs.d/lisp/init-eww.el +++ b/.emacs.d/lisp/init-eww.el @@ -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)