summaryrefslogtreecommitdiffhomepage
path: root/custom
diff options
context:
space:
mode:
Diffstat (limited to 'custom')
-rw-r--r--custom/jao-custom-blog.el225
-rw-r--r--custom/jao-custom-completion.el425
-rw-r--r--custom/jao-custom-email.el318
-rw-r--r--custom/jao-custom-eww.el272
-rw-r--r--custom/jao-custom-exwm.el535
-rw-r--r--custom/jao-custom-gnus.el767
-rw-r--r--custom/jao-custom-notmuch.el657
-rw-r--r--custom/jao-custom-org.el314
-rw-r--r--custom/jao-custom-w3m.el211
9 files changed, 3724 insertions, 0 deletions
diff --git a/custom/jao-custom-blog.el b/custom/jao-custom-blog.el
new file mode 100644
index 0000000..a11c5c0
--- /dev/null
+++ b/custom/jao-custom-blog.el
@@ -0,0 +1,225 @@
+;; -*- lexical-binding: t -*-
+
+;;; Vars and setup
+(jao-load-path "org-static-blog")
+(when (> emacs-major-version 26) (use-package htmlize :ensure t))
+(defvar jao-blog-base-dir "~/doc/jao.io")
+(defun jao-blog-dir (p) (expand-file-name p jao-blog-base-dir))
+
+(setq jao-org-blog-tag-files
+ (seq-difference (directory-files (jao-blog-dir "blog") nil "tag-.*")
+ "tag-norss.html")
+
+ jao-org-blog-tags
+ (mapcar (lambda (f)
+ (string-match "tag-\\(.+\\)\\.html" f)
+ (format "<a href=\"/blog/%s\">%s</a>"
+ f (match-string 1 f)))
+ jao-org-blog-tag-files)
+
+ jao-org-blog-tag-rss
+ (mapcar (lambda (f)
+ (string-match "\\(.+\\)-rss\\.xml" f)
+ (format "<a href=\"/blog/%s\">%s</a>"
+ f (match-string 1 f)))
+ (directory-files (jao-blog-dir "blog") nil ".*-rss.xml"))
+
+ jao-org-blog-tag-names
+ (mapcar (lambda (f)
+ (string-match "tag-\\(.+\\)\\.html" f)
+ (match-string 1 f))
+ jao-org-blog-tag-files))
+
+;;; Header
+(setq org-static-blog-page-header
+ (concat
+ "<meta name=\"author\" content=\"jao\">\n"
+ "<meta name=\"referrer\" content=\"no-referrer\">\n"
+ "<link rel=\"stylesheet\" href=\"/static/style.css\""
+ " type=\"text/css\">\n"
+ "<link rel=\"apple-touch-icon\" sizes=\"180x180\""
+ " href=\"/static/apple-touch-icon.png\" >\n"
+ "<link rel=\"icon\" type=\"image/png\""
+ " sizes=\"32x32\" href=\"/static/favicon-32x32.png\">\n"
+ "<link rel=\"icon\" type=\"image/png\""
+ " sizes=\"16x16\" href=\"/static/favicon-16x16.png\">\n"
+ "<link rel=\"icon\" href=\"/static/favicon.ico\">\n"
+ "<link rel=\"manifest\" href=\"/static/site.webmanifest\">\n")
+
+ org-static-blog-page-preamble
+ (concat
+ "<div class=\"header\">"
+ " <a href=\"https://jao.io\">programming (and other) musings</a>"
+ " <div class=\"sitelinks\">"
+ " <a href=\"/blog/about.html\">about</a>"
+ " | <a href=\"/blog/hacking.html\">hacking</a>"
+ " | <a href=\"/blog/archive.html\">archive</a>"
+ " | <div class=\"dropdown\">"
+ " <a href=\"/blog/tags.html\" class=\"dropbtn\">tags</a>"
+ " <div class=\"dropdown-content\">"
+ (mapconcat #'identity jao-org-blog-tags "")
+ " </div>"
+ " </div>"
+ " | <div class=\"dropdown\">"
+ " <a href=\"/blog/rss.xml\" class=\"dropbtn\">rss</a>"
+ " <div class=\"dropdown-content\">"
+ (mapconcat #'identity jao-org-blog-tag-rss "")
+ " </div>"
+ " </div>"
+ " </div>"
+ "</div>"))
+
+;;; Footer
+(setq org-static-blog-page-postamble
+ (with-temp-buffer
+ (insert-file-contents "~/.emacs.d/commons.html")
+ (buffer-string)))
+
+;;; Package
+(use-package org-static-blog
+ :ensure t
+ :init
+ (setq org-static-blog-use-preview t
+ org-static-blog-preview-link-p t
+ org-static-blog-preview-start "<!-- preview-start -->"
+ org-static-blog-preview-end "<!-- preview-end -->"
+ org-static-blog-preview-date-first-p t
+ org-static-blog-index-length 30
+ org-static-blog-preview-convert-titles t
+ org-static-blog-preview-ellipsis "more ..."
+ org-static-blog-enable-tags t
+ org-static-blog-tags-file "tags.html"
+ org-static-blog-rss-file "rss.xml"
+ org-static-blog-publish-url "https://jao.io/blog/"
+ org-static-blog-publish-title "programming (and other) musings"
+ org-static-blog-posts-directory (jao-blog-dir "posts/")
+ org-static-blog-drafts-directory (jao-blog-dir "pages/")
+ org-static-blog-publish-directory (jao-blog-dir "blog/")
+ org-static-blog-rss-extra "" ; "<author>mail@jao.io</author>\n"
+ org-static-blog-rss-max-entries 30
+ org-static-blog-rss-excluded-tag "norss"
+ org-static-blog-enable-tag-rss t
+ org-export-with-toc nil
+ org-export-with-section-numbers nil)
+
+ :config
+ (defun jao-org-static-post-path (pf dt)
+ (cond ((string-match-p "pages/.*\\|in-no-particular-order" pf)
+ (file-name-nondirectory pf))
+ ((string-match-p "drafts/.*" pf) pf)
+ ((string-match-p "^[[:digit:]]+-.*" pf) pf)
+ (t (concat (format-time-string "%Y-%m-%d-" dt)
+ (file-name-nondirectory pf)))))
+ (advice-add 'org-static-blog-generate-post-path :override
+ #'jao-org-static-post-path)
+
+ :bind (:map org-mode-map (("C-c B" . jao-transient-org-blog))))
+
+;;; New entries
+(defun jao-org-blog-publish-file (fname)
+ (interactive (list (read-file-name "Publish: "
+ nil
+ (buffer-file-name)
+ t
+ (buffer-file-name))))
+ (let ((geiser-active-implementations '(guile))
+ (geiser-default-implementation 'guile)
+ (whitespace-style nil))
+ (org-static-blog-publish-file fname)))
+
+(defconst jao-org-static-blog--prev-beg "#+html: <!-- preview-start -->")
+
+(defconst jao-org-static-blog--prev-end "#+html: <!-- preview-end -->")
+
+(defun jao-org-static-blog-create-new-post (&optional draft)
+ (interactive)
+ (let* ((title (read-string "Title: "))
+ (file (replace-regexp-in-string "\s" "-" (downcase title)))
+ (tags (completing-read-multiple "Tags: " jao-org-blog-tag-names)))
+ (find-file (expand-file-name (concat file ".org")
+ (if draft
+ org-static-blog-drafts-directory
+ org-static-blog-posts-directory)))
+ (insert "#+title: " title "\n"
+ "#+date: " (format-time-string "<%Y-%m-%d %H:%M>") "\n"
+ "#+filetags: "
+ (mapconcat #'identity tags " ")
+ "\n\n")
+ (when (member "books" tags)
+ (insert jao-org-static-blog--prev-beg "\n\n[[../img/" file ".jpg]]\n\n"))
+ (save-excursion (insert jao-org-static-blog--prev-end "\n"))))
+
+;;; Drafts
+(defun jao-org-static-blog-update-date ()
+ (interactive)
+ (when (y-or-n-p "Update date? ")
+ (goto-char (point-min))
+ (when (re-search-forward "^#\\+date: " nil t)
+ (delete-line)
+ (insert (format-time-string "<%Y-%m-%d %H:%M>"))
+ (save-buffer))))
+
+(defun jao-org-static-blog-create-new-draft ()
+ (interactive)
+ (jao-org-static-blog-create-new-post t))
+
+(defun jao-org-static-blog-publish-draft ()
+ (interactive)
+ (let* ((from (read-file-name "Post: "
+ org-static-blog-drafts-directory
+ nil t))
+ (to (expand-file-name (file-name-nondirectory from)
+ org-static-blog-posts-directory)))
+ (rename-file from to)
+ (when-let ((b (get-buffer from)))
+ (kill-buffer b))
+ (find-file to)
+ (jao-org-static-blog-update-date)
+ (when (y-or-n-p "Generate HTML? ")
+ (jao-org-blog-publish))))
+
+(defun jao-org-static-blog-edit-draft ()
+ (interactive)
+ (find-file (read-file-name "Edit: "
+ org-static-blog-drafts-directory
+ nil
+ t)))
+
+;;; Publish
+(defun jao-org-blog-publish (&optional force)
+ (interactive "P")
+ (let ((geiser-active-implementations '(guile))
+ (geiser-default-implementation 'guile)
+ (whitespace-style nil))
+ (org-static-blog-publish force)))
+
+(defun jao-org-blog-republish ()
+ (interactive)
+ (jao-org-blog-publish t))
+
+;;; Transient
+(defun jao-org-static-prev-begin ()
+ (interactive)
+ (insert jao-org-static-blog--prev-beg))
+
+(defun jao-org-static-prev-end ()
+ (interactive)
+ (insert jao-org-static-blog--prev-end))
+
+(transient-define-prefix jao-transient-org-blog ()
+ [["Insert blog snippet"
+ ("s" "preview begin" jao-org-static-prev-begin)
+ ("S" "preview end" jao-org-static-prev-end)
+ ("T" "update date" jao-org-static-blog-update-date)]
+ ["Edit blog"
+ ("n" "create post" jao-org-static-blog-create-new-post)
+ ("d" "create draft" jao-org-static-blog-create-new-draft)
+ ("e" "edit draft" jao-org-static-blog-edit-draft)]
+ ["Publish blog"
+ ("D" "publish draft" jao-org-static-blog-publish-draft)
+ ("f" "publish single file" jao-org-blog-publish-file)
+ ("p" "publish all" jao-org-blog-publish)
+ ("r" "republish" jao-org-blog-republish)]])
+
+;;; .
+(provide 'jao-custom-blog)
diff --git a/custom/jao-custom-completion.el b/custom/jao-custom-completion.el
new file mode 100644
index 0000000..b44f9b6
--- /dev/null
+++ b/custom/jao-custom-completion.el
@@ -0,0 +1,425 @@
+;; -*- lexical-binding: t; -*-
+
+;;; builtin completion
+(setq tab-always-indent 'complete
+ read-extended-command-predicate #'command-completion-default-include-p
+ completion-auto-select 'second-tab
+ completion-auto-help 'always
+ completion-category-defaults nil
+ completion-cycle-threshold 4
+ completions-detailed t
+ completions-header-format nil
+ completion-ignore-case t
+ completion-show-help nil
+ completion-show-inline-help t
+ completions-format 'one-column
+ completion-styles '(basic substring partial-completion emacs22)
+ completion-category-overrides
+ '((file (styles partial-completion))
+ (command (styles initials substring partial-completion))
+ (symbol (styles initials substring partial-completion))
+ (variable (styles initials substring partial-completion)))
+ completion-wrap-movement t)
+
+;;; crm indicator
+(defun jao-completion--crm-indicator (args)
+ "Add prompt indicator to `completing-read-multiple' filter ARGS."
+ (cons (concat "[CRM] " (car args)) (cdr args)))
+
+(advice-add #'completing-read-multiple
+ :filter-args #'jao-completion--crm-indicator)
+
+;;; orderless
+(use-package orderless
+ :ensure t
+ :demand t
+ :config
+ (orderless-define-completion-style orderless+initialism
+ (orderless-matching-styles '(orderless-initialism
+ orderless-prefixes
+ orderless-literal
+ orderless-regexp)))
+ (defvar jao-orderless-overrides
+ '((file (styles partial-completion orderless))
+ (command (styles orderless+initialism))))
+
+ (setq orderless-matching-styles
+ '(orderless-literal orderless-regexp orderless-prefixes)))
+
+;;; marginalia
+(use-package marginalia
+ :ensure t
+ :bind (:map minibuffer-local-map ("C-M-a" . marginalia-cycle))
+
+ :custom ((marginalia-align 'left)
+ (marginalia-align-offset 1)
+ (marginalia-field-width 200)
+ (marginalia-annotators
+ '(marginalia-annotators-heavy marginalia-annotators-light nil))
+ (marginalia-separator " ")))
+
+(marginalia-mode 1)
+
+;;; vertico
+(use-package vertico
+ :ensure t
+ :init
+ (defvar jao-vertico-reverse t)
+
+ (setq vertico-count 20
+ vertico-cycle t
+ vertico-resize t
+ vertico-multiform-categories nil
+ vertico-multiform-commands
+ `((".*"
+ (completion-styles orderless basic)
+ (completion-category-overrides . ,jao-orderless-overrides)))
+ vertico-buffer-display-action
+ `(display-buffer-below-selected (window-height . 0.5)))
+
+ (dolist (c '(completion-at-point complete-symbol indent-for-tab-command))
+ (let ((s `(,c buffer (vertico-resize) (jao-vertico-reverse))))
+ (add-to-list 'vertico-multiform-commands s)))
+
+ :config
+ (defun jao-vertico--display (fun lines)
+ (if (not jao-vertico-reverse)
+ (funcall fun lines)
+ (move-overlay vertico--candidates-ov (point-min) (point-min))
+ (overlay-put vertico--candidates-ov 'after-string (apply #'concat lines))
+ (vertico--resize-window (length lines))))
+
+ (advice-add 'vertico--display-candidates :around #'jao-vertico--display))
+
+(use-package vertico-directory
+ :after vertico
+ :bind (:map vertico-map (("RET" . vertico-directory-enter)
+ ("M-<backspace>" . vertico-directory-delete-word)
+ ("<backspace>" . vertico-directory-delete-char)
+ ("DEL" . vertico-directory-delete-char))))
+
+(vertico-mode)
+(vertico-multiform-mode)
+
+;;; consult
+;;;; package
+(use-package consult
+ :ensure t
+ :bind (("C-x M-:" . consult-complex-command)
+ ("C-x b" . consult-buffer)
+ ("C-x C-b" . consult-buffer)
+ ("C-x 4 b" . consult-buffer-other-window)
+ ("C-c b" . project-find-file)
+ ("C-c h" . nil)
+ ("C-c i" . consult-imenu)
+ ("C-c I" . consult-project-imenu)
+ ("C-h I" . consult-info)
+ ;; ("C-c o" . consult-outline)
+ ("C-c k" . consult-ripgrep)
+ ("C-c L" . consult-locate)
+ ("C-c s" . consult-line)
+ ("C-x r x" . consult-register)
+ ("C-x r b" . consult-bookmark)
+ ("C-x C-f" . jao-find-file)
+ ("M-g b" . consult-bookmark)
+ ("M-g m" . consult-mark)
+ ("M-g e" . consult-error)
+ ("M-s m" . consult-multi-occur)
+ ("M-y" . consult-yank-pop)
+ ("C-s" . isearch-forward)
+ ("<help> a" . consult-apropos))
+
+ :custom ((consult-preview-key (kbd "`")))
+
+ :init
+ (fset 'multi-occur #'consult-multi-occur)
+ (setq org-refile-use-outline-path t
+ org-imenu-depth 7)
+
+ :config
+ (defun jao-consult--completion-in-region (&rest args)
+ (apply (if (and (not (bound-and-true-p corfu-mode))
+ (not (bound-and-true-p company-mode))
+ (bound-and-true-p vertico-mode))
+ #'consult-completion-in-region
+ #'completion--in-region)
+ args))
+
+ (setq completion-in-region-function #'jao-consult--completion-in-region)
+
+ (defun jao-find-file (arg)
+ (interactive "P")
+ (call-interactively (if arg 'consult-file-externally 'find-file)))
+
+ (define-key consult-narrow-map (vconcat consult-narrow-key "?")
+ #'consult-narrow-help)
+
+ (with-eval-after-load "esh-mode"
+ (define-key eshell-mode-map (kbd "C-c h") #'consult-history))
+
+ (with-eval-after-load "comint"
+ (define-key comint-mode-map (kbd "C-c h") #'consult-history))
+
+ (consult-customize consult-mark :preview-key 'any)
+ (add-hook 'completion-list-mode-hook #'consult-preview-at-point-mode))
+
+;;;; consult-dir
+;; (use-package consult-dir
+;; :ensure t
+;; :bind (("C-x C-d" . consult-dir)
+;; :map minibuffer-local-completion-map
+;; (("C-x C-d" . consult-dir)
+;; ("C-x C-j" . consult-dir-jump-file))))
+
+;;;; narrow helpers
+(defvar jao-consult-narrow nil)
+
+(defun jao-consult-initial-narrow ()
+ (when-let (c (cond ((eq this-command #'consult-buffer)
+ (cdr (assoc (jao-afio-frame-name) jao-consult-narrow)))
+ ((eq this-command #'consult-mode-command) ?m)))
+ (setq unread-command-events (append unread-command-events `(,c 32)))))
+
+(add-hook 'minibuffer-setup-hook #'jao-consult-initial-narrow)
+
+(defmacro jao-consult--mode-buffers (&rest modes)
+ `(lambda ()
+ (seq-map #'buffer-name
+ (seq-filter (lambda (b)
+ (with-current-buffer b
+ (derived-mode-p ,@modes)))
+ (buffer-list)))))
+
+(defun jao-consult-add-buffer-source (src &optional aframe key)
+ (add-to-list 'consult-buffer-sources src t)
+ (when (and aframe key)
+ (add-to-list 'jao-consult-narrow (cons aframe key))))
+
+;;; embark
+;;;; package
+(use-package embark
+ :ensure t
+ :demand t
+ :init
+ (setq embark-quit-after-action nil
+ embark-indicators '(embark-mixed-indicator
+ ;; embark-minimal-indicator
+ embark-highlight-indicator
+ embark-isearch-highlight-indicator)
+ embark-mixed-indicator-both t
+ embark-mixed-indicator-delay 1
+ embark-verbose-indicator-buffer-sections '(bindings)
+ embark-verbose-indicator-excluded-commands
+ '(embark-become embark-export embark-collect)
+ embark-verbose-indicator-nested t
+ embark-verbose-indicator-display-action
+ '((display-buffer-at-bottom)
+ (window-parameters (mode-line-format . none))
+ (window-height . fit-window-to-buffer)))
+
+ ;; (setq prefix-help-command #'describe-prefix-bindings)
+ ;; (add-to-list 'vertico-multiform-categories '(embark-keybinding grid))
+
+ :bind (("C-;" . embark-act)
+ ("C-c ;" . embark-act)
+ ("C-'" . embark-dwim)
+ ("C-c '" . embark-dwim)
+ (:map minibuffer-local-map
+ (("C-'" . embark-dwim)
+ ("C-c '" . embark-dwim)
+ ("C-," . embark-become)
+ ("C-c ," . embark-become)
+ ("C-o" . embark-export)))))
+
+(use-package embark-consult
+ :ensure t
+ :after (embark consult))
+
+(with-eval-after-load 'consult
+ (with-eval-after-load 'embark
+ (require 'embark-consult)))
+
+;;;; randomsig
+(defun jao-random-sig-read (_ignored)
+ "Import region as signature and edit it."
+ (randomsig-message-read-sig t))
+
+(define-key embark-region-map "m" #'jao-random-sig-read)
+(define-key embark-region-map "M" #'apply-macro-to-region-lines)
+
+;;;; dict/say
+(defun jao-say (&optional word)
+ "Isn't it nice to have a computer that can talk to you?"
+ (interactive "sWhat? ")
+ (shell-command-to-string (format "say %s" word))
+ "")
+
+(define-key embark-identifier-map "D" #'dictionary-search)
+(define-key embark-identifier-map "S" #'jao-say)
+
+;;;; org targets
+(declare-function org-link-any-re "ol")
+(declare-function org-open-link-from-string "ol")
+(declare-function org-in-regexp "org-macs")
+
+(defun jao-embark-targets--org-link ()
+ (when (derived-mode-p 'org-mode)
+ (let ((lnk (org-element-property :raw-link (org-element-context))))
+ (and lnk (cons 'org-link lnk)))))
+
+(defun jao-embark-targets--gl-org-link ()
+ (when (org-in-regexp org-link-bracket-re)
+ (cons 'gl-org-link (match-string-no-properties 0))))
+
+(defvar jao-embark-targets-gl-org-link-map
+ (define-keymap "RET" #'org-open-at-point-global))
+
+(defvar jao-embark-targets-org-link-map
+ (define-keymap "RET" #'org-open-link-from-string))
+
+(add-to-list 'embark-target-finders #'jao-embark-targets--gl-org-link)
+(add-to-list 'embark-keymap-alist
+ '(gl-org-link . jao-embark-targets-gl-org-link-map))
+
+(add-to-list 'embark-target-finders #'jao-embark-targets--org-link)
+(add-to-list 'embark-keymap-alist
+ '(org-link . jao-embark-targets-org-link-map))
+
+;;;; url targets
+(declare-function w3m-anchor "w3m")
+
+(defun jao-embark-targets--w3m-anchor ()
+ (when (not (region-active-p))
+ (when-let ((url (or (jao-url-around-point)
+ (thing-at-point 'url)
+ (and (derived-mode-p 'w3m-mode)
+ (or (w3m-anchor) w3m-current-url))
+ (and (derived-mode-p 'eww-mode)
+ (eww-current-url)))))
+ (when (string-match-p "^https?.*" url)
+ (cons 'url url)))))
+
+(add-to-list 'embark-target-finders #'jao-embark-targets--w3m-anchor)
+
+(defun jao-embark-url (url)
+ "Browse URL, externally if we're already in an emacs browser."
+ (if (derived-mode-p 'w3m-mode 'eww-mode)
+ (jao-browse-with-external-browser url)
+ (browse-url url)))
+
+(define-key embark-url-map (kbd "RET") #'jao-embark-url)
+(define-key embark-url-map (kbd "f") #'browse-url-firefox)
+(define-key embark-url-map (kbd "x") #'jao-rss-subscribe)
+(define-key embark-url-map (kbd "m") 'jao-browse-with-external-browser)
+(define-key embark-url-map (kbd "p") 'jao-mpc-add-or-play-url)
+
+;;;; video url targets
+(defvar jao-embark-targets-video-sites
+ '("youtu.be" "youtube.com" "blip.tv" "vimeo.com" "infoq.com"))
+
+(defun jao-embark--video-url-rx (&optional sites)
+ (format "^https?://\\(?:www\\.\\)?%s/.+"
+ (regexp-opt (or sites jao-embark-targets-video-sites) t)))
+
+(defvar jao-embark-targets-video-url-rx (jao-embark--video-url-rx)
+ "A regular expression matching URLs that point to video streams")
+
+(defun jao-embark-targets--refine-url (_ url)
+ (if (string-match-p jao-embark-targets-video-url-rx url)
+ (cons 'video-url url)
+ (cons 'url url)))
+
+(defun jao-embark-targets--play-video (player url)
+ (interactive "sURL: ")
+ (let ((cmd (format "%s %s" player (shell-quote-argument url))))
+ (jao-afio-goto-www)
+ (start-process-shell-command player nil cmd)))
+
+(defun jao-embark-targets-mpv (&optional url)
+ "Play video stream with mpv"
+ (interactive "sURL: ")
+ (jao-embark-targets--play-video "mpv" url))
+
+(defun jao-embark-targets-vlc (&optional url)
+ "Play video stream with vlc"
+ (interactive "sURL: ")
+ (jao-embark-targets--play-video "vlc" url))
+
+(defvar jao-embark-targets-video-url-map
+ (define-keymap "v" #'jao-embark-targets-mpv "RET" #'jao-embark-targets-mpv)
+ "Actions on URLs pointing to remote video streams.")
+
+(add-to-list 'embark-transformer-alist '(url . jao-embark-targets--refine-url))
+(add-to-list 'embark-keymap-alist '(video-url . jao-embark-targets-video-url-map))
+(define-key embark-url-map "v" #'jao-embark-targets-vlc)
+(define-key embark-url-map "V" #'jao-embark-targets-vlc)
+
+;;;; vc targets
+
+
+;;; avy
+(use-package avy
+ :ensure t
+ :init (setq avy-style 'pre
+ avy-background t
+ avy-timeout-seconds 0.6
+ avy-single-candidate-jump t)
+
+ :config
+
+ (defun avy-embark-act (pt)
+ "Use Embark to act on the completion at PT."
+ (save-excursion
+ (goto-char pt)
+ (embark-act)))
+ (add-to-list 'avy-dispatch-alist '(?\; . avy-embark-act))
+
+ :bind (("s-j" . avy-goto-char-timer)
+ ("C-M-j" . avy-goto-char-timer)))
+
+;;; link-hint
+(use-package link-hint
+ :ensure t
+ :init (setq link-hint-avy-style 'pre
+ link-hint-message nil)
+
+ :config
+ (defun jao-link-hint-open-link-ext ()
+ (interactive)
+ (let ((jao-browse-url-function jao-browse-url-external-function))
+ (link-hint-open-link)))
+
+ :bind (("C-l" . link-hint-open-link)
+ ("C-M-l" . jao-link-hint-open-link-ext)
+ ("C-S-l" . jao-link-hint-open-link-ext)
+ ("C-x C-l" . recenter-top-bottom)))
+
+(with-eval-after-load "notmuch"
+ (defun jao-link-hint--notmuch-next-part (&optional bound)
+ (when-let (p (next-single-property-change (point) :notmuch-part nil bound))
+ (and (< p (or bound (point-max))) p)))
+
+ (defun jao-link-hint--notmuch-part-p ()
+ (and (get-text-property (point) :notmuch-part)
+ (when-let (b (button-at (point))) (button-label b))))
+
+ (link-hint-define-type 'notmuch-part
+ :next #'jao-link-hint--notmuch-next-part
+ :at-point-p #'jao-link-hint--notmuch-part-p
+ :vars '(notmuch-show-mode)
+ :open #'push-button
+ :open-message "Toggled"
+ :open-multiple t)
+
+ (push 'link-hint-notmuch-part link-hint-types))
+
+;;; xref
+(setq xref-show-definitions-function #'xref-show-definitions-completing-read)
+
+;; (use-package dumb-jump
+;; :ensure t
+;; :after xref
+;; :config (add-hook 'xref-backend-functions #'dumb-jump-xref-activate))
+
+;;; .
+(provide 'jao-custom-completion)
diff --git a/custom/jao-custom-email.el b/custom/jao-custom-email.el
new file mode 100644
index 0000000..a3d1a92
--- /dev/null
+++ b/custom/jao-custom-email.el
@@ -0,0 +1,318 @@
+;; -*- lexical-binding: t; -*-
+
+;;; main email system
+(require 'jao-afio)
+(setq jao-afio-mail-function 'gnus)
+;; (setq jao-afio-mail-function 'notmuch)
+
+(defvar jao-notmuch-enabled (eq jao-afio-mail-function 'notmuch))
+
+;;; personal emails and others
+(defvar jao-mails)
+(defvar jao-extra-mails)
+(defvar jao-mails-regexp (regexp-opt jao-mails))
+
+;;; gnus
+(setq gnus-init-file "~/.emacs.d/gnus.el"
+ gnus-home-directory "~/.emacs.d/gnus"
+ gnus-directory gnus-home-directory
+ gnus-cache-directory (expand-file-name "cache" gnus-home-directory)
+ gnus-kill-files-directory (expand-file-name "News" gnus-home-directory)
+ message-directory (expand-file-name "Mail" gnus-home-directory)
+ mail-source-directory (expand-file-name "Mail" gnus-home-directory))
+;;; proton
+(use-package jao-proton-utils)
+
+;;; message mode
+;;;; customization
+(setq message-send-mail-function 'message-send-mail-with-sendmail
+ message-sendmail-envelope-from 'header
+ message-sendmail-f-is-evil nil)
+(setq imap-store-password t)
+(setq password-cache-expiry nil)
+(setq message-generate-headers-first t)
+(setq message-forward-before-signature nil)
+(setq message-alternative-emails
+ (regexp-opt (append jao-mails jao-extra-mails)))
+(setq message-dont-reply-to-names
+ (regexp-opt (append jao-mails '("noreply@" "@noreply"
+ "no-reply@" "@no-reply"
+ "notifications@github"))))
+(setq message-citation-line-format "On %a, %b %d %Y, %N wrote:\n")
+(setq message-citation-line-function 'message-insert-formatted-citation-line)
+
+(setq message-user-fqdn "mail.jao.io")
+
+(setq message-kill-buffer-on-exit t)
+(setq message-max-buffers 5)
+(setq message-insert-signature t)
+(setq message-from-style 'angles
+ user-mail-address (car jao-mails)
+ mail-host-address system-name
+ message-syntax-checks '((sender . disabled))
+ message-default-headers
+ (concat
+ "X-Attribution: jao\n"
+ "X-Clacks-Overhead: GNU Terry Pratchett\n"
+ "X-URL: <https://jao.io/>\n")
+ message-hidden-headers
+ '("^References:" "^Face:" "^X-Face:" "^X-Draft-From:")
+ message-make-forward-subject-function 'message-forward-subject-fwd)
+
+(setq message-expand-name-standard-ui t)
+
+;;;; adjust bcc
+(defvar jao-message--bcc-alist
+ `((,(regexp-quote "mail@jao.io") . "proton@jao.io")
+ (,(regexp-quote "jao@gnu.org") . "hacking@jao.io")))
+
+(defun jao-message-insert-bcc ()
+ (when jao-notmuch-enabled
+ (let ((f (or (message-fetch-field "From") "")))
+ (when-let (b (seq-some (lambda (x) (when (string-match-p (car x) f) (cdr x)))
+ jao-message--bcc-alist))
+ (insert "Bcc: " b "\n")))))
+
+;; (when jao-notmuch-enabled
+;; (add-hook 'message-header-setup-hook #'jao-message-insert-bcc))
+
+;;;; to->from
+(defvar jao-message-to-from nil)
+
+(defun jao-message-adjust-from ()
+ (let ((to (concat (message-fetch-field "To") (message-fetch-field "Cc"))))
+ (when-let* ((tf (seq-find (lambda (tf) (string-match-p (car tf) to))
+ jao-message-to-from))
+ (from (message-make-from "Jose A Ortega Ruiz" (cdr tf))))
+ (save-restriction
+ (widen)
+ (message-replace-header "From" from)))))
+
+(when jao-notmuch-enabled
+ (add-hook 'message-header-setup-hook #'jao-message-adjust-from))
+
+;;;; encryption
+(setq gnutls-min-prime-bits nil)
+(setq gnus-buttonized-mime-types
+ '("multipart/encrypted" "multipart/signed" "multipart/alternative"))
+
+(setq mm-verify-option 'always)
+(setq mm-decrypt-option 'always)
+
+(setq mm-sign-option 'guided)
+(setq mm-encrypt-option 'guided)
+
+(setq mml-secure-passphrase-cache-expiry (* 3600 24)
+ password-cache-expiry (* 3600 24))
+
+(setq smime-CA-directory "/etc/ssl/certs/"
+ smime-certificate-directory
+ (expand-file-name "certs/" gnus-directory))
+
+(with-eval-after-load "mm-decode"
+ ;; Tells Gnus to inline the part
+ (add-to-list 'mm-inlined-types "application/pgp$")
+ ;; Tells Gnus how to display the part when it is requested
+ (add-to-list 'mm-inline-media-tests '("application/pgp$"
+ mm-inline-text identity))
+ ;; Tell Gnus not to wait for a request, just display the thing
+ ;; straight away.
+ (add-to-list 'mm-automatic-display "application/pgp$")
+ ;; But don't display the signatures, please.
+ (setq mm-automatic-display (remove "application/pgp-signature"
+ mm-automatic-display)))
+
+;; decide whether to encrypt or just sign outgoing messages
+(defvar jao-message-try-sign nil)
+(defun jao-message-maybe-sign ()
+ (when (and jao-message-try-sign (y-or-n-p "Sign message? "))
+ (if (y-or-n-p "Encrypt message? ")
+ (let ((recipient (message-fetch-field "To")))
+ (if (or (pgg-lookup-key recipient)
+ (and (y-or-n-p (format "Fetch %s's key? " recipient))
+ (pgg-fetch-key pgg-default-keyserver-address
+ recipient)))
+ (mml-secure-message-encrypt-pgp)
+ (mml-secure-message-sign-pgp)))
+ (mml-secure-message-sign-pgp))))
+
+;; for ma gnus
+(eval-after-load "rfc2047"
+ '(add-to-list 'rfc2047-header-encoding-alist
+ '("User-Agent" . address-mime)))
+
+;;;; check attachment
+(defvar jao-message-attachment-regexp "\\([Ww]e send\\|[Ii] send\\|attach\\)")
+(defun jao-message-check-attachment ()
+ "Check if there is an attachment in the message if I claim it."
+ (save-excursion
+ (message-goto-body)
+ (when (search-forward-regexp jao-message-attachment-regexp nil t nil)
+ (message-goto-body)
+ (unless (or (search-forward "<#part" nil t nil)
+ (message-y-or-n-p
+ "No attachment. Send the message? " nil nil))
+ (error "No message sent")))))
+
+;;;; check fcc/gcc
+(defun jao-message-check-gcc ()
+ "Ask whether to keep a copy of message."
+ (save-excursion
+ (save-restriction
+ (message-narrow-to-headers)
+ (when (and (or (message-fetch-field "Gcc")
+ (message-fetch-field "Fcc"))
+ (not (y-or-n-p "Archive? ")))
+ (message-remove-header "\\(?:[BFG]cc\\)")))))
+
+;;;; check recipient
+(defun jao-message-check-recipient ()
+ (save-excursion
+ (save-restriction
+ (message-narrow-to-headers)
+ (when-let ((to (message-fetch-field "To")))
+ (when (string-match-p jao-mails-regexp to)
+ (unless (y-or-n-p "Message is addressed to yourself. Continue?")
+ (error "Message not sent")))))))
+
+;;;; randomsig
+(with-eval-after-load "message"
+ (when (require 'randomsig nil t)
+ (define-key message-mode-map (kbd "C-c s") 'randomsig-replace-sig)
+ (define-key message-mode-map (kbd "C-c S") 'randomsig-select-sig)
+ (setq randomsig-dir (expand-file-name "~/etc/config/emacs"))
+ (setq randomsig-files '("signatures.txt"))
+ ;; or (setq randomsig-files (randomsig-search-sigfiles))
+ ;; or (setq randomsig-files 'randomsig-search-sigfiles)
+ (setq message-signature 'randomsig-signature)
+ (setq randomsig-delimiter-pattern "^%$"
+ randomsig-delimiter "%")))
+
+;;;; send mail hooks
+(dolist (h '(jao-message-check-gcc
+ jao-message-check-recipient
+ jao-message-maybe-sign))
+ (add-hook 'message-send-hook h))
+
+(unless jao-notmuch-enabled
+ (add-hook 'message-send-hook #'jao-message-check-attachment))
+
+;;;; keybindings
+(with-eval-after-load "message"
+ ;; (define-key message-mode-map [f7] 'mml-secure-message-sign-pgp)
+ (define-key message-mode-map [f8] 'mml-secure-message-encrypt-pgp)
+ (define-key message-mode-map (kbd "C-c y") #'yank-media))
+
+;;; sendmail/smtp
+(defun jao-sendmail-gmail ()
+ (setq smtpmail-auth-supported '(login cram-md5 plain))
+ (setq smtpmail-smtp-server "smtp.gmail.com")
+ (setq smtpmail-smtp-service 587))
+
+(defun jao-sendmail-local ()
+ (setq send-mail-function 'sendmail-send-it)
+ (setq smtpmail-auth-supported nil) ;; (cram-md5 plain login)
+ (setq smtpmail-servers-requiring-authorization nil)
+ (setq smtpmail-smtp-user nil)
+ (setq smtpmail-smtp-server "127.0.0.1")
+ (setq smtpmail-smtp-service 25))
+
+(defun jao-sendmail-msmtp ()
+ (setq send-mail-function 'sendmail-send-it
+ sendmail-program "/usr/bin/msmtp"
+ mail-specify-envelope-from t
+ message-sendmail-envelope-from 'header
+ mail-envelope-from 'header))
+
+(jao-sendmail-local)
+
+;;; bbdb
+;; (jao-load-path "bbdb/lisp")
+(use-package bbdb
+ :ensure t
+ :init (setq bbdb-complete-name-allow-cycling t
+ bbdb-completion-display-record nil
+ bbdb-gui t
+ bbdb-message-all-addresses t
+ bbdb-complete-mail-allow-cycling t
+ bbdb-north-american-phone-numbers-p nil
+ bbdb-add-aka t
+ bbdb-add-name 2
+ bbdb-message-all-addresses t
+ bbdb-mua-pop-up t ;; 'horiz
+ bbdb-mua-pop-up-window-size 0.3
+ bbdb-layout 'multi-line
+ bbdb-mua-update-interactive-p '(query . create)
+ bbdb-mua-auto-update-p 'bbdb-select-message
+ bbdb-user-mail-address-re jao-mails-regexp
+ bbdb-auto-notes-ignore-headers
+ `(("From" . ,jao-mails-regexp)
+ ("From" . ".*@.*github\.com.*")
+ ("To" . ".*@.*github\.com.*")
+ ("Reply-to" . ".*")
+ ("References" . ".*"))
+ bbdb-auto-notes-ignore-messages
+ `(("To" . ".*@.*github\\.com.*")
+ ("From" . ".*@.*github\\.com.*")
+ ("From" . "info-list")
+ ("From" . "no-?reply\\|deploy")
+ ("X-Mailer" . "MailChimp"))
+ bbdb-accept-message-alist
+ `(("To" . ,jao-mails-regexp)
+ ("Cc" . ,jao-mails-regexp)
+ ("BCc" . ,jao-mails-regexp))
+ bbdb-ignore-message-alist bbdb-auto-notes-ignore-messages)
+ :config
+ (add-hook 'message-setup-hook 'bbdb-mail-aliases)
+ ;; (add-hook 'bbdb-notice-mail-hook 'bbdb-auto-notes)
+ (add-hook 'bbdb-after-change-hook (lambda (arg) (bbdb-save)))
+ (require 'bbdb-anniv) ;; BBDB 3.x this gets birthdays in org agenda and diary
+ (add-hook 'diary-list-entries-hook 'bbdb-anniv-diary-entries)
+
+ (setq bbdb-file (expand-file-name "~/.emacs.d/bbdb"))
+ (if jao-notmuch-enabled
+ (bbdb-initialize 'message 'notmuch)
+ (bbdb-initialize 'message 'pgp 'gnus)))
+
+;; (load "bbdb-loaddefs")
+
+;;; narrowing
+(defvar jao-mail-consult-buffer-history nil)
+
+(defun jao-mail-buffer-p (b)
+ (or (member (buffer-name b)
+ '("*Calendar*" "inbox.org" "*Org Agenda*"
+ "*Fancy Diary Entries*" "diary"))
+ (with-current-buffer b
+ (derived-mode-p 'notmuch-show-mode
+ 'notmuch-search-mode
+ 'notmuch-tree-mode
+ 'notmuch-hello-mode
+ 'notmuch-message-mode
+ 'gnus-group-mode
+ 'gnus-summary-mode
+ 'gnus-article-mode
+ 'message-mode))))
+
+(defvar jao-mail-consult-source
+ (list :name "mail buffer"
+ :category 'buffer
+ :hidden t
+ :narrow (cons ?n "mail buffer")
+ :history 'jao-mail-consult-buffer-history
+ :action (lambda (b)
+ (when (not (string-blank-p (or b "")))
+ (jao-afio-goto-mail)
+ (if (get-buffer-window b)
+ (pop-to-buffer b)
+ (pop-to-buffer-same-window b))))
+ :items (lambda ()
+ (mapcar #'buffer-name
+ (seq-filter #'jao-mail-buffer-p (buffer-list))))))
+
+(jao-consult-add-buffer-source 'jao-mail-consult-source)
+
+(require 'jao-custom-notmuch)
+
+;;; .
+(provide 'jao-custom-email)
diff --git a/custom/jao-custom-eww.el b/custom/jao-custom-eww.el
new file mode 100644
index 0000000..0409fc5
--- /dev/null
+++ b/custom/jao-custom-eww.el
@@ -0,0 +1,272 @@
+;; -*- lexical-binding: t -*-
+
+;;; integration with browse-url and afio
+(defun jao-eww-browse-url (url &rest _r)
+ "Browse URL using eww."
+ (if (derived-mode-p 'eww-mode)
+ (eww url)
+ (jao-afio-goto-www)
+ (select-window (frame-first-window))
+ (let* ((url (url-encode-url url))
+ (bf (seq-find `(lambda (b)
+ (with-current-buffer b
+ (string= ,url
+ (url-encode-url (eww-current-url)))))
+ (jao-eww-session-eww-buffers))))
+ (cond (bf (switch-to-buffer bf))
+ ((string-match-p url "^file://") (eww-open-file url))
+ (t (eww url 4))))))
+
+(setq jao-browse-url-function #'jao-eww-browse-url)
+(setq eww-use-browse-url "^\\(gemini\\|gopher\\):")
+
+;;; multipart html renderer
+(defun jao-shr-html-renderer (handle)
+ (let ((fill-column nil)
+ (shr-width 150)
+ (shr-max-width 150))
+ (mm-shr handle)))
+
+(setq mm-text-html-renderer #'jao-shr-html-renderer)
+
+;;; opening URLs
+(defun jao-eww-copy-link ()
+ (interactive)
+ (when-let (lnk (or (car (eww-links-at-point)) (eww-current-url)))
+ (message "%s" lnk)
+ (kill-new lnk)))
+
+(defun jao-eww-browse (arg)
+ (interactive "P" eww-mode)
+ (setq eww-prompt-history
+ (cl-remove-duplicates eww-prompt-history :test #'string=))
+ (let ((url (completing-read (if arg "eww in new buffer: " "eww: ")
+ eww-prompt-history nil nil nil
+ 'eww-prompt-history (eww-current-url))))
+ (eww url (when arg 4))))
+
+(defun jao-eww-browse-new ()
+ (interactive nil eww-mode)
+ (jao-eww-browse t))
+
+(defun jao-eww-reload (images)
+ (interactive "P" eww-mode)
+ (if images
+ (let ((shr-blocked-images nil))
+ (eww-reload t))
+ (call-interactively 'eww-reload)))
+
+;;; consult narrowing
+(with-eval-after-load "consult"
+ (defvar jao-eww-consult-history nil)
+ (defvar jao-eww-buffer-source
+ (list :name "eww buffer"
+ :category 'eww-buffer
+ :hidden t
+ :narrow (cons ?e "eww")
+ :annotate (lambda (c) (get-text-property 0 'url c))
+ :history 'jao-eww-consult-history
+ :action (lambda (b)
+ (jao-afio-goto-www)
+ (switch-to-buffer (get-text-property 0 'buffer b)))
+ :items
+ (lambda ()
+ (seq-map (lambda (b)
+ (with-current-buffer b
+ (let ((tl (or (plist-get eww-data :title) ""))
+ (url (or (eww-current-url) (buffer-name))))
+ (propertize (if (string-blank-p tl) url tl)
+ 'buffer b 'url url))))
+ (seq-filter #'jao-www--buffer-p (buffer-list))))))
+ (jao-consult-add-buffer-source 'jao-eww-buffer-source))
+
+;;; images
+(defun jao-eww-next-image ()
+ (interactive nil eww-mode)
+ (when-let (p (text-property-search-forward 'image-displayer nil nil t))
+ (goto-char (prop-match-beginning p))))
+
+;;; close page and reopen
+(defvar jao-eww--closed-urls ())
+
+(defun jao-eww-close ()
+ (interactive nil eww-mode)
+ (when-let (current (eww-current-url))
+ (add-to-list 'jao-eww--closed-urls current))
+ (let ((nxt (car (jao-eww-session-invisible-buffers))))
+ (kill-current-buffer)
+ (when nxt (switch-to-buffer nxt nil t))))
+
+(defun jao-eww-reopen (arg)
+ (interactive "P")
+ (if (> (length jao-eww--closed-urls) 0)
+ (let ((url (completing-read "URL: " jao-eww--closed-urls)))
+ (jao-afio-goto-www)
+ (setq jao-eww--closed-urls (remove url jao-eww--closed-urls))
+ (eww url (when arg 4)))
+ (message "No previously closed URLs.")))
+
+(defun jao-eww-reopen-new ()
+ (interactive)
+ (jao-eww-reopen t))
+
+;;; sessions
+(use-package jao-eww-session
+ :custom ((jao-eww-session-file "~/.emacs.d/cache/eww-session.eld")))
+
+;;; eww to org
+(defun jao-eww-to-org (&optional dest)
+ (interactive)
+ (unless (org-region-active-p)
+ (let ((shr-width 80)) (eww-readable)))
+ (let* ((start (if (org-region-active-p) (region-beginning) (point-min)))
+ (end (if (org-region-active-p) (region-end) (point-max)))
+ (buff (or dest (generate-new-buffer "*eww-to-org*")))
+ (link (eww-current-url))
+ (title (or (plist-get eww-data :title) "")))
+ (with-current-buffer buff
+ (insert "#+title: " title "\n#+link: " link "\n\n")
+ (org-mode))
+ (save-excursion
+ (goto-char start)
+ (while (< (point) end)
+ (let* ((p (point))
+ (props (text-properties-at p))
+ (k (seq-find (lambda (x) (plist-get props x))
+ '(shr-url image-url outline-level face)))
+ (prop (and k (list k (plist-get props k))))
+ (next (if prop
+ (next-single-property-change p (car prop) nil end)
+ (next-property-change p nil end)))
+ (txt (buffer-substring (point) next))
+ (txt (replace-regexp-in-string "\\*" "ยท" txt)))
+ (with-current-buffer buff
+ (insert
+ (pcase prop
+ ((and (or `(shr-url ,url) `(image-url ,url))
+ (guard (string-match-p "^http" url)))
+ (let ((tt (replace-regexp-in-string "\n\\([^$]\\)" " \\1" txt)))
+ (org-link-make-string url tt)))
+ (`(outline-level ,n)
+ (concat (make-string (- (* 2 n) 1) ?*) " " txt "\n"))
+ ('(face italic) (format "/%s/ " (string-trim txt)))
+ ('(face bold) (format "*%s* " (string-trim txt)))
+ (_ txt))))
+ (goto-char next))))
+ (pop-to-buffer buff)
+ (goto-char (point-min))))
+
+;;; rdrview
+;; https://jiewawa.me/2024/04/another-way-of-integrating-mozilla-readability-in-emacs-eww/
+(define-minor-mode eww-rdrview-mode
+ "Toggle whether to use `rdrview' to make eww buffers more readable."
+ :lighter " R"
+ (if eww-rdrview-mode
+ (progn
+ (setq eww-retrieve-command '("rdrview" "-T" "title,sitename,body" "-H"))
+ (add-hook 'eww-after-render-hook #'eww-rdrview-update-title))
+ (progn
+ (setq eww-retrieve-command nil)
+ (remove-hook 'eww-after-render-hook #'eww-rdrview-update-title))))
+
+(defun eww-rdrview-update-title ()
+ "Change title key in `eww-data' with first line of buffer.
+It should be the title of the web page as returned by `rdrview'"
+ (save-excursion
+ (goto-char (point-min))
+ (plist-put eww-data :title (string-trim (thing-at-point 'line t))))
+ (eww--after-page-change))
+
+(defun eww-rdrview-toggle-and-reload ()
+ "Toggle `eww-rdrview-mode' and reload page in current eww buffer."
+ (interactive)
+ (if eww-rdrview-mode (eww-rdrview-mode -1)
+ (eww-rdrview-mode 1))
+ (eww-reload))
+;;; package
+(use-package shr
+ :custom ((shr-width nil)
+ (shr-use-colors t)
+ (shr-use-fonts nil)
+ (shr-max-width 160)
+ (shr-blocked-images nil)
+ (shr-inhibit-images t)
+ (shr-max-image-proportion 0.8)
+ (shr-hr-line ?โ€•)))
+
+(use-package eww
+ :demand t
+ :custom ((eww-browse-url-new-window-is-tab nil)
+ (eww-download-directory jao-sink-dir)
+ (eww-header-line-format " %u")
+ (eww-form-checkbox-selected-symbol "โ˜’")
+ (eww-buffer-name-length 180)
+ (eww-readable-urls '("guardian\\.co\\.uk"
+ "theguardian\\.com"
+ "eldiario\\.es"
+ "theconversation")))
+
+ :config
+ (with-eval-after-load "org" (require 'ol-eww nil t))
+
+ (defun jao-eww-buffer-name ()
+ (when-let ((s (or (plist-get eww-data :title)
+ (plist-get eww-data :url))))
+ (when (not (string-blank-p s)) (format "%s" s))))
+ (setq eww-auto-rename-buffer #'jao-eww-buffer-name)
+
+ (defun jao-eww-readable (rdrview)
+ (interactive "P" eww-mode)
+ (if rdrview
+ (eww-rdrview-toggle-and-reload)
+ (eww-readable)))
+
+ :bind (:map eww-mode-map (("b" . eww-back-url)
+ ("B" . eww-forward-url)
+ ("d" . jao-download)
+ ("f" . link-hint-open-link)
+ ("F" . embark-on-link)
+ ("L" . eww-forward-url)
+ ("N" . jao-eww-next-image)
+ ("o" . jao-eww-browse)
+ ("O" . jao-eww-browse-new)
+ ("r" . jao-eww-reload)
+ ("R" . jao-eww-readable)
+ ("s" . eww-search-words)
+ ("S" . jao-eww-browse-new)
+ ("T" . jao-mastodon-toot-url)
+ ("u" . jao-eww-reopen)
+ ("U" . jao-eww-reopen-new)
+ ("w" . jao-eww-to-org)
+ ("q" . jao-eww-close)
+ ("x" . jao-rss-subscribe)
+ ("y" . jao-eww-copy-link)
+ ("\\" . eww-view-source)
+ ("C-c C-w" . jao-eww-close)
+ ("M-i" . eww-toggle-images))))
+
+;;; fixes for shr image rendering
+(require 'shr)
+
+(defun jao-shr--kill-nl (p)
+ (save-excursion
+ (goto-char p)
+ (when (looking-at-p "\n") (delete-char 1))))
+
+(defun jao-shr-tag-img (fn &rest args)
+ (let ((p (point)))
+ (prog1 (apply fn args)
+ (when (> (point) p) (jao-shr--kill-nl p)))))
+
+(defun jao-shr-insert (fn &rest args)
+ (let ((p (when (and (not (bolp))
+ (get-text-property (1- (point)) 'image-url))
+ (point))))
+ (prog1 (apply fn args)
+ (when (and p (> (point) p)) (jao-shr--kill-nl p)))))
+
+(advice-add 'shr-tag-img :around #'jao-shr-tag-img)
+(advice-add 'shr-insert :around #'jao-shr-insert)
+
+;;; .
+(provide 'jao-custom-eww)
diff --git a/custom/jao-custom-exwm.el b/custom/jao-custom-exwm.el
new file mode 100644
index 0000000..d90eeda
--- /dev/null
+++ b/custom/jao-custom-exwm.el
@@ -0,0 +1,535 @@
+;; -*- lexical-binding: t; -*-
+
+(require 'jao-pdf)
+
+;;; Load and basic config
+(defvar jao-exwm--use-afio t)
+
+;; (jao-load-path "exwm")
+
+(use-package exwm
+ :ensure t
+ :demand t
+ :init (setq exwm-debug nil
+ exwm-workspace-number 1
+ exwm-workspace-show-all-buffers t
+ exwm-workspace-warp-cursor nil
+ exwm-layout-show-all-buffers t
+ exwm-floating-border-color
+ (if (jao-colors-scheme-dark-p) "black" "grey90")
+ ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58245 :
+ x-no-window-manager t))
+
+(use-package exwm-edit :ensure t)
+
+;;; Frame(s) as workspaces
+(defun jao-exwm--new-frame-p ()
+ (not (frame-parameter nil 'jao-frames-initialized)))
+
+(defun jao-exwm--mark-frame (force)
+ (prog1 (or force (jao-exwm--new-frame-p))
+ (set-frame-parameter nil 'jao-frames-initialized t)))
+
+(defun jao-exwm--goto-main (&optional init)
+ (interactive "P")
+ (exwm-workspace-switch-create 1)
+ (when (jao-exwm--mark-frame init) (jao-trisect)))
+
+(defun jao-exwm--goto-mail (&optional init)
+ (interactive "P")
+ (exwm-workspace-switch-create 2)
+ (when (jao-exwm--mark-frame init)
+ (jao-afio-open-gnus)))
+
+(defun jao-exwm--goto-www (&optional init)
+ (interactive "P")
+ (exwm-workspace-switch-create 5)
+ (when (jao-exwm--mark-frame init)
+ (jao-afio-open-www)
+ (let ((scroll-bar-mode 'left))
+ (toggle-scroll-bar 1)
+ (set-frame-parameter (window-frame) 'scroll-bar-width 12))
+ (jao-toggle-inactive-mode-line)))
+
+(defun jao-exwm--goto-docs (&optional init)
+ (interactive "P")
+ (exwm-workspace-switch-create 4)
+ (when (jao-exwm--mark-frame init)
+ (jao-afio-open-doc)))
+
+(defun jao-exwm-open-doc (file)
+ (jao-exwm--goto-docs)
+ (jao-find-or-open file))
+
+(defun jao-exwm-no-afio-setup ()
+ (interactive)
+ (defalias 'jao-open-gnus-frame 'jao-exwm--goto-mail)
+ (defalias 'jao-goto-www-frame 'jao-exwm--goto-www)
+ (setq jao-open-doc-fun #'jao-exwm-open-doc)
+ (setq minibuffer-follows-selected-frame t)
+ (global-set-key "\C-cf" 'jao-exwm--goto-main)
+ (global-set-key "\C-cg" 'jao-exwm--goto-mail)
+ (global-set-key "\C-cw" 'jao-exwm--goto-www)
+ (global-set-key "\C-cz" 'jao-exwm--goto-docs))
+
+(if jao-exwm--use-afio
+ (setq minibuffer-follows-selected-frame nil)
+ (jao-exwm-no-afio-setup))
+
+;; tracking
+(add-hook 'exwm-workspace-switch-hook 'tracking-remove-visible-buffers)
+
+;;; Buffer names
+(defun jao-exwm--use-title-p ()
+ (and exwm-title (not (string-blank-p exwm-title))))
+
+(defun jao-exwm-rename-buffer/class ()
+ (unless (jao-exwm--use-title-p)
+ (exwm-workspace-rename-buffer exwm-class-name)))
+
+(defun jao-exwm-rename-buffer/title ()
+ (cond ((or (not exwm-instance-name)
+ (jao-exwm--use-title-p))
+ (exwm-workspace-rename-buffer exwm-title))
+ ((string= "Zathura" exwm-class-name)
+ (exwm-workspace-rename-buffer
+ (format "zathura: %s" (file-name-nondirectory exwm-title))))))
+
+(defun jao-exwm--set-exwm-name ()
+ (when (not jao-exwm--name)
+ (setq jao-exwm--name jao-exwm--current-name
+ jao-exwm--current-name nil)))
+
+(add-hook 'exwm-mode-hook 'jao-exwm--set-exwm-name)
+(add-hook 'exwm-update-class-hook 'jao-exwm-rename-buffer/class)
+(add-hook 'exwm-update-title-hook 'jao-minibuffer-refresh)
+(add-hook 'exwm-update-title-hook 'jao-exwm-rename-buffer/title)
+
+;;; Float windows
+(defvar jao-exwm-max-x (x-display-pixel-width))
+(defvar jao-exwm-max-y (x-display-pixel-height))
+
+(defun jao-exwm--float-to (x y &optional w h)
+ (let* ((w (or w (frame-pixel-width)))
+ (h (or h (frame-pixel-height)))
+ (x (if (< x 0) (- jao-exwm-max-x (- x) w) x))
+ (y (if (< y 0) (- jao-exwm-max-y (- y) h) y))
+ (p (or (frame-parameter nil 'jao-position) (frame-position))))
+ (exwm-floating-move (- x (car p)) (- y (cdr p)))
+ (exwm-layout-enlarge-window-horizontally (- w (frame-pixel-width)))
+ (exwm-layout-enlarge-window (- h (frame-pixel-height)))
+ (set-frame-parameter nil 'jao-position (cons x y))))
+
+(defun jao-exwm--center-float (&optional w h)
+ (interactive)
+ (let* ((mx jao-exwm-max-x)
+ (my jao-exwm-max-y)
+ (w (or w (frame-pixel-width)))
+ (h (or h (/ (* w my) mx))))
+ (jao-exwm--float-to (/ (- mx w) 2) (/ (- my h) 2) w h)))
+
+(defun jao-exwm--setup-float ()
+ (set-frame-parameter nil 'jao-position nil)
+ (cond ((string= "Firefox" exwm-class-name)
+ (jao-exwm--center-float 900 600))
+ ((member exwm-class-name '("mpv" "vlc"))
+ (jao-exwm--center-float 1200))))
+
+(defvar jao-exwm-floating-classes '("mpv" "vlc"))
+(setq jao-exwm-floating-classes nil)
+
+(defun jao-exwm--maybe-float ()
+ (when (member exwm-class-name jao-exwm-floating-classes)
+ (when (not exwm--floating-frame)
+ (exwm-floating-toggle-floating))))
+
+(add-hook 'exwm-floating-setup-hook #'jao-exwm--setup-float)
+(add-hook 'exwm-manage-finish-hook #'jao-exwm--maybe-float)
+
+;; Minibuffer and system tray
+(setq jao-minibuffer-frame-width 271)
+(add-hook 'exwm-workspace-switch-hook #'jao-minibuffer-refresh)
+
+(require 'exwm-systemtray)
+(exwm-systemtray-enable)
+
+(defun jao-exwm--watch-tray (sym newval op where)
+ (setq jao-minibuffer-right-margin (* 2 (length newval)))
+ (jao-minibuffer-refresh))
+
+(add-variable-watcher 'exwm-systemtray--list #'jao-exwm--watch-tray)
+
+;; Switch to buffer / app
+(defvar-local jao-exwm--name nil)
+(defvar jao-exwm--current-name nil)
+
+(defun jao-exwm--check-name (name)
+ (or (string= jao-exwm--name name)
+ (string= (buffer-name) name)
+ (string= exwm-class-name name)
+ (string= exwm-title name)))
+
+(defun jao-exwm-find-class-buffer (cln)
+ (if (jao-exwm--check-name cln)
+ (current-buffer)
+ (let* ((cur-buff (current-buffer))
+ (bfs (seq-filter (lambda (b)
+ (and (not (eq b cur-buff))
+ (with-current-buffer b
+ (jao-exwm--check-name cln))))
+ (buffer-list))))
+ (when (car bfs) (car (reverse bfs))))))
+
+(defun jao-exwm-switch-to-class/title (cln)
+ (interactive)
+ (when cln
+ (if (jao-exwm--check-name cln)
+ (current-buffer)
+ (when-let ((b (jao-exwm-find-class-buffer cln)))
+ (pop-to-buffer b)))))
+
+(defun jao-exwm-switch-to-next-class ()
+ (interactive)
+ (jao-exwm-switch-to-class/title exwm-class-name))
+
+(defun jao-exwm-switch-to-next-x ()
+ (interactive)
+ (let ((bfs (seq-filter (lambda (b) (buffer-local-value 'exwm-class-name b))
+ (buffer-list (window-frame)))))
+ (when (car bfs) (switch-to-buffer (car (reverse bfs))))))
+
+;;; App runner helpers
+(defun jao-exwm-run (command)
+ (interactive
+ (list (read-shell-command "$ "
+ (if current-prefix-arg
+ (cons (concat " " (buffer-file-name)) 0)
+ ""))))
+ (setq jao-exwm--current-name nil)
+ (start-process-shell-command command nil command))
+
+(defmacro jao-exwm-runner (&rest args)
+ `(lambda () (interactive) (start-process "" nil ,@args)))
+
+(defun jao-exwm-workspace (n)
+ (if jao-exwm--use-afio
+ (jao-afio-goto-nth n)
+ (exwm-workspace-switch-create n)))
+
+(defmacro jao-def-exwm-runner (name ws class &rest args)
+ `(defun ,name (&rest other-args)
+ (interactive)
+ ,@(when ws `((jao-exwm-workspace ,ws)))
+ (if (jao-exwm-switch-to-class/title ,class)
+ ,(cond ((equal ws -1) '(delete-other-windows))
+ ((stringp (car args)) (cdr args))
+ (t args))
+ (setq jao-exwm--current-name ,class)
+ ,(if (stringp (car args))
+ `(start-process-shell-command ,(car args)
+ "* exwm - console *"
+ (string-join (append (list ,@args)
+ other-args)
+ " "))
+ args))))
+
+(defmacro jao-def-exwm-toggler (name ws class &rest args)
+ (let ((toggler (intern (format "%s*" name)))
+ (arg (gensym)))
+ `(progn (jao-def-exwm-runner ,name ,ws ,class ,@args)
+ (defun ,toggler (,arg)
+ (interactive "P")
+ (if (and (not ,arg) (equal exwm-class-name ,class))
+ (jao-afio-toggle)
+ (,name))))))
+
+(defun jao-exwm--send-str (str)
+ (dolist (k (string-to-list (kbd str)))
+ (exwm-input--fake-key k)))
+
+;;; Runners
+(jao-def-exwm-runner jao-exwm-vlc 4 "VLC" "vlc")
+
+(jao-def-exwm-runner jao-exwm-slack 0 "Slack" "slack")
+(jao-def-exwm-runner jao-exwm-signal 0 "Signal" "signal-desktop")
+
+(jao-def-exwm-runner jao-exwm-proton-bridge 0 "*proton-bridge*" "protonmail-bridge")
+
+;; (jao-def-exwm-runner jao-exwm-htop 0 "htop-xterm"
+;; "xterm" "-title" "htop-xterm" "-e" "htop")
+(jao-def-exwm-runner jao-exwm-htop 0 "htop" jao-term-htop)
+
+;; (jao-def-exwm-runner jao-exwm-aptitude 0 "aptitude-xterm"
+;; "xterm" "-title" "aptitude-xterm" "-e" "aptitude")
+(jao-def-exwm-runner jao-exwm-aptitude 0 "aptitude" jao-term-aptitude)
+
+(jao-def-exwm-runner jao-exwm-blueman 0 "Blueman-manager" "blueman-manager")
+(jao-def-exwm-runner jao-exwm-ncmpcpp 0 "ncmpcpp" "xterm" "-e" "ncmpcpp" "-p" "6669")
+(jao-def-exwm-runner jao-exwm-mpc 0 "*MPC-Status*" mpc)
+
+(jao-def-exwm-runner jao-exwm-proton-vpn 0 "*pvpn*" proton-vpn-status)
+(jao-def-exwm-runner jao-exwm-enwc 0 "*ENWC*" enwc)
+(jao-def-exwm-runner jao-exwm-bluetooth 0 "*Bluetooth*" bluetooth-list-devices)
+(jao-def-exwm-runner jao-exwm-packages 0 "*Packages*" list-packages nil)
+(jao-def-exwm-runner jao-exwm-proced 0 "*Proced*" proced)
+
+(jao-def-exwm-runner jao-exwm-open-with-zathura nil nil "zathura" (buffer-file-name))
+(jao-def-exwm-runner jao-exwm-open-with-mupdf nil nil "mupdf" (buffer-file-name))
+(jao-def-exwm-runner jao-exwm-xterm 0 nil "xterm")
+
+;; (jao-def-exwm-toggler jao-exwm-tidal -1 "tidal-hifi" "tidal-hifi")
+;; (jao-def-exwm-toggler jao-exwm-spt -1 "spt" "kitty" "-e" "spt")
+;; (defalias 'jao-streaming-list #'jao-exwm-spt*)
+
+(defun jao-exwm-import-screen (&optional area)
+ (interactive "P")
+ (when (not (file-directory-p "/tmp/screenshot"))
+ (make-directory "/tmp/screenshot"))
+ (let ((c (format "import %s %s"
+ (if area "" "-window root")
+ "/tmp/screenshot/$(date +'%g%m%d-%H%M%S').png")))
+ (start-process-shell-command "import" "* exwm - console *" c)))
+
+;;; Zathura support
+(defun jao-zathura--buffer-p (b)
+ (string= "Zathura" (or (buffer-local-value 'exwm-class-name b) "")))
+
+(defun jao-zathura--buffers ()
+ (seq-filter #'jao-zathura--buffer-p (buffer-list)))
+
+(defun jao-zathura--file-info (b)
+ (with-current-buffer b
+ (jao-pdf-zathura-file-info (or exwm-title ""))))
+
+(defun jao-zathura-goto-page (page-no)
+ (jao-exwm--send-str (format "%sg" page-no)))
+
+(defun jao-zathura-open-doc (&optional file-name page-no height)
+ (interactive)
+ (let* ((file-name (expand-file-name (or file-name (buffer-file-name))))
+ (buffer (seq-find `(lambda (b)
+ (string= ,file-name
+ (car (jao-zathura--file-info b))))
+ (jao-zathura--buffers)))
+ (page-no (or page-no (jao-doc-view-current-page))))
+ (if jao-exwm--use-afio (jao-afio-goto-docs) (jao-exwm--goto-docs))
+ (if (not buffer)
+ (jao-exwm-run (if page-no
+ (format "zathura -P %s '%s'" page-no file-name)
+ (format "zathura '%s'" file-name)))
+ (pop-to-buffer buffer)
+ (when page-no (jao-zathura-goto-page page-no)))
+ (current-buffer)))
+
+(defun jao-exwm--zathura-setup ()
+ (when (and (string= exwm-class-name "Zathura")
+ (not jao-pdf--outline))
+ (let ((info (jao-zathura--file-info (current-buffer))))
+ (jao-doc-session-mark (car info))
+ (jao-doc-session-save)
+ (doc-view-imenu-index (car info) #'jao-zathura-goto-page))))
+
+(add-hook 'exwm-update-title-hook #'jao-exwm--zathura-setup t)
+
+(defun jao-exwm-pdf-zathura-close-all ()
+ (interactive)
+ (dolist (b (jao-zathura--buffers))
+ (ignore-errors
+ (switch-to-buffer b)
+ (jao-exwm--send-str "q")))
+ t)
+
+(defun jao-exwm-zathura-goto-org (&optional arg)
+ (interactive "P")
+ (when-let ((info (jao-zathura--file-info (current-buffer))))
+ (when-let ((file (jao-org-find-for-pdf (car info))))
+ (let ((newp (not (file-exists-p file))))
+ (when (or arg newp) (org-store-link nil t))
+ (find-file-other-window file)
+ (when newp
+ (jao-org-insert-doc-skeleton)
+ (org-insert-link))))))
+
+(defun jao-exwm-zathura-goto-org* ()
+ (interactive)
+ (jao-exwm-zathura-goto-org t))
+
+(defun jao-exwm-org-store-zathura-link ()
+ (when-let ((info (jao-zathura--file-info (current-buffer))))
+ (let* ((file-name (car info))
+ (page (cadr info))
+ (desc (jao-pdf-section-title page file-name)))
+ (jao-org-links-store-pdf-link file-name page desc))))
+
+(defun jao-exwm-pdf-enable-zathura ()
+ (interactive)
+ (add-hook 'kill-emacs-query-functions #'jao-exwm-pdf-zathura-close-all t)
+ (setq jao-browse-doc-use-emacs-p nil)
+ (setq jao-org-open-pdf-fun #'jao-zathura-open-doc)
+ (setq jao-org-links-pdf-store-fun #'jao-exwm-org-store-zathura-link)
+ (setq jao-open-doc-fun #'jao-zathura-open-doc))
+
+(defun jao-exwm-pdf-disable-zathura ()
+ (interactive)
+ (remove-hook 'kill-emacs-query-functions #'jao-exwm-pdf-zathura-close-all)
+ (setq jao-browse-doc-use-emacs-p t)
+ (setq jao-org-open-pdf-fun #'jao-find-or-open)
+ (setq jao-org-links-pdf-store-fun nil)
+ (setq jao-open-doc-fun #'jao-find-or-open))
+
+(defun jao-exwm-org-to-pdf-file ()
+ (expand-file-name (concat "doc/" (file-name-base buffer-file-name) ".pdf")
+ (file-name-directory jao-org-notes-dir)))
+
+(defun jao-exwm-zathura-goto-pdf ()
+ (interactive)
+ (if jao-browse-doc-use-emacs-p
+ (jao-org-goto-pdf)
+ (when-let (pdf (jao-exwm-org-to-pdf-file))
+ (jao-zathura-open-doc pdf))))
+
+(with-eval-after-load "org"
+ (define-key org-mode-map (kbd "C-c o") #'jao-exwm-zathura-goto-pdf))
+
+(when (not jao-browse-doc-use-emacs-p)
+ (jao-exwm-pdf-enable-zathura))
+
+(defun jao-exwm-select-pdf ()
+ (interactive)
+ (let ((b (read-buffer "Document: " nil t
+ (lambda (b)
+ (let ((b (cdr b)))
+ (or (jao-zathura--buffer-p b)
+ (member (buffer-local-value 'major-mode b)
+ '(pdf-view-mode doc-view-mode))))))))
+ (jao-afio-goto-docs)
+ (pop-to-buffer b)))
+
+
+(jao-transient-major-mode+ doc-view
+ ["External viewers"
+ ("z" "open with zathura" jao-zathura-open-doc)
+ ("m" "open with mupdf" jao-exwm-open-with-mupdf)])
+
+;;; Firefox support
+(jao-def-exwm-toggler jao-exwm-firefox -1 "firefox" "firefox")
+
+(defun jao-exwm-browse-with-firefox (&rest args)
+ (jao-exwm-firefox)
+ (apply #'browse-url-firefox args))
+
+(setq browse-url-secondary-browser-function #'jao-exwm-browse-with-firefox)
+
+(defun jao-exwm-kill-firefox-url ()
+ (interactive)
+ (when-let (b (jao-exwm-find-class-buffer "Firefox"))
+ (let ((cb (current-buffer)))
+ (switch-to-buffer b)
+ (jao-exwm--send-str "yy")
+ (prog1 (current-kill 1)
+ (switch-to-buffer cb)))))
+
+;;; Transients
+(defun jao-exwm--floating-p () exwm--floating-frame)
+(defun jao-exwm--m0-5 () (interactive nil exwm-mode) (exwm-floating-move 0 -5))
+(defun jao-exwm--m05 () (interactive nil exwm-mode) (exwm-floating-move 0 5))
+(defun jao-exwm--m-50 () (interactive nil exwm-mode) (exwm-floating-move -5 0))
+(defun jao-exwm--m50 () (interactive nil exwm-mode) (exwm-floating-move 5 0))
+(defun jao-exwm--e-5 () (interactive nil exwm-mode) (exwm-layout-enlarge-window -5))
+(defun jao-exwm--e5 () (interactive nil exwm-mode) (exwm-layout-enlarge-window 5))
+(defun jao-exwm--eh5 () (interactive nil exwm-mode) (exwm-layout-enlarge-window 5 t))
+(defun jao-exwm--eh-5 () (interactive nil exwm-mode) (exwm-layout-enlarge-window -5 t))
+(defun jao-exwm--tl () (interactive nil exwm-mode) (jao-exwm--float-to 20 20))
+(defun jao-exwm--tr () (interactive nil exwm-mode) (jao-exwm--float-to -20 20))
+(defun jao-exwm--bl () (interactive nil exwm-mode) (jao-exwm--float-to 20 -20))
+(defun jao-exwm--br () (interactive nil exwm-mode) (jao-exwm--float-to -20 -20))
+
+(defun jao-exwm--def-center-float ()
+ (interactive)
+ (exwm-floating-toggle-floating)
+ (jao-exwm--center-float 900 600))
+
+(transient-define-prefix jao-transient-float ()
+ "Operations on EXWM floating windows."
+ :transient-non-suffix 'transient--do-quit-one
+ [["Float"
+ ("f" "float" exwm-floating-toggle-floating)
+ ("F" "full" exwm-layout-toggle-fullscreen)
+ ("c" "center" jao-exwm--center-float :if jao-exwm--floating-p)
+ ("c" "float and resize" jao-exwm--def-center-float
+ :if-not jao-exwm--floating-p)
+ ("x" "hide" exwm-floating-hide :if jao-exwm--floating-p)]
+ ["Slide" :if jao-exwm--floating-p
+ ("k" "up" jao-exwm--m0-5 :transient t)
+ ("j" "down" jao-exwm--m05 :transient t)
+ ("h" "left" jao-exwm--m-50 :transient t)
+ ("l" "right" jao-exwm--m50 :transient t)]
+ ["Resize" :if jao-exwm--floating-p
+ ("K" "up" jao-exwm--e5 :transient t)
+ ("J" "down" jao-exwm--e-5 :transient t)
+ ("H" "left" jao-exwm--eh5 :transient t)
+ ("L" "right" jao-exwm--eh-5 :transient t)]
+ ["Nudge" :if jao-exwm--floating-p
+ ("t" "top-left" jao-exwm--tl)
+ ("T" "top-right" jao-exwm--tr)
+ ("b" "bottom-left" jao-exwm--bl)
+ ("B" "bottom-right " jao-exwm--br)]])
+
+(defun jao-exwm--buffer ()
+ (interactive)
+ (jao-buffer-same-mode 'exwm-mode nil 'exwm-workspace-switch-to-buffer))
+
+;;; Keybindings
+(define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
+(define-key exwm-mode-map [?\s-f] #'jao-transient-float)
+(define-key exwm-mode-map (kbd "C-c o") #'jao-exwm-zathura-goto-org)
+(define-key exwm-mode-map (kbd "C-c O") #'jao-exwm-zathura-goto-org*)
+(define-key exwm-mode-map (kbd "M-o") #'jao-afio-toggle)
+(define-key exwm-mode-map (kbd "M-p") #'jao-prev-window)
+
+(setq
+ exwm-input-global-keys
+ '(([?\s-0] . jao-afio-goto-scratch)
+ ([?\s-1] . jao-afio-goto-main)
+ ([?\s-2] . jao-afio-goto-mail)
+ ([?\s-3] . jao-afio-goto-www)
+ ([?\s-4] . jao-afio-goto-docs)
+ ([?\s-5] . jao-afio-goto-chats)
+ ([?\s-A] . jao-org-agenda)
+ ([?\s-a] . jao-first-window)
+ ([?\s-b] . jao-transient-org-blog)
+ ([?\s-d] . jao-exwm-tidal*)
+ ([?\s-e] . jao-exwm-firefox*)
+ ([?\s-m] . jao-transient-media)
+ ;; ([?\s-O] . switch-window-then-swap-buffer)
+ ([?\s-o] . jao-afio-toggle)
+ ([?\s-p] . jao-prev-window)
+ ([?\s-R] . app-launcher-run-app)
+ ([?\s-r] . jao-transient-recoll)
+ ([?\s-s] . jao-transient-streaming)
+ ([?\s-n] . jao-transient-ednc)
+ ([?\s-t] . eat)
+ ([?\s-w] . jao-transient-utils)
+ ([?\s-z] . jao-transient-sleep)
+ ([XF86AudioMute] . jao-mixer-master-toggle)
+ ([XF86AudioPlay] . jao-player-toggle)
+ ([XF86AudioPause] . jao-player-toggle)
+ ([XF86AudioNext] . jao-player-next)
+ ([XF86AudioPrev] . jao-player-previous)
+ ([XF86AudioStop] . jao-player-stop)
+ ([XF86AudioRaiseVolume] . jao-mixer-master-up)
+ ([XF86AudioLowerVolume] . jao-mixer-master-down)
+ ([XF86MonBrightnessUp] . jao-bright-up)
+ ([XF86MonBrightnessDown] . jao-bright-down)
+ ([?\s-\`] . jao-exwm-switch-to-next-x)
+ ([s-tab] . jao-exwm-switch-to-next-class)
+ ([print] . jao-exwm-import-screen)
+ ([f5] . jao-weather)
+ ([f6] . jao-toggle-audio-applet)
+ ([f8] . jao-toggle-nm-applet)
+ ([f9] . jao-bright-show)))
+
+;; (customize-set-variable 'exwm-input-global-keys exwm-input-global-keys)
+
+;;; .
+(provide 'jao-custom-exwm)
diff --git a/custom/jao-custom-gnus.el b/custom/jao-custom-gnus.el
new file mode 100644
index 0000000..b7eb851
--- /dev/null
+++ b/custom/jao-custom-gnus.el
@@ -0,0 +1,767 @@
+;; gnus configuration -*- lexical-binding: t -*-
+
+;;; features
+(defvar jao-gnus-use-local-imap nil)
+(defvar jao-gnus-use-leafnode nil)
+(defvar jao-gnus-use-gandi-imap nil)
+(defvar jao-gnus-use-pm-imap nil)
+(defvar jao-gnus-use-gmane nil)
+(defvar jao-gnus-use-nnml nil)
+(defvar jao-gnus-use-maildirs nil)
+(defvar jao-notmuch-enabled nil)
+;;; directories
+(defun jao-gnus-dir (dir)
+ (expand-file-name dir gnus-home-directory))
+
+(setq smtpmail-queue-dir (jao-gnus-dir "Mail/queued-mail/"))
+
+(setq mail-source-directory (jao-gnus-dir "Mail/")
+ message-directory (jao-gnus-dir "Mail/"))
+
+(setq gnus-default-directory (expand-file-name "~")
+ gnus-startup-file (jao-gnus-dir "newsrc")
+ gnus-agent-directory (jao-gnus-dir "News/agent")
+ gnus-home-score-file (jao-gnus-dir "scores")
+ gnus-article-save-directory (jao-gnus-dir "saved/")
+ nntp-authinfo-file (jao-gnus-dir "authinfo")
+ nnmail-message-id-cache-file (jao-gnus-dir "nnmail-cache")
+ nndraft-directory (jao-gnus-dir "drafts")
+ nnrss-directory (jao-gnus-dir "rss"))
+
+;;; looks
+;;;; verbosity
+(setq gnus-verbose 4)
+;;;; geometry
+(defvar jao-gnus-use-three-panes t)
+(defvar jao-gnus-groups-width 50)
+(defvar jao-gnus-wide-width 190)
+
+(setq gnus-use-trees nil
+ gnus-generate-tree-function 'gnus-generate-horizontal-tree
+ gnus-tree-minimize-window nil)
+
+(when jao-gnus-use-three-panes
+
+ ;; (dolist (m '(calendar-mode org-agenda-mode gnus-group-mode))
+ ;; (add-to-list 'display-buffer-alist `((major-mode . ,m) (dedicated t))))
+
+ (setq calendar-left-margin 6)
+
+ (let ((side-bar '(vertical 1.0
+ ("inbox.org" 0.4)
+ ("*Org Agenda*" 1.0)
+ ("*Calendar*" 8)))
+ (wide-len jao-gnus-wide-width)
+ (groups-len jao-gnus-groups-width)
+ (summary-len (- jao-gnus-wide-width jao-gnus-groups-width)))
+ (gnus-add-configuration
+ `(article
+ (horizontal 1.0
+ (vertical ,groups-len (group 1.0))
+ (vertical ,summary-len
+ (summary 0.25 point)
+ (article 1.0))
+ ,side-bar)))
+
+ (gnus-add-configuration
+ `(group (horizontal 1.0 (group ,wide-len point) ,side-bar)))
+
+ (gnus-add-configuration
+ `(message (horizontal 1.0 (message ,wide-len point) ,side-bar)))
+
+ (gnus-add-configuration
+ `(reply-yank (horizontal 1.0 (message ,wide-len point) ,side-bar)))
+
+ (gnus-add-configuration
+ `(summary
+ (horizontal 1.0
+ (vertical ,groups-len (group 1.0))
+ (vertical ,summary-len (summary 1.0 point))
+ ,side-bar)))
+
+ (gnus-add-configuration
+ `(reply
+ (horizontal 1.0
+ (message ,(- wide-len 100) point)
+ (article 100)
+ ,side-bar)))))
+
+;;;; no blue icon
+(advice-add 'gnus-mode-line-buffer-identification :override #'identity)
+(setq gnus-mode-line-image-cache nil)
+
+;;; search
+(setq gnus-search-use-parsed-queries nil
+ gnus-search-notmuch-raw-queries-p nil
+ gnus-permanently-visible-groups "^nnselect:.*"
+ gnus-search-ignored-newsgroups "nndraft.*\\|nnselect.*")
+
+(with-eval-after-load "gnus-search"
+ (defclass gnus-search-recoll (gnus-search-indexed)
+ ((separator :type string :initform ".")
+ (program :initform "recoll")
+ (raw-queries-p :initform t)))
+
+ (cl-defmethod gnus-search-indexed-extract ((_engine gnus-search-recoll))
+ (prog1 (and (looking-at "^file://\\(.+\\)$") (list (match-string 1) 100))
+ (forward-line 1)))
+
+ (cl-defmethod gnus-search-transform-expression ((_engine gnus-search-recoll)
+ expr)
+ expr)
+
+ (cl-defmethod gnus-search-indexed-search-command ((engine gnus-search-recoll)
+ (qstring string)
+ _query
+ &optional groups)
+ (let* ((subdir (slot-value engine 'remove-prefix))
+ (sep (slot-value engine 'separator))
+ (gdirs (mapcar (lambda (g)
+ (let ((g (gnus-group-short-name g)))
+ (replace-regexp-in-string "\\." sep g)))
+ (or groups
+ (and (not (string= "" subdir)) (list subdir)))))
+ (dirsq (and gdirs
+ (concat "("
+ (mapconcat (lambda (d) (format "dir:%s" d))
+ gdirs " OR ")
+ ")")))
+ (q (concat "mime:message " dirsq " (" qstring ")")))
+ ;; (message "query is: %s" q)
+ `("-b" "-t" "-q" ,q))))
+
+;; (add-to-list 'gnus-parameters '("^nnselect:.*" (nnselect-rescan . t)))
+
+;;; news
+(defvar jao-gnus-leafnode-spool "/var/spool/news/")
+(setq gnus-select-method
+ (cond
+ (jao-gnus-use-leafnode
+ `(nntp "localhost"
+ (gnus-search-engine gnus-search-recoll
+ (remove-prefix ,jao-gnus-leafnode-spool)
+ (separator "/"))))
+ (jao-gnus-use-gmane '(nntp "news.gmane.io"))
+ (t '(nnnil ""))))
+
+(setq gnus-secondary-select-methods '())
+
+(setq nnheader-read-timeout 0.02
+ gnus-save-newsrc-file nil) ; .newsrc only needed by other newsreaders
+
+;; leafnode articles group parameters
+(defvar jao-gnus-image-groups '("xkcd"))
+
+(defvar jao-gnus-leafnode-group-params
+ `((,(format "gwene\\..*%s.*" (regexp-opt jao-gnus-image-groups))
+ (mm-html-inhibit-images nil)
+ (mm-html-blocked-images nil))
+ ("\\(gmane\\|gwene\\)\\..*"
+ (jao-gnus--archiving-group "nnml:feeds.trove")
+ (posting-style (address "jao@gnu.org")))))
+
+(when jao-gnus-use-leafnode
+ (dolist (p jao-gnus-leafnode-group-params)
+ (add-to-list 'gnus-parameters p t)))
+
+;;; mail
+;;;; nnmail
+(setq nnmail-treat-duplicates 'delete
+ nnmail-scan-directory-mail-source-once nil
+ nnmail-cache-accepted-message-ids t
+ nnmail-message-id-cache-length 100000
+ nnmail-split-fancy-with-parent-ignore-groups nil
+ nnmail-use-long-file-names t
+ nnmail-crosspost t
+ nnmail-resplit-incoming t
+ nnmail-mail-splitting-decodes t
+ nnmail-split-methods 'nnmail-split-fancy)
+
+;;;; nnml
+(setq gnus-message-archive-group nil
+ nnml-get-new-mail t
+ nnml-directory message-directory)
+
+(setq mail-sources
+ (let* ((pwd (auth-source-pick-first-password :host "proton-bridge"))
+ (mds (mapcar (lambda (f)
+ `(maildir :path ,(expand-file-name f "~/var/mail/")))
+ '("local/" "feeds/")))
+ (ims (mapcar (lambda (b)
+ `(imap :server "127.0.0.1" :port 1143
+ :user "mail@jao.io" :password ,pwd
+ :stream starttls :predicate "1:*"
+ :fetchflag "\\Deleted \\Seen"
+ :mailbox ,(concat "Labels/#" b)))
+ '("inbox" "drivel" "hacking" "bills"
+ "bigml" "prog" "words"))))
+ (append mds ims)))
+
+(when jao-gnus-use-nnml
+ (add-to-list
+ 'gnus-secondary-select-methods
+ `(nnml "" (gnus-search-engine gnus-search-recoll
+ (remove-prefix ,(jao-gnus-dir "Mail/"))))))
+
+(defvar jao-gnus-nnml-group-params
+ `(("nnml:\\(local\\|trash\\|spam\\)"
+ (auto-expire . t)
+ (total-expire . t)
+ (expiry-wait . 1)
+ (expiry-target . delete))
+ ("nnml:jao\\..*"
+ (posting-style ("Gcc" "nnml:jao.trove")) ;; ("Bcc" "proton@jao.io")
+ (jao-gnus--trash-group "nnml:trash")
+ (jao-gnus--spam-group "nnml:spam")
+ (jao-gnus--archiving-group "nnml:jao.trove")
+ (gcc-self . t))
+ ("nnml:jao\\.hacking"
+ (posting-style ("Gcc" "nnml:jao.hacking")
+ (address "jao@gnu.org"))) ;; ("Bcc" "hacking@jao.io")
+ ("nnml:jao\\.drivel"
+ (auto-expire . t)
+ (total-expire . t)
+ (expiry-wait . 3)
+ (expiry-target . delete))
+ ("nnml:bigml\\..*"
+ (gcc-self . nil)
+ (auto-expire . t)
+ (total-expire . t)
+ (expiry-wait . 3)
+ (expiry-target . delete)
+ (posting-style (address "jao@bigml.com"))
+ (jao-gnus--trash-group "nnml:trash")
+ (jao-gnus--spam-group "nnml:spam")
+ (jao-gnus--archiving-group "nnml:bigml.trove"))
+ ("nnml:bigml\\.inbox"
+ (gcc-self . t)
+ (auto-expire . t)
+ (total-expire . t)
+ (expiry-wait . 7)
+ (expiry-target . "nnml:bigml.trove"))
+ ("nnml:bigml\\.alba"
+ (gcc-self . t)
+ (auto-expire . nil)
+ (total-expire . nil)
+ (expiry-target . nil)
+ (expiry-wait . nil))
+ ("nnml:bigml\\.trove"
+ (auto-expire . t)
+ (total-expire . t)
+ (expiry-target . delete)
+ (expiry-wait . 365))
+ ("nnml:feeds\\.\\(.*\\)"
+ (posting-style ("Gcc" "nnml:feeds.trove")
+ (address "jao@gnu.org"))
+ (auto-expire . t)
+ (total-expire . t)
+ (expiry-wait . 7)
+ (expiry-target . delete)
+ (comment . "feeds.\\1")
+ (jao-gnus--archiving-group "nnml:feeds.trove"))
+ ("nnml:feeds\\.\\(news\\|emacs-\\(bugs\\|diffs|\\github\\)\\)$"
+ (expiry-wait . 2))
+ ("nnml:feeds\\.trove"
+ (auto-expire . nil)
+ (total-expire . nil))
+ ("nnml:feeds\\.fun"
+ (mm-html-inhibit-images nil)
+ (mm-html-blocked-images nil))))
+
+(when jao-gnus-use-nnml
+ (dolist (p jao-gnus-nnml-group-params)
+ (add-to-list 'gnus-parameters p t)))
+
+;;;; imap
+(setq nnimap-quirks nil)
+
+(when jao-gnus-use-local-imap
+ (add-to-list 'gnus-secondary-select-methods
+ `(nnimap "" (nnimap-address "localhost"))))
+
+(when jao-gnus-use-pm-imap
+ (add-to-list 'gnus-secondary-select-methods
+ '(nnimap "pm"
+ (nnimap-address "127.0.0.1")
+ (nnimap-stream network)
+ (nnimap-server-port 1143))))
+
+(when jao-gnus-use-gandi-imap
+ (add-to-list 'gnus-secondary-select-methods
+ '(nnimap "gandi" (nnimap-address "mail.gandi.net"))))
+
+;;; groups
+(setq gnus-group-line-format " %m%S%p%3y%P%* %~(pad-right 30)G %B\n"
+ ;; " %m%S%p%P:%~(pad-right 35)c %3y %B\n"
+ ;; " %m%S%p%3y%P%* %~(pad-right 30)C %B\n"
+ gnus-topic-line-format "%i[ %(%{%n%}%) -- %A ]%v\n"
+ gnus-group-uncollapsed-levels 2
+ gnus-auto-select-subject 'unread
+ gnus-large-newsgroup 2000)
+
+(add-hook 'gnus-select-group-hook 'gnus-group-set-timestamp)
+(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
+
+;;; summary
+;;;; configuration
+(setq gnus-summary-ignore-duplicates t
+ gnus-suppress-duplicates t
+ ;; gnus-summary-ignored-from-addresses jao-mails-regexp
+ gnus-process-mark-toggle t
+ gnus-auto-select-next 'almost-quietly)
+
+;;;; threading
+(setq gnus-face-1 'jao-gnus-face-tree
+ gnus-show-threads t
+ gnus-thread-hide-subtree t
+ gnus-build-sparse-threads nil
+ gnus-refer-thread-use-search t
+ gnus-summary-make-false-root 'adopt
+ gnus-summary-gather-subject-limit nil ;; 120
+ gnus-summary-thread-gathering-function #'gnus-gather-threads-by-subject
+ gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
+ gnus-thread-sort-functions '(gnus-thread-sort-by-number))
+
+(defun jao-fix-protonmail-references (header)
+ (let ((references (mail-header-references header)))
+ (setf (mail-header-references header)
+ (mapconcat #'(lambda (x)
+ (if (string-match "protonmail.internalid" x) "" x))
+ (gnus-split-references references)
+ " "))
+ header))
+
+(setq gnus-alter-header-function 'jao-fix-protonmail-references)
+
+;;;; search on enter nnselect
+(defun jao-gnus--maybe-reselect (&rest _i)
+ (when (string-match-p "^nnselect" (or (gnus-group-name-at-point) ""))
+ (save-excursion (gnus-group-get-new-news-this-group))))
+
+(advice-add 'gnus-group-select-group :before #'jao-gnus--maybe-reselect)
+
+;;;; summary line
+(setq gnus-not-empty-thread-mark ?โ†“) ; โ†“) ?ยท
+(setq jao-gnus--summary-line-fmt
+ (concat "%%U %%*%%R %%uj "
+ "[ %%~(max-right 23)~(pad-right 23)uf "
+ " %%I%%~(pad-left 2)t ] %%s"
+ "%%-%s="
+ "%%~(max-right 8)~(pad-left 8)&user-date;"
+ "\n"))
+
+(defun jao-gnus--set-summary-line (&optional w)
+ (let* ((d (if jao-gnus-use-three-panes (+ jao-gnus-groups-width 11) 12))
+ (w (- (or w (window-width)) d)))
+ (setq gnus-summary-line-format (format jao-gnus--summary-line-fmt w))))
+
+(add-hook 'gnus-select-group-hook 'jao-gnus--set-summary-line)
+;; (jao-gnus--set-summary-line 187)
+
+(add-to-list 'nnmail-extra-headers 'Cc)
+(add-to-list 'nnmail-extra-headers 'BCc)
+
+(use-package gnus-sum
+ :config
+ (add-to-list 'gnus-extra-headers 'Cc)
+ (add-to-list 'gnus-extra-headers 'BCc))
+
+
+(defun gnus-user-format-function-j (headers)
+ (let ((to (gnus-extra-header 'To headers)))
+ (if (string-match jao-mails-regexp to)
+ (if (string-match "," to) "ยฌ" "ยป") ;; "~" "=")
+ (if (or (string-match jao-mails-regexp
+ (gnus-extra-header 'Cc headers))
+ (string-match jao-mails-regexp
+ (gnus-extra-header 'BCc headers)))
+ "ยฌ" ;; "~"
+ " "))))
+
+(defconst jao-gnus--news-rx
+ (concat (regexp-opt '("ElDiaro.es "
+ "ElDiario.es - ElDiario.es: "
+ "The Guardian: "
+ "Aeon | a world of ideas: "
+ "Planet Debian: "))
+ "\\|The Conversation โ€“ Articles (.+): "
+ "\\|unofficial mirror of [^:]+: "
+ "\\|[gq].+ updates on arXiv.org: "))
+
+(defun gnus-user-format-function-f (headers)
+ (let* ((from (gnus-header-from headers))
+ (from (gnus-summary-extract-address-component from))
+ (from (replace-regexp-in-string jao-gnus--news-rx "" from)))
+ from))
+
+(setq gnus-user-date-format-alist
+ '(((gnus-seconds-today) . "%H:%M")
+ ((+ 86400 (gnus-seconds-today)) . "'%H:%M")
+ ;; (604800 . "%a %H:%M") ;; that's one week
+ ((gnus-seconds-month) . "%a %d")
+ ((gnus-seconds-year) . "%b %d")
+ (t . "%b '%y")))
+
+;;;; moving messages around
+(defvar-local jao-gnus--spam-group nil)
+(defvar-local jao-gnus--archiving-group nil)
+(defvar-local jao-gnus--archive-as-copy-p nil)
+
+(defvar jao-gnus--last-move nil)
+(defun jao-gnus-move-hook (a headers c to d)
+ (setq jao-gnus--last-move (cons to (mail-header-id headers))))
+(defun jao-gnus-goto-last-moved ()
+ (interactive)
+ (when jao-gnus--last-move
+ (when (eq major-mode 'gnus-summary-mode) (gnus-summary-exit))
+ (gnus-group-goto-group (car jao-gnus--last-move))
+ (gnus-group-select-group)
+ (gnus-summary-goto-article (cdr jao-gnus--last-move) nil t)))
+(add-hook 'gnus-summary-article-move-hook 'jao-gnus-move-hook)
+
+(defun jao-gnus-archive (follow)
+ (interactive "P")
+ (if jao-gnus--archiving-group
+ (progn
+ (if (or jao-gnus--archive-as-copy-p
+ (not (gnus-check-backend-function
+ 'request-move-article gnus-newsgroup-name)))
+ (gnus-summary-copy-article nil jao-gnus--archiving-group)
+ (gnus-summary-move-article nil jao-gnus--archiving-group))
+ (when follow (jao-gnus-goto-last-moved)))
+ (gnus-summary-mark-as-read)
+ (gnus-summary-delete-article)))
+
+(defun jao-gnus-archive-tickingly ()
+ (interactive)
+ (gnus-summary-tick-article)
+ (jao-gnus-archive)
+ (when jao-gnus--archive-as-copy-p
+ (gnus-summary-mark-as-read)))
+
+(defun jao-gnus-show-tickled ()
+ (interactive)
+ (gnus-summary-limit-to-marks "!"))
+
+(make-variable-buffer-local
+ (defvar jao-gnus--trash-group nil))
+
+(defun jao-gnus-trash ()
+ (interactive)
+ (gnus-summary-mark-as-read)
+ (if jao-gnus--trash-group
+ (gnus-summary-move-article nil jao-gnus--trash-group)
+ (gnus-summary-delete-article)))
+
+(defun jao-gnus-move-to-spam ()
+ (interactive)
+ (gnus-summary-mark-as-read)
+ (gnus-summary-move-article nil jao-gnus--spam-group))
+
+(define-key gnus-summary-mode-map "Ba" 'jao-gnus-archive)
+(define-key gnus-summary-mode-map "BA" 'jao-gnus-archive-tickingly)
+(define-key gnus-summary-mode-map "Bl" 'jao-gnus-goto-last-moved)
+
+(define-key gnus-summary-mode-map (kbd "B DEL") 'jao-gnus-trash)
+(define-key gnus-summary-mode-map (kbd "B <backspace>") 'jao-gnus-trash)
+(define-key gnus-summary-mode-map "Bs" 'jao-gnus-move-to-spam)
+(define-key gnus-summary-mode-map "/!" 'jao-gnus-show-tickled)
+(define-key gnus-summary-mode-map [f7] 'gnus-summary-force-verify-and-decrypt)
+
+;;;; saving emails
+(setq gnus-default-article-saver 'gnus-summary-save-article-mail)
+(defvar jao-gnus-file-save-directory (expand-file-name "~/tmp"))
+(defun jao-gnus-file-save (newsgroup headers &optional last-file)
+ (expand-file-name (format "%s.eml" (mail-header-subject headers))
+ jao-gnus-file-save-directory))
+(setq gnus-mail-save-name 'jao-gnus-file-save)
+
+;;;; arXiv capture
+(use-package org-capture
+ :config
+ (add-to-list 'org-capture-templates
+ '("X" "arXiv" entry (file "notes/physics/arxiv.org")
+ "* %:subject\n %i" :immediate-finish t)
+ t)
+ (org-capture-upgrade-templates org-capture-templates))
+
+(defun jao-gnus-arXiv-capture ()
+ (interactive)
+ (gnus-summary-select-article-buffer)
+ (gnus-article-goto-part 0)
+ (forward-paragraph)
+ (setq-local transient-mark-mode 'lambda)
+ (set-mark (point))
+ (goto-char (point-max))
+ (org-capture nil "X"))
+
+;;; article
+;;;; config, headers
+(setq mail-source-delete-incoming t)
+(setq gnus-gcc-mark-as-read t)
+(setq gnus-treat-display-smileys nil)
+(setq gnus-treat-fill-long-lines nil)
+(setq gnus-treat-fill-article 120)
+(setq gnus-treat-fold-headers nil)
+(setq gnus-treat-strip-leading-blank-lines t)
+(setq gnus-article-auto-eval-lisp-snippets nil)
+(setq gnus-posting-styles '((".*" (name "Jose A. Ortega Ruiz"))))
+(setq gnus-single-article-buffer nil)
+(setq gnus-article-update-lapsed-header 60)
+(setq gnus-article-update-date-headers 60)
+
+(with-eval-after-load "gnus-art"
+ (setq gnus-visible-headers
+ (concat
+ gnus-visible-headers
+ "\\|^List-[iI][Dd]:\\|^X-Newsreader:\\|^X-Mailer:"
+ "\\|^User-Agent:\\|^X-User-Agent:\\|^X-RSS-Feed:")))
+
+;;;; html and images
+(setq gnus-button-url 'browse-url-generic
+ gnus-inhibit-images t
+ mm-discouraged-alternatives nil ;; '("text/html" "text/richtext")
+ mm-inline-large-images 'resize)
+
+(defvar-local jao-gnus--images nil)
+
+(defun jao-gnus--init-images ()
+ (with-current-buffer gnus-article-buffer
+ (setq jao-gnus--images nil)))
+
+(add-hook 'gnus-select-article-hook #'jao-gnus--init-images)
+
+(defun jao-gnus-browse-html ()
+ (interactive)
+ (let ((browse-url-browser-function jao-browse-url-external-function)
+ (browse-url-handlers nil)
+ (browse-url-default-handlers nil))
+ (gnus-article-browse-html-article)))
+
+(defun jao-gnus-show-images ()
+ (interactive)
+ (if window-system
+ (save-window-excursion
+ (gnus-summary-select-article-buffer)
+ (save-excursion
+ (if (and jao-afio-use-w3m (fboundp 'w3m-toggle-inline-images))
+ (w3m-toggle-inline-images)
+ (setq jao-gnus--images (not jao-gnus--images))
+ (if jao-gnus--images
+ (gnus-article-show-images)
+ (gnus-article-remove-images)))))
+ (jao-gnus-browse-html)))
+
+;;;; format from:
+
+(defvar jao-gnus--from-rx
+ (concat "From: \\\"?\\( *" jao-gnus--news-rx "\\)"))
+
+(defun jao-gnus-format-from ()
+ (save-excursion
+ (goto-char (point-min))
+ (when (re-search-forward jao-gnus--from-rx nil t)
+ (replace-match "" nil nil nil 1))))
+
+(add-hook 'gnus-part-display-hook 'jao-gnus-format-from)
+
+;;;; follow links and enclosures
+(defun jao-gnus-follow-link (&optional external)
+ (interactive "P")
+ (when (eq major-mode 'gnus-summary-mode)
+ (gnus-summary-select-article-buffer))
+ (save-excursion
+ (goto-char (point-min))
+ (when (or (search-forward-regexp "^Via: h" nil t)
+ (search-forward-regexp "^URL: h" nil t)
+ (and (search-forward-regexp "^Link$" nil t)
+ (not (beginning-of-line))))
+ (if external
+ (jao-browse-with-external-browser)
+ (browse-url (jao-url-around-point))))))
+
+(defun jao-gnus-open-enclosure ()
+ (interactive)
+ (save-window-excursion
+ (gnus-summary-select-article-buffer)
+ (save-excursion
+ (goto-char (point-min))
+ (let ((offset (or (and (search-forward-regexp "^Enclosure: " nil t) 2)
+ (and (search-forward-regexp "^Enclosure$" nil t) -2))))
+ (when offset (forward-char offset))
+ (if-let ((url (jao-url-around-point)))
+ (jao-mpc-add-or-play-url url)
+ (error "No enclosure found"))))))
+
+;;;; delayed messages
+(require 'gnus-util)
+(gnus-delay-initialize)
+(setq gnus-delay-default-delay "3h")
+(eval-after-load "message"
+ '(setq message-draft-headers (remove 'Date message-draft-headers)))
+
+;;; daemon and exit
+(setq gnus-interactive-exit t)
+(defun jao-quit-gnus () (gnus-group-exit) t)
+(add-hook 'kill-emacs-query-functions #'jao-quit-gnus)
+
+;; daemon config
+(setq mail-user-agent 'gnus-user-agent)
+(setq gnus-asynchronous t)
+(setq gnus-use-article-prefetch nil)
+(setq gnus-save-killed-list nil)
+(setq gnus-check-new-newsgroups nil)
+
+(require 'gnus-demon)
+
+(defun jao-gnus--scan ()
+ (let ((inhibit-message t))
+ (gnus-demon-scan-news)
+ (jao-gnus--notify)))
+
+(gnus-demon-add-handler 'jao-gnus--scan 5 1)
+
+;;; add-ons
+;;;; notifications
+;;;;; minibuffer
+(defvar jao-gnus-tracked-groups
+ (let ((feeds (thread-first
+ (directory-files mail-source-directory nil "feeds\\.[^e]")
+ (seq-difference '("feeds.trove")))))
+ `(("nnml:bigml\\.inbox" "B" jao-themes-f00)
+ ("nnml:bigml\\.alba" "A" jao-themes-f00)
+ ("nnml:bigml\\.bugs" "b" jao-themes-error)
+ ("nnml:bigml\\.support" "S" default)
+ ("nnml:jao\\.\\(inbox\\|trove\\)" "I" jao-themes-f01)
+ ("nnml:bigml\\.[^ibs]" "W" jao-themes-dimm)
+ ("nnml:jao.hacking" "H" jao-themes-dimm)
+ ("nnml:jao.[^isth]" "J" jao-themes-dimm)
+ (,(format "^nnml:%s" (regexp-opt feeds)) "F" jao-themes-dimm)
+ ("feeds\\.e" "E" jao-themes-dimm)
+ ("nnml:local" "l" jao-themes-dimm))))
+
+(defun jao-gnus--unread-counts ()
+ (seq-reduce (lambda (r g)
+ (let ((n (gnus-group-unread (car g))))
+ (if (and (numberp n) (> n 0))
+ (prog1 (cons (cons (car g) n) r)
+ (gnus-message 7 "%s in %s" n g))
+ r)))
+ gnus-newsrc-alist
+ ()))
+
+(defun jao-gnus--unread-label (counts rx label face)
+ (let ((n (seq-reduce (lambda (n c)
+ (if (string-match-p rx (car c)) (+ n (cdr c)) n))
+ counts
+ 0)))
+ (when (> n 0) `(:propertize ,(format "%s%d " label n) face ,face))))
+
+(defvar jao-gnus--notify-strs ())
+
+(defun jao-gnus--notify-strs ()
+ (let ((counts (jao-gnus--unread-counts)))
+ (seq-filter #'identity
+ (seq-map (lambda (args)
+ (apply 'jao-gnus--unread-label counts args))
+ jao-gnus-tracked-groups))))
+
+(defun jao-gnus--notify ()
+ (setq jao-gnus--notify-strs (jao-gnus--notify-strs))
+ (jao-minibuffer-refresh))
+
+(with-eval-after-load "jao-minibuffer"
+ (jao-minibuffer-add-variable 'jao-gnus--notify-strs -20))
+
+(add-hook 'gnus-started-hook #'jao-gnus--notify)
+(add-hook 'gnus-summary-exit-hook #'jao-gnus--notify)
+(add-hook 'gnus-after-getting-new-news-hook #'jao-gnus--notify)
+
+;;;;; agenda updates
+(add-hook 'gnus-summary-exit-hook #'jao-org-agenda)
+
+
+;;;; open mail file in gnus
+(defun jao-gnus-file-to-group (file &optional maildir newsdir m-server n-server)
+ "Compute the Gnus group name from the given file name.
+ IN: /home/jao/.emacs.d/gnus/Mail/jao.trove/32, /home/jao/.emacs.d/gnus/Mail/
+ OUT: nnml:jao.trove "
+ (let* ((maildir (or maildir message-directory))
+ (newsdir (or newsdir jao-gnus-leafnode-spool))
+ (m-server (or m-server "nnml"))
+ (n-server (or n-server "nntp+localhost"))
+ (nntp (and newsdir (string-match-p newsdir file)))
+ (g (directory-file-name (file-name-directory file)))
+ (g (replace-regexp-in-string (file-name-as-directory maildir) "" g))
+ (g (replace-regexp-in-string (file-name-as-directory newsdir) "" g))
+ (g (cond (nntp (concat n-server ":" g))
+ ((file-name-directory g)
+ (replace-regexp-in-string "^\\([^/]+\\)/"
+ (concat m-server ":\\1/")
+ (file-name-directory g) t))
+ (t (concat m-server ":" g))))
+ (g (replace-regexp-in-string "/" "." g))
+ (g (replace-regexp-in-string "[/.]$" "" g)))
+ (cond ((string-match ":$" g) (concat g "inbox"))
+ (nntp g)
+ (t (replace-regexp-in-string ":\\." ":" g)))))
+
+(defun jao-gnus-goto-file (filename &optional _page)
+ (let ((group (jao-gnus-file-to-group filename))
+ (id (file-name-nondirectory filename)))
+ (if (and group id)
+ (org-gnus-follow-link group id)
+ (message "Couldn't get relevant info for switching to Gnus."))))
+
+;;;; afio
+(defun jao-gnus--on-afio-switch ()
+ (when (derived-mode-p 'gnus-group-mode)
+ (let ((no (or (gnus-group-unread (gnus-group-group-name)) 0)))
+ (unless (> no 0) (gnus-group-first-unread-group)))))
+
+(add-hook 'jao-afio-switch-hook #'jao-gnus--on-afio-switch)
+
+(defun jao-gnus-refresh-workspace ()
+ (interactive)
+ (save-window-excursion (calendar) (jao-org-agenda)))
+
+;;;; gnus-icalendar
+(require 'ol-gnus)
+(use-package gnus-icalendar
+ :demand t
+ :init (setq gnus-icalendar-org-capture-file
+ (expand-file-name "inbox.org" org-directory)
+ gnus-icalendar-org-capture-headline '("Appointments"))
+ :config (gnus-icalendar-org-setup))
+
+;;;; bbdb
+(with-eval-after-load "bbdb"
+ ;; (bbdb-initialize 'gnus 'message 'pgp)
+ (bbdb-mua-auto-update-init 'gnus)
+ (with-eval-after-load "gnus-sum"
+ (define-key gnus-summary-mode-map ":" 'bbdb-mua-annotate-sender)
+ (define-key gnus-summary-mode-map ";" 'bbdb-mua-annotate-recipients)))
+
+;;;; randomsig
+(with-eval-after-load "randomsig"
+ (with-eval-after-load "gnus-sum"
+ (define-key gnus-summary-save-map "-" 'gnus/randomsig-summary-read-sig)))
+
+;;;; recoll
+(unless jao-notmuch-enabled
+ (with-eval-after-load "org"
+ (org-link-set-parameters "message" :follow #'jao-gnus-goto-file))
+ (with-eval-after-load "consult-recoll"
+ (add-to-list 'consult-recoll-open-fns
+ '("message/rfc822" . jao-gnus-goto-file))))
+;;; keyboard shortcuts
+(define-key gnus-article-mode-map "i" 'jao-gnus-show-images)
+(define-key gnus-summary-mode-map "i" 'jao-gnus-show-images)
+(define-key gnus-article-mode-map "\M-g" 'jao-gnus-follow-link)
+(define-key gnus-summary-mode-map "\M-g" 'jao-gnus-follow-link)
+(define-key gnus-summary-mode-map "v" 'scroll-other-window)
+(define-key gnus-summary-mode-map "V" 'scroll-other-window-down)
+(define-key gnus-summary-mode-map "X" 'jao-gnus-arXiv-capture)
+(define-key gnus-summary-mode-map "e" 'jao-gnus-open-enclosure)
+(define-key gnus-summary-mode-map "\C-l" nil)
+(define-key gnus-group-mode-map "a" 'jao-gnus-refresh-workspace)
diff --git a/custom/jao-custom-notmuch.el b/custom/jao-custom-notmuch.el
new file mode 100644
index 0000000..3919897
--- /dev/null
+++ b/custom/jao-custom-notmuch.el
@@ -0,0 +1,657 @@
+;; -*- lexical-binding: t; -*-
+;;; minibuffer
+(defvar jao-notmuch-minibuffer-string "")
+
+(defvar jao-notmuch-minibuffer-queries
+ `((:name "" :query "tag:new and not tag:draft" :face jao-themes-f00)
+ (:name "B" :query "tag:new and tag:bigml and tag:inbox" :face default)
+ (:name "A" :query "tag:new and tag:alba" :face default)
+ (:name "b" :query "tag:new and tag:bigml and tag:bugs"
+ :face jao-themes-error)
+ (:name "S" :query "tag:new and tag:bigml and tag:support" :face default)
+ (:name "W"
+ :query "tag:new and tag:bigml and not tag:\"/support|bugs|inbox/\""
+ :face default)
+ (:name "I" :query "tag:new and tag:jao and tag:inbox" :face jao-themes-warning)
+ (:name "W" :query "tag:new and tag:jao and tag:write" :face jao-themes-warning)
+ (:name "J"
+ :query ,(concat "tag:new and tag:jao and not "
+ "tag:\"/local|hacking|draft|inbox|prog|words|write/\"")
+ :face default)
+ (:name "H" :query "tag:new and tag:hacking and not tag:\"/emacs/\"")
+ (:name "E" :query "tag:new and tag:\"/emacs/\"")
+ (:name "l" :query "tag:new and tag:local")
+ (:name "F" :query "tag:new and tag:feeds and not tag:\"/emacs/\"")))
+
+(defun jao-notmuch-notify ()
+ (let ((cnts (notmuch-hello-query-counts jao-notmuch-minibuffer-queries)))
+ (setq jao-notmuch-minibuffer-string
+ (mapconcat (lambda (c)
+ (propertize (format "%s%s"
+ (plist-get c :name)
+ (plist-get c :count))
+ 'face (or (plist-get c :face)
+ 'jao-themes-dimm)))
+ cnts
+ " "))
+ (jao-minibuffer-refresh)))
+
+(when jao-notmuch-enabled
+ (jao-minibuffer-add-variable 'jao-notmuch-minibuffer-string -20))
+
+;;; saved searches
+(defvar jao-notmuch--new "tag:\"/^(unread|new)$/\"")
+(defvar jao-notmuch--newa (concat jao-notmuch--new " AND "))
+
+(defun jao-notmuch--q (d0 d1 &optional k qs st)
+ (let ((q (or (when qs (mapconcat #'identity qs " AND "))
+ (concat jao-notmuch--newa
+ (mapconcat (lambda (d) (when d (concat "tag:" d)))
+ (list d0 d1) " AND ")))))
+ (list :name (concat d0 (when (and d1 (not (string= "" d1))) "/") d1)
+ :key k :query q :search-type (or st 'tree)
+ :sort-order 'oldest-first)))
+
+(defun jao-notmuch--qn (d0 d1 k qs &optional st)
+ (jao-notmuch--q d0 d1 k (cons jao-notmuch--new qs) st))
+
+(defun jao-notmuch--sq (tag &optional k d0 d1)
+ (jao-notmuch--qn (or d0 "feeds") (or d1 tag) k (list (concat "tag:" tag))))
+
+(defun jao-notmuch-tree-widen-search ()
+ (interactive)
+ (when-let ((query (notmuch-tree-get-query)))
+ (let ((notmuch-show-process-crypto (notmuch-tree--message-process-crypto)))
+ (notmuch-tree-close-message-window)
+ (notmuch-tree (string-replace jao-notmuch--newa "" query)))))
+
+(defun jao-notmuch-widen-searches (searches &optional extra)
+ (mapcar (lambda (s)
+ (let* ((q (plist-get s :query))
+ (qs (string-replace jao-notmuch--newa "" q)))
+ (plist-put (copy-sequence s) :query (concat qs extra))))
+ searches))
+
+(defun jao-notmuch-hello--insert-searches (searches title)
+ (when-let (searches (notmuch-hello-query-counts searches))
+ (let* ((cnt (when title
+ (seq-reduce (lambda (c q)
+ (+ c (or (plist-get q :count) 0)))
+ searches
+ 0)))
+ (title (if title (format "[ %d %s ]\n\n" cnt title) "\n"))
+ (notmuch-column-control 1.0))
+ (widget-insert (propertize title 'face 'jao-themes-f00))
+ (notmuch-hello-insert-buttons searches))))
+
+(defmacro jao-notmuch-def-searches (name searches)
+ (declare (indent 1))
+ (let ((name (and name (format "%s" name)))
+ (id (intern (format "jao-notmuch-%s-searches" (or name (gensym))))))
+ `(progn (defvar ,id ,searches)
+ (defun ,id () (jao-notmuch-hello--insert-searches ,id ,name))
+ (setq notmuch-saved-searches (append notmuch-saved-searches ,id))
+ (add-to-list 'notmuch-hello-sections ',id t))))
+
+(setq notmuch-hello-sections nil notmuch-saved-searches nil)
+
+(jao-notmuch-def-searches bigml
+ `(,(jao-notmuch--q "bigml" "inbox" "bi")
+ ,(jao-notmuch--q "bigml" "alba" "ba")
+ ,(jao-notmuch--q "bigml" "support" "bs")
+ ,(jao-notmuch--q "bigml" "bugs" "bb")
+ ,(jao-notmuch--q "bigml" "drivel" "bd")
+ ,(jao-notmuch--q "bigml" "lists" "bl")))
+
+(jao-notmuch-def-searches inbox
+ `(,(jao-notmuch--q "jao" "inbox" "ji")
+ ,(jao-notmuch--qn "jao" "bills" "jb" '("tag:bills"))
+ ,(jao-notmuch--qn "jao" "write" "jw" '("tag:write"))
+ ,(jao-notmuch--q "jao" "drivel" "jd")
+ ,(jao-notmuch--q "jao" "mdk" "jm")
+ ,(jao-notmuch--qn "jao" "hacking" "jh" '("tag:hacking" "not tag:\"/emacs/\""))
+ ,(jao-notmuch--qn "jao" "local" "jl" '("tag:local"))))
+
+(jao-notmuch-def-searches news
+ (mapcar #'jao-notmuch--sq '("news" "noticias" "fun" "words" "computers")))
+
+(jao-notmuch-def-searches hacking
+ (mapcar #'jao-notmuch--sq '("xmobar" "geiser" "mdk" "mailutils" "notmuch")))
+
+(jao-notmuch-def-searches prog
+ (append (mapcar #'jao-notmuch--sq
+ '( "lobsters" "clojure" "lisp" "scheme"
+ "haskell" "idris" "erlang" "pharo"))
+ `(,(jao-notmuch--qn "feeds" "prog" "fp"
+ '("tag:prog" "not tag:\"/emacs/\"")))))
+
+(jao-notmuch-def-searches emacs
+ `(,(jao-notmuch--sq "emacs" "ee" "emacs" "feeds")
+ ,(jao-notmuch--sq "emacs-help" "eh" "emacs" "help")
+ ,(jao-notmuch--sq "emacs-github" "eg" "emacs" "github")
+ ,(jao-notmuch--sq "emacs-devel" "ed" "emacs" "devel")
+ ,(jao-notmuch--sq "emacs-bugs" "eb" "emacs" "bugs")
+ ,(jao-notmuch--sq "emacs-diffs" "ec" "emacs" "diffs")))
+
+(jao-notmuch-def-searches sci
+ (mapcar #'jao-notmuch--sq
+ '("philosophy" "math" "physics" "sci" "gr-qc" "quant-ph")))
+
+(jao-notmuch-def-searches flags
+ (jao-notmuch-widen-searches notmuch-saved-searches " AND tag:flagged"))
+
+(jao-notmuch-def-searches nil
+ `(,(jao-notmuch--q "bml" "flagged" "rb" '("tag:flagged" "tag:bigml"))
+ ,(jao-notmuch--q "jao" "flagged" "rj" '("tag:flagged" "tag:jao"))
+ ,(jao-notmuch--q "feeds" "flagged" "rf" '("tag:flagged" "tag:feeds"))))
+
+(jao-notmuch-def-searches today
+ `(,(jao-notmuch--q "new" nil "nn" '("tag:new" "not tag:draft"))
+ ,(jao-notmuch--q "jao" "drafts" "d" '("tag:draft"))
+ ,(jao-notmuch--q "bml" "sent" "ts"
+ '("tag:bigml" "date:1d.." "tag:sent"))
+ ,(jao-notmuch--q "jao" "sent" "tS"
+ '("tag:\"/jao|hacking/\"" "date:1d.." "tag:sent"))
+ ,(jao-notmuch--q "bml" "today" "tb"
+ '("not tag:sent" "tag:bigml" "date:24h.."))
+ ,(jao-notmuch--q "jao" "today" "tj"
+ '("tag:jao" "date:24h.."
+ "not tag:\"/(sent|feeds|spam|local)/\""))))
+
+(jao-notmuch-def-searches trove
+ (mapcar (lambda (m) (list :query (concat "tag:trove and tag:" m)
+ :name (concat "trove/" m)
+ :key (concat "t" (substring m 0 1))
+ :search-type 'tree))
+ '("jao" "hacking" "feeds" "bills")))
+
+(jao-notmuch-def-searches nil
+ '((:query "not tag:trove and not tag:bigml" :name "jao/untroved" :search-type tree)
+ (:query "tag:sent and tag:bigml" :name "bigml/sent" :search-type tree)
+ (:query "tag:sent and not tag:bigml" :name "jao/sent" :search-type tree)
+ (:query "*" :name "messages" :search-type tree)))
+
+(defvar jao-notmuch-widened-searches
+ (jao-notmuch-widen-searches notmuch-saved-searches))
+
+(defun jao-notmuch-jump-search (&optional widen)
+ (interactive "P")
+ (let ((notmuch-saved-searches
+ (if widen jao-notmuch-widened-searches notmuch-saved-searches)))
+ (notmuch-jump-search)))
+
+;;; tags
+(defvar jao-notmuch--shared-tags
+ '("new" "unread" "flagged" "signed" "sent" "attachment" "forwarded" "inbox"
+ "encrypted" "gmane" "gnus" "feeds" "rss" "mce" "trove" "prog" "emacs"))
+
+(defun jao-notmuch--subtags (tag &rest excl)
+ (let* ((cmd (concat "notmuch search --output=tags tag:" tag))
+ (ts (split-string (shell-command-to-string cmd))))
+ (seq-difference ts (append jao-notmuch--shared-tags (cons tag excl)))))
+
+(setq notmuch-archive-tags '("+trove" "-new" "-drivel" "-words" "-inbox")
+ notmuch-show-mark-read-tags '("-new" "-unread")
+ notmuch-tag-formats
+ (let (;; (d `(:foreground ,(face-attribute 'jao-themes-dimm :foreground)))
+ (e `(:foreground ,(face-attribute 'jao-themes-error :foreground))))
+ `(("unread")
+ ("signed")
+ ("new" "ยท")
+ ("replied" "โ†ฉ" (propertize tag 'face '(:family "Fira Code")))
+ ("sent" "๐Ÿ›ช")
+ ("attachment" "๐Ÿ“Ž")
+ ("deleted" "๐Ÿ—™" (propertize tag 'face '(:underline nil ,@e)))
+ ("flagged" "โœ“")
+ ("jao" "j")
+ ("bigml" "b")
+ ("feeds" "f")
+ ("lists" "l")
+ ("gmane" "g")))
+ notmuch-tag-deleted-formats
+ '(("unread")
+ ("new")
+ ("flagged")
+ ("deleted")
+ (".*" (notmuch-apply-face tag 'notmuch-tag-deleted))))
+
+(with-eval-after-load "notmuch-tag"
+ (advice-add #'notmuch-read-tag-changes
+ :filter-return (lambda (x) (mapcar #'string-trim x))))
+
+;;; package
+;; (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/")
+(jao-load-path "notmuch")
+
+(use-package notmuch
+ :init
+ (setq notmuch-address-use-company t
+ notmuch-address-command 'as-is
+ notmuch-always-prompt-for-sender t
+ notmuch-draft-folder "drafts"
+ notmuch-draft-quoted-tags '("part")
+ notmuch-fcc-dirs
+ '(("\\(support\\|education\\)@bigml.com" . nil)
+ ("mail@jao.io" . nil)
+ (".*@bigml.com" . "bigml -new -unread +sent +bigml")
+ (".*" . "jao -new -unread +sent +jao"))
+ notmuch-maildir-use-notmuch-insert t)
+
+ :custom ((notmuch-address-internal-completion '(sent nil)))
+
+ :config
+
+ (add-hook 'message-send-hook #'notmuch-mua-attachment-check)
+
+ (when jao-notmuch-enabled
+ (define-key message-mode-map (kbd "C-c C-d") #'notmuch-draft-postpone)
+ (setq message-directory "~/var/mail/"
+ message-auto-save-directory "/tmp"
+ mail-user-agent 'message-user-agent))
+
+ :bind (:map notmuch-common-keymap
+ (("E" . jao-notmuch-open-enclosure)
+ ("B" . notmuch-show-resend-message)
+ ("b" . jao-notmuch-browse-urls))))
+
+(use-package jao-notmuch :demand t)
+
+;;; hello
+(defun jao-notmuch-hello--header () (insert " "))
+(when (display-graphic-p)
+ (add-to-list 'notmuch-hello-sections 'jao-notmuch-hello--header))
+
+(add-to-list 'notmuch-hello-sections 'notmuch-hello-insert-alltags t)
+
+(defun jao-notmuch-refresh-agenda ()
+ (interactive)
+ (save-window-excursion (calendar) (jao-org-agenda)))
+
+(defun jao-notmuch-hello-first ()
+ (interactive)
+ (let ((inhibit-message t))
+ (goto-char (point-min))
+ (widget-forward 1)))
+
+(defun jao-notmuch-refresh-hello (&optional agenda)
+ (interactive "P")
+ (ignore-errors
+ (when (and (string= "mail" (jao-afio-frame-name))
+ (derived-mode-p 'notmuch-hello-mode))
+ (when (not (string-blank-p jao-notmuch-minibuffer-string))
+ (let ((notmuch-hello-auto-refresh nil)) (notmuch-hello)))
+ (let ((jao-minibuffer-inhibit t))
+ (when agenda (jao-notmuch-refresh-agenda)))
+ (unless (widget-at) (jao-notmuch-hello-first))
+ (jao-minibuffer-refresh))))
+
+(defvar jao-notmuch-hello--sec-rx "^\\(\\[ [0-9]+\\|All tags:.+\\)")
+
+(defun jao-notmuch-hello-next-section ()
+ (interactive)
+ (when (re-search-forward jao-notmuch-hello--sec-rx nil t)
+ (widget-forward 1)))
+
+(defun jao-notmuch-hello-prev-section ()
+ (interactive)
+ (beginning-of-line)
+ (unless (looking-at-p jao-notmuch-hello--sec-rx)
+ (re-search-backward jao-notmuch-hello--sec-rx nil t))
+ (when (re-search-backward jao-notmuch-hello--sec-rx nil t)
+ (end-of-line)
+ (widget-forward 1)))
+
+(defun jao-notmuch-hello-next ()
+ (interactive)
+ (if (widget-at)
+ (widget-button-press (point))
+ (jao-notmuch-hello-next-section)))
+
+(use-package notmuch-hello
+ :init
+ (setq notmuch-column-control 1.0
+ notmuch-hello-hide-tags nil
+ notmuch-hello-thousands-separator ","
+ notmuch-hello-auto-refresh t
+ notmuch-show-all-tags-list nil
+ notmuch-show-logo nil
+ notmuch-show-empty-saved-searches nil)
+
+ (add-to-list 'display-buffer-alist
+ '("\\*notmuch-hello\\*"
+ (display-buffer-reuse-window)
+ (body-function . (lambda (w) (set-window-margins w 1)))))
+
+ :hook ((notmuch-hello-refresh . jao-notmuch-notify))
+
+ :config
+ (when jao-notmuch-enabled
+ (add-hook 'jao-afio-switch-hook #'jao-notmuch-refresh-hello))
+
+ :bind (:map notmuch-hello-mode-map
+ (("a" . jao-notmuch-refresh-agenda)
+ ("g" . jao-notmuch-refresh-hello)
+ ("j" . jao-notmuch-jump-search)
+ ("n" . jao-notmuch-hello-next)
+ ("p" . widget-backward)
+ ("SPC" . widget-button-press)
+ ("/" . consult-notmuch)
+ ("." . jao-notmuch-hello-first)
+ ("[" . jao-notmuch-hello-prev-section)
+ ("]" . jao-notmuch-hello-next-section))))
+
+;;; show
+(defun jao-notmuch-open-enclosure (add)
+ (interactive "P")
+ (with-current-notmuch-show-message
+ (goto-char (point-min))
+ (if (not (search-forward "Enclosure:" nil t))
+ (user-error "No enclosure in message body")
+ (re-search-forward "https?://" nil t)
+ (if-let (url (thing-at-point-url-at-point))
+ (progn
+ (message "%s %s ..." (if add "Adding" "Playing") url)
+ (unless add (jao-mpc-clear))
+ (jao-mpc-add-url url)
+ (unless add (jao-mpc-play)))
+ (error "Found an enclosure, but not a link!")))))
+
+(defconst jao-mail-clean-rx
+ (regexp-opt '("ElDiario.es - ElDiario.es: " "The Guardian: "
+ "The Conversation โ€“ Articles (UK): "
+ "gr-qc updates on arXiv.org: "
+ "quant-ph updates on arXiv.org: ")))
+
+(defun jao-mail-clean-address (args)
+ (when-let ((address (car args)))
+ (list (thread-last (replace-regexp-in-string jao-mail-clean-rx "" address)
+ (replace-regexp-in-string " " ", ")))))
+
+(use-package notmuch-show
+ :init
+ (setq gnus-blocked-images "."
+ notmuch-message-headers
+ '("Subject" "To" "Cc" "Date" "Reply-To" "List-Id" "X-RSS-Feed")
+ notmuch-show-only-matching-messages t
+ notmuch-show-part-button-default-action 'notmuch-show-view-part
+ notmuch-wash-signature-lines-max 0
+ notmuch-wash-wrap-lines-length 120
+ notmuch-wash-citation-lines-prefix 120
+ notmuch-wash-citation-lines-suffix 120
+ notmuch-show-text/html-blocked-images "."
+ notmuch-show-header-line nil ;; #'jao-notmuch-message-header-line
+ jao-notmuch-header-line-format "[%N / %M / %T] %n / %m / %t")
+
+ :config
+
+ (advice-add 'notmuch-clean-address :filter-args #'jao-mail-clean-address)
+ (add-hook 'notmuch-show-mode-hook (lambda () (setq fill-column 80)))
+
+ :bind
+ (:map notmuch-show-mode-map
+ (("h" . jao-notmuch-goto-tree-buffer)
+ ("r" . notmuch-show-reply)
+ ("R" . notmuch-show-reply-sender)
+ ("TAB" . jao-notmuch-show-next-button)
+ ([backtab] . jao-notmuch-show-previous-button)
+ ("RET" . jao-notmuch-show-ret))))
+
+;;; search
+(use-package notmuch-search
+ :init (setq notmuch-search-result-format
+ '(("date" . "%12s ")
+ ("count" . "%-7s ")
+ ("authors" . "%-35s")
+ ("subject" . " %-100s")
+ (jao-notmuch-format-tags . " (%s)"))
+ notmuch-search-buffer-name-format "*%s*"
+ notmuch-saved-search-buffer-name-format "*%s*")
+ :bind (:map notmuch-search-mode-map
+ (("RET" . notmuch-tree-from-search-thread)
+ ("M-RET" . notmuch-search-show-thread))))
+
+;;; tree
+(defun jao-notmuch-tree--forward (&optional prev)
+ (interactive)
+ (forward-line (if prev -1 1))
+ (when prev (forward-char 2))
+ (jao-notmuch-tree-scroll-or-next))
+
+(defun jao-notmuch-tree--backward ()
+ (interactive)
+ (jao-notmuch-tree--forward t))
+
+(defun jao-notmuch--via-url ()
+ (when (window-live-p notmuch-tree-message-window)
+ (with-selected-window notmuch-tree-message-window
+ (goto-char (point-min))
+ (when (re-search-forward "^Via: http" nil t)
+ (thing-at-point-url-at-point)))))
+
+(defun jao-notmuch-browse-url (ext)
+ (interactive "P")
+ (when-let (url (or (jao-notmuch--via-url)
+ (car (last (jao-notmuch-message-urls)))))
+ (funcall (if ext browse-url-secondary-browser-function #'browse-url)
+ url)))
+
+(defun jao-notmuch-adjust-tree-fonts (&optional family)
+ (let ((fg (face-attribute 'jao-themes-dimm :foreground)))
+ (dolist (f '(notmuch-tree-match-tree-face
+ notmuch-tree-no-match-tree-face))
+ (if family
+ (set-face-attribute f nil :family family :foreground fg)
+ (set-face-attribute f nil :foreground fg)))))
+
+(use-package notmuch-tree
+ :init
+ (setq notmuch-tree-result-format
+ `(("date" . "%12s ")
+ ("authors" . "%-25s")
+ ;; (jao-notmuch-format-author . 25)
+ (jao-notmuch-format-msg-ticks . ,jao-mails-regexp)
+ (jao-notmuch-format-tree-and-subject . "%>-85s")
+ (jao-notmuch-format-tags . " (%s)"))
+ notmuch-unthreaded-result-format notmuch-search-result-format
+ consult-notmuch-result-format
+ `((jao-notmuch-format-msg-ticks . ,jao-mails-regexp)
+ ("date" . "%12s ")
+ ("authors" . "%-35s")
+ ("subject" . " %-100s")
+ (jao-notmuch-format-tags . " (%s)"))
+ notmuch-tree-thread-symbols
+ '((prefix . "โ”€") (top . "โ”€") (top-tee . "โ”ฌ")
+ (vertical . "โ”‚") (vertical-tee . "โ”œ") (bottom . "โ•ฐ")
+ (arrow . ""))
+ ;; notmuch-tree-thread-symbols
+ ;; '((prefix . " ") (top . " ") (top-tee . " ")
+ ;; (vertical . " ") (vertical-tee . " ") (bottom . " ")
+ ;; (arrow . ""))
+ notmuch-tree-outline-enabled t
+ notmuch-tree-outline-visibility 'hide-others
+ notmuch-tree-outline-auto-close t
+ notmuch-tree-outline-open-on-next t)
+ :config
+
+ (when (display-graphic-p)
+ (jao-notmuch-adjust-tree-fonts
+ (when (string-prefix-p "Hack" jao-themes-default-face) "Source Code Pro")))
+
+ (defun jao-notmuch-before-tree (&rest _args)
+ (when (string= (buffer-name) "*notmuch-hello*")
+ (window-configuration-to-register ?G)
+ (split-window-right 40)
+ (other-window 1)))
+
+ (defvar jao-notmuch--visits 0)
+
+ (defun jao-notmuch-after-tree-quit (&optional _both)
+ (when (not (derived-mode-p 'notmuch-tree-mode 'notmuch-hello-mode))
+ (jump-to-register ?G))
+ (jao-notmuch-refresh-hello (= 0 (mod (cl-incf jao-notmuch--visits) 50))))
+
+ (defun jao-notmuch-tree--sentinel (proc)
+ (when (eq (process-status proc) 'exit)
+ (let ((inhibit-read-only t))
+ (save-excursion
+ (goto-char (point-max))
+ (when (re-search-backward "^End of search results." nil t)
+ (delete-line))))
+ (jao-notmuch-thread-info-mode)))
+
+ (add-hook 'notmuch-tree-process-exit-functions #'jao-notmuch-tree--sentinel)
+
+ (advice-add 'notmuch-tree :before #'jao-notmuch-before-tree)
+ (advice-add 'notmuch-tree-quit :after #'jao-notmuch-after-tree-quit)
+
+ :bind (:map notmuch-tree-mode-map
+ (("b" . jao-notmuch-browse-urls)
+ ("d" . jao-notmuch-tree-toggle-delete)
+ ("D" . jao-notmuch-tree-toggle-delete-thread)
+ ("h" . jao-notmuch-goto-message-buffer)
+ ("i" . jao-notmuch-toggle-images)
+ ("k" . jao-notmuch-tree-read-thread)
+ ("N" . jao-notmuch-tree--forward)
+ ("O" . notmuch-tree-toggle-order)
+ ("o" . jao-notmuch-tree-widen-search)
+ ("P" . jao-notmuch-tree--backward)
+ ("r" . notmuch-tree-reply)
+ ("R" . notmuch-tree-reply-sender)
+ ("s" . jao-notmuch-tree-toggle-spam)
+ ("u" . jao-notmuch-tree-toggle-flag)
+ ("v" . notmuch-tree-scroll-message-window)
+ ("V" . notmuch-tree-scroll-message-window-back)
+ ("x" . jao-notmuch-arXiv-capture)
+ ("<" . jao-notmuch-tree-beginning-of-buffer)
+ (">" . jao-notmuch-tree-end-of-buffer)
+ ("\\" . notmuch-tree-view-raw-message)
+ ("." . jao-notmuch-toggle-mime-parts)
+ (";" . bbdb-mua-display-sender)
+ ("=" . jao-notmuch-tree-toggle-message)
+ ("RET" . jao-notmuch-tree-show-or-scroll)
+ ("SPC" . jao-notmuch-tree-scroll-or-next)
+ ("M-g" . jao-notmuch-browse-url)
+ ("M-u" . jao-notmuch-tree-reset-tags))))
+
+;;; browse-url
+(defvar jao-notmuch-url-rx "^notmuch:\\(/+\\|id:\\)\\(.+\\)")
+
+(defun jao-notmuch-open-url (url &rest _)
+ (and (string-match jao-notmuch-url-rx url)
+ (notmuch-show (concat "id:" (match-string 2 url)))))
+
+(add-to-list 'browse-url-handlers
+ (cons jao-notmuch-url-rx 'jao-notmuch-open-url))
+
+;;; org mode
+(defvar jao-org-notmuch-last-subject nil)
+(defun jao-org-notmuch-last-subject () jao-org-notmuch-last-subject)
+
+(defun jao-notmuch--add-tags (tags)
+ (if (derived-mode-p 'notmuch-show-mode)
+ (notmuch-show-add-tag tags)
+ (notmuch-tree-add-tag tags)))
+
+(defun org-notmuch-store-link ()
+ "Store a link to a notmuch mail message."
+ (cl-case major-mode
+ ((notmuch-show-mode notmuch-tree-mode)
+ ;; Store link to the current message
+ (let* ((id (notmuch-show-get-message-id))
+ (link (concat "notmuch:" id))
+ (subj (notmuch-show-get-subject))
+ (description (format "Mail: %s" subj)))
+ (setq jao-org-notmuch-last-subject subj)
+ (when (y-or-n-p "Archive message? ")
+ (jao-notmuch--add-tags '("+trove")))
+ (when (y-or-n-p "Flag message? ")
+ (jao-notmuch--add-tags '("+flagged")))
+ (org-link-store-props :type "notmuch"
+ :link link
+ :description description)))
+ (notmuch-search-mode
+ ;; Store link to the thread on the current line
+ (let* ((id (notmuch-search-find-thread-id))
+ (link (concat "notmuch:" id))
+ (subj (notmuch-search-find-subject))
+ (description (format "Mail: %s" subj)))
+ (setq jao-org-notmuch-last-subject subj)
+ (org-link-store-props
+ :type "notmuch"
+ :link link
+ :description description)))))
+
+(with-eval-after-load "org"
+ (org-link-set-parameters "notmuch"
+ :follow 'notmuch-show
+ :store 'org-notmuch-store-link))
+;;; arXiv
+(use-package org-capture
+ :config
+ (add-to-list 'org-capture-templates
+ '("X" "arXiv" entry (file "notes/physics/arxiv.org")
+ "* %(jao-org-notmuch-last-subject)\n %i"
+ :immediate-finish t)
+ t)
+ (org-capture-upgrade-templates org-capture-templates))
+
+(defun jao-notmuch-arXiv-capture ()
+ (interactive)
+ (save-window-excursion
+ (jao-notmuch-goto-message-buffer)
+ (save-excursion
+ (goto-char (point-min))
+ (re-search-forward "\\[ text/html \\]")
+ (forward-paragraph)
+ (setq-local transient-mark-mode 'lambda)
+ (set-mark (point))
+ (goto-char (point-max))
+ (org-capture nil "X"))))
+
+;;; html renderer
+(when jao-notmuch-enabled (setq mm-text-html-renderer 'shr))
+
+;;; consult
+(jao-load-path "consult-notmuch")
+(require 'consult-notmuch)
+(setq consult-notmuch-newest-first t)
+(consult-customize consult-notmuch :preview-key 'any)
+
+(defvar jao-consult-notmuch-history nil)
+
+(defvar jao-mailbox-folders '("bigml" "jao"))
+
+(defun jao-consult-notmuch-folder (&optional tree folder)
+ (interactive "P")
+ (let* ((folder (if folder
+ (file-name-as-directory folder)
+ (completing-read "Group: "
+ jao-mailbox-folders
+ nil nil nil
+ jao-consult-notmuch-history
+ ".")))
+ (folder (replace-regexp-in-string "/\\(.\\)" ".\\1" folder))
+ (init (read-string "Initial query: "))
+ (init (format "folder:/%s/ %s" folder init)))
+ (if tree (consult-notmuch-tree init) (consult-notmuch init))))
+
+(with-eval-after-load "notmuch-hello"
+ (define-key notmuch-hello-mode-map "f" #'jao-consult-notmuch-folder))
+;;; recoll
+(defun jao-notmuch-open-file (fname &optional _page)
+ (with-temp-buffer
+ (insert-file-contents-literally fname)
+ (goto-char (point-min))
+ (and (re-search-forward "^Message-ID: <\\([^>]+\\)>$" nil t)
+ (notmuch-show (concat "id:" (match-string 1))))))
+
+(when jao-notmuch-enabled
+ (with-eval-after-load "org"
+ (org-link-set-parameters "message" :follow #'jao-notmuch-open-file))
+
+ (with-eval-after-load "consult-recoll"
+ (add-to-list 'consult-recoll-open-fns
+ '("message/rfc822" . jao-notmuch-open-file))))
+
+;;; .
+(provide 'jao-custom-notmuch)
diff --git a/custom/jao-custom-org.el b/custom/jao-custom-org.el
new file mode 100644
index 0000000..02e7a03
--- /dev/null
+++ b/custom/jao-custom-org.el
@@ -0,0 +1,314 @@
+;; -*- lexical-binding: t -*-
+
+;;; General configuration
+(defvar jao-org-dir (expand-file-name "~/doc/org"))
+
+(use-package org
+ :ensure t
+ :demand t
+ :custom ((org-export-backends '(ascii html latex texinfo)))
+ :init
+ (defalias 'jao-open-gnus-frame 'jao-afio-goto-mail)
+
+ (setq org-adapt-indentation t
+ org-catch-invisible-edits 'smart
+ org-complete-tags-always-offer-all-agenda-tags t
+ org-cycle-separator-lines 0 ;; no blank lines when all colapsed
+ org-deadline-warning-days 14
+ org-directory jao-org-dir
+ org-default-notes-file (expand-file-name "inbox.org" org-directory)
+ org-ellipsis " .." ;; โ†ด
+ org-email-link-description-format "Email %c: %s"
+ org-enforce-todo-dependencies t
+ org-fast-tag-selection-single-key 'expert
+ org-insert-heading-respect-content nil ;; for C-RET
+ ;; org-list-demote-modify-bullet '(("+" . "-") ("-" . "+") ("*" . "+"))
+ org-link-frame-setup
+ '((gnus . (lambda (&optional x) (jao-open-gnus-frame)))
+ (file . find-file-other-window))
+ org-log-done nil
+ org-modules '(bibtex info eww eshell git-link)
+ org-odd-levels-only t
+ org-outline-path-complete-in-steps nil
+ org-refile-allow-creating-parent-nodes 'confirm
+ org-refile-targets '((nil :maxlevel . 5)
+ (org-agenda-files :maxlevel . 5))
+ org-refile-use-outline-path 'file
+ org-return-follows-link t
+ org-reverse-note-order t
+ org-special-ctrl-a/e t
+ org-src-fontify-natively t
+ org-startup-folded t
+ org-tag-alist nil
+ org-tags-column -75
+ org-todo-keywords
+ '((sequence "TODO(t)" "STARTED(s!)" "|" "DONE(d!)")
+ (sequence "REPLY(r)" "WAITING(w!)" "|" "DONE(d!)")
+ (sequence "TOREAD(T)" "READING(R!)" "|" "READ(a!)")
+ (sequence "|" "CANCELLED(x!)" "SOMEDAY(o!)" "DONE(d!)"))
+ org-use-fast-todo-selection t
+ org-use-speed-commands nil ;; t and then ? to see help
+ org-gnus-prefer-web-links nil))
+
+;;; Agenda
+(setq org-agenda-custom-commands
+ '(("j" agenda "" ((org-agenda-ndays 14)
+ (org-agenda-overriding-header " ")))
+ ("w" todo "WAITING" nil)
+ ("W" agenda "" ((org-agenda-ndays 21))))
+ org-agenda-files (mapcar (lambda (f)
+ (expand-file-name f jao-org-dir))
+ '("inbox.org" "bigml.org"))
+ org-agenda-block-separator " "
+ org-agenda-breadcrumbs-separator "โ€ข"
+ org-agenda-current-time-string "โ€ข" ;; "*"
+ ;; '((daily today require-timed)
+ ;; (800 1000 1200 1400 1600 1800 2000) "" "ยท")
+ org-agenda-hide-tags-regexp ".*"
+ org-agenda-include-diary t
+ org-agenda-include-inactive-timestamps t
+ org-agenda-inhibit-startup nil
+ org-agenda-restore-windows-after-quit t
+ org-agenda-show-all-dates t
+ org-agenda-skip-deadline-if-done t
+ org-agenda-skip-scheduled-if-done nil
+ org-agenda-span 14
+ org-agenda-start-on-weekday nil
+ org-agenda-time-grid '((daily require-timed) () "" "ยท")
+ org-agenda-window-setup 'current-window)
+
+(defun jao-org-agenda ()
+ (interactive)
+ (org-agenda nil "j"))
+
+(defun jao-org-agenda-hook ()
+ (setq-local cursor-in-non-selected-windows nil))
+
+(add-hook 'org-agenda-mode-hook #'jao-org-agenda-hook)
+
+(add-to-list 'display-buffer-alist
+ '("\\*Org Agenda\\*"
+ (display-buffer-reuse-window)
+ (body-function . (lambda (w) (set-window-margins w 2 1)))))
+
+
+;;; Capture templates
+(setq org-capture-templates
+ '(("t" "TODO" entry
+ (file+headline "inbox.org" "Todo")
+ "* TODO %?\n %i%a" :prepend t)
+ ("r" "REPLY" entry
+ (file+headline "inbox.org" "Todo")
+ "* REPLY %:subject%?\n %t\n %i%a" :prepend t)
+ ("a" "Appointment" entry
+ (file+olp "inbox.org" "Appointments")
+ "* %^T %?\n %a" :time-prompt t)
+ ("i" "Inbox note" entry (file+headline "inbox.org" "Notes")
+ "* %a\n %i%?(added on: %u)" :prepend t)))
+;; (org-capture-upgrade-templates org-capture-templates)
+
+;;; MIME and file apps
+(setq org-file-apps
+ '((system . mailcap)
+ (".*\\.djvu" . system)
+ (t . emacs)))
+
+;;; Appearance
+(use-package org-appear
+ :disabled t
+ :ensure t
+ :init (setq org-appear-autolinks nil
+ org-appear-delay 0.0
+ org-appear-manual-linger t)
+ :hook (org-mode . org-appear-mode))
+
+;;; Images
+;; #+caption: Image caption.
+;; #+attr_org: :width 100
+;; [[file:path/to/image.png]]
+
+(setq org-startup-indented nil
+ org-pretty-entities nil
+ org-hide-emphasis-markers t
+ org-hide-leading-stars t
+ org-startup-with-inline-images t
+ org-cycle-inline-images-display t
+ org-display-remote-inline-images 'download ;; 'skip 'cache
+ org-image-actual-width '(500))
+
+;;; LaTeX
+(use-package org-fragtog
+ :after org
+ :ensure t
+ :hook ((org-mode . org-fragtog-mode)))
+
+(require 'org-fragtog)
+
+(setq org-format-latex-options
+ `(:foreground default
+ :background
+ ,(if (jao-colors-scheme-dark-p) "black" "white")
+ :scale 1.25
+ :html-foreground "black"
+ :html-background "Transparent"
+ :html-scale 1.0
+ :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))
+ org-preview-latex-image-directory
+ (expand-file-name "~/.emacs.d/cache/ltximg/")
+ org-latex-hyperref-template nil
+ org-highlight-latex-and-related '(latex script entities))
+
+(require 'ox-latex)
+
+;;; Export (minted and pandoc)
+(setq org-latex-listings 'minted
+ org-latex-packages-alist '(("" "minted"))
+ org-latex-pdf-process
+ '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
+ "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
+
+(use-package ox-pandoc
+ :after org
+ :ensure t)
+
+;;; Babel and literate programming
+(setq org-src-window-setup 'other-window) ;; current-window
+(require 'org-tempo nil t) ;; <s TAB for 9.2 and later
+
+;; (use-package ob-prolog
+;; :ensure t
+;; :after org)
+
+(org-babel-do-load-languages
+ 'org-babel-load-languages
+ '((calc . t)
+ (clojure . t)
+ (emacs-lisp .t)
+ (gnuplot .t)
+ (haskell . t)
+ (makefile . t)
+ (ocaml . t)
+ (org . t)
+ (python . t)
+ (scheme .t)
+ (shell . t)
+ ;; (prolog . t)
+ ))
+
+;;; Org cliplink (link from clipboard)
+(use-package org-cliplink
+ :ensure t
+ :bind (:map org-mode-map ("C-c C-f" . org-cliplink))
+ :config
+ (add-to-list 'org-capture-templates
+ '("k" "Cliplink capture task" entry
+ (file+headline "inbox.org" "Todo")
+ "* TODO %(org-cliplink-capture) %?" :prepend t)
+ t))
+
+;;; Notes
+(use-package jao-org-notes
+ :commands (jao-org-notes-setup)
+ :config
+ (defun jao-org-notes-note-p ()
+ (string-prefix-p jao-org-notes-dir (buffer-file-name)))
+
+ (defun jao-org-notes-recoll ()
+ "Use consult-recoll to search notes."
+ (interactive)
+ (consult-recoll (format "dir:%s " jao-org-notes-dir)))
+
+ (jao-transient-major-mode org
+ ["Notes"
+ ("c" "open or create note" jao-org-notes-create)
+ ("/" "find and open note" jao-org-notes-open)
+ ("\\" "find and open note by tags" jao-org-notes-consult-tags)]
+ ["Extended search"
+ ("g" "ripgrep notes" jao-org-notes-consult-ripgrep)
+ ("r" "recoll notes" jao-org-notes-recoll)]
+ ["Current note" :if jao-org-notes-note-p
+ ("i" "insert link" jao-org-notes-insert-link)
+ ("t" "insert tags" jao-org-notes-insert-tags)
+ ("v" "show backlinks" jao-org-notes-backlinks)]))
+
+(jao-org-notes-setup "n")
+
+;;; Links
+(require 'ol-eshell nil t)
+;; (require 'ol-bbdb nil t)
+(require 'ol-info nil t)
+(setq org-link-abbrev-alist '(("jao.io" "https://jao.io/")))
+
+(defun jao-org-link-at-point (&optional copy)
+ (when (thing-at-point-looking-at "\\[\\[\\([^]]+\\)\\]\\[[^]]+\\]\\]")
+ (when copy (kill-ring-save (match-beginning 1) (match-end 1)))
+ (match-string-no-properties 1)))
+
+(defun jao-org-copy-link-at-point ()
+ (interactive)
+ (message "%s" (or (jao-org-link-at-point t) "No link at point")))
+
+(defun jao-org-insert-link (url title)
+ (insert (format "[[%s][%s]]" url title)))
+
+(defun jao-insert-eww-link ()
+ "Look for last eww buffer and insert an org link to it."
+ (interactive)
+ (when-let (b (car (jao-eww-session-eww-buffers)))
+ (let ((lnk (with-current-buffer b
+ (format "[[%s][%s]]"
+ (eww-current-url)
+ (jao-eww-buffer-title)))))
+ (insert lnk))))
+
+(use-package jao-org-links
+ :commands jao-org-links-setup
+ :bind (("C-c T" . jao-org-insert-doc)))
+
+(jao-org-links-setup jao-sink-dir)
+
+(with-eval-after-load "pdf-view"
+ (define-key pdf-view-mode-map (kbd "C-c o") #'jao-org-pdf-goto-org)
+ (define-key pdf-view-mode-map (kbd "C-c O") #'jao-org-pdf-goto-org*))
+
+(with-eval-after-load "doc-view"
+ (define-key doc-view-mode-map (kbd "C-c o") #'jao-org-pdf-goto-org)
+ (define-key doc-view-mode-map (kbd "C-c O") #'jao-org-pdf-goto-org*))
+
+;; eldoc
+(defun jao-org-eldoc--hook ()
+ (set (make-local-variable 'eldoc-documentation-function)
+ 'jao-org-link-at-point)
+ (eldoc-mode))
+(add-hook 'org-mode-hook 'jao-org-eldoc--hook)
+
+;;; savedoc
+(defun jao-org--show-if-hidden ()
+ (when (outline-invisible-p)
+ (save-excursion
+ (outline-previous-visible-heading 1)
+ (org-show-subtree))))
+(add-hook 'org-mode-hook 'jao-org--show-if-hidden t)
+
+;;; Keybindings
+(define-key mode-specific-map [?a] 'org-agenda)
+(define-key org-mode-map "\C-cv" 'jao-org-copy-link-at-point)
+(define-key org-mode-map [(control ?c) tab] 'org-force-cycle-archived)
+(define-key org-mode-map [(f7)] 'org-archive-to-archive-sibling)
+(define-key org-mode-map "\C-cE" 'jao-insert-eww-link)
+(define-key org-mode-map "\C-cW" 'jao-insert-eww-link)
+(define-key org-mode-map "\C-c'" 'org-edit-src-code)
+(define-key org-mode-map "\C-cO" 'outline-hide-other)
+(global-set-key "\C-cr" 'org-capture)
+(global-set-key "\C-c\C-l" 'org-store-link)
+;; (global-set-key "\C-cL" 'org-insert-link-global)
+(global-set-key "\C-cO" 'org-open-at-point-global)
+
+(jao-transient-major-mode+ org
+ ["Links"
+ ("le" "insert current eww link" jao-insert-eww-link)
+ ("lf" "insert link from clipboard" org-cliplink)
+ ("lc" "copy link at point" jao-org-copy-link-at-point)])
+
+;;; .
+(provide 'jao-custom-org)
diff --git a/custom/jao-custom-w3m.el b/custom/jao-custom-w3m.el
new file mode 100644
index 0000000..43b9e2d
--- /dev/null
+++ b/custom/jao-custom-w3m.el
@@ -0,0 +1,211 @@
+;; -*- lexical-binding: t -*-
+
+;;; browse-url and afio
+(defun jao-w3m-find-url (url)
+ (let* ((url (w3m-canonicalize-url url))
+ (fn `(lambda (b)
+ (with-current-buffer b
+ (string= ,url (w3m-canonicalize-url w3m-current-url))))))
+ (when-let (b (seq-find fn (w3m-list-buffers)))
+ (pop-to-buffer b))))
+
+(defun jao-w3m-browse-url (url &rest r)
+ (jao-afio-goto-www)
+ (select-window (frame-first-window))
+ (unless (jao-w3m-find-url url)
+ (w3m-goto-url-new-session url)))
+
+(defun jao-w3m-download (arg)
+ (interactive "P")
+ (jao-download (w3m-anchor) arg))
+
+(setq jao-afio-use-w3m t)
+(setq jao-browse-url-function 'jao-w3m-browse-url)
+
+;;; multipart html renderer
+(defun jao-w3m-html-renderer (handle)
+ (let ((w3m-message-silent t)
+ (w3m-fill-column 120)
+ (mm-w3m-safe-url-regexp nil)
+ (mm-inline-text-html-with-w3m-keymap t))
+ (condition-case e
+ (mm-inline-text-html-render-with-w3m handle)
+ (error (message "Error rendering page with w3m: %s" e)
+ (delete-region (point) (point-max))
+ (let ((shr-use-fonts nil))
+ (mm-shr handle))))))
+
+(setq mm-text-html-renderer 'jao-w3m-html-renderer)
+
+;;; notmuch integration
+(defvar-local jao-notmuch--showing-images nil)
+
+(defun jao-notmuch--setup-w3m-images (&optional activate)
+ (setq-local w3m-ignored-image-url-regexp
+ (unless jao-notmuch--showing-images
+ notmuch-show-text/html-blocked-images))
+ (when activate
+ (setq-local scroll-margin 0)
+ (w3m-toggle-inline-images (if jao-notmuch--showing-images t 'turnoff))))
+
+(defun jao-notmuch--w3m-toggle-images ()
+ (save-window-excursion
+ (when (or (derived-mode-p 'notmuch-show-mode)
+ (jao-notmuch-goto-message-buffer nil t))
+ (goto-char (point-min))
+ (when (re-search-forward "^\\[ text/html " nil t)
+ (when (looking-at-p "(hidden)")
+ (notmuch-show-toggle-part-invisibility))
+ (forward-line 1)
+ (setq jao-notmuch--showing-images (not jao-notmuch--showing-images))
+ (jao-notmuch--setup-w3m-images t)))))
+
+(add-hook 'notmuch-show-mode-hook #'jao-notmuch--setup-w3m-images)
+
+;;; org integration
+(defun jao-w3m-get-link ()
+ (let ((wb (w3m-alive-p)))
+ (when wb
+ (let ((url (with-current-buffer wb w3m-current-url))
+ (title (w3m-buffer-title wb)))
+ (cons url title)))))
+
+(defun jao-insert-w3m-link ()
+ (interactive)
+ (let ((link (jao-w3m-get-link)))
+ (when link (insert "[[" (car link) "][" (cdr link) "]]"))))
+
+(with-eval-after-load "org"
+ (require 'ol-w3m nil t)
+ (define-key org-mode-map "\C-cW" 'jao-insert-w3m-link))
+
+;;; capture page
+(defun jao-w3m-capture-page ()
+ (interactive)
+ (let* ((title (w3m-current-title))
+ (url w3m-current-url)
+ (html (y-or-n-p "Save as HTML (y) or PS (n)? "))
+ (basename (concat (read-string "File name: ")
+ (if html ".html" ".ps")))
+ (name (expand-file-name basename jao-sink-dir)))
+ (if html
+ (progn
+ (w3m-view-source)
+ (write-region (point-min) (point-max) name nil nil nil t)
+ (w3m-view-source))
+ (progn
+ (split-window-horizontally 85)
+ (w3m-redisplay-this-page)
+ (ps-print-buffer name)
+ (delete-other-windows)
+ (w3m-redisplay-this-page)))
+ (kill-new (format "[[doc:%s][%s]] ([[%s][original]])"
+ basename title url))))
+
+;;; consult narrowing
+(with-eval-after-load "w3m-util"
+ (with-eval-after-load "consult"
+ (defvar jao-consult-w3m-buffer-history nil)
+ (defun jao-www--item (b)
+ (with-current-buffer b
+ (propertize (or w3m-current-title (buffer-name))
+ 'buffer b
+ 'url (or w3m-current-url (buffer-name)))))
+ (defvar jao-consult-w3m-source
+ (list :name "www buffer"
+ :category 'www-buffer
+ :hidden t
+ :narrow (cons ?w "www")
+ :annotate (lambda (b) (when b (get-text-property 0 'url b)))
+ :history 'jao-consult-w3m-buffer-history
+ :items (lambda ()
+ (seq-map #'jao-www--item
+ (seq-filter #'jao-www--buffer-p (buffer-list))))
+ :action (lambda (b)
+ (jao-afio-goto-www)
+ (switch-to-buffer (get-text-property 0 'buffer b)))))
+ (jao-consult-add-buffer-source 'jao-consult-w3m-source)))
+
+;;; package
+(use-package w3m
+ :ensure t
+ :demand t
+ :custom ((w3m-key-binding 'info)
+ (w3m-display-mode 'dual-pane))
+ :init
+ (setq w3m-add-user-agent nil
+ w3m-confirm-leaving-secure-page nil
+ w3m-cookie-accept-bad-cookies t
+ w3m-cookie-accept-domains '(".github.com"
+ ".librarything.com"
+ ".goodreads.com"
+ ".sr.ht"
+ ".gnu.org"
+ ".codeberg.org"
+ "codeberg.org"
+ ".bookshop.org"
+ ".reddit.com")
+ w3m-cookie-reject-domains '(".")
+ w3m-default-display-inline-images nil
+ w3m-default-save-directory "~/doc/sink"
+ w3m-do-cleanup-temp-files nil
+ w3m-external-view-temp-directory "/tmp"
+ w3m-fill-column 110
+ w3m-goto-article-function 'jao-w3m-browse-url
+ w3m-form-input-textarea-buffer-lines 40
+ w3m-history-minimize-in-new-session t
+ w3m-history-reuse-history-elements nil
+ w3m-init-file nil
+ w3m-image-no-idle-timer t
+ w3m-make-new-session t
+ w3m-profile-directory "~/.w3m"
+ w3m-redisplay-pages-automatically-p nil
+ w3m-resize-images t
+ w3m-safe-url-regexp nil
+ w3m-search-default-engine "duckduckgo" ; "google-en"
+ w3m-select-buffer-horizontal-window nil
+ w3m-select-buffer-window-ratio '(20 . 40)
+ w3m-session-load-last-sessions t
+ w3m-session-load-crashed-sessions 'ask
+ w3m-show-graphic-icons-in-header-line nil
+ w3m-show-graphic-icons-in-mode-line nil
+ w3m-toggle-inline-images-permanently nil
+ w3m-use-tab nil
+ w3m-use-tab-line nil
+ w3m-use-title-buffer-name t
+ w3m-use-cookies t
+ w3m-use-filter nil
+ w3m-use-favicon nil
+ w3m-use-header-line nil
+ w3m-use-refresh nil
+ w3m-use-symbol t)
+
+ :config
+ :bind (:map w3m-mode-map
+ (("+" . w3m-zoom-in-image)
+ ("-" . w3m-zoom-out-image)
+ ("C-c C-@" . tracking-next-buffer)
+ ("C-c C-SPC" . tracking-next-buffer)
+ ("C-c C-b" . nil)
+ ("C-l" . nil)
+ ("C-c c" . jao-w3m-capture-page)
+ ("b" . w3m-view-previous-page)
+ ("B" . w3m-view-next-page)
+ ("c" . w3m-print-this-url)
+ ("d" . jao-w3m-download)
+ ("D" . w3m-download)
+ ("f" . w3m-lnum-follow)
+ ("v" . jao-view-video)
+ ("q" . w3m-delete-buffer)
+ ("w" . org-w3m-copy-for-org-mode)
+ ("x" . jao-rss-subscribe)
+ ("y" . w3m-print-current-url))))
+
+;;; textsec
+;; the way in which w3m constructs ALT text for links to images confuses
+;; makes it suspicious under textsec link check.
+(with-eval-after-load "textsec"
+ (advice-add 'textsec-link-suspicious-p :override #'ignore))
+
+;;; .
+(provide 'jao-custom-w3m)