diff options
author | Case Duckworth | 2022-04-12 22:41:03 -0500 |
---|---|---|
committer | Case Duckworth | 2022-04-12 22:41:03 -0500 |
commit | bb756ce658f2e1a4bf904ce19392fed3015d2463 (patch) | |
tree | cf19ca16be52ae9307088dbe2fb03a32ab2cbaed /lisp | |
parent | Remove unused w3m setup form (diff) | |
download | emacs-bb756ce658f2e1a4bf904ce19392fed3015d2463.tar.gz emacs-bb756ce658f2e1a4bf904ce19392fed3015d2463.zip |
Dang ol +shr.el file
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+shr.el | 51 |
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). | ||
11 | If 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). | ||
34 | If 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. | ||
44 | Add 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 | ||