summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-04-12 22:41:03 -0500
committerCase Duckworth2022-04-12 22:41:03 -0500
commitbb756ce658f2e1a4bf904ce19392fed3015d2463 (patch)
treecf19ca16be52ae9307088dbe2fb03a32ab2cbaed
parentRemove unused w3m setup form (diff)
downloademacs-bb756ce658f2e1a4bf904ce19392fed3015d2463.tar.gz
emacs-bb756ce658f2e1a4bf904ce19392fed3015d2463.zip
Dang ol +shr.el file
-rw-r--r--lisp/+shr.el51
1 files changed, 51 insertions, 0 deletions
diff --git a/lisp/+shr.el b/lisp/+shr.el new file mode 100644 index 0000000..af4bf5b --- /dev/null +++ b/lisp/+shr.el
@@ -0,0 +1,51 @@
1;;; +shr.el --- SHR extras -*- lexical-binding: t; -*-
2
3;;; Commentary:
4
5;;; Code:
6
7;;; [[https://github.com/oantolin/emacs-config/blob/master/my-lisp/shr-heading.el][shr-heading]], by oantolin
8
9(defun +shr-heading-next (&optional arg)
10 "Move forward by ARG headings (any h1-h4).
11If ARG is negative move backwards, ARG defaults to 1."
12 (interactive "p")
13 (unless arg (setq arg 1))
14 (catch 'return
15 (dotimes (_ (abs arg))
16 (when (> arg 0) (end-of-line))
17 (if-let ((match
18 (funcall (if (> arg 0)
19 #'text-property-search-forward
20 #'text-property-search-backward)
21 'face '(shr-h1 shr-h2 shr-h3 shr-h4)
22 (lambda (tags face)
23 (cl-loop for x in (if (consp face) face (list face))
24 thereis (memq x tags))))))
25 (goto-char
26 (if (> arg 0) (prop-match-beginning match) (prop-match-end match)))
27 (throw 'return nil))
28 (when (< arg 0) (beginning-of-line)))
29 (beginning-of-line)
30 (point)))
31
32(defun +shr-heading-previous (&optional arg)
33 "Move backward by ARG headings (any h1-h4).
34If ARG is negative move forwards instead, ARG defaults to 1."
35 (interactive "p")
36 (+shr-heading-next (- (or arg 1))))
37
38(defun +shr-heading--line-at-point ()
39 "Return the current line."
40 (buffer-substring (line-beginning-position) (line-end-position)))
41
42(defun +shr-heading-setup-imenu ()
43 "Setup imenu for h1-h4 headings in eww buffer.
44Add this function to appropriate major mode hooks such as
45`eww-mode-hook' or `elfeed-show-mode-hook'."
46 (setq-local
47 imenu-prev-index-position-function #'+shr-heading-previous
48 imenu-extract-index-name-function #'+shr-heading--line-at-point))
49
50(provide '+shr)
51;;; +shr.el ends here