From 7c9772917c90449a260402b45eabf830fd3580a3 Mon Sep 17 00:00:00 2001 From: chenyanming Date: Sat, 15 Jun 2024 12:15:32 +0800 Subject: [PATCH] Add config.el and restructure README --- FEATURES.org | 407 ++++++++++++++++++++++++++++++++ README.org | 649 +++------------------------------------------------ RELEASES.org | 124 ++++++++++ config.el | 383 ++++++++++++++++++++++++++++++ shrface.el | 2 +- 5 files changed, 941 insertions(+), 624 deletions(-) create mode 100644 FEATURES.org create mode 100644 RELEASES.org create mode 100644 config.el diff --git a/FEATURES.org b/FEATURES.org new file mode 100644 index 0000000..261aaeb --- /dev/null +++ b/FEATURES.org @@ -0,0 +1,407 @@ +#+title: Features +#+STARTUP: nofold +* Features +** shrface-mode +PS: I personally don't use it, instead of enabling a minor mode, I hacked the render function directly, check [[file:config.el][config.el]] + +~shrface-mode~ is a minor mode that help you enable/disable the following additional features: +1. =imenu= +2. =outline-minior-mode= +3. Setup shr faces + +Please be careful, every time you run ~shrface-mode~, faces will be enable/disable globally for +all shr rendered buffers. Since I have not found a good way to enable/disable the faces per +buffer yet. + +If you want to enable shrface just when you need to, you should avoid to use ~add-hook~ like the +recommended settings above, and just enable/disable =shrface-mode= via =M-x=. + + +** shrface-occur +List all headlines, and you can easily jump between them by +mouse click. + +** shrface-links +List all URLs and classify them. +You can easily go to the +occurrence (Left Click/Enter), copy the URL (Middle Click) or browse the URL +(Right Click). Besides, if [[https://github.com/domtronn/all-the-icons.el][all-the-icons]] is available, web icon for each link +will be shown. + +** shrface-links-counsel +List all URLs with =counsel=. +- The URLs are listed in order based the position on the buffer. +- The first candidate to select is the *next url* counting from the current cursor + position. In this case, you can use =C-M-m (ivy-call)=, =C-M-n + (ivy-next-line-and-call)=, and =C-M-p (ivy-previous-line-and-call)= to jump + around all URLs without losing your position. +- =C-o= to fire the action menu on the selected candidate. +- =C-c C-o= to fire the =ivy-occur= + +** shrface-headline-counsel +List all headlines with =counsel=. +- It is a better solution than =imenu= and =shrface-occur.= +- It can work without the headline bullets. You can disable the bullets via + =(setq shrface-toggle-bullets t)= and still be able to jump around the headlines. +- The first candidate to select is the *current context headline* of the current + cursor position. In this case, you can use =C-M-m (ivy-call)=, =C-M-n + (ivy-next-line-and-call)=, and =C-M-p (ivy-previous-line-and-call)= to jump + around all headlines without losing your position. +- =C-o= to fire the action menu on the selected candidate. +- =C-c C-o= to fire the =ivy-occur= + +** shrface-links-helm +List all URLs with =helm=. +- =TAB= to preview the link +- =RET= to goto the link + +** shrface-headline-helm +List all headlines with =helm=. +- =TAB= to preview the headline +- =RET= to goto the headline + +** shrface-links-consult +List all links with =consult=. + +** shrface-headline-consult +List all headlines with =consult=. + + +** shrface-next-headline, shrface-previous-headline +These two headline functions are designed to replace =outline-next-headline= and +=outline-previous-headline=. They scan the headline number text properties and +jump to the headlines which means it can work under no bullets circumstance if +=(setq shrface-toggle-bullets t)=. + +** Headline bullets (h1 to h6) +*** Customize the headline bullets +You can configure your favorite bullets up to 6 levels of headings (cycled +through if less than 6 bullets in setting). + +You can set it with: +#+BEGIN_SRC emacs-lisp +(setq shrface-bullets-bullet-list ("◉" "○" "✸" "✿")) +#+END_SRC + +PS: The bullets setting can be derived from =org-bullets-bullet-list= or +=org-superstar-headline-bullets-list=, if [[https://github.com/sabof/org-bullets][org-bullets]] or [[https://github.com/integral-dw/org-superstar-mode][org-superstar]] is +available. + +*** Toggle headline bullets locally/temporary + +The quick way to toggle(disable/enable) headline bullets locally/temporary: +#+BEGIN_SRC emacs-lisp +M-x shrface-toggle-bullets +#+END_SRC + +Please notice: In =mu4e-view-mode=, using =shrface-toggle-bullets= will toggle +bullets globally. + +*** Disable headline bullets globally +If you do not like headline bullets, disable them globally by: + +#+BEGIN_SRC emacs-lisp +(setq shrface-toggle-bullets t) +#+END_SRC + +Please notice, the following features are also disabled: +1. function =shrface-occur= +2. variable =shrface-mode= + +However, the following features are still be able to use: +1. function =shrface-links= +2. function =shrface-links-counsel= +3. function =shrface-headline-counsel= +4. function =shrface-previous-headline= +5. function =shrface-next-headline= +6. function =shrface-links-helm= +7. function =shrface-headline-helm= +8. function =shrface-links-consult= +9. function =shrface-headline-consult= + +** Item bullet +You can configure your favorite item bullet for shrface + +You can set it with: +#+BEGIN_SRC emacs-lisp +(setq shrface-item-bullet "-") +#+END_SRC + +PS: Only one type of item bullet is supported, prettified by +=shrface-item-bullet-face= + +** Paragraph indentation and fill column +Both ~shrface-paragraph-indentation~ and ~shrface-paragraph-fill-column~ are obsolete. + +Pleas use =shr-indentation= to control the indentation, and ~shr-width~ to adjust the text width (fill-column). + +** Versatile URL +You can enable versatile URL faces support simply by: +#+BEGIN_SRC emacs-lisp +(setq shrface-href-versatile t) +#+END_SRC + +The following types of URL can be customized. + +- http +- https +- ftp +- file +- mailto +- other + +** Supported faces +Here are the faces supported: +#+BEGIN_SRC emacs-lisp + +;;; Faces for `shrface-basic + +(defcustom shrface-bullets-bullet-list + (or (bound-and-true-p org-bullets-bullet-list) + (bound-and-true-p org-superstar-headline-bullets-list) + '("◉" + "○" + "✸" + "✿")) + "Bullets for headings" + :group 'shrface + :type '(repeat (string :tag "Bullet character"))) + +(defface shrface-href-face '((t :inherit org-link)) + "Default face if `shrface-href-versatile' is nil" + :group 'shrface-faces) + +(defface shrface-href-other-face '((t :inherit org-link :foreground "#87cefa")) + "Face used for other than http:// https:// ftp:// +file:// mailto:// if `shrface-href-versatile' is NON-nil. For +example, it can be used for fontifying charter links with epub +files when using nov.el." + :group 'shrface-faces) + +(defface shrface-href-http-face '((t :inherit org-link :foreground "#39CCCC")) + "Face used for , http:// if `shrface-href-versatile' is +NON-nil" + :group 'shrface-faces) + +(defface shrface-href-https-face '((t :inherit org-link :foreground "#7FDBFF")) + "Face used for , https:// if `shrface-href-versatile' is +NON-nil" + :group 'shrface-faces) + +(defface shrface-href-ftp-face '((t :inherit org-link :foreground "#3D9970")) + "Face used for , ftp:// if `shrface-href-versatile' is +NON-nil" + :group 'shrface-faces) + +(defface shrface-href-file-face '((t :inherit org-link :foreground "#2ECC40")) + "Face used for , file:// if `shrface-href-versatile' is +NON-nil" + :group 'shrface-faces) + +(defface shrface-href-mailto-face '((t :inherit org-link :foreground "#FF851B")) + "Face used for , mailto:// if `shrface-href-versatile' is +NON-nil" + :group 'shrface-faces) + +(defface shrface-h1-face '((t :inherit org-level-1)) + "Face used for

