summaryrefslogtreecommitdiffhomepage
path: root/custom
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-06-07 23:48:59 +0100
committerjao <jao@gnu.org>2022-06-08 01:42:13 +0100
commit200692bb1fb8acdcc467862d92a1d24ac3e381bc (patch)
treeeef0883005d7211787ac3365f8ac5be2aa3db023 /custom
parent7f5113e71f1d6038091850d4030e90b766903779 (diff)
downloadelibs-200692bb1fb8acdcc467862d92a1d24ac3e381bc.tar.gz
elibs-200692bb1fb8acdcc467862d92a1d24ac3e381bc.tar.bz2
desorgification
Diffstat (limited to 'custom')
-rw-r--r--custom/jao-custom-blog.el226
-rw-r--r--custom/jao-custom-completion.el530
-rw-r--r--custom/jao-custom-email.el291
-rw-r--r--custom/jao-custom-eww.el182
-rw-r--r--custom/jao-custom-exwm.el528
-rw-r--r--custom/jao-custom-notmuch.el652
-rw-r--r--custom/jao-custom-org.el284
7 files changed, 2693 insertions, 0 deletions
diff --git a/custom/jao-custom-blog.el b/custom/jao-custom-blog.el
new file mode 100644
index 0000000..6d2d3f6
--- /dev/null
+++ b/custom/jao-custom-blog.el
@@ -0,0 +1,226 @@
+;; -*- 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))
+ (org-static-blog-publish-file fname)))
+
+(defconst jao-org-static-blog--prev-beg
+ "#+begin_export html\n <!-- preview-start -->\n#+end_export ")
+
+(defconst jao-org-static-blog--prev-end
+ "#+begin_export html\n <!-- preview-end -->\n#+end_export ")
+
+(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[[https://jao.io/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)
+ (let ((kill-whole-line nil)) (kill-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))
+ (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))
+
+(jao-transient-major-mode+ org
+ ["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..a0efbb1
--- /dev/null
+++ b/custom/jao-custom-completion.el
@@ -0,0 +1,530 @@
+;; -*- lexical-binding: t -*-
+
+;;; imenu
+(use-package imenu
+ :init (setq org-imenu-depth 7)
+ :config
+ (defun jao-imenu-hook ()
+ (cond ((derived-mode-p 'org-mode) (org-reveal t))
+ (outline-minor-mode (outline-show-entry))))
+ (add-hook 'imenu-after-jump-hook #'jao-imenu-hook))
+
+;;; completion styles
+;;;; completion configuration
+(setq tab-always-indent 'complete
+ read-extended-command-predicate #'command-completion-default-include-p
+ completion-category-defaults nil
+ completion-cycle-threshold nil
+ completions-detailed t
+ completion-show-help nil
+ completion-show-inline-help nil
+ completion-ignore-case t
+ completion-wrap-movement t
+ completion-auto-select nil
+ 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))))
+
+;;;; 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
+ :init
+ :config
+ (orderless-define-completion-style orderless+initialism
+ (orderless-matching-styles '(orderless-initialism
+ orderless-prefixes
+ orderless-literal
+ orderless-regexp)))
+
+ (defun jao-orderless--set-locally ()
+ (setq-local completion-styles
+ '(substring partial-completion orderless)
+
+ completion-category-overrides
+ '((file (styles partial-completion orderless))
+ (command (styles orderless+initialism)))
+ orderless-matching-styles
+ '(orderless-literal orderless-regexp orderless-prefixes)))
+ (add-hook 'minibuffer-setup-hook #'jao-orderless--set-locally))
+
+;;; 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)
+
+;;; company
+(use-package company
+ :ensure t
+ :custom ((company-backends '(company-capf
+ ;; company-bbdb
+ company-files
+ company-dabbrev
+ company-keywords))
+ (company-global-modes '(not slack-message-buffer-mode
+ circe-channel-mode
+ telega-chat-mode))
+ (company-format-margin-function nil) ;; #'company-text-icons-margin
+ (company-idle-delay 0.2)
+ (company-lighter "")
+ (company-lighter-base "")
+ (company-show-numbers nil)
+ (company-selection-wrap-around t)
+ (company-tooltip-limit 15)
+ (company-tooltip-align-annotations t)
+ (company-tooltip-offset-display 'lines)) ;; 'scrollbar
+
+ :config
+ (defun jao-complete-at-point ()
+ "Complete using company unless we're in the minibuffer."
+ (interactive)
+ (if (or (not company-mode) (window-minibuffer-p))
+ (completion-at-point)
+ (company-manual-begin)))
+
+ (defun jao-company-use-in-tab ()
+ (global-set-key [remap completion-at-point] #'jao-complete-at-point)
+ (global-set-key [remap completion-symbol] #'jao-complete-at-point)
+ (global-set-key (kbd "M-TAB") #'jao-complete-at-point))
+
+ (jao-company-use-in-tab)
+
+ :bind (:map company-active-map
+
+ ("<tab>" . company-complete-common-or-cycle)
+ ("TAB" . company-complete-common-or-cycle)
+
+ ("C-h" . company-show-doc-buffer)
+ ("M-." . company-show-location)
+ ("C-<return>" . company-complete-selection)
+ ([remap return] . company-abort)
+ ("RET" . company-abort)
+
+ :filter (or (not (derived-mode-p 'eshell-mode))
+ (company-explicit-action-p))
+ ("<return>" . company-complete-selection)
+ ("RET" . company-complete-selection))
+ :diminish)
+
+(unless (display-graphic-p) (global-company-mode 1))
+
+;;; vertico
+(use-package vertico
+ :ensure t
+ :init
+ (setq vertico-count 20
+ vertico-cycle t
+ vertico-resize t
+ org-refile-use-outline-path t)
+
+ :config
+
+ ;; (setq completion-in-region-function
+ ;; (lambda (&rest args)
+ ;; (apply (if (and (not window-system) vertico-mode)
+ ;; #'consult-completion-in-region
+ ;; #'completion--in-region)
+ ;; args)))
+
+ (defun jao-vertico--display-candidates (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
+ :override #'jao-vertico--display-candidates))
+
+(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))))
+
+(vertico-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" . consult-history)
+ ("C-c i" . consult-imenu)
+ ("C-c I" . consult-project-imenu)
+ ("C-c k" . consult-ripgrep)
+ ("C-c K" . consult-git-grep)
+ ("C-c L" . consult-locate)
+ ;; ("C-h m" . consult-mode-command)
+ ("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-s o" . consult-outline)
+ ("M-y" . consult-yank-pop)
+ ("C-s" . isearch-forward)
+ ("C-S-s" . consult-line)
+ ("<help> a" . consult-apropos))
+
+ :custom ((consult-preview-key (kbd "`")))
+
+ :init
+ (fset 'multi-occur #'consult-multi-occur)
+
+ :config
+
+ (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)
+
+ (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-current-frame)
+ 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))))
+
+;;;; narrowing chats
+(defvar jao-chat-buffer-source
+ (list :name "chats"
+ :category 'buffer
+ :action #'pop-to-buffer
+ :hidden t
+ :narrow (cons ?c "chats")
+ :items (jao-consult--mode-buffers 'erc-mode
+ 'circe-channel-mode
+ 'circe-query-mode
+ 'signel-chat-mode
+ 'slack-message-buffer-mode
+ 'slack-thread-message-buffer-mode
+ 'telega-root-mode
+ 'telega-chat-mode)))
+(with-eval-after-load "consult"
+ (jao-consult-add-buffer-source 'jao-chat-buffer-source))
+
+;;; embark
+;;;; package
+(use-package embark
+ :ensure t
+ :demand t
+ :init
+ (setq embark-quit-after-action nil
+ embark-indicator #'embark-mixed-indicator
+ embark-verbose-indicator-buffer-sections '(bindings)
+ embark-mixed-indicator-both t
+ 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)))
+
+ :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)
+ (when (org-in-regexp org-link-bracket-re)
+ (let ((lnk (match-string-no-properties 1)))
+ (if (string-match-p "https?://.+" (or lnk ""))
+ (cons 'url lnk)
+ (cons 'org-link (match-string-no-properties 0)))))))
+
+(embark-define-keymap jao-embark-targets-org-link-map
+ "Actions for org links"
+ ((kbd "RET") org-open-link-from-string))
+
+(defun jao-embark-targets--gl-org-link ()
+ (when (org-in-regexp org-link-bracket-re)
+ (cons 'gl-org-link (match-string-no-properties 0))))
+
+(embark-define-keymap jao-embark-targets-gl-org-link-map
+ "Actions for exteranl org links"
+ ((kbd "RET") org-open-at-point-global))
+
+(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-browse-add-url-to-mpc)
+
+;;;; 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))
+
+(embark-define-keymap jao-embark-targets-video-url-map
+ "Actions on URLs pointing to remote video streams."
+ :parent embark-url-map
+ ("v" jao-embark-targets-vlc)
+ ("RET" jao-embark-targets-mpv))
+
+(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)
+
+;;; 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)
+
+ :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)))
+
+;;; recoll
+(jao-load-path "consult-recoll")
+
+(defun jao-recoll-format (title url mtype)
+ (let* ((u (replace-regexp-in-string "/home/jao/" "" url))
+ (u (replace-regexp-in-string
+ "\\(doc\\|org/doc\\|.emacs.d/gnus/Mail\\|var/mail\\)/" "" u)))
+ (format "%s (%s, %s)"
+ title
+ (propertize u 'face 'jao-themes-f00)
+ (propertize mtype 'face 'jao-themes-f01))))
+
+(defun jao-recoll-open-html (file)
+ (jao-afio--goto-www)
+ (eww-open-file file))
+
+(defun jao-recoll-consult-messages ()
+ (interactive)
+ (consult-recoll "mime:message "))
+
+(defun jao-recoll-consult-docs ()
+ (interactive)
+ (consult-recoll (format "dir:%s/doc " jao-org-dir)))
+
+(defun jao-recoll-messages ()
+ (interactive)
+ (jao-recoll "mime:message "))
+
+(defun jao-recoll-docs ()
+ (interactive)
+ (jao-recoll (format "dir:%s/doc " jao-org-dir)))
+
+(defun jao-recoll-notes ()
+ (interactive)
+ (jao-recoll (format "dir:%s " jao-org-notes-dir)))
+
+(defun jao-recoll-consult-notes ()
+ "Use consult-recoll to search notes."
+ (interactive)
+ (consult-recoll (format "dir:%s " jao-org-notes-dir)))
+
+(defun jao-recoll-open-with-notmuch (fname)
+ (let ((id (with-temp-buffer
+ (insert-file fname)
+ (goto-char (point-min))
+ (when (re-search-forward "[Mm]essage-[Ii][Dd]: <?\\([^><]+\\)>?"
+ nil t)
+ (match-string 1)))))
+ (when id (notmuch-show (concat "id:" id)))))
+
+(use-package consult-recoll
+ :init (setq consult-recoll-open-fns
+ '(("application/pdf" . jao-open-doc)
+ ("message/rfc822" . jao-recoll-open-with-notmuch)
+ ("text/html" . jao-recoll-open-html))
+ consult-recoll-search-flags nil
+ consult-recoll-format-candidate #'jao-recoll-format)
+ :config
+ (transient-define-prefix jao-recoll-transient ()
+ [["Consult recoll queries"
+ ("r" "consult recoll query" consult-recoll)
+ ("n" "consult recoll on notes" jao-recoll-consult-notes)
+ ("d" "consult recoll on docs" jao-recoll-consult-docs)
+ ("m" "consult recoll on messages" jao-recoll-consult-messages)]
+ ["Recoll queries"
+ ("R" "recoll query" jao-recoll)
+ ("N" "recoll on notes" jao-recoll-notes)
+ ("D" "consult recoll on docs" jao-recoll-docs)
+ ("M" "consult recoll on messages" jao-recoll-messages)]])
+
+ :bind (("s-r" . #'jao-recoll-transient)))
+
+;;; .
+(provide 'jao-custom-completion)
diff --git a/custom/jao-custom-email.el b/custom/jao-custom-email.el
new file mode 100644
index 0000000..37c8acb
--- /dev/null
+++ b/custom/jao-custom-email.el
@@ -0,0 +1,291 @@
+;; -*- lexical-binding: t; -*-
+
+;;; personal emails and others
+(defvar jao-mails)
+(defvar jao-extra-mails)
+(defvar jao-mails-regexp (regexp-opt jao-mails))
+(defvar jao-notmuch-enabled (eq jao-afio-mail-function 'notmuch))
+
+;;; 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))
+
+(let ((org-file (expand-file-name "gnus.org" jao-emacs-dir)))
+ (when (file-newer-than-file-p org-file gnus-init-file)
+ (org-babel-tangle-file org-file)))
+
+;;; 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-rx (regexp-opt '("mail.io" "gnu.org")))
+
+(defun jao-message-insert-bcc ()
+ (let ((f (or (message-fetch-field "From") "")))
+ (when (or (string-blank-p f) (string-match-p jao-message--bcc-rx f))
+ (insert "Bcc: proton@jao.io\n"))))
+
+(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-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)
+
+;;; mailcap
+(use-package mailcap
+ :config
+ (add-to-list 'mailcap-mime-extensions '(".JPEG" . "image/jpeg"))
+ (add-to-list 'mailcap-mime-extensions '(".JPG" . "image/jpeg"))
+
+ (defun jao-icalendar-import-buffer ()
+ (let ((icalendar-import-format "%s%u%l%d"))
+ (icalendar-import-buffer diary-file t nil))
+ (kill-buffer)
+ (message "Event imported into diary"))
+
+ :custom
+ ((mailcap-user-mime-data
+ '((jao-icalendar-import-buffer "application/ics")
+ ("viewpdf.sh %s" "application/pdf")))))
+
+;;; multipart html renderer
+(defun jao-w3m-html-renderer (handle)
+ (let ((w3m-message-silent t)
+ (mm-w3m-safe-url-regexp nil))
+ (condition-case nil
+ (mm-inline-text-html-render-with-w3m handle)
+ (error (delete-region (point) (point-max))
+ (let ((shr-use-fonts nil)
+ (shr-use-colors nil))
+ (mm-shr handle))))))
+
+(defun jao-shr-html-renderer (handle)
+ (let (;; (shr-use-fonts t)
+ ;; (shr-use-colors t)
+ (shr-width 130))
+ (mm-shr handle)))
+
+;; (setq mm-text-html-renderer #'jao-w3m-html-renderer)
+(setq mm-text-html-renderer #'jao-shr-html-renderer)
+
+;;; 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))))
+
+(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 "Mail" ?n)
+
+;;; .
+(provide 'jao-custom-email)
diff --git a/custom/jao-custom-eww.el b/custom/jao-custom-eww.el
new file mode 100644
index 0000000..531cc2b
--- /dev/null
+++ b/custom/jao-custom-eww.el
@@ -0,0 +1,182 @@
+;; -*- 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--list-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\\):")
+
+;;; 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 "Web" ?e))
+
+;;; 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")))
+
+;;; Package
+(use-package shr
+ :custom ((shr-width nil)
+ (shr-use-colors t)
+ (shr-use-fonts t)
+ (shr-max-width 130)
+ (shr-blocked-images nil)
+ (shr-inhibit-images t)
+ (shr-max-image-proportion 1.0)
+ (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))
+
+ :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)
+
+ :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)
+ ("s" . eww-search-words)
+ ("S" . jao-eww-browse-new)
+ ("u" . jao-eww-reopen)
+ ("U" . jao-eww-reopen-new)
+ ("w" . org-eww-copy-for-org-mode)
+ ("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..2b94068
--- /dev/null
+++ b/custom/jao-custom-exwm.el
@@ -0,0 +1,528 @@
+;; -*- lexical-binding: t; -*-
+
+;;; Load and basic config
+(defvar jao-exwm--use-afio t)
+
+(jao-load-path "exwm")
+
+(use-package exwm
+ :ensure 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")))
+
+(use-package exwm-edit :ensure t)
+(require 'exwm)
+
+;;; 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 5) '(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--goto-main)
+ (,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 5 "tidal-hifi" "tidal-hifi")
+(defalias 'jao-streaming-list #'jao-exwm-tidal)
+
+(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-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-doc-view--imenu-file))
+ (let ((info (jao-zathura--file-info (current-buffer))))
+ (jao-doc-view-session-mark (car info))
+ (jao-doc-view-save-session)
+ (jao-doc-view--enable-imenu (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-pdf-to-org-file (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-doc-view-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-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)
+ (define-key org-mode-map (kbd "C-c o") #'jao-org-org-goto-pdf)
+ (remove-hook 'kill-emacs-query-functions #'jao-exwm-pdf-zathura-close-all)
+ (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-zathura-goto-pdf ()
+ (interactive)
+ (if jao-browse-doc-use-emacs-p
+ (jao-org-org-goto-pdf)
+ (when-let (pdf (jao-org-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)))
+
+
+(let ((viewers ["External viewers"
+ ("z" "open with zathura" jao-zathura-open-doc)
+ ("m" "open with mupdf" jao-exwm-open-with-mupdf)]))
+ (jao-transient-major-mode+ pdf-view viewers)
+ (jao-transient-major-mode+ doc-view viewers))
+
+;;; Firefox support
+(jao-def-exwm-toggler jao-exwm-firefox 5 "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") #'other-window)
+(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-A] . org-agenda-list)
+ ([?\s-a] . jao-first-window)
+ ([?\s-b] . jao-transient-org-blog)
+ ;; ([?\s-d] . jao-exwm-tidal*)
+ ([?\s-d] . jao-mpc-echo-current)
+ ([?\s-e] . jao-exwm-firefox*)
+ ([?\s-m] . jao-transient-media)
+ ;; ([?\s-O] . jao-transpose-windows)
+ ;; ([?\s-o] . jao-other-window)
+ ;; ([?\s-P] . jao-transpose-windows-prev)
+ ([?\s-O] . ace-swap-window)
+ ([?\s-o] . ace-window)
+ ([?\s-p] . jao-prev-window)
+ ([?\s-R] . app-launcher-run-app)
+ ([?\s-r] . jao-recoll-transient)
+ ([?\s-s] . jao-transient-streaming)
+ ([?\s-t] . vterm)
+ ([?\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-notmuch.el b/custom/jao-custom-notmuch.el
new file mode 100644
index 0000000..28da05f
--- /dev/null
+++ b/custom/jao-custom-notmuch.el
@@ -0,0 +1,652 @@
+;; -*- 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 "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 "J"
+ :query "tag:new and tag:jao and not tag:\"/local|hacking|draft|inbox|prog|words/\""
+ :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))))
+
+(defvar jao-notmuch--shared-tags
+ '("new" "unread" "flagged" "signed" "sent" "attachment" "forwarded"
+ "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)))))
+
+(defvar jao-notmuch-feed-searches-news
+ (mapcar #'jao-notmuch--sq '("news" "fun" "words" "computers")))
+
+(defvar jao-notmuch-feed-searches-hack
+ (mapcar #'jao-notmuch--sq
+ '("xmobar" "geiser" "mdk" "mailutils" "notmuch")))
+
+(defvar jao-notmuch-feed-searches-lang
+ (append (mapcar #'jao-notmuch--sq
+ '( "lobsters" "clojure" "lisp" "scheme"
+ "haskell" "idris" "erlang" "pharo"))
+ `(,(jao-notmuch--qn "feeds" "prog" "fp"
+ '("tag:prog" "not tag:\"/emacs/\"")))))
+
+(defvar jao-notmuch-feed-searches-sci
+ (mapcar #'jao-notmuch--sq
+ '("philosophy" "math" "physics" "sci" "gr-qc" "quant-ph")))
+
+(defvar jao-notmuch-feed-searches
+ (append jao-notmuch-feed-searches-news
+ jao-notmuch-feed-searches-hack
+ jao-notmuch-feed-searches-lang
+ jao-notmuch-feed-searches-sci))
+
+(defvar jao-notmuch-bigml-searches
+ `(,(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")))
+
+(defvar jao-notmuch-inbox-searches
+ `(,(jao-notmuch--q "jao" "inbox" "ji")
+ ,(jao-notmuch--q "jao" "bills" "jb")
+ ,(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"))))
+
+(defvar jao-notmuch-mark-searches
+ `(,(jao-notmuch--q "jao" "drafts" "d" '("tag:draft"))
+ ,(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"))))
+
+(defvar jao-notmuch-emacs-searches
+ `(,(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--sq "emacs-orgmode" "eo" "emacs" "org")))
+
+(setq notmuch-saved-searches
+ (append jao-notmuch-inbox-searches
+ jao-notmuch-bigml-searches
+ jao-notmuch-mark-searches
+ jao-notmuch-feed-searches
+ jao-notmuch-emacs-searches))
+
+(defvar jao-notmuch-dynamic-searches
+ `(,(jao-notmuch--q "bml" "today" "tb" '("tag:bigml" "date:24h.."))
+ ,(jao-notmuch--q "jao" "today" "tj"
+ '("tag:jao" "date:24h.."
+ "not tag:\"/(feeds|spam|local)/\""))))
+
+(defvar jao-notmuch-new-searches
+ `(,(jao-notmuch--q "new" nil "nn" '("tag:new" "not tag:draft"))
+ ,(jao-notmuch--q "unread" nil "nu" '("tag:unread"))
+ (:query "*" :name "messages")))
+
+(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))
+
+(defvar jao-notmuch-widened-searches
+ (jao-notmuch-widen-searches notmuch-saved-searches))
+
+(defvar jao-notmuch-flagged-searches
+ (let ((s (seq-difference notmuch-saved-searches
+ jao-notmuch-mark-searches)))
+ (jao-notmuch-widen-searches s " AND tag:flagged")))
+
+(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
+(setq notmuch-archive-tags '("+trove" "-new" "-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)
+ :weight bold)))
+ `(("unread")
+ ("signed")
+ ("new" "N")
+ ("replied" "โ†ฉ" (propertize tag 'face '(:family "Fira Code")))
+ ("sent" "S")
+ ("attachment" "๐Ÿ“Ž")
+ ("deleted" "๐Ÿ—™" (propertize tag 'face '(:underline nil ,@e)))
+ ;; ("attachment" "+")
+ ;; ("deleted" "xxx" (propertize tag 'face '(:underline nil ,@e)))
+ ("flagged" "!" (propertize tag 'face ',e))
+ ("jao" "j")
+ ("bigml" "b")
+ ("feeds" "f")
+ ("gmane" "g")))
+ notmuch-tag-deleted-formats
+ '(("unread")
+ ("new")
+ (".*" (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/")
+
+(use-package notmuch
+ :init
+ (setq notmuch-address-use-company t
+ notmuch-address-command (if jao-notmuch-enabled 'internal 'as-is)
+ notmuch-always-prompt-for-sender t
+ notmuch-draft-folder "local"
+ notmuch-draft-quoted-tags '("part")
+ notmuch-address-internal-completion '(received nil)
+ notmuch-fcc-dirs
+ '(("\\(support\\|education\\)@bigml.com" . nil)
+ (".*@bigml.com" . "bigml/trove +bigml +sent -new -unread")
+ (".*" . "jao/trove +jao +sent +trove -new -unread"))
+ notmuch-maildir-use-notmuch-insert t)
+
+ :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--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")))
+ (widget-insert (propertize title 'face 'jao-themes-f00))
+ (let ((notmuch-column-control 1.0)
+ (start (point)))
+ (notmuch-hello-insert-buttons searches)
+ (indent-rigidly start (point) notmuch-hello-indent))
+ cnt)))
+
+(defun jao-notmuch-hello-insert-inbox-searches ()
+ (jao-notmuch-hello--insert-searches jao-notmuch-inbox-searches "inbox"))
+
+(defun jao-notmuch-hello-insert-bigml-searches ()
+ (jao-notmuch-hello--insert-searches jao-notmuch-bigml-searches "bigml"))
+
+(defun jao-notmuch-hello-insert-mark-searches ()
+ (jao-notmuch-hello--insert-searches jao-notmuch-mark-searches "marks")
+ (jao-notmuch-hello--insert-searches jao-notmuch-flagged-searches nil))
+
+(defun jao-notmuch-hello-insert-feeds-searches ()
+ (let ((sect "feeds"))
+ (dolist (s `(,jao-notmuch-feed-searches-news
+ ,jao-notmuch-feed-searches-hack
+ ,jao-notmuch-feed-searches-lang
+ ,jao-notmuch-feed-searches-sci))
+ (let ((i (funcall #'jao-notmuch-hello--insert-searches s sect)))
+ (setq sect (unless i sect))))))
+
+(defun jao-notmuch-hello-insert-emacs-searches ()
+ (jao-notmuch-hello--insert-searches jao-notmuch-emacs-searches "emacs"))
+
+(defun jao-notmuch-hello-insert-dynamic-searches ()
+ (jao-notmuch-hello--insert-searches jao-notmuch-dynamic-searches "dynamic")
+ (jao-notmuch-hello--insert-searches jao-notmuch-new-searches nil))
+
+(defun jao-notmuch-refresh-agenda ()
+ (interactive)
+ (save-window-excursion (org-agenda-list))
+ (let ((b (current-buffer)))
+ (pop-to-buffer "*Calendar*")
+ (goto-char (point-min))
+ (calendar-goto-today)
+ (pop-to-buffer b)))
+
+(defun jao-notmuch-hello-first ()
+ (interactive)
+ (let ((inhibit-message t))
+ (beginning-of-buffer)
+ (widget-forward 1)))
+
+(defun jao-notmuch-refresh-hello (&optional agenda)
+ (interactive "P")
+ (ignore-errors
+ (when (and (string= "Mail" (jao-afio-current-frame))
+ (derived-mode-p 'notmuch-hello-mode))
+ (when (not (string-blank-p jao-notmuch-minibuffer-string))
+ (let ((notmuch-hello-auto-refresh nil)) (notmuch-hello)))
+ (when agenda (jao-notmuch-refresh-agenda))
+ (unless (widget-at) (jao-notmuch-hello-first)))))
+
+(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 t
+ notmuch-hello-sections '(jao-notmuch-hello-insert-bigml-searches
+ jao-notmuch-hello-insert-inbox-searches
+ jao-notmuch-hello-insert-feeds-searches
+ jao-notmuch-hello-insert-emacs-searches
+ jao-notmuch-hello-insert-mark-searches
+ jao-notmuch-hello-insert-dynamic-searches
+ notmuch-hello-insert-alltags)
+ 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)
+
+ :hook ((notmuch-hello-refresh . jao-notmuch-notify)
+ (jao-afio-switch . jao-notmuch-refresh-hello))
+
+ :bind (:map notmuch-hello-mode-map
+ (("a" . jao-notmuch-refresh-agenda)
+ ("j" . jao-notmuch-jump-search)
+ ("n" . jao-notmuch-hello-next)
+ ("p" . widget-backward)
+ ("S" . consult-notmuch)
+ ("g" . jao-notmuch-refresh-hello)
+ ("." . jao-notmuch-hello-first)
+ ("SPC" . widget-button-press)
+ ("[" . 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): ")))
+
+(defun jao-mail-clean-address (args)
+ (when-let ((address (car args)))
+ (list (if (string-match ".+ updates on arXiv.org: \\(.+\\)" address)
+ (with-temp-buffer
+ (insert (match-string 1 address))
+ (let ((shr-width 1000))
+ (shr-render-region (point-min) (point-max)))
+ (replace-regexp-in-string "\"" "" (buffer-string)))
+ (replace-regexp-in-string jao-mail-clean-rx "" address)))))
+
+(use-package notmuch-show
+ :init
+ (setq gnus-blocked-images "."
+ notmuch-message-headers
+ '("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 80
+ notmuch-wash-citation-lines-prefix 10
+ notmuch-wash-citation-lines-suffix 20
+ notmuch-show-text/html-blocked-images "."
+ notmuch-show-header-line #'jao-notmuch-message-header-line)
+
+ :config
+
+ (advice-add 'notmuch-clean-address :filter-args #'jao-mail-clean-address)
+
+ :bind
+ (:map notmuch-show-mode-map
+ (("h" . jao-notmuch-goto-tree-buffer)
+ ("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 ")
+ (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 . "")))
+ :config
+
+ (when (display-graphic-p)
+ (jao-notmuch-adjust-tree-fonts
+ (when (string-prefix-p "Hack" jao-themes-default-face) "Source Code Pro")))
+
+ (jao-notmuch-tree-setup "T")
+
+ (defun jao-notmuch-before-tree (&rest args)
+ (when (string= (buffer-name) "*notmuch-hello*")
+ (split-window-right 40)
+ (other-window 1)))
+
+ (defvar jao-notmuch--visits 0)
+
+ (defun jao-notmuch-after-tree-quit (&optional both)
+ (when (and (not (derived-mode-p 'notmuch-tree-mode 'notmuch-hello-mode))
+ (save-window-excursion (other-window -1)
+ (derived-mode-p 'notmuch-hello-mode)))
+ (delete-window)
+ (jao-notmuch-refresh-hello (= 0 (mod (cl-incf jao-notmuch--visits) 10)))))
+
+ (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)
+ ("H" . jao-notmuch-click-message-buffer)
+ ("i" . jao-notmuch-toggle-images)
+ ("K" . jao-notmuch-tag-jump-and-next)
+ ("k" . jao-notmuch-tree-read-thread)
+ ("n" . jao-notmuch-tree-next)
+ ("N" . jao-notmuch-tree--forward)
+ ("O" . notmuch-tree-toggle-order)
+ ("o" . jao-notmuch-tree-widen-search)
+ ("p" . jao-notmuch-tree-previous)
+ ("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)
+ ("=" . 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))))
+
+;;; 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 as todo? ")
+ (jao-notmuch--add-tags '("+flagged")))
+ (org-store-link-props "notmuch" link 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-store-link-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)
+(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))
+
+;;; link hint
+(with-eval-after-load "link-hint"
+ (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))
+
+;;; .
+(provide 'jao-custom-notmuch)
diff --git a/custom/jao-custom-org.el b/custom/jao-custom-org.el
new file mode 100644
index 0000000..aa4f9e0
--- /dev/null
+++ b/custom/jao-custom-org.el
@@ -0,0 +1,284 @@
+;; -*- lexical-binding: t -*-
+
+;;; General configuration
+(use-package org
+ :ensure 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-default-notes-file (expand-file-name "inbox.org" org-directory)
+ org-directory jao-org-dir
+ org-display-remote-inline-images 'download ;; 'skip 'cache
+ org-ellipsis " .." ;; โ†ด
+ org-email-link-description-format "Email %c: %s"
+ org-enforce-todo-dependencies t
+ org-fast-tag-selection-single-key 'expert
+ ;; 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))
+(require 'org)
+
+;;; Agenda
+(setq ;; org-agenda-custom-commands
+ ;; '(("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 "โ€ข" ;; "*"
+ org-agenda-time-grid
+ '((daily today require-timed)
+ (800 1000 1200 1400 1600 1800 2000) "" "ยท")
+ 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-window-setup 'current-window)
+
+;;; 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
+;; Show hidden emphasis markers
+(use-package org-appear
+ :ensure t
+ :hook (org-mode . org-appear-mode))
+
+;; #+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-image-actual-width '(300))
+
+;;; 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)
+(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"))
+
+;;; 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 poly-org :ensure t)
+
+(use-package ob-prolog
+ :ensure t
+ :after org)
+
+(org-babel-do-load-languages
+ 'org-babel-load-languages
+ '((calc . t)
+ (clojure . t)
+ ;; (elixir . 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"
+ ("o" "find and open note" jao-org-notes-open)
+ ("c" "open or create note" jao-org-notes-open-or-create)
+ ("\\" "grep notes" jao-org-notes-grep)
+ ("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--list-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)