headlines." + :group 'shrface-faces) + +(defface shrface-h2-face '((t :inherit org-level-2)) + "Face used for

headlines." + :group 'shrface-faces) + +(defface shrface-h3-face '((t :inherit org-level-3)) + "Face used for

headlines." + :group 'shrface-faces) + +(defface shrface-h4-face '((t :inherit org-level-4)) + "Face used for

headlines." + :group 'shrface-faces) + +(defface shrface-h5-face '((t :inherit org-level-5)) + "Face used for

headlines." + :group 'shrface-faces) + +(defface shrface-h6-face '((t :inherit org-level-6)) + "Face used for
headlines." + :group 'shrface-faces) + +(defface shrface-verbatim '((t :inherit org-verbatim)) + "Face used for verbatim/emphasis - ." + :group 'shrface-faces) + +(defface shrface-item-bullet-face '((t :inherit org-list-dt)) + "Face used for unordered list bullet" + :group 'shrface-faces) + +(defface shrface-item-number-face '((t :inherit org-list-dt)) + "Face used for ordered list numbers" + :group 'shrface-faces) + +(defface shrface-description-list-term-face '((t :inherit org-list-dt)) + "Face used for description list terms
" + :group 'shrface-faces) + +(defface shrface-figure '((t :inherit org-table)) + "Face used for figure
, e.g. figure captions." + :group 'shrface-faces) + +;;; Faces for `shrface-analysis' realted buffers + +(defface shrface-links-title-face '((t :inherit default)) + "Face used for *shrface-links* title" + :group 'shrface-analysis-faces) + +(defface shrface-links-url-face '((t :inherit font-lock-comment-face)) + "Face used for *shrface-links* url" + :group 'shrface-analysis-faces) + +(defface shrface-links-mouse-face '((t :inherit mode-line-highlight)) + "Face used for *shrface-links* mouse face" + :group 'shrface-analysis-faces) + +;;; Faces for `shrface-trail' realted buffers + +(defface shrface-code '((t :inherit org-code)) + "TODO Face used for inline code" + :group 'shrface-faces) +#+END_SRC + +** Export Html to Org +Exporting HTML to Org doesn't need to enable ~shrface-mode~, or run ~shrface-basic~ / ~shrface-trail~, you just make sure you ~(require 'shrface)~ before using the exporting features: + +- ~shrface-html-export-as-org~: Export current html buffer to an org buffer. +- ~shrface-html-export-to-org~: Export current html buffer to an org file. +- ~shrface-org-title~: Dynamically bound and overwrite the org title. +- ~shrface-request-url~: Dynamically bound the request url, so that ~shrface~ can fix the relative/absolute urls based on the request url. + +If you use [[https://github.com/alphapapa/org-web-tools][org-web-tools]] to download the http page into org, you can also override its pandoc +engine with shr engine as following: + +#+begin_src emacs-lisp +(advice-add 'org-web-tools--html-to-org-with-pandoc :override 'shrface-html-convert-as-org-string) +#+end_src + +Here are two simple examples to use ~shrface-html-export-as-org~, and ~shrface-html-export-to-org~, using [[https://github.com/tkf/emacs-request][Request]]. + +Download an URL and output an Org buffer/file: +#+begin_src emacs-lisp +(defun request-url-as-org (url) + (interactive "sRequest url: ") + (require 'shrface) + (require 'request) + (request url + :parser 'buffer-string + :headers '(("User-Agent" . "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")) + :sync nil + :success (cl-function + (lambda (&key data &allow-other-keys) + (let ((shrface-request-url url)) + (shrface-html-export-as-org data)))))) + +(defun request-url-to-org (url) + (interactive "sRequest url: ") + (require 'shrface) + (require 'request) + (request url + :parser 'buffer-string + :headers '(("User-Agent" . "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")) + :sync nil + :success (cl-function + (lambda (&key data &allow-other-keys) + (let ((shrface-request-url url)) + (shrface-html-export-to-org data "request.org")))))) + +#+end_src + +If you use [[https://github.com/alphapapa/org-web-tools][org-web-tools]], it is very easy to capture the web as a readable format: +#+begin_src emacs-lisp +(defun request-url-readable (url) + (interactive "sRequest url: ") + (require 'shrface) + (require 'request) + (require 'org-web-tools) + (request url + :parser 'buffer-string + :headers '(("User-Agent" . "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")) + :sync nil + :success (cl-function + (lambda (&key data &allow-other-keys) + (let* ((web (org-web-tools--eww-readable data)) + (title (car web)) + (html (cdr web)) + (shrface-org-title title) + (shrface-request-url url)) + (shrface-html-export-as-org html)))))) +#+end_src + +** Enable org-like ellipsis +To enable =shrface-ellipsis= the "three-dots" after each headline when it is +hidden just like org mode, please manually add the predefined function: +=shrface-outline-visibility-changed= to =outline-view-change-hook=, +#+begin_src emacs-lisp +(add-hook 'outline-view-change-hook 'shrface-outline-visibility-changed) +#+end_src +** Enable source codes highlight +You can install [[https://github.com/xuchunyang/shr-tag-pre-highlight.el][shr-tag-pre-highlight.el]] to enable source codes highlight and +background color. + +#+BEGIN_SRC emacs-lisp +(use-package shr-tag-pre-highlight + :ensure t + :after shr + :config + (add-to-list 'shr-external-rendering-functions + '(pre . shr-tag-pre-highlight)) + (when (version< emacs-version "26") + (with-eval-after-load 'eww + (advice-add 'eww-display-html :around + 'eww-display-html--override-shr-external-rendering-functions)))) +#+END_SRC + +*** Hacking the =shr-tag-pre-highlight.el= + +If you want to add indentation, background color, =#+BEGIN_SRC lang=, and =#+END_SRC= for, you can overwrite the function as following: + +#+BEGIN_SRC emacs-lisp +(require 'shr-tag-pre-highlight) +(add-to-list 'shr-external-rendering-functions '(pre . shrface-shr-tag-pre-highlight)) +(defun shrface-shr-tag-pre-highlight (pre) + "Highlighting code in PRE." + (let* ((shr-folding-mode 'none) + (shr-current-font 'default) + (code (with-temp-buffer + (shr-generic pre) + ;; (indent-rigidly (point-min) (point-max) 2) + (buffer-string))) + (lang (or (shr-tag-pre-highlight-guess-language-attr pre) + (let ((sym (language-detection-string code))) + (and sym (symbol-name sym))))) + (mode (and lang + (shr-tag-pre-highlight--get-lang-mode lang)))) + (shr-ensure-newline) + (shr-ensure-newline) + (setq start (point)) + (insert + (propertize (concat "#+BEGIN_SRC " lang "\n") 'face 'org-block-begin-line) + (or (and (fboundp mode) + (with-demoted-errors "Error while fontifying: %S" + (shr-tag-pre-highlight-fontify code mode))) + code) + (propertize "#+END_SRC" 'face 'org-block-end-line )) + (shr-ensure-newline) + (setq end (point)) + (if light + (add-face-text-property start end '(:background "#D8DEE9" :extend t)) + (add-face-text-property start end '(:background "#292b2e" :extend t))) + (shr-ensure-newline) + (insert "\n"))) +#+END_SRC + +Sometimes a wrong language is detected, but it is still great for highlight, even just for eye pleasing. + +**** Screenshots when both enable =shrface= and the code highlights +#+attr_org: :width 600px +[[file:img/code-highlight.png]] + diff --git a/README.org b/README.org index 5d89030..4dc44a6 100644 --- a/README.org +++ b/README.org @@ -8,7 +8,9 @@ - [[#description][Description]] - [[#installation][Installation]] - [[#configuration][Configuration]] -- [[#newslogs][News/Logs]] +- [[#features][Features]] +- [[#releases][Releases]] +- [[#contributor][Contributor]] * Description This package extends =shr= / =eww= with org features and analysis capability. It can be used in @@ -29,6 +31,7 @@ buffer/file, or download/archive web pages. + Switch/jump the headlines just like org-mode in [[https://www.gnu.org/software/emacs/manual/html_mono/eww.html][eww]] and [[https://github.com/wasamasa/nov.el][nov.el]] with =imenu= + Toggle/cycle the headlines just like org-mode in [[https://www.gnu.org/software/emacs/manual/html_mono/eww.html][eww]] and [[https://github.com/wasamasa/nov.el][nov.el]] with [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Outline-Mode.html][outline minor mode]] , =org-cycle/org-shifttab=, or =shrface-outline-cycle= / =shrface-outline-cycle-buffer=. ++ ~org-indent-mode~ support + Analysis capability: - Headline analysis: List all headlines with clickable texts, or jump around with [[https://github.com/abo-abo/swiper][ivy]]. - URL analysis: List all classified URL with clickable texts in a buffer, or jump around with @@ -55,86 +58,17 @@ M-x package-install shrface #+END_SRC * Configuration +** My Setup +Check [[file:config.el][config.el]] -** Quick Start -*** use-package -I recommend configure with ~use-package~, it is more elegant: -#+BEGIN_SRC emacs-lisp - -(use-package shrface - :defer t - :config - (shrface-basic) - (shrface-trial) - (shrface-default-keybindings) ; setup default keybindings - (setq shrface-href-versatile t)) - -(use-package eww - :defer t - :init - (add-hook 'eww-after-render-hook #'shrface-mode) - :config - (require 'shrface)) - -(use-package nov - :defer t - :init - (add-hook 'nov-mode-hook #'shrface-mode) - :config - (require 'shrface) - (setq nov-shr-rendering-functions '((img . nov-render-img) (title . nov-render-title))) - (setq nov-shr-rendering-functions (append nov-shr-rendering-functions shr-external-rendering-functions))) - -(use-package anki - :defer t - :load-path "~/.emacs.d/lisp/anki/" - :init - (add-hook 'anki-mode-hook #'shrface-mode) - (autoload 'anki "anki") - (autoload 'anki-browser "anki") - (autoload 'anki-list-decks "anki") - :config - (require 'shrface) - (setq anki-shr-rendering-functions (append anki-shr-rendering-functions shr-external-rendering-functions)) - (setq sql-sqlite-program "/usr/bin/sqlite3") - (setq anki-collection-dir "/Users/chandamon/Library/Application Support/Anki2/User 1")) -#+END_SRC - -- Check this section to see the supported faces: - #+html: Supported Faces - -- Check the experimental faces notes here: - #+html: Experimental faces - -- There is another library =inherit-org= to inherit org faces to even more non-org - buffers, and it is no dependency/relationships with =shrface=, check here - https://github.com/chenyanming/inherit-org +This file is my personal configuration for ~shrface~ and I updates it frequently. +And I configured it along with other packages. It can greatly improve your +reading experience while also having great performance when using those +packages. +You can use it as a reference to configure your own shrface. -*** Font setup -The default font is ~variable-pitch~. -#+BEGIN_SRC emacs-lisp -(set-face-attribute 'variable-pitch nil :font (format "%s:pixelsize=%d" "iA Writer Quattro S" 15)) -#+END_SRC - -** Keybinding Settings -You can to call =shrface-default-keybindings= to enable the recommended keybindings. -#+begin_src emacs-lisp -(defun shrface-default-keybindings () - (interactive) - "Sets up the default keybindings for `shrface-mode'." - (define-key shrface-mode-map (kbd "TAB") 'shrface-outline-cycle) - (define-key shrface-mode-map (kbd "") 'shrface-outline-cycle-buffer) - (define-key shrface-mode-map (kbd "C-t") 'shrface-toggle-bullets) - (define-key shrface-mode-map (kbd "C-j") 'shrface-next-headline) - (define-key shrface-mode-map (kbd "C-k") 'shrface-previous-headline) - (define-key shrface-mode-map (kbd "M-l") 'shrface-links-counsel) ; or 'shrface-links-helm or 'shrface-links-consult - (define-key shrface-mode-map (kbd "M-h") 'shrface-headline-counsel)) ; or 'shrface-headline-helm or 'shrface-headline-consult -#+end_src - -Since the keybindings may conflict with other modes, such as =nov-mode-map=, =eww-mode-map=, =mu4e-mode-map=. If you want to enable shrface's keybindings on these modes, you have to bind the functions to those maps as well. - -Here is the keybinding example: +** Keybindings Example #+BEGIN_SRC emacs-lisp (with-eval-after-load 'nov (define-key nov-mode-map (kbd "") 'shrface-outline-cycle) @@ -162,553 +96,22 @@ Here is the keybinding example: (define-key mu4e-view-mode-map (kbd "C-k") 'shrface-previous-headline) (define-key mu4e-view-mode-map (kbd "M-l") 'shrface-links-counsel) ; or 'shrface-links-helm or 'shrface-links-consult (define-key mu4e-view-mode-map (kbd "M-h") 'shrface-headline-counsel)) ; or 'shrface-headline-helm or 'shrface-headline-consult -#+END_SRC - -In additional to the keys provided by ~shrface-mode~, the following features should also work, you can test and find which fits your requirement: -*** ~org-mode~ -1. =org-cycle=, -2. =org-shifttab= -3. =org-content= -4. =org-overview= -etc. - -*** ~outline-minor-mode~ -*** ~imenu-mode~ -** Features Anatomy +;; my personaly keybindings (Doom Eamcs) +(map! :map nov-mode-map + :after nov + :g "" 'shrface-outline-cycle ;; redundant, just make sure it work + :nie "TAB" 'shrface-outline-cycle ;; redundant, just make sure it work + :nie "S-" 'shrface-outline-cycle-buffer ;; redundant, just make sure it work + :g [backtab] 'shrface-outline-cycle-buffer ;; redundant, just make sure it work + :nie "" 'shrface-outline-cycle-buffer ;; redundant, just make sure it work + :nie "C-j" 'shrface-next-headline + :nie "C-k" 'shrface-previous-headline) -*** shrface-mode -~shrface-mode~ is a minor mode that help you enable/disable the following additional features: -1. =imenu= -2. =outline-minior-mode= -3. Setup shr faces - -Please be careful, every time you run ~shrface-mode~, faces will be enable/disable globally for -all shr rendered buffers. Since I have not found a good way to enable/disable the faces per -buffer yet. - -If you want to enable shrface just when you need to, you should avoid to use ~add-hook~ like the -recommended settings above, and just enable/disable =shrface-mode= via =M-x=. - - -*** shrface-occur -List all headlines, and you can easily jump between them by -mouse click. - -*** shrface-links -List all URLs and classify them. -You can easily go to the -occurrence (Left Click/Enter), copy the URL (Middle Click) or browse the URL -(Right Click). Besides, if [[https://github.com/domtronn/all-the-icons.el][all-the-icons]] is available, web icon for each link -will be shown. - -*** shrface-links-counsel -List all URLs with =counsel=. -- The URLs are listed in order based the position on the buffer. -- The first candidate to select is the *next url* counting from the current cursor - position. In this case, you can use =C-M-m (ivy-call)=, =C-M-n - (ivy-next-line-and-call)=, and =C-M-p (ivy-previous-line-and-call)= to jump - around all URLs without losing your position. -- =C-o= to fire the action menu on the selected candidate. -- =C-c C-o= to fire the =ivy-occur= - -*** shrface-headline-counsel -List all headlines with =counsel=. -- It is a better solution than =imenu= and =shrface-occur.= -- It can work without the headline bullets. You can disable the bullets via - =(setq shrface-toggle-bullets t)= and still be able to jump around the headlines. -- The first candidate to select is the *current context headline* of the current - cursor position. In this case, you can use =C-M-m (ivy-call)=, =C-M-n - (ivy-next-line-and-call)=, and =C-M-p (ivy-previous-line-and-call)= to jump - around all headlines without losing your position. -- =C-o= to fire the action menu on the selected candidate. -- =C-c C-o= to fire the =ivy-occur= - -*** shrface-links-helm -List all URLs with =helm=. -- =TAB= to preview the link -- =RET= to goto the link - -*** shrface-headline-helm -List all headlines with =helm=. -- =TAB= to preview the headline -- =RET= to goto the headline - -*** shrface-links-consult -List all links with =consult=. - -*** shrface-headline-consult -List all headlines with =consult=. - - -*** shrface-next-headline, shrface-previous-headline -These two headline functions are designed to replace =outline-next-headline= and -=outline-previous-headline=. They scan the headline number text properties and -jump to the headlines which means it can work under no bullets circumstance if -=(setq shrface-toggle-bullets t)=. - -*** Headline bullets (h1 to h6) -**** Customize the headline bullets -You can configure your favorite bullets up to 6 levels of headings (cycled -through if less than 6 bullets in setting). - -You can set it with: -#+BEGIN_SRC emacs-lisp -(setq shrface-bullets-bullet-list ("◉" "○" "✸" "✿")) #+END_SRC +* [[file:FEATURES.org][Features]] -PS: The bullets setting can be derived from =org-bullets-bullet-list= or -=org-superstar-headline-bullets-list=, if [[https://github.com/sabof/org-bullets][org-bullets]] or [[https://github.com/integral-dw/org-superstar-mode][org-superstar]] is -available. - -**** Toggle headline bullets locally/temporary - -The quick way to toggle(disable/enable) headline bullets locally/temporary: -#+BEGIN_SRC emacs-lisp -M-x shrface-toggle-bullets -#+END_SRC - -Please notice: In =mu4e-view-mode=, using =shrface-toggle-bullets= will toggle -bullets globally. - -**** Disable headline bullets globally -If you do not like headline bullets, disable them globally by: - -#+BEGIN_SRC emacs-lisp -(setq shrface-toggle-bullets t) -#+END_SRC - -Please notice, the following features are also disabled: -1. function =shrface-occur= -2. variable =shrface-mode= - -However, the following features are still be able to use: -1. function =shrface-links= -2. function =shrface-links-counsel= -3. function =shrface-headline-counsel= -4. function =shrface-previous-headline= -5. function =shrface-next-headline= -6. function =shrface-links-helm= -7. function =shrface-headline-helm= -8. function =shrface-links-consult= -9. function =shrface-headline-consult= - -*** Item bullet -You can configure your favorite item bullet for shrface - -You can set it with: -#+BEGIN_SRC emacs-lisp -(setq shrface-item-bullet "-") -#+END_SRC - -PS: Only one type of item bullet is supported, prettified by -=shrface-item-bullet-face= - -*** Paragraph indentation and fill column -Both ~shrface-paragraph-indentation~ and ~shrface-paragraph-fill-column~ are obsolete. - -Pleas use =shr-indentation= to control the indentation, and ~shr-width~ to adjust the text width (fill-column). - -*** Versatile URL -You can enable versatile URL faces support simply by: -#+BEGIN_SRC emacs-lisp -(setq shrface-href-versatile t) -#+END_SRC - -The following types of URL can be customized. - -- http -- https -- ftp -- file -- mailto -- other - -*** Supported faces -Here are the faces supported: -#+BEGIN_SRC emacs-lisp - -;;; Faces for `shrface-basic - -(defcustom shrface-bullets-bullet-list - (or (bound-and-true-p org-bullets-bullet-list) - (bound-and-true-p org-superstar-headline-bullets-list) - '("◉" - "○" - "✸" - "✿")) - "Bullets for headings" - :group 'shrface - :type '(repeat (string :tag "Bullet character"))) - -(defface shrface-href-face '((t :inherit org-link)) - "Default face if `shrface-href-versatile' is nil" - :group 'shrface-faces) - -(defface shrface-href-other-face '((t :inherit org-link :foreground "#87cefa")) - "Face used for other than http:// https:// ftp:// -file:// mailto:// if `shrface-href-versatile' is NON-nil. For -example, it can be used for fontifying charter links with epub -files when using nov.el." - :group 'shrface-faces) - -(defface shrface-href-http-face '((t :inherit org-link :foreground "#39CCCC")) - "Face used for , http:// if `shrface-href-versatile' is -NON-nil" - :group 'shrface-faces) - -(defface shrface-href-https-face '((t :inherit org-link :foreground "#7FDBFF")) - "Face used for , https:// if `shrface-href-versatile' is -NON-nil" - :group 'shrface-faces) - -(defface shrface-href-ftp-face '((t :inherit org-link :foreground "#3D9970")) - "Face used for , ftp:// if `shrface-href-versatile' is -NON-nil" - :group 'shrface-faces) - -(defface shrface-href-file-face '((t :inherit org-link :foreground "#2ECC40")) - "Face used for , file:// if `shrface-href-versatile' is -NON-nil" - :group 'shrface-faces) - -(defface shrface-href-mailto-face '((t :inherit org-link :foreground "#FF851B")) - "Face used for , mailto:// if `shrface-href-versatile' is -NON-nil" - :group 'shrface-faces) - -(defface shrface-h1-face '((t :inherit org-level-1)) - "Face used for

headlines." - :group 'shrface-faces) - -(defface shrface-h2-face '((t :inherit org-level-2)) - "Face used for

headlines." - :group 'shrface-faces) - -(defface shrface-h3-face '((t :inherit org-level-3)) - "Face used for

headlines." - :group 'shrface-faces) - -(defface shrface-h4-face '((t :inherit org-level-4)) - "Face used for

headlines." - :group 'shrface-faces) - -(defface shrface-h5-face '((t :inherit org-level-5)) - "Face used for

headlines." - :group 'shrface-faces) - -(defface shrface-h6-face '((t :inherit org-level-6)) - "Face used for
headlines." - :group 'shrface-faces) - -(defface shrface-verbatim '((t :inherit org-verbatim)) - "Face used for verbatim/emphasis - ." - :group 'shrface-faces) - -(defface shrface-item-bullet-face '((t :inherit org-list-dt)) - "Face used for unordered list bullet" - :group 'shrface-faces) - -(defface shrface-item-number-face '((t :inherit org-list-dt)) - "Face used for ordered list numbers" - :group 'shrface-faces) - -(defface shrface-description-list-term-face '((t :inherit org-list-dt)) - "Face used for description list terms
" - :group 'shrface-faces) - -(defface shrface-figure '((t :inherit org-table)) - "Face used for figure
, e.g. figure captions." - :group 'shrface-faces) - -;;; Faces for `shrface-analysis' realted buffers - -(defface shrface-links-title-face '((t :inherit default)) - "Face used for *shrface-links* title" - :group 'shrface-analysis-faces) - -(defface shrface-links-url-face '((t :inherit font-lock-comment-face)) - "Face used for *shrface-links* url" - :group 'shrface-analysis-faces) - -(defface shrface-links-mouse-face '((t :inherit mode-line-highlight)) - "Face used for *shrface-links* mouse face" - :group 'shrface-analysis-faces) - -#+END_SRC - -*** Experimental face(s) - -#+BEGIN_SRC emacs-lisp - -;;; Faces for `shrface-trail' realted buffers - -(defface shrface-code '((t :inherit org-code)) - "TODO Face used for inline code" - :group 'shrface-faces) -#+END_SRC - -*** Export Html to Org -Exporting HTML to Org doesn't need to enable ~shrface-mode~, or run ~shrface-basic~ / ~shrface-trail~, you just make sure you ~(require 'shrface)~ before using the exporting features: - -- ~shrface-html-export-as-org~: Export current html buffer to an org buffer. -- ~shrface-html-export-to-org~: Export current html buffer to an org file. -- ~shrface-org-title~: Dynamically bound and overwrite the org title. -- ~shrface-request-url~: Dynamically bound the request url, so that ~shrface~ can fix the relative/absolute urls based on the request url. - -If you use [[https://github.com/alphapapa/org-web-tools][org-web-tools]] to download the http page into org, you can also override its pandoc -engine with shr engine as following: - -#+begin_src emacs-lisp -(advice-add 'org-web-tools--html-to-org-with-pandoc :override 'shrface-html-convert-as-org-string) -#+end_src - -Here are two simple examples to use ~shrface-html-export-as-org~, and ~shrface-html-export-to-org~, using [[https://github.com/tkf/emacs-request][Request]]. - -Download an URL and output an Org buffer/file: -#+begin_src emacs-lisp -(defun request-url-as-org (url) - (interactive "sRequest url: ") - (require 'shrface) - (require 'request) - (request url - :parser 'buffer-string - :headers '(("User-Agent" . "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")) - :sync nil - :success (cl-function - (lambda (&key data &allow-other-keys) - (let ((shrface-request-url url)) - (shrface-html-export-as-org data)))))) - -(defun request-url-to-org (url) - (interactive "sRequest url: ") - (require 'shrface) - (require 'request) - (request url - :parser 'buffer-string - :headers '(("User-Agent" . "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")) - :sync nil - :success (cl-function - (lambda (&key data &allow-other-keys) - (let ((shrface-request-url url)) - (shrface-html-export-to-org data "request.org")))))) - -#+end_src - -If you use [[https://github.com/alphapapa/org-web-tools][org-web-tools]], it is very easy to capture the web as a readable format: -#+begin_src emacs-lisp -(defun request-url-readable (url) - (interactive "sRequest url: ") - (require 'shrface) - (require 'request) - (require 'org-web-tools) - (request url - :parser 'buffer-string - :headers '(("User-Agent" . "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")) - :sync nil - :success (cl-function - (lambda (&key data &allow-other-keys) - (let* ((web (org-web-tools--eww-readable data)) - (title (car web)) - (html (cdr web)) - (shrface-org-title title) - (shrface-request-url url)) - (shrface-html-export-as-org html)))))) -#+end_src - -*** Enable org-like ellipsis -To enable =shrface-ellipsis= the "three-dots" after each headline when it is -hidden just like org mode, please manually add the predefined function: -=shrface-outline-visibility-changed= to =outline-view-change-hook=, -#+begin_src emacs-lisp -(add-hook 'outline-view-change-hook 'shrface-outline-visibility-changed) -#+end_src - -** (Optional) Enable source codes highlight -You can install [[https://github.com/xuchunyang/shr-tag-pre-highlight.el][shr-tag-pre-highlight.el]] to enable source codes highlight and -background color. - -#+BEGIN_SRC emacs-lisp -(use-package shr-tag-pre-highlight - :ensure t - :after shr - :config - (add-to-list 'shr-external-rendering-functions - '(pre . shr-tag-pre-highlight)) - (when (version< emacs-version "26") - (with-eval-after-load 'eww - (advice-add 'eww-display-html :around - 'eww-display-html--override-shr-external-rendering-functions)))) -#+END_SRC - -*** Hacking the =shr-tag-pre-highlight.el= - -If you want to add indentation, background color, =#+BEGIN_SRC lang=, and =#+END_SRC= for, you can overwrite the function as following: - -#+BEGIN_SRC emacs-lisp -(require 'shr-tag-pre-highlight) -(add-to-list 'shr-external-rendering-functions '(pre . shrface-shr-tag-pre-highlight)) -(defun shrface-shr-tag-pre-highlight (pre) - "Highlighting code in PRE." - (let* ((shr-folding-mode 'none) - (shr-current-font 'default) - (code (with-temp-buffer - (shr-generic pre) - ;; (indent-rigidly (point-min) (point-max) 2) - (buffer-string))) - (lang (or (shr-tag-pre-highlight-guess-language-attr pre) - (let ((sym (language-detection-string code))) - (and sym (symbol-name sym))))) - (mode (and lang - (shr-tag-pre-highlight--get-lang-mode lang)))) - (shr-ensure-newline) - (shr-ensure-newline) - (setq start (point)) - (insert - (propertize (concat "#+BEGIN_SRC " lang "\n") 'face 'org-block-begin-line) - (or (and (fboundp mode) - (with-demoted-errors "Error while fontifying: %S" - (shr-tag-pre-highlight-fontify code mode))) - code) - (propertize "#+END_SRC" 'face 'org-block-end-line )) - (shr-ensure-newline) - (setq end (point)) - (if light - (add-face-text-property start end '(:background "#D8DEE9" :extend t)) - (add-face-text-property start end '(:background "#292b2e" :extend t))) - (shr-ensure-newline) - (insert "\n"))) -#+END_SRC - -Sometimes a wrong language is detected, but it is still great for highlight, even just for eye pleasing. - -**** Screenshots when both enable =shrface= and the code highlights -#+attr_org: :width 600px -[[file:img/code-highlight.png]] - -* News/Logs -** TBD -- Remove =org-indent-mode= support (Because =org-indent-mode= can not work on non-org - mode at this moment) - -** =2024-03-31= -Version 2.6.4 -- Add ~shrface-links-consult~ -- Add ~shrface-headline-consult~ -- Add ~shrface-ellipsis~ and ~shrface-outline-visibility-changed~ function for - =outline-view-change-hook= - -** =2021-01-23= -Version *2.6.3*: -- Add ~shrface-html-export-as-org~ -- Add ~shrface-html-export-to-org~ -- Add ~shrface-tag-u~ -- Add ~shrface-tag-strong~ - -** =2021-01-20= -Version *2.6.2*: -- Add keys for ~shrface-mode~. -- Move settings to shrface-mode. So that we can use ~shrface-mode~ on other shr rendered buffers - via ~M-x~. - -** =2020-11-08= -Version *2.6.1*: -- Add: shrface-outline-cycle -- Add: shrface-outline-cycle-buffer - -** =2020-05-07= -Version *2.6*: -- New Function: =shrface-headline-helm= and =shrface-links-helm= - -** =2020-05-02= -Version *2.5*: -- New Function: =shrface-headline-counsel=: better solution than =imenu= to list all - headlines -- New Function: =shrface-next-headline=: better solution than - =outline-next-headline=, it can work without headline bullets -- New Function: =shrface-previous-headline=: better solution than - =outline-previous-headline=, it can work without headline bullets - -** =2020-05-01= -Version *2.4*: -- Improved: Improve the user experience for =shrface-links-counsel= -- New face: =shrface-figure= - -** =2020-04-29= -Version *2.3*: -- New customization: =shrface-toggle-bullets= Quick way to toggle the headline - bullets. - -** =2020-04-26= -Version *2.2*: -- New customization: =shrface-imenu-depth= The maximum level for Imenu access to - shrface headlines. -- New Feature: =shrface-links= and =shrface-links-counsel= The first - =shrface-analysis= feature, to list all possible URL in a new buffer. - -** =2020-04-23= -Version *2.1*: -- New Feature: =shrface-occur= -- New faces: - - =shrface-href-http-face= - - =shrface-href-https-face= - - =shrface-href-ftp-face= - - =shrface-href-file-face= - - =shrface-href-mailto-face= - - =shrface-href-other-face= - -** =2020-04-20= -Version *2.0*: -- New face: =shrface-description-list-term-face= - -** =2020-04-19= -Version *1.9*: -- New Functions: =shrface-basic= and =shrface-trail= - -** =2020-04-18= -Version *1.8*: -- New face: =shrface-item-number-face= -- New Minor Mode: =shrface-mode= - -** =2020-04-17= -Version *1.7*: -- New feature: =shrface-item-bullet= -- New face: =shrface-item-bullet-face= - -Version *1.6*: -- New feature: =org-indent-mode= support (Enabled by default) - -** =2020-04-16= -Version *1.5*: -- New feature: =outline minior mode= support (Enabled by default, but not the keybindings) - -** =2020-04-15= -Version *1.4*: -- New feature: =imenu= support - -** =2020-04-13= -Version *1.3*: -- New face: =shrface-code= (Experimental face, disabled by default) - -** =2020-04-12= -Version *1.2*: -- New face: =shrface-verbatim= - -** =2020-04-11= -Version *1.1*: -- Fixed bug: Wrong indentation handling make some items in paragraph disappear - (such as images) +* [[file:RELEASES.org][Releases]] -** =2020-04-10= -Version *1.0*: -- New face: =shrface-bullets-bullet-list= -- New face: =shrface-h1-face= -- New face: =shrface-h2-face= -- New face: =shrface-h3-face= -- New face: =shrface-h4-face= -- New face: =shrface-h5-face= -- New face: =shrface-h6-face= -- New face: =shrface-h6-face= -- New face: =shrface-href-face= -- New customizable variable: =shrface-paragraph-indentation= -- New customizable variable: =shrface-paragraph-fill-column= +* Contributor +#+html: diff --git a/RELEASES.org b/RELEASES.org new file mode 100644 index 0000000..cd5bdd5 --- /dev/null +++ b/RELEASES.org @@ -0,0 +1,124 @@ +#+title: Releases +#+STARTUP: nofold +* RELEASES +** =2024-03-31= +Version 2.6.4 +- Add ~shrface-links-consult~ +- Add ~shrface-headline-consult~ +- Add ~shrface-ellipsis~ and ~shrface-outline-visibility-changed~ function for + =outline-view-change-hook= + +** =2021-01-23= +Version *2.6.3*: +- Add ~shrface-html-export-as-org~ +- Add ~shrface-html-export-to-org~ +- Add ~shrface-tag-u~ +- Add ~shrface-tag-strong~ + +** =2021-01-20= +Version *2.6.2*: +- Add keys for ~shrface-mode~. +- Move settings to shrface-mode. So that we can use ~shrface-mode~ on other shr rendered buffers + via ~M-x~. + +** =2020-11-08= +Version *2.6.1*: +- Add: shrface-outline-cycle +- Add: shrface-outline-cycle-buffer + +** =2020-05-07= +Version *2.6*: +- New Function: =shrface-headline-helm= and =shrface-links-helm= + +** =2020-05-02= +Version *2.5*: +- New Function: =shrface-headline-counsel=: better solution than =imenu= to list all + headlines +- New Function: =shrface-next-headline=: better solution than + =outline-next-headline=, it can work without headline bullets +- New Function: =shrface-previous-headline=: better solution than + =outline-previous-headline=, it can work without headline bullets + +** =2020-05-01= +Version *2.4*: +- Improved: Improve the user experience for =shrface-links-counsel= +- New face: =shrface-figure= + +** =2020-04-29= +Version *2.3*: +- New customization: =shrface-toggle-bullets= Quick way to toggle the headline + bullets. + +** =2020-04-26= +Version *2.2*: +- New customization: =shrface-imenu-depth= The maximum level for Imenu access to + shrface headlines. +- New Feature: =shrface-links= and =shrface-links-counsel= The first + =shrface-analysis= feature, to list all possible URL in a new buffer. + +** =2020-04-23= +Version *2.1*: +- New Feature: =shrface-occur= +- New faces: + - =shrface-href-http-face= + - =shrface-href-https-face= + - =shrface-href-ftp-face= + - =shrface-href-file-face= + - =shrface-href-mailto-face= + - =shrface-href-other-face= + +** =2020-04-20= +Version *2.0*: +- New face: =shrface-description-list-term-face= + +** =2020-04-19= +Version *1.9*: +- New Functions: =shrface-basic= and =shrface-trail= + +** =2020-04-18= +Version *1.8*: +- New face: =shrface-item-number-face= +- New Minor Mode: =shrface-mode= + +** =2020-04-17= +Version *1.7*: +- New feature: =shrface-item-bullet= +- New face: =shrface-item-bullet-face= + +Version *1.6*: +- New feature: =org-indent-mode= support (Enabled by default) + +** =2020-04-16= +Version *1.5*: +- New feature: =outline minior mode= support (Enabled by default, but not the keybindings) + +** =2020-04-15= +Version *1.4*: +- New feature: =imenu= support + +** =2020-04-13= +Version *1.3*: +- New face: =shrface-code= (Experimental face, disabled by default) + +** =2020-04-12= +Version *1.2*: +- New face: =shrface-verbatim= + +** =2020-04-11= +Version *1.1*: +- Fixed bug: Wrong indentation handling make some items in paragraph disappear + (such as images) + +** =2020-04-10= +Version *1.0*: +- New face: =shrface-bullets-bullet-list= +- New face: =shrface-h1-face= +- New face: =shrface-h2-face= +- New face: =shrface-h3-face= +- New face: =shrface-h4-face= +- New face: =shrface-h5-face= +- New face: =shrface-h6-face= +- New face: =shrface-h6-face= +- New face: =shrface-href-face= +- New customizable variable: =shrface-paragraph-indentation= +- New customizable variable: =shrface-paragraph-fill-column= diff --git a/config.el b/config.el new file mode 100644 index 0000000..f67fa6a --- /dev/null +++ b/config.el @@ -0,0 +1,383 @@ +;;; config.el --- shrface configs -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Damon Chan + +;; Author: Damon Chan +;; URL: https://github.com/chenyanming/shrface +;; Keywords: faces +;; Created: 10 April 2020 +;; Version: 2.6.4 +;; Package-Requires: ((emacs "25.1") (org "9.0") (language-detection "0.1.0")) + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; This file is my personal configuration for shrface. +;; You can use it as a reference to configure your own shrface. + +(use-package shrface + :defer t + :config + (setq shr-cookie-policy nil) + (if (string-equal system-type "android") + (setq shrface-bullets-bullet-list + '("▼" + "▾" + "▿" + "▾")) + (setq shrface-bullets-bullet-list + '("▼" + "▽" + "▿" + "▾" + ) + ) + ) + + + (add-hook 'outline-view-change-hook 'shrface-outline-visibility-changed) + + (require 'shr-tag-pre-highlight) + (setq shr-tag-pre-highlight-lang-modes + '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist) + ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql) + ("calc" . fundamental) ("C" . c) ("cpp" . c++) ("C++" . c++) + ("screen" . shell-script) ("shell" . sh) ("bash" . sh) + ("rust" . rustic) + ("rust" . rustic) + ("awk" . bash) + ("json" . "js") + ;; Used by language-detection.el + ("emacslisp" . emacs-lisp) + ;; Used by Google Code Prettify + ("el" . emacs-lisp))) + + (defun shrface-shr-tag-pre-highlight (pre) + "Highlighting code in PRE." + (let* ((shr-folding-mode 'none) + (shr-current-font 'default) + (code (with-temp-buffer + (shr-generic pre) + ;; (indent-rigidly (point-min) (point-max) 2) + (buffer-string))) + (lang (or (shr-tag-pre-highlight-guess-language-attr pre) + (let ((sym (language-detection-string code))) + (and sym (symbol-name sym))))) + (mode (and lang + (shr-tag-pre-highlight--get-lang-mode lang)))) + (shr-ensure-newline) + (shr-ensure-newline) + (setq start (point)) + (insert + ;; (propertize (concat "#+BEGIN_SRC " lang "\n") 'face 'org-block-begin-line) + (or (and (fboundp mode) + (with-demoted-errors "Error while fontifying: %S" + (shr-tag-pre-highlight-fontify code mode))) + code) + ;; (propertize "#+END_SRC" 'face 'org-block-end-line ) + ) + (shr-ensure-newline) + (setq end (point)) + (pcase (frame-parameter nil 'background-mode) + ('light + (add-face-text-property start end '(:background "#D8DEE9" :extend t))) + ('dark + (add-face-text-property start end '(:background "#292b2e" :extend t)))) + (shr-ensure-newline) + (insert "\n")))) + +(use-package calibredb + :defer t + :config + (advice-add 'calibredb-show-entry :around #'shrface-calibredb-advice) + (defun shrface-calibredb-advice (orig-fun &rest args) + (require 'eww) + (let ((shrface-org nil) + (shr-bullet (concat (char-to-string shrface-item-bullet) " ")) + (shr-width 60) + (shr-indentation 3) + (shr-table-vertical-line "|") + (shr-external-rendering-functions + (append '((title . eww-tag-title) + (form . eww-tag-form) + (input . eww-tag-input) + (button . eww-form-submit) + (textarea . eww-tag-textarea) + (select . eww-tag-select) + (link . eww-tag-link) + (meta . eww-tag-meta) + ;; (a . eww-tag-a) + (code . shrface-tag-code) + (pre . shrface-shr-tag-pre-highlight)) + shrface-supported-faces-alist)) + (shrface-toggle-bullets nil) + (shrface-href-versatile t) + (shr-use-fonts nil)) + (apply orig-fun args)))) + +(use-package eww + :defer t + :config + (require 'shrface) + (advice-add 'eww-display-html :around #'shrface-eww-advice) + (add-hook 'eww-after-render-hook #'org-indent-mode) + (add-hook 'eww-after-render-hook #'eldoc-mode) + (add-hook 'eww-after-render-hook #'eldoc-box-hover-mode) + (add-hook 'eww-after-render-hook #'shrface-eww-setup) + (defun shrface-eww-setup () + (unless shrface-toggle-bullets + (shrface-regexp) + (setq-local imenu-create-index-function #'shrface-imenu-get-tree)) + ;; (add-function :before-until (local 'eldoc-documentation-function) #'paw-get-eldoc-note) + ;; workaround to show annotations in eww + (when (bound-and-true-p paw-annotation-mode) + (paw-clear-annotation-overlay) + (paw-show-all-annotations) )) + + (defun shrface-eww-advice (orig-fun &rest args) + (require 'eww) + (let ((shrface-org nil) + (shr-bullet (concat (char-to-string shrface-item-bullet) " ")) + (shr-table-vertical-line "|") + (shr-width 65) + (shr-indentation 0) + (shr-external-rendering-functions + (append '((title . eww-tag-title) + (form . eww-tag-form) + (input . eww-tag-input) + (button . eww-form-submit) + (textarea . eww-tag-textarea) + (select . eww-tag-select) + (link . eww-tag-link) + (meta . eww-tag-meta) + ;; (a . eww-tag-a) + (code . shrface-tag-code) + (pre . shrface-shr-tag-pre-highlight)) + shrface-supported-faces-alist)) + (shrface-toggle-bullets nil) + (shrface-href-versatile t) + (shr-use-fonts nil)) + (apply orig-fun args)))) + +(use-package anki + :defer t + :config + (add-hook 'anki-mode-hook #'org-indent-mode) + (advice-add 'anki-render-html :around #'shrface-anki-advice) + (advice-add 'anki-render-region :around #'shrface-anki-advice) + (add-hook 'anki-mode-hook #'eldoc-mode) + (add-hook 'anki-mode-hook #'eldoc-box-hover-mode) + (add-hook 'anki-mode-hook #'shrface-anki-setup) + + (defun shrface-anki-setup () + (unless shrface-toggle-bullets + (shrface-regexp) + (setq-local imenu-create-index-function #'shrface-imenu-get-tree)) + ;; (add-function :before-until (local 'eldoc-documentation-function) #'paw-get-eldoc-note) + ) + + (defun shrface-anki-advice (orig-fun &rest args) + (require 'eww) + (let ((shrface-org nil) + (shr-bullet (concat (char-to-string shrface-item-bullet) " ")) + (shr-table-vertical-line "") + (shr-width 90) + (shr-indentation 3) + (anki-shr-rendering-functions + (append '((img . anki-render-img) + (pre . shrface-shr-tag-pre-highlight) + (code . shrface-tag-code) + (form . eww-tag-form) + (input . eww-tag-input) + (button . eww-form-submit) + (textarea . eww-tag-textarea) + (select . eww-tag-select) + (link . eww-tag-link) + (meta . eww-tag-meta)) + shrface-supported-faces-alist)) + (shrface-toggle-bullets nil) + (shrface-href-versatile t)) + (apply orig-fun args)))) + +(use-package nov + :defer t + :config + (add-hook 'nov-mode-hook #'eldoc-mode) + (add-hook 'nov-mode-hook #'org-indent-mode) + (add-hook 'nov-mode-hook #'eldoc-box-hover-mode) + (add-hook 'nov-mode-hook #'shrface-nov-setup) + (require 'shrface) + (setq nov-render-html-function #'my-nov-render-html) + (advice-add 'my-nov-visit-relative-file :override #'nov-visit-relative-file)) + +(defun my-nov-render-html () + (require 'eww) + (let ((shrface-org nil) + (shr-bullet (concat (char-to-string shrface-item-bullet) " ")) + (shr-table-vertical-line "|") + ;; make it large enough, it would not fill the column + ;; I uses visual-line-mode, writeroom-mode for improving the reading experience instead + (shr-width (if (string-equal system-type "android") 700 700)) + (shr-indentation (if (string-equal system-type "android") 0 0)) ;; remove all unnecessary indentation + (tab-width 8) + (shr-external-rendering-functions + (append '((img . nov-render-img) + ;; (title . nov-render-title) + (pre . shrface-shr-tag-pre-highlight) + (code . shrface-tag-code) + (form . eww-tag-form) + (input . eww-tag-input) + (button . eww-form-submit) + (textarea . eww-tag-textarea) + (select . eww-tag-select) + (link . eww-tag-link) + (meta . eww-tag-meta)) + shrface-supported-faces-alist)) + (shrface-toggle-bullets nil) + (shrface-href-versatile t) + (shr-use-fonts nil) ; nil to use default font + (shr-map nov-mode-map)) + + ;; HACK: `shr-external-rendering-functions' doesn't cover + ;; every usage of `shr-tag-img' + (cl-letf (((symbol-function 'shr-tag-img) 'nov-render-img)) + (shr-render-region (point-min) (point-max))) + + ;; workaround, show annotations when document updates + (when (bound-and-true-p paw-annotation-mode) + (paw-clear-annotation-overlay) + (paw-show-all-annotations) ))) + +(defun shrface-nov-setup () + (unless shrface-toggle-bullets + (shrface-regexp)) + (set-visited-file-name nil t) + (setq tab-width 8) + (if (string-equal system-type "android") + (setq-local touch-screen-enable-hscroll nil)) + ;; (add-function :before-until (local 'eldoc-documentation-function) #'paw-get-eldoc-note) + ) + +(defun my-nov-visit-relative-file (filename target) + "Visit the document as specified by FILENAME and TARGET." + (let (index) + (when (not (zerop (length filename))) + (let* ((current-path (cdr (aref nov-documents nov-documents-index))) + (directory (file-name-directory current-path)) + (path (file-truename (nov-make-path directory (file-name-nondirectory filename )))) + (match (nov-find-document + (lambda (doc) (equal path (file-truename (cdr doc))))))) + (when (not match) + (error "Couldn't locate document")) + (setq index match))) + (let ((shr-target-id target)) + (nov-goto-document (or index nov-documents-index)))) + (when target + (let ((pos (next-single-property-change (point-min) 'shr-target-id))) + (when (not pos) + (error "Couldn't locate target")) + (goto-char pos) + (recenter (1- (max 1 scroll-margin)))))) + + +(use-package wallabag + :defer t + :config + (add-hook 'wallabag-entry-mode-hook #'org-indent-mode) + (add-hook 'wallabag-entry-mode-hook #'eldoc-mode) + (add-hook 'wallabag-entry-mode-hook #'eldoc-box-hover-mode) + (add-hook 'wallabag-entry-mode-hook #'shrface-wallabag-setup) + + ;; (advice-add 'wallabag-show-entry :after #'(lambda (&rest args) + ;; (interactive) + ;; (if (cadr (imenu--make-index-alist t)) + ;; (imenu-list-noselect)))) + + (advice-add 'wallabag-entry-quit :after #'(lambda (&rest args) + (interactive) + (if (get-buffer "*Ilist*") + (kill-buffer "*Ilist*")))) + + (require 'shrface) + + (defun shrface-wallabag-setup () + (unless shrface-toggle-bullets + (shrface-regexp) + (setq-local imenu-create-index-function #'shrface-imenu-get-tree)) + (if (string-equal system-type "android") + (setq-local touch-screen-enable-hscroll nil)) + ;; (add-function :before-until (local 'eldoc-documentation-function) #'paw-get-eldoc-note) + ) + + (setq wallabag-render-html-function #'my-wallabag-render-html) + (defun my-wallabag-render-html (begin end) + (require 'eww) + (let ((shrface-org nil) + (shr-bullet (concat (char-to-string shrface-item-bullet) " ")) + ;; make it large enough, it would not fill the column + ;; I uses visual-line-mode, writeroom-mode for improving the reading experience instead + (shr-width (if (string-equal system-type "android") 700 700)) + (shr-indentation (if (string-equal system-type "android") 0 0)) + (shr-table-vertical-line "|") + (shr-external-rendering-functions + (append '((title . eww-tag-title) + (form . eww-tag-form) + (input . eww-tag-input) + (button . eww-form-submit) + (textarea . eww-tag-textarea) + (select . eww-tag-select) + (link . eww-tag-link) + (meta . eww-tag-meta) + ;; (a . eww-tag-a) + (code . shrface-tag-code) + (pre . shrface-shr-tag-pre-highlight)) + shrface-supported-faces-alist)) + (shrface-toggle-bullets nil) + (shrface-href-versatile t) + (shr-use-fonts nil)) + (shr-render-region begin end)) + ;; workaround, show annotations when document updates + (when (bound-and-true-p paw-annotation-mode) + (paw-clear-annotation-overlay) + (paw-show-all-annotations) ))) + +(use-package mu4e + :defer t + :config + (advice-add 'mu4e-shr2text :around #'shrface-mu4e-advice) + (defun shrface-mu4e-advice (orig-fun &rest args) + (require 'eww) + (let ((shrface-org nil) + (shr-bullet (concat (char-to-string shrface-item-bullet) " ")) + (shr-table-vertical-line "") + (shr-width 90) + (shr-indentation 3) + (shr-external-rendering-functions + (append '((title . eww-tag-title) + (form . eww-tag-form) + (input . eww-tag-input) + (button . eww-form-submit) + (textarea . eww-tag-textarea) + (select . eww-tag-select) + (link . eww-tag-link) + (meta . eww-tag-meta) + ;; (a . eww-tag-a) + (code . shrface-tag-code) + (pre . shrface-shr-tag-pre-highlight)) + shrface-supported-faces-alist)) + (shrface-toggle-bullets nil) + (shrface-href-versatile t) + (shr-use-fonts nil)) + (apply orig-fun args)))) diff --git a/shrface.el b/shrface.el index 091e1f4..32de1b7 100644 --- a/shrface.el +++ b/shrface.el @@ -131,7 +131,7 @@ The following features are also disabled: :group 'shrface :type 'boolean) -(defcustom shrface-ellipsis "..." +(defcustom shrface-ellipsis "…" "The ellipsis to use in the shrface headlines." :group 'shrface :type 'string)