diff options
Diffstat (limited to 'custom')
| -rw-r--r-- | custom/jao-custom-blog.el | 223 | ||||
| -rw-r--r-- | custom/jao-custom-browse.el | 199 | ||||
| -rw-r--r-- | custom/jao-custom-chats.el | 242 | ||||
| -rw-r--r-- | custom/jao-custom-completion.el | 426 | ||||
| -rw-r--r-- | custom/jao-custom-email.el | 335 | ||||
| -rw-r--r-- | custom/jao-custom-eww.el | 255 | ||||
| -rw-r--r-- | custom/jao-custom-exwm.el | 538 | ||||
| -rw-r--r-- | custom/jao-custom-gnus.el | 826 | ||||
| -rw-r--r-- | custom/jao-custom-mac.el | 24 | ||||
| -rw-r--r-- | custom/jao-custom-multimedia.el | 119 | ||||
| -rw-r--r-- | custom/jao-custom-notmuch.el | 664 | ||||
| -rw-r--r-- | custom/jao-custom-org.el | 347 | ||||
| -rw-r--r-- | custom/jao-custom-pdf.el | 83 | ||||
| -rw-r--r-- | custom/jao-custom-programming.el | 556 | ||||
| -rw-r--r-- | custom/jao-custom-shells.el | 6 | ||||
| -rw-r--r-- | custom/jao-custom-w3m.el | 211 | ||||
| -rw-r--r-- | custom/jao-custom-x11.el | 192 | 
17 files changed, 5246 insertions, 0 deletions
| diff --git a/custom/jao-custom-blog.el b/custom/jao-custom-blog.el new file mode 100644 index 0000000..7515440 --- /dev/null +++ b/custom/jao-custom-blog.el @@ -0,0 +1,223 @@ +;; -*- lexical-binding: t -*- + +;;; Vars and setup +(use-package htmlize :ensure t) + +(defvar jao-blog-base-dir (expand-file-name "www" jao-doc-dir)) +(defvar jao-blog-publish-dir (expand-file-name "jao.io" jao-blog-base-dir)) +(defun jao-blog-dir (p) (expand-file-name p jao-blog-base-dir)) +(defun jao-blog-publish-dir (p) (expand-file-name p jao-blog-publish-dir)) + + +(defvar jao-org-blog-tag-files +  (seq-difference (directory-files (jao-blog-publish-dir "blog") nil "tag-.*") +                  "tag-norss.html")) + +(defvar 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)) + +(defvar 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-publish-dir "blog") nil ".*-rss.xml"))) + +(defvar 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-publish-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))) +  (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) +  (goto-char (point-min)) +  (when (re-search-forward "^#\\+date: " nil t) +    (org-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) +          (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-browse.el b/custom/jao-custom-browse.el new file mode 100644 index 0000000..99b7fda --- /dev/null +++ b/custom/jao-custom-browse.el @@ -0,0 +1,199 @@ +;; -*- lexical-binding: t -*- + +;;; Deps +(require 'jao-url) + +;;; variables +(defvar jao-browse-url-function nil) +(defvar jao-browse-url-external-function nil) + +;;; url around point + +(defun jao--url-prompt (&optional prefix) +  (let* ((def (jao-url-around-point t)) +         (prompt (concat prefix "URL" (if def (format " (%s): " def) ": ")))) +    (read-string prompt nil nil def))) + +;;; downloads using wget +(defun jao-wget--get-title (filename) +  (or (and (derived-mode-p 'w3m-mode) (w3m-current-title)) +      (plist-get eww-data :title) +      (and (not (string-blank-p (or filename ""))) +           (subst-char-in-string ?- ? +                                 (capitalize (file-name-base filename)))))) + +(defun jao-wget (url &optional user pwd) +  "Download URL using wget and kill a link for an org note." +  (let* ((def (file-name-nondirectory url)) +         (pmt (format "Save %s to: " url)) +         (read-file-name-function nil) +         (dest (expand-file-name +                (read-file-name pmt jao-sink-dir nil nil def))) +         (title (jao-wget--get-title dest)) +         (src-url (or (jao-url-around-point t) (file-name-directory url))) +         (auth (when (and user pwd) +                 `(,(format "--http-user=%s" user) +                   ,(format "--http-password=%s" pwd)))) +         (lnk (concat "doc:" (file-name-nondirectory dest)))) +    (switch-to-buffer-other-window (get-buffer-create "*downloads*")) +    (erase-buffer) +    (kill-new (format "%s (from %s)" +                      (org-link-make-string lnk title) +                      (org-link-make-string src-url "here"))) +    (apply 'make-term `("downloads" "wget" nil ,@auth "-O" ,dest ,url)))) + +(defun jao-download (url &optional pws) +  "Download URL using wget" +  (interactive (list (jao--url-prompt))) +  (when url +    (let ((usr (and pws (read-string "Login name: "))) +          (pwd (and pws (read-passwd "Password: ")))) +      (jao-wget url usr pwd)))) + +(with-eval-after-load "embark" +  (define-key embark-url-map (kbd "d") #'jao-download)) + +;;; video +(defvar jao-video--url-rx +  (format "^https?://\\(?:www\\.\\)?%s/.+" +          (regexp-opt '("youtu.be" +                        "youtube.com" +                        "blip.tv" +                        "vimeo.com" +                        "infoq.com") +                      t))) + +(defvar jao-video--ext-rx +  (format "^https?://.+/.+\\.%s" (regexp-opt '("mp3" "webm" "mp4")))) + +(defun jao-video--url-p (url) +  (or (string-match-p jao-video--url-rx url) +      (string-match-p jao-video--ext-rx url))) + +(defun jao--remote-run (url prg) +  (let ((args (format "%s %s" prg (shell-quote-argument url)))) +    (start-process-shell-command prg nil args))) + +(defun jao--mpv (url &rest _args) (jao--remote-run url "mpv")) +(defun jao--vlc (url &rest _args) (jao--remote-run url "vlc")) + +(defvar jao--video-player 'jao--mpv) + +(defun jao-view-video (url) +  "Tries to stream a video from the current or given URL" +  (interactive (list (jao--url-prompt "Video "))) +  (when url (funcall jao--video-player url))) + +(defun jao-maybe-view-video (url &rest _ignored) +  (interactive) +  (let ((w (read-char "View video (v) or web page (w)? "))) +    (cond ((eq w ?v) (jao-view-video url)) +          ((eq w ?w) (funcall jao-browse-url-function url)) +          (t (message "Aborted"))))) + +;;; web browsers +(defun jao-www--buffer-p (b) +  (with-current-buffer b +    (or (derived-mode-p 'w3m-mode 'eww-mode) +        (and (boundp 'exwm-class-name) +             (member exwm-class-name '("vlc" "mpv")))))) + +;;; browse-url +(require 'browse-url) + +(setq browse-url-generic-program (jao-d-l "open" "firefox")) + +(defun jao-browse-with-external-browser (&rest url) +  "Browse with external hogging" +  (interactive "s") +  (let ((url (or (car url) (jao-url-around-point)))) +    (if (not url) +        (message "No URL at point") +      (cond ((and (jao-exwm-enabled-p) (fboundp 'jao-exwm-firefox)) +             (jao-exwm-firefox)) +            (jao-river-enabled (jao-river-to-ws 2)) +            (jao-sway-enabled (jao-sway-firefox))) +      (browse-url-generic url)))) + +(setq jao-browse-url-external-function 'jao-browse-with-external-browser) + +(defun jao--fln (url) +  (shell-quote-argument +   (if (string-match "^[^:]*:/*?\\(/?[^/].*\\)" url) +       (match-string-no-properties 1 url) +     url))) + +(defun jao--browse-doc (url &rest _ignored) +  (let* ((url (substring-no-properties url)) +         (file (jao--fln url))) +    (when file +      (unless (file-exists-p file) +        (error "File %s does not exist" file)) +      (jao-open-doc file)))) + +(defun jao--make-file-rx (exts) +  (format "file:/?/?.+\\.%s$" (regexp-opt exts))) + +(defvar jao--see-exts (jao--make-file-rx '("jpg" "jpeg" "png"))) + +(defvar jao--doc-exts +  (jao--make-file-rx '("ps" "ps.gz" "pdf" "dvi" "djvu" "chm"))) + +(defvar jao-browse-url-wget-exts +  '("ps" "pdf" "dvi" "djvu" "zip" "gz" "tgz")) + +(defvar jao-browse-external-domains +  '("github.com" "gitlab.com" "slack.com" "spotify.com" "drive.google.com" +    "meet.google.com" "docs.google.com" "x.com" "twitter.com" +    "t.com" "linkedin.com" "bigml.com" "slack.com" "zoom.us")) + +(defvar jao-browse--external-regexp +  (format "https?://\\(.+\\.\\)*%s\\(/.*\\)?" +          (regexp-opt jao-browse-external-domains))) + +(defun jao-wget--regexp () +  (concat "^http[s]?://.+\\(\\." +          (mapconcat 'identity jao-browse-url-wget-exts "\\|\\.") +          "\\)\\'")) + +(defun jao--see (url &rest _r) +  (start-process-shell-command "see" nil (format "see %s" (jao--fln url)))) + +(defun jao--find-file-other-window (url &rest _) +  (find-file-other-window (jao--fln url))) + +(defvar jao-browse--sound-rx +  (format "^https?://.*/.*\\.%s" (regexp-opt '("mp3" "flv")))) + +(defun jao-browse-play-sound-url (url &rest _) +  (jao-mpc-add-or-play-url url)) + +(defun jao-browse-url-browse (&rest args) +  (apply jao-browse-url-function args)) + +(jao-d-l + (setq browse-url-handlers +       `((jao-video--url-p . jao-mac-open) +         (,jao--doc-exts . jao-mac-open) +         (,jao--see-exts . jao-mac-open) +         ("^file://?.+\\.html?$" . ,jao-browse-url-function) +         ("^file://?" . jao--find-file-other-window) +         (,jao-browse--external-regexp . ,jao-browse-url-external-function) +         (,jao-browse--sound-rx . jao-browse-play-sound-url) +         ("." . jao-browse-url-browse))) + (setq browse-url-handlers +       `((jao-video--url-p . jao-maybe-view-video) +         (,jao--doc-exts . jao--browse-doc) +         (,jao--see-exts . jao--see) +         ("^file://?.+\\.html?$" . ,jao-browse-url-function) +         ("^file://?" . jao--find-file-other-window) +         (,jao-browse--external-regexp . ,jao-browse-url-external-function) +         ("^https?://.*\\.gotomeeting\\.com\\.*" . browse-url-chrome) +         (,jao-browse--sound-rx . jao-browse-play-sound-url) +         (,(jao-wget--regexp) . jao-download) +         ("." . jao-browse-url-browse)))) + + +(provide 'jao-custom-browse) + +;;; jao-custom-browse.el ends here diff --git a/custom/jao-custom-chats.el b/custom/jao-custom-chats.el new file mode 100644 index 0000000..c2105c6 --- /dev/null +++ b/custom/jao-custom-chats.el @@ -0,0 +1,242 @@ +;; -*- lexical-binding: t -*- + + +;;;; circe +(defvar jao-libera-channels ()) +(defvar jao-oftc-channels ()) +(defvar jao-bitlbee-channels ()) +(defvar jao-slack-channels ()) + +(use-package circe +  :ensure t +  :bind (:map circe-channel-mode-map +              (("C-c C-a" . lui-track-jump-to-indicator))) +  :init +  (setq circe-chat-buffer-name "{target} - {network}" +        circe-default-realname "https://jao.io" +        circe-default-part-message "" +        circe-default-quit-message "" +        circe-ignore-list nil +        circe-server-coding-system '(undecided . undecided) +        circe-server-killed-confirmation 'ask-and-kill-all +        circe-server-auto-join-default-type :after-auth +        circe-server-buffer-name "{network} - {host}:{port}" +        circe-format-say "({nick}) {body}" +        circe-format-self-say "(jao) {body}" +        circe-new-buffer-behavior 'ignore +        circe-new-buffer-behavior-ignore-auto-joins t +        circe-nickserv-ghost-style 'after-auth +        circe-prompt-string ": " +        circe-completion-suffix ", " +        circe-reduce-lurker-spam t + +        circe-lagmon-mode-line-format-string "" ;;  "%.0f " +        circe-lagmon-mode-line-unknown-lag-string "" ;; "? " +        circe-lagmon-timer-tick 120 +        circe-lagmon-reconnect-interval 180 + +        lui-max-buffer-size 30000 +        lui-fill-column 80 +        lui-time-stamp-position 'right +        lui-time-stamp-format "%H:%M" +        lui-flyspell-p nil + +        lui-track-indicator (if window-system 'fringe 'bar) +        lui-track-behavior 'before-tracking-next-buffer) +  :config + +  (defsubst jao-circe-nick-no () +    (if (derived-mode-p 'circe-query-mode) +        2 +      (length (circe-channel-nicks)))) + +  (defsubst jao-circe-netowrk () +    (or (plist-get lui-logging-format-arguments :network) "")) + +  (define-minor-mode jao-circe-user-number-mode "" +    :lighter (:eval (format " [%s]" (jao-circe-nick-no)))) + +  (defun jao-circe-channel-hook () +    (when jao-mode-line-in-minibuffer +      (setq header-line-format +            '(" %b" (:eval (format "@%s - %s nicks" +                                   (jao-circe-netowrk) +                                   (jao-circe-nick-no)))))) +    (jao-circe-user-number-mode 1)) + +  (add-hook 'circe-channel-mode-hook #'jao-circe-channel-hook) +  (add-hook 'circe-query-mode-hook #'jao-circe-channel-hook) + +  (defun circe-command-RECOVER (&rest _ignore) +    "Recover nick" +    (jao-with-auth "freenode" u p +      (circe-command-MSG "nickserv" (format "IDENTIFY %s %s" u p)) +      (circe-command-MSG "nickserv" (format "GHOST %s" u)) +      (circe-command-MSG "nickserv" (format "RELEASE %s" u)) +      (circe-command-NICK u))) + +  (defun circe-command-NNICKS (&rest _) +    "Echo number of nicks" +    (circe-display-server-message +     (format "%d nicks in this channel" (jao-circe-nick-no)))) + +  (defun circe-command-SENDFILE (line) +    "/sendfile for localslackirc" +    (circe-command-QUOTE (format "sendfile %s" line))) + +  (advice-add 'circe-command-NAMES :after #'circe-command-NNICKS) + +  (defun jao-circe-reconnect-unmonitored () +    (interactive) +    (dolist (b (buffer-list)) +      (with-current-buffer b +        (when (and (derived-mode-p 'circe-server-mode) +                   circe-lagmon-disabled) +          (circe-reconnect))))) + +  (add-to-list 'jao-sleep-awake-functions #'jao-circe-reconnect-unmonitored) + +  (setq circe-network-options +        (list (jao-with-auth "libera" u p +                (list "Libera Chat" :nick u :channels jao-libera-channels +                      :tls t :sasl-username u :sasl-password p)) +              (jao-with-auth "oftc" u p +                (list "OFTC" +                      :nick u :channels jao-oftc-channels :nickserv-password p +                      :tls t :sasl-username u :sasl-password p)) +              (jao-with-auth "bitlbee" u p +                (list "Bitlbee" :host "127.0.0.1" :nick u +                      :channels jao-bitlbee-channels :lagmon-disabled t +                      :nickserv-password u :user p)))) + +  (jao-shorten-modes 'circe-channel-mode +                     'circe-server-mode +                     'circe-query-mode) + +  (enable-circe-display-images) +  (enable-lui-track) +  (circe-lagmon-mode)) + +;;;; telegram +(use-package telega +  :ensure t +  :custom +  (telega-use-tracking-for '(unmuted) ;; '(or unmuted mention) +                           telega-rainbow-color-custom-for nil +                           telega-msg-rainbow-title nil +                           telega-sticker-set-download t +                           telega-symbol-checkmark "·" +                           telega-symbol-heavy-checkmark "×" +                           telega-symbol-verified "*") +  :config +  (define-key global-map (kbd "C-c C-t") telega-prefix-map) +  (setq telega-chat-show-avatars nil +        telega-chat-prompt-insexp '(telega-ins "> ") +        telega-completing-read-function #'completing-read +        telega-root-show-avatars nil +        telega-emoji-use-images nil +        telega-temp-dir "/tmp/telega" +        telega-symbol-horizontal-bar +        (propertize "-" 'face 'jao-themes-f00) +        telega-symbol-vertical-bar +        (propertize "| " 'face 'jao-themes-dimm) +        telega-mode-line-string-format +        '(:eval (telega-mode-line-unread-unmuted)) +        telega-use-images (display-graphic-p) +        telega-open-file-function #'jao--see +        telega-open-message-as-file +        (unless (display-graphic-p) '(photo video animation))) +  (with-eval-after-load "tracking" +    (jao-shorten-modes 'telega-chat-mode) +    (jao-tracking-faces 'telega-tracking)) +  (telega-mode-line-mode 1)) + +(defun jao-telega () +  (interactive) +  (jao-tracking-go-to-chats) +  (if (get-buffer telega-root-buffer-name) +      (pop-to-buffer telega-root-buffer-name) +    (telega))) + +;;;; ement +(use-package ement +  :disabled t +  :ensure t +  :init (setq ement-save-sessions t +              ement-sessions-file (locate-user-emacs-file "cache/ement.el") +              ement-room-avatars nil +              ement-notify-dbus-p nil +              ement-room-left-margin-width 0 +              ement-room-right-margin-width 11 +              ement-room-timestamp-format "%H:%M" +              ement-room-timestamp-header-format "--------") + +  :custom ((ement-room-message-format-spec "(%S) %B%r%R %t")) + +  :config +  (defun jao-ement-track (event room session) +    (when (ement-notify--room-unread-p event room session) +      (when-let ((n (ement-room--buffer-name room)) +                 (b (get-buffer n))) +        (tracking-add-buffer b)))) + +  (add-hook 'ement-event-hook #'jao-ement-track) +  (jao-shorten-modes 'ement-room-mode) +  (jao-tracking-cleaner "^\\*Ement Room: \\(.+\\)\\*" "@\\1")) + +;;;; startup +(defun jao-chats (&optional p) +  (interactive "P") +  (when (or p (y-or-n-p "Connect to telegram? ")) +    (telega)) +  (when (and (fboundp 'ement-connect) (or p (y-or-n-p "Connect to matrix? "))) +    (unless (get-buffer "*Ement Rooms*") +      (jao-with-auth "matrix.org" u p (ement-connect :user-id u :password p)))) +  ;; (when (and (fboundp 'mastodon) (or p (y-or-n-p "Connect to mastodon? "))) +  ;;   (mastodon)) +  (dolist (c '(("Libera Chat" . "irc.libera.chat:6697"))) +    (unless (get-buffer (cdr c)) +      (when (or p (y-or-n-p (format "Connect to %s? " (car c)))) +        (circe (car c)))))) + +(defun jao-all-chats () +  (interactive) +  (when jao-tracking-use-scratch +    (jao-afio-goto-chats) +    (delete-other-windows)) +  (jao-chats t)) + +(defun jao-chats-telega () +  (interactive) +  (jao-buffer-same-mode '(telega-root-mode telega-chat-mode))) + +(defun jao-chats-slack () +  (interactive) +  (jao-buffer-same-mode 'slack-message-buffer-mode)) + +(defun jao-chats-irc () +  (interactive) +  (jao-buffer-same-mode '(circe-channel-mode circe-query-mode erc-mode))) + +;;;; consult narrowing +(defvar jao-chat-buffer-source +  (list :name "chats" +        :category 'buffer +        :action (lambda (b) (jao-afio-pop-to-buffer 0 b)) +        :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 +                                          'ement-room-mode +                                          'ement-room-list-mode))) +(with-eval-after-load "consult" +  (jao-consult-add-buffer-source 'jao-chat-buffer-source)) + + +(provide 'jao-custom-chats) diff --git a/custom/jao-custom-completion.el b/custom/jao-custom-completion.el new file mode 100644 index 0000000..98b853c --- /dev/null +++ b/custom/jao-custom-completion.el @@ -0,0 +1,426 @@ +;; -*- lexical-binding: t; -*- + +(require 'jao-r2e) + +;;; 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" . switch-to-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)) + +  :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-r2e-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..2e886ff --- /dev/null +++ b/custom/jao-custom-email.el @@ -0,0 +1,335 @@ +;; -*- lexical-binding: t; -*- + +;;; main email system +(require 'jao-afio) +(setq jao-afio-mail-function (jao-d-l 'gnus 'notmuch)) + +(defvar jao-notmuch-enabled (eq jao-afio-mail-function 'notmuch)) + +;;; personal emails and others +(defvar jao-mails) +(defvar jao-extra-mails nil) +(defvar jao-mails-regexp (regexp-opt jao-mails)) +(defvar jao-maildir (jao-d-l "~/Documents/mail" "~/var/mail")) +;;; 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 +(jao-when-linux (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 gnus-home-directory) +    (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 'smtpmail-send-it) ;; send-mail-function +  ;; (setq sendmail-program "/usr/sbin/sendmail") +  (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-send-it () +  (with-temp-message "Sending email..." +    (sendmail-send-it))) + +(defun jao-sendmail-msmtp () +  (setq send-mail-function 'sendmail-send-it +        sendmail-program (executable-find "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-dedicated-window t +              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) + +  (setq bbdb-layout-alist +        '((one-line (order phone mail-alias mail notes) +                    (name-end . 24) +                    (toggle . t)) +          (multi-line (omit uuid creation-date timestamp name-format name-face) +                      (toggle . t) +                      (indentation . 4)) +          (pop-up-multi-line +           (omit uuid creation-date timestamp name-format name-face) +           (indentation . 4)) +          (full-multi-line (indentation . 4)))) +  :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..221f442 --- /dev/null +++ b/custom/jao-custom-eww.el @@ -0,0 +1,255 @@ +;; -*- lexical-binding: t -*- + +(require 'jao-r2e) + +;;; 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* ((w (min 120 (- (window-width) 10))) +         (fill-column nil) +         (shr-width w) +         (shr-max-width w)) +    (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 "P") +  (unless (or (and (interactive-p) dest) (org-region-active-p)) +    (let ((shr-width 80)) (eww-readable))) +  (let* ((dest (unless (interactive-p) dest)) +         (start (if (org-region-active-p) (region-beginning) (point-min))) +         (end (if (org-region-active-p) (region-end) (point-max))) +         (link (eww-current-url)) +         (title (plist-get eww-data :title)) +         (buff (save-current-buffer (or dest (jao-org-notes-create title))))) +    (with-current-buffer buff +      (insert "#+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)))) + +;;; auto-readable +(defvar jao-eww-auto-readable-urls +  (regexp-opt '("guardian.co.uk" +                "theguardian.com" +                "github.com" +                "eldiario.es"))) + +(defun jao-eww-autoread () +  (when (string-match-p jao-eww-auto-readable-urls (or (eww-current-url))) +    (eww-readable))) + +(add-hook 'eww-after-render-hook #'jao-eww-autoread) + +;;; 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)) + +  :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) +                            ("R" . 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-r2e-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) + +;; (advice-remove 'shr-tag-img #'jao-shr-tag-img) +;; (advice-remove 'shr-insert #'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..5e4a354 --- /dev/null +++ b/custom/jao-custom-exwm.el @@ -0,0 +1,538 @@ +;; -*- 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 ((member exwm-class-name '("firefox" "Firefox" "Sofice")) +         (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-mode 1) + +(defun jao-exwm--watch-tray (sym newval op where) +  (setq jao-minibuffer-right-margin (/ newval (string-pixel-width "a"))) +  (jao-minibuffer-refresh)) + +(add-variable-watcher 'exwm-systemtray-width #'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) +                           (with-current-buffer b +                             (derived-mode-p 'exwm-mode))) +                         (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-pdf-open-in-emacs 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-pdf-open-in-emacs 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-pdf-open-in-emacs +      (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-pdf-open-in-emacs) +  (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) +(exwm-wm-mode) + +;;; . +(provide 'jao-custom-exwm) diff --git a/custom/jao-custom-gnus.el b/custom/jao-custom-gnus.el new file mode 100644 index 0000000..7483e39 --- /dev/null +++ b/custom/jao-custom-gnus.el @@ -0,0 +1,826 @@ +;; 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) +(defvar jao-gnus-nnml-group-params 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")) + +(setq gnus-uncacheable-groups "^nnml") + +;;; looks +;;;; verbosity +(setq gnus-verbose 4) +;;;; geometry +(defvar jao-gnus-use-three-panes (not jao-notmuch-enabled)) +(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) + +(setq calendar-left-margin 6) + +(defun jao-gnus-use-three-panes () +  (let ((side-bar `(vertical 1.0 +                             ("inbox.org" 0.4) +                             ("*Org Agenda*" 1.0) +                             ("*Calendar*" ,(jao-d-l 9 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))))) + +(defun jao-gnus-use-two-panes () +  (let ((groups-len jao-gnus-groups-width) +        (summary-len (- jao-gnus-wide-width jao-gnus-groups-width)) +        (msg-edit '(horizontal 1.0 +                               (message 1.0 point) +                               (vertical 0.5 +                                         ("*Org Agenda*" 0.5) +                                         ("inbox.org" 1.0))))) +    (gnus-add-configuration +     `(article +       (horizontal 1.0 +                   (vertical ,groups-len (group 1.0)) +                   (vertical 1.0 +                             (summary 0.25 point) +                             (article 1.0))))) + +    (gnus-add-configuration +     `(group (horizontal 1.0 +                         (group 0.5 point) +                         (vertical 1.0 +                                   ("*Org Agenda*" 1.0) +                                   ("*Calendar*" 9))))) + +    (gnus-add-configuration +     `(summary +       (horizontal 1.0 +                   (vertical ,groups-len (group 1.0)) +                   (vertical 1.0 (summary 1.0 point))))) + +    (gnus-add-configuration `(message ,msg-edit)) + +    (gnus-add-configuration `(forward ,msg-edit)) + +    (gnus-add-configuration `(reply-yank ,msg-edit)) + +    (gnus-add-configuration +     `(reply (horizontal 1.0 (message 0.5 point) (article 1.0)))))) + +(if jao-gnus-use-three-panes +    (jao-gnus-use-three-panes) +  (jao-gnus-use-two-panes)) + +;;;; 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 t +      gnus-permanently-visible-groups "^nnselect:.*" +      gnus-search-ignored-newsgroups "nndraft.*\\|nnselect.*") + +(use-package jao-recoll +  :if (jao-is-linux)) + +;; (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) + +(defvar jao-local-mail-sources +  (append (mapcar (lambda (f) +                    `(maildir :path ,(expand-file-name f jao-maildir))) +                  '("local/" "feeds/")) +          (jao-when-darwin '((file :path "/var/mail/jao"))))) + +(defun jao-pm-label-mail-sources (pwd &rest labels) +  (mapcar (lambda (b) +            `(imap :server "127.0.0.1" :port 1143 +                   :user "jaor@pm.me" :password ,pwd +                   :stream starttls :predicate "1:*" +                   :fetchflag "\\Deleted \\Seen" +                   :mailbox ,(concat "Labels/#" b))) +          (or labels '("inbox" "drivel" "hacking" "bills" "prog" "words")))) + +(defun jao-pm-folder-mail-sources (pwd &rest folders) +  (mapcar (lambda (b) +            `(imap :server "127.0.0.1" :port 1143 +                   :user "jaor@pm.me" :password ,pwd +                   :stream starttls :predicate "" +                   :fetchflag "" +                   :mailbox ,(if b (concat "Folders/" b) "INBOX"))) +          (or folders '(nil "drivel" "hacking" "bills" "prog" "words")))) + +(setq mail-sources +      (let* ((pwd (auth-source-pick-first-password :host "proton-bridge")) +             (ims (jao-pm-label-mail-sources pwd))) +        (append jao-local-mail-sources ims))) + +(when jao-gnus-use-nnml +  (let ((prefix (expand-file-name "gnus/" jao-maildir))) +    (add-to-list +     ;; `(nnml "" ,(jao-recoll-gnus-search-engine (jao-gnus-dir "Mail/"))) +     'gnus-secondary-select-methods +     `(nnml "" (gnus-search-engine gnus-search-notmuch +                                   (remove-prefix ,prefix)))))) + +(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 25)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-face-2 'jao-themes-f11 +      gnus-topic-line-format "%i %2{%~(pad-right 8)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) + +;;; rss +(setq nnrss-use-local t ;; M-x nnrss-generate-download-script +      nnrss-ignore-article-fields '(category +                                    dc:creator +                                    dc:date +                                    enclosure +                                    guid +                                    link +                                    media:content +                                    media:thumbnail +                                    media:title +                                    post-id +                                    pubDate +                                    slash:comments)) + +(add-to-list 'gnus-parameters `(,(format "nnrss:%s.*" +                                         (regexp-opt jao-gnus-image-groups t)) +                                (mm-html-inhibit-images nil) +                                (mm-html-blocked-images nil))) +;;; 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-date +      gnus-thread-sort-functions '(gnus-thread-sort-by-date)) + +(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) +              (+ jao-gnus-groups-width 12))) +         (w (or w (if jao-gnus-use-three-panes (window-width) (frame-width)))) +         (w (- w d))) +    (setq gnus-summary-line-format (format jao-gnus--summary-line-fmt w)))) + +(add-hook 'gnus-select-group-hook 'jao-gnus--set-summary-line) + +(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") +                 "* %(jao-gnus-subject)\n\n  %i\n\n  %(jao-gnus-org-url)" +                 :immediate-finish t) +               t) +  (add-to-list 'org-capture-templates +               '("X" "arXiv" entry (file "notes/physics/arxiv.org") +                 "* %(jao-gnus-subject)\n\n%(jao-gnus-org-paragraph \"%i\")" +                 :immediate-finish t) +               t) +  (org-capture-upgrade-templates org-capture-templates)) + +(defvar jao-gnus-org-url nil) +(defun jao-gnus-org-url () jao-gnus-org-url) +(defun jao-gnus-org-paragraph (x) +  (with-temp-buffer +    (insert "  " (string-trim (or x "")) "\n  ") +    (goto-char 0) +    (fill-paragraph) +    (goto-char (point-max)) +    (open-rectangle 0 (point)) +    (concat (buffer-string) "\n  " (or jao-gnus-org-url "")))) +(defvar jao-gnus-subject nil) +(defun jao-gnus-subject () jao-gnus-subject) + +(defun jao-gnus-arXiv-capture () +  (interactive) +  (unless (derived-mode-p '(gnus-summary-mode)) (gnus-article-show-summary)) +  (setq jao-gnus-subject (gnus-summary-article-subject)) +  (gnus-summary-select-article-buffer) +  (gnus-article-goto-part 0) +  (let ((transient-mark-mode t)) +    (set-mark (point)) +    (forward-paragraph) +    (or (and (save-excursion +               (when (re-search-forward "^Link" nil t) +                 (beginning-of-line) +                 (setq jao-gnus-org-url (org-eww-url-below-point)))) +             (org-capture nil "X")) +        (and (save-excursion +               (when (re-search-forward "^URL: " nil t) +                 (setq jao-gnus-org-url (thing-at-point-url-at-point)))) +             (org-capture nil "x")))) +  (gnus-article-show-summary)) + +;;; 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) +(setq gnus-article-truncate-lines t) + +(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:[\n ]h" nil t) +              (and (search-forward-regexp "^Link$" nil t) +                   (not (beginning-of-line)))) +      (cond (external (jao-browse-with-external-browser)) +            ((featurep 'jao-custom-eww) (eww (jao-url-around-point))) +            (t (browse-url (jao-url-around-point))))))) + +(defun jao-gnus-from-eww (keep-eww-buffer) +  (interactive "P") +  (unless keep-eww-buffer (jao-eww-close)) +  (jao-afio-goto-mail) +  (gnus-article-show-summary)) + +(with-eval-after-load 'eww +  (define-key eww-mode-map (kbd "h") #'jao-gnus-from-eww)) + +(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-shell-exec "notmuch-gnus-tags.sh") +    (when-let* ((a (get-buffer "*Org Agenda*"))) +      (with-current-buffer a (org-agenda-redo-all))) +    (jao-gnus--notify))) + +(defun jao-gnus--scan-local-mail () +  (let ((inhibit-message nil)) +    (message "Scanning local news in demon...") +    (let ((mail-sources jao-local-mail-sources)) +      (gnus-demon-scan-news)) +    (jao-gnus--notify))) + +(defun jao-gnus-add-demon () +  (interactive) +  (message "Adding scan demon for Gnus...") +  (gnus-demon-add-handler 'jao-gnus--scan 5 1)) + +(defun jao-gnus-remove-demon () +  (interactive) +  (message "Removing scan demon for Gnus...") +  (gnus-demon-remove-handler 'jao-gnus--scan)) + +(jao-gnus-add-demon) +(gnus-demon-init) + +;; this is, in theory, not needed; but at some point in the way to emacs +;; version 31 this idle timers have ceased to work after a sleep/awake cycle +(jao-when-linux (add-to-list 'jao-sleep-awake-functions #'jao-gnus-add-demon)) + +;;; add-ons +;;;; notifications +;;;;; minibuffer +(defvar jao-gnus--notify-strs ()) + +(defun jao-gnus--xbar-echo () +  (let* ((total (cdr (assoc "Gnus" gnus-topic-unreads))) +         (jao (cdr (assoc "jao" gnus-topic-unreads))) +         (str (concat (when (> total 0) (format "%d" total)) +                      " " +                      (when (> jao 0) (format "J%d" jao))))) +    (jao-shell-exec +     (format "echo '%s | color=#8b3626 | size=11' >/tmp/xbar" str)))) + +(defvar jao-gnus-group-notifications +  '(("Gnus" "" jao-themes-dimm) +    ("jao" "J" jao-themes-warning) +    ("news" "N" jao-themes-dimm) +    ("prog" "P" jao-themes-dimm) +    ("sci" "S" jao-themes-dimm))) + +(defun jao-gnus--notify-group-str (p) +  (let* ((n (cdr p)) +         (f (cdr (assoc (car p) jao-gnus-group-notifications)))) +    (when (and f (> n 0)) +      `(:propertize ,(format "%s%d " (car f) n) face ,(cadr f))))) + +(defun jao-gnus--notify () +  (setq jao-gnus--notify-strs +        (seq-keep 'jao-gnus--notify-group-str gnus-topic-unreads)) +  (jao-when-darwin (jao-gnus--xbar-echo)) +  (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 and other updates on summary exit +(let ((exit-count 0)) +  (defun jao-gnus--on-summary-exit () +    (when (> (setq exit-count (+ 1 exit-count)) 20) +      (setq exit-count 0) +      (jao-org-agenda)) +    (jao-gnus--notify))) + +(add-hook 'gnus-summary-exit-hook #'jao-gnus--on-summary-exit) +(add-hook 'gnus-exit-group-hook #'jao-gnus--notify) + +;;;; 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) +    (jao-gnus--notify) +    (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)))) +;;;; notmuch +(use-package jao-notmuch-gnus +  :demand t +  :init +  (jao-when-darwin +   (setq jao-notmuch-gnus-mail-directory +         (expand-file-name "gnus" jao-maildir)))) + +(jao-load-path "consult-notmuch") + +(use-package consult-notmuch +  :ensure t +  :bind (:map gnus-group-mode-map ("/" . #'jao-gnus-consult-notmuch))) + +;;; 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) + +(jao-when-darwin + (define-key gnus-group-mode-map "O" 'jao-mac-open-nnw)) diff --git a/custom/jao-custom-mac.el b/custom/jao-custom-mac.el new file mode 100644 index 0000000..d5ebc2e --- /dev/null +++ b/custom/jao-custom-mac.el @@ -0,0 +1,24 @@ +;;; jao-custom-mac.el --- Setup for mac env        -*- lexical-binding: t; -*- + +(setenv "HOMEBREW_PREFIX" "/opt/homebrew") +(setenv "HOMEBREW_CELLAR" "/opt/hombrew/Cellar") +(setenv "HOMEBREW_REPOSITORY" "/opt/homebrew") + +(setenv "GUILE_LOAD_PATH" "/opt/homebrew/share/guile/site/3.0") +(setenv "GUILE_LOAD_COMPILED_PATH" "/opt/homebrew/lib/guile/3.0/site-ccache") +(setenv "GUILE_SYSTEM_EXTENSIONS_PATH" "/opt/homebrew/lib/guile/3.0/extensions") + +(dolist (p '("/Applications/Emacs.app/Contents/MacOS/bin-arm64-11" +             "/Applications/Emacs.app/Contents/MacOS/libexec-arm64-11" +             "/opt/homebrew/sbin" +             "/opt/homebrew/bin" +             "~/.local/bin" +             "~/.cabal/bin" +             "~/.cargo/bin" +             "/Library/TeX/texbin")) +  (jao-exec-path p)) + +(add-to-list 'Info-directory-list "/opt/homebrew/share/info") + +(provide 'jao-custom-mac) +;;; jao-custom-mac.el ends here diff --git a/custom/jao-custom-multimedia.el b/custom/jao-custom-multimedia.el new file mode 100644 index 0000000..aab9cf1 --- /dev/null +++ b/custom/jao-custom-multimedia.el @@ -0,0 +1,119 @@ +;; -*- lexical-binding: t -*- + +;;; utilities + +(defun jao-mixer-get-level (&optional dev nomsg) +  (interactive) +  (let* ((dev (or dev "Master")) +         (s (shell-command-to-string (format "amixer sget %s" dev))) +         (s (car (last (split-string s "\n" t))))) +    (when (string-match ".*Front .*\\[\\([0-9]+\\)%\\] .*" s) +      (let ((level (match-string 1 s))) +        (unless nomsg (message "%s level: %s%%" dev level)) +        (string-to-number level))))) + +(defun jao-mixer-set (dev v) +  (jao-shell-exec* t "amixer" "sset" dev v) +  (jao-mixer-get-level dev)) + +(defun jao-mixer-master-toggle () +  (interactive) +  (jao-mixer-set "Master" "toggle")) + +(defun jao-mixer-master-up () +  (interactive) +  (jao-mixer-set "Master" "10%+")) + +(defun jao-mixer-master-down () +  (interactive) +  (jao-mixer-set "Master" "10%-")) + +(defun jao-mixer-capture-up () +  (interactive) +  (jao-mixer-set "Capture" "10%+")) + +(defun jao-mixer-capture-down () +  (interactive) +  (jao-mixer-set "Capture" "10%-")) + +(jao-shell-def-exec jao-audio-applet "pasystray") + +(defun jao-toggle-audio-applet () +  (interactive) +  (or (jao-shell-kill-p "paystray") (jao-audio-applet))) + +(global-set-key (kbd "<f4>") #'jao-toggle-audio-applet) + +;;; streaming aliases +(defalias 'jao-streaming-list #'ignore) +(defalias 'jao-streaming-like #'ignore) +(defalias 'jao-streaming-dislike #'ignore) +(defalias 'jao-streaming-toggle-shuffle #'ignore) +(defalias 'jao-streaming-lyrics #'ignore) +(defalias 'jao-streaming-toggle #'ignore) +(defalias 'jao-streaming-next #'ignore) +(defalias 'jao-streaming-prev #'ignore) +(defalias 'jao-streaming-current #'ignore) +(defalias 'jao-streaming-seek #'ignore) +(defalias 'jao-streaming-seek-back #'ignore) +(defalias 'jao-streaming-volume #'ignore) +(defalias 'jao-streaming-volume-down #'ignore) + +(defun jao-toggle-pasystray-applet () +  (interactive) +  (or (jao-shell-kill-p "pasystray") (jao-shell-exec "pasystray"))) + +(transient-define-prefix jao-transient-streaming () +  [:description +   (lambda () (format "Streaming using %s" jao-mpris-player)) +   ;; ["Search" :if jao-mpris-mopidy-p +   ;;  ("a" "album" jao-streaming-album) +   ;;  ("A" "artist" jao-streaming-artist) +   ;;  ("t" "track" jao-streaming-track) +   ;;  ("P" "playlist" jao-streaming-playlist)] +   ["Play" +    ("s" "toggle" jao-streaming-toggle) +    ("n" "next" jao-streaming-next) +    ("p" "previous" jao-streaming-prev) +    ("T" "toggle player" jao-streaming-toggle-player)] +   ["Seek & shout" +    ("f" "seek fwd" jao-streaming-seek :transient t) +    ("F" "seek bwd" jao-streaming-seek-back :transient t) +    ("u" "up" jao-streaming-volume :transient t) +    ("d" "down" jao-streaming-volume-down :transient t)] +   ["Browse" +    ;; ("l" "playing list" jao-streaming-list :if jao-mpris-mopidy-p) +    ("L" "lyrics" jao-streaming-lyrics) +    ("w" "currently playing" jao-streaming-current)] +   ;; ["Act"  :if jao-mpris-mopidy-p +   ;;  ("k" "like" jao-streaming-like) +   ;;  ("K" "dislike" jao-streaming-dislike) +   ;;  ("S" "toggle shuffle" jao-streaming-toggle-shuffle)] +   ] +  ) + +;;; mpris +(defun jao-mpris-lyrics (&optional force) +  (interactive "P") +  (jao-show-lyrics force #'jao-mpris-artist-title)) + +(use-package jao-mpris :demand t) + +(defun jao-mpris-setup-aliases () +  (setq espotify-play-uri-function #'espotify-play-uri-with-dbus) +  ;; (setq jao-mpris-player "mopidy") +  (defalias 'jao-streaming-list #'jao-mpc-show-playlist) +  (defalias 'jao-streaming-lyrics #'jao-mpris-lyrics) +  (defalias 'jao-streaming-toggle #'jao-mpris-play-pause) +  (defalias 'jao-streaming-next #'jao-mpris-next) +  (defalias 'jao-streaming-prev #'jao-mpris-previous) +  (defalias 'jao-streaming-current #'jao-mpris-show-osd) +  (defalias 'jao-streaming-seek #'jao-mpris-seek) +  (defalias 'jao-streaming-seek-back #'jao-mpris-seek-back) +  (defalias 'jao-streaming-volume #'jao-mpris-vol) +  (defalias 'jao-streaming-volume-down #'jao-mpris-vol-down)) + +(jao-mpris-register "playerctld" :session 70) + +;;; - provide +(provide 'jao-custom-multimedia) diff --git a/custom/jao-custom-notmuch.el b/custom/jao-custom-notmuch.el new file mode 100644 index 0000000..1297284 --- /dev/null +++ b/custom/jao-custom-notmuch.el @@ -0,0 +1,664 @@ +;; -*- 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")) + +(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 (file-name-as-directory jao-maildir) +          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) + +  (defun jao-notmuch-use-two-panes () +    (interactive) +    (advice-add 'notmuch-tree :before #'jao-notmuch-before-tree) +    (advice-add 'notmuch-tree-quit :after #'jao-notmuch-after-tree-quit)) + +  (when jao-notmuch-enabled (jao-notmuch-use-two-panes)) + +  :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 +  (when jao-notmuch-enabled +    (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-when-linux + (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 +(jao-when-linux + (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..9dd6ab9 --- /dev/null +++ b/custom/jao-custom-org.el @@ -0,0 +1,347 @@ +;; -*- lexical-binding: t -*- + +;;; General configuration +(defvar jao-org-dir (expand-file-name "org" jao-doc-dir)) + +(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-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-persist-directory (expand-file-name "cache/org-persist" +                                                user-emacs-directory) +        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 +(defun jao-org-agenda-fmt-date (date) +  (org-agenda-format-date-aligned date)) + +(setq org-agenda-custom-commands +      '(("j" agenda "" ((org-agenda-overriding-header "Agenda \n") +                        (org-agenda-ndays-to-span 14))) +        ("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")) +      org-agenda-block-separator " " +      org-agenda-breadcrumbs-separator "•" +      org-agenda-current-time-string "•" ;; "*" +      org-agenda-format-date #'jao-org-agenda-fmt-date +      org-agenda-hide-tags-regexp ".*" +      org-agenda-include-diary t +      org-agenda-include-inactive-timestamps t +      org-agenda-inhibit-startup nil +      org-agenda-prefix-format +      '((agenda . " %i  %?-12t% s") +        (todo . " %i %-12:c") +        (tags . " %i %-12:c") +        (search . " %i %-12:c")) +      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 t +      org-agenda-skip-timestamp-if-done t +      org-agenda-skip-timestamp-if-deadline-is-shown t +      org-agenda-skip-scheduled-if-deadline-is-shown t +      org-agenda-span 14 +      ;; org-agenda-start-on-weekday nil +      ;; ;; org-agenda-time-grid '((daily require-timed) () "" "·") +      ;; '((daily today require-timed) +      ;;   (800 1000 1200 1400 1600 1800 2000) "" "·") +      org-agenda-window-setup 'current-window) + +(defun jao-org-agenda () +  (interactive) +  (org-agenda nil "j") +  (jao-org-agenda-hook)) + +(defun jao-org-agenda-hook (&optional w) +  (when-let* ((w (or w (get-buffer-window "*Org Agenda*")))) +    (set-window-margins w 2 1) +    (with-current-buffer (window-buffer w) +      (setq-local cursor-in-non-selected-windows nil +                  line-spacing 0.2)))) + +(add-to-list 'display-buffer-alist +             '((major-mode . org-agenda-mode) +               (display-buffer-reuse-window) +               (window-parameters (mode-line-format . none)) +               (body-function . jao-org-agenda-hook))) + +;;; 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 %a\n  %t\n %?" :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 +  :demand t +  :hook ((org-mode . org-fragtog-mode))) + +(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 (org) +(require 'ox-org) + +;;; 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")) + +;;; 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) +   (C . t) +   ;; (prolog . t) +   )) + +(jao-define-attached-buffer "\\*Org Src\\( .*\\)?\\*" 0.5) + +;;; 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*)) + +;;;; mac links +(jao-when-darwin + (use-package org-mac-link +   :ensure t)) + +;;; 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) + +;;; jao-org-focus +(use-package jao-org-focus +  :after org +  :config +  (with-eval-after-load "jao-custom-completion" +    (jao-consult-add-buffer-source 'jao-org-focus-consult-buffer-source)) +  :bind ((:map org-mode-map (("C-M-o" . jao-org-focus))))) + +;;; 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 (kbd "C-c O") 'org-toggle-narrow-to-subtree) +(define-key org-mode-map (kbd "C-x C-n") 'org-next-link) +(define-key org-mode-map (kbd "C-x C-p") 'org-previous-link) +(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 :if jao-is-linux) +   ("lm" "insert mac link" org-mac-link-get-link :if jao-is-darwin) +   ("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-pdf.el b/custom/jao-custom-pdf.el new file mode 100644 index 0000000..50612bf --- /dev/null +++ b/custom/jao-custom-pdf.el @@ -0,0 +1,83 @@ +;; -*- lexical-binding: t -*- + +;;;; open pdfs +(use-package saveplace-pdf-view +  :ensure t +  :demand t +  :after doc-view) + +(use-package jao-pdf +  :demand t +  :config +  (setq jao-open-doc-fun 'jao-find-or-open) +  (setq jao-org-open-pdf-fun jao-open-doc-fun)) + +;;;; doc-view +(use-package doc-view +  :init +  (setq doc-view-cache-directory "~/.emacs.d/cache/docview" +        doc-view-resolution 110 +        doc-view-continuous t +        doc-view-conversion-refresh-interval 1 +        doc-view-mupdf-use-svg t) +  (defalias 'jao-doc-view-externally +    (jao-d-l 'jao-mac-open-in-skim 'jao-open-with-zathura)) +  :hook ((doc-view-mode . jao-doc-session-mark)) +  :bind (:map doc-view-mode-map +              ("j" . doc-view-next-line-or-next-page) +              ("J" . doc-view-search-next-match) +              ("k" . doc-view-previous-line-or-previous-page) +              ("K" . doc-view-search-previous-match) +              ("z" . jao-doc-view-externally))) + +(use-package jao-doc-session :demand t) + +(use-package jao-doc-view +  :demand t +  :bind (:map doc-view-mode-map +              ("b" . jao-doc-view-back) +              ("B" . jao-doc-view-forward) +              ("S" . jao-doc-session-save) +              ("u" . jao-doc-view-visit-url))) + +;;;; transient +(defun jao-org-pdf-goto-org-linking () +  (interactive) +  (jao-org-pdf-goto-org 4)) + +(jao-transient-major-mode doc-view +  ["Notes" +   ("o" "notes file" jao-org-pdf-goto-org) +   ("O" "notes file, linking" jao-org-pdf-goto-org-linking)] +  ["Navigation" +   ("b" "back jump" jao-doc-view-back) +   ("B" "forward jump" jao-doc-view-back) +   ("u" "visit URL" jao-doc-view-visit-url)] +  ["Slices" +   ("cb" "bounding box" doc-view-set-slice-from-bounding-box) +   ("cm" "using mouse" doc-view-set-slice-using-mouse)] +  ["Session" +   ("s" "load session" jao-afio-open-pdf-session) +   ("S" "save session" jao-doc-session-save) +   ("d" "visit cache directory" doc-view-dired-cache)] +  ["External viewers" +   ("z" "open with zathura" jao-open-with-zathura :if jao-is-linux) +   ("z" "open with skim" jao-mac-open-in-skim :if jao-is-darwin)]) + +(with-eval-after-load "pdf-view" +  (jao-transient-major-mode pdf-view +    ["Notes" +     ("o" "notes file" jao-org-pdf-goto-org) +     ("O" "notes file, linking" jao-org-pdf-goto-org-linking)] +    ["Navigation" +     ("b" "back jump" pdf-history-backward) +     ("f" "forward jump" pdf-history-forward)] +    ["Session" +     ("s" "load session" jao-afio-open-pdf-session) +     ("S" "save session" jao-doc-session-save)] +    ["External viewers" +     ("z" "open with zathura" jao-open-with-zathura)])) + +;; (transient-get-suffix 'jao-transient-pdf-view '(0 -1)) + +(provide 'jao-custom-pdf) diff --git a/custom/jao-custom-programming.el b/custom/jao-custom-programming.el new file mode 100644 index 0000000..ed62b32 --- /dev/null +++ b/custom/jao-custom-programming.el @@ -0,0 +1,556 @@ +;; -*- lexical-binding: t -*- + +;;; Tools +;;;; automatic modes +(add-to-list 'auto-mode-alist '("\\.mix\\'" . hexl-mode)) +(add-to-list 'auto-mode-alist '("\\.m4\\'" . m4-mode)) +(add-to-list 'auto-mode-alist '("\\.am\\'" . makefile-mode)) +(add-to-list 'auto-mode-alist '("\\.pl\\'\\|\\.pm\\'" . cperl-mode)) + +;;;; symbol overlay +(use-package symbol-overlay +  :ensure t +  :config +  (defun jao-symbol-reveal (&rest _) +    (when outline-minor-mode (outline-show-entry))) +  (advice-add 'symbol-overlay-basic-jump :after 'jao-symbol-reveal) + +  (defun jao-symbol-put-and-next () +    (interactive) +    (symbol-overlay-put) +    (symbol-overlay-jump-next)) + +  (defun jao-symbol-put-and-prev () +    (interactive) +    (symbol-overlay-put) +    (symbol-overlay-jump-prev)) + +  :bind (:map prog-mode-map (("M-i" . symbol-overlay-put) +                             ("M-n" . jao-symbol-put-and-next) +                             ("M-p" . jao-symbol-put-and-prev))) +  :hook (prog-mode . symbol-overlay-mode) +  :diminish " ^") + +;;;; eglot +(use-package eglot +  :config +  (add-hook 'eglot--managed-mode-hook (lambda () (flymake-mode -1))) +  :bind (:map eglot-mode-map (("C-h ." . jao-eldoc-toggle)))) + +;;;; paredit and parens +(require 'paren) +(show-paren-mode t) +(setq show-paren-context-when-offscreen t +      show-paren-when-point-inside-paren nil) + +(use-package paredit +  :ensure t +  :commands paredit-mode +  :hook ((pie-mode . paredit-mode) +         (scheme-mode . paredit-mode) +         (clojure-mode . paredit-mode) +         (emacs-lisp-mode . paredit-mode) +         ;; (eval-expression-minibuffer-setup . paredit-mode) +         (lisp-interaction-mode . disable-paredit-mode)) +  :diminish ((paredit-mode . " þ"))) + +;;;; diff/ediff +(setq ediff-split-window-function 'split-window-horizontally) +(setq ediff-make-buffers-readonly-at-startup nil) +(setq ediff-window-setup-function 'ediff-setup-windows-plain) +(setq ediff-keep-variants nil) + +;;;; flymake +(use-package flymake +  :ensure t +  :custom ((flymake-mode-line-format '(" " flymake-mode-line-counters))) +  :config +  (jao-define-attached-buffer "^\\*Flymake diagnostics .*\\*\\'") + +  (transient-define-prefix jao-transient-flymake () +    ["Flymake" +     ("d" "show diagnostics" flymake-show-buffer-diagnostics) +     ("i" "show diagnostic" flymake-show-diagnostic) +     ("n" "next error" flymake-goto-next-error) +     ("p" "previous error" flymake-goto-prev-error) +     ("c" "consult flymake" consult-flymake)]) + +  :bind (:map flymake-mode-map (("M-m" . jao-transient-flymake)))) + +;;;; outline minor mode +(use-package outline +  :init (setq outline-minor-mode-use-buttons nil +              outline-minor-mode-use-margins nil +              outline-minor-mode-cycle t)) + +(defvar-local jao-outline-folded nil) +(dolist (v '(4 5 outline-show-only-headings)) +  (add-to-list 'safe-local-variable-values `(outline-default-state . ,v))) + +(defun jao-outline-minor-mode-hide-all (&optional arg) +  (interactive "P") +  (outline-hide-sublevels (if arg 5 4))) + +(defun jao-outline-minor-expand-all () +  (when jao-outline-minor-mode (outline-show-all))) + +(defun jao-outline-minor-mode-toogle-fold (&optional arg) +  (interactive "P") +  (if (setq jao-outline-folded (not jao-outline-folded)) +      (jao-outline-minor-mode-hide-all arg) +    (jao-outline-minor-expand-all))) + +(use-package outline-minor-faces +  :ensure t +  :after outline) + +(define-minor-mode jao-outline-minor-mode +  "Minor outline mode for programming languages" +  :lighter "" +  :keymap `((,(kbd "C-c C-n") . outline-next-visible-heading) +            (,(kbd "C-c C-p") . outline-previous-visible-heading) +            (,(kbd "C-c o") . consult-outline) +            (,(kbd "<f3>") . jao-outline-minor-mode-toogle-fold)) +  (if jao-outline-minor-mode +      (progn (setq-local outline-level #'outline-level +                         outline-regexp (format "[%s]\\{3,\\} " comment-start)) +             (outline-minor-mode 1) +             (outline-minor-faces-mode 1)) +    (outline-minor-mode -1) +    (outline-minor-faces-mode -1))) + +(add-hook 'find-function-after-hook #'jao-outline-minor-expand-all) + + + +;;; Build tools +;;;; compilation +;;;;; compilation mode options +(require 'compile) +(setq compilation-scroll-output t) +(setq compilation-error-regexp-alist +      (remove 'omake compilation-error-regexp-alist)) +;; (add-hook 'compilation-mode-hook #'visual-line-mode) + +;;;;; mode line (no "Compiling"!) +(require 'compile) +(diminish 'compilation-minor-mode " ‡") +(when (< emacs-major-version 27) +  (setcdr (assq 'compilation-in-progress minor-mode-alist) '(" ‡"))) +(when (> emacs-major-version 26) +  (setcdr (assq 'compilation-in-progress mode-line-modes) '("‡ "))) + +;;;;; colorizing compilation buffer +(setq compilation-message-face 'default) +(require 'ansi-color) +(defun endless/colorize-compilation () +  "Colorize from `compilation-filter-start' to `point'." +  (let ((inhibit-read-only t)) +    (ansi-color-apply-on-region +     compilation-filter-start (point)))) + +(add-hook 'compilation-filter-hook #'endless/colorize-compilation) + +;;;;; compilation commands +(use-package jao-compilation +  :commands jao-compilation-setup +  :bind (("C-c C" . compile) +         ("C-c c" . jao-compile))) +(jao-compilation-setup) + +;;;;; next error +(setq next-error-find-buffer-function +      #'next-error-buffer-on-selected-frame +      next-error-verbose t) + + +;;;; cmake +(use-package cmake-mode :ensure t) + +(use-package eldoc-cmake +  :ensure t +  :after cmake-mode +  :hook ((cmake-mode . eldoc-cmake-enable))) + +(use-package project-cmake :ensure t) + + + +;;; Programming languages +;;;; Elisp +(add-hook 'emacs-lisp-mode-hook #'jao-outline-minor-mode) + +(use-package edit-list :ensure t) +;; (use-package package-lint :ensure t) +;; (use-package tree-inspector :ensure t) + +(defun elisp-disassemble (function) +  (interactive (list (function-called-at-point))) +  (disassemble function)) + +(defun elisp-pp (sexp) +  (with-output-to-temp-buffer "*Pp Eval Output*" +    (pp sexp) +    (with-current-buffer standard-output +      (emacs-lisp-mode)))) + +(defun elisp-macroexpand (form) +  (interactive (list (form-at-point 'sexp))) +  (elisp-pp (macroexpand form))) + +(defun elisp-macroexpand-all (form) +  (interactive (list (form-at-point 'sexp))) +  (elisp-pp (macroexpand-all form))) + +(defun elisp-find-definition (name) +  (interactive (list (thing-at-point 'symbol))) +  (cond (name +         (let ((symbol (intern-soft name)) +               (search (lambda (fun sym) +                         (let* ((r (save-excursion (funcall fun sym))) +                                (buffer (car r)) +                                (point (cdr r))) +                           (cond ((not point) +                                  (error "Found no definition for %s in %s" +                                         name buffer)) +                                 (t +                                  (switch-to-buffer buffer) +                                  (goto-char point) +                                  (recenter 1))))))) +           (cond ((fboundp symbol) +                  (xref-push-marker-stack) +                  (funcall search 'find-function-noselect symbol)) +                 ((boundp symbol) +                  (xref-push-marker-stack) +                  (funcall search 'find-variable-noselect symbol)) +                 (t +                  (message "Symbol not bound: %S" symbol))))) +        (t (message "No symbol at point")))) + + +(defun elisp-bytecompile-and-load () +  (interactive) +  (or buffer-file-name +      (error "The buffer must be saved in a file first")) +  (require 'bytecomp) +  ;; Recompile if file or buffer has changed since last compilation. +  (when  (and (buffer-modified-p) +              (y-or-n-p (format "save buffer %s first? " (buffer-name)))) +    (save-buffer)) +  (let ((filename (expand-file-name buffer-file-name))) +    (with-temp-buffer +      (byte-compile-file filename)))) + +(use-package elisp-mode +  :bind (:map emacs-lisp-mode-map +              (("C-c C-M" . emacs-lisp-macroexpand) +               ("C-c C-m" . elisp-macroexpand-all) +               ("C-c C-k" . elisp-bytecompile-and-load) +               ;; ("C-c C-p" . pp-eval-last-sexp) +               ("M-." . elisp-find-definition) +               ("M-," . pop-tag-mark) +               ("C-c <" . lc-show-package-summary)))) + +;;;; Rust + +(use-package rust-mode +  :ensure t +  :init +  (setq rust-mode-treesitter-derive t)) + +(use-package rustic +  :ensure t +  :after (rust-mode) +  :config +  (setq rustic-format-on-save nil +        rustic-lsp-client 'eglot) +  :custom +  (rustic-cargo-use-last-stored-arguments t) +  (rustic-analyzer-command '("rustup" "run" "stable" "rust-analyzer"))) + + + +;;;; Clojure +(use-package clojure-mode +  :ensure t +  :hook (clojure-mode . jao-clojure--fix-things) +  :config +  (defun jao-clojure--fix-things () +    (setq-local completion-styles '(basic partial-completion emacs22)) +    (eldoc-mode 1) +    (setq mode-name "λ")) + +  (defun jao-kaocha-file-name () +    (let* ((filename (match-string 2)) +           (path (replace-regexp-in-string "\\." "/" (match-string 1)))) +      (substring-no-properties (concat "test/" path filename)))) + +  (defconst jao-kaocha-compilation-error +    '(kaocha-error +      "^FAIL in \\(.+\\.\\)[^ ]+ (\\([^:]+\\.clj[cs]?\\):\\([0-9]+\\))" +      jao-kaocha-file-name 3)) + +  (use-package compile +    :config +    (add-to-list 'compilation-error-regexp-alist-alist +                 jao-kaocha-compilation-error))) + +(use-package jao-clojure +  :demand t +  :after cider-test +  :bind (:map clojure-mode-map (("C-c o" . jao-clojure-other-file)))) + +(use-package cider +  :ensure t +  :commands cider-mode +  :init (setq cider-annotate-completion-candidates t +              cider-auto-select-error-buffer nil +              cider-auto-select-test-report-buffer nil +              cider-clojure-cli-aliases ":test" +              cider-eldoc-display-for-symbol-at-point t +              cider-eldoc-ns-function #'identity ;; #'cider-last-ns-segment +              cider-enrich-classpath nil +              cider-lein-parameters "repl :headless :host localhost" +              cider-mode-line  " ÷" +              cider-prompt-for-symbol nil +              cider-repl-history-file +              (expand-file-name "~/.emacs.d/cache/cider.history") +              cider-repl-pop-to-buffer-on-connect nil +              cider-repl-use-pretty-printing t +              cider-show-error-buffer 'except-in-repl +              cider-test-show-report-on-success nil +              cider-use-fringe-indicators nil +              cider-use-overlays nil +              clojure-docstring-fill-column 72 +              nrepl-prompt-to-kill-server-buffer-on-quit nil) +  :bind (("<f3>" . cider-selector))) + +(with-eval-after-load "cider-test" +  (advice-add 'cider-scale-background-color :override +              (lambda () (frame-parameter nil 'background-color))) +  (setq cider-test-items-background-color +        (frame-parameter nil 'background-color))) + +(use-package cider-macroexpansion +  :after cider +  :diminish " µ") + +;;;; Geiser +(defun jao-org--set-geiser-impl () (setq-local geiser-repl--impl 'guile)) +(add-hook 'org-mode-hook #'jao-org--set-geiser-impl) + +(jao-load-path "geiser") +;; (package-vc-install-from-checkout ...) +(use-package geiser +  :demand t +  :init +  (setq geiser-repl-history-filename "~/.emacs.d/cache/geiser-history" +        geiser-repl-startup-time 20000 +        geiser-debug-auto-display-images t +        geiser-log-verbose t) +  :config +  (dolist (m '(geiser-repl-mode geiser-doc-mode geiser-debug-mode)) +    (jao-define-attached-buffer `(major-mode . ,m) 0.4))) + +(jao-load-path "geiser-guile") +(use-package geiser-guile) + +(jao-load-path "geiser-chez") +(use-package geiser-chez +  :init (setq geiser-chez-binary (jao-d-l "chez" "scheme"))) + +;; (jao-load-path "geiser/mit") +;; (use-package geiser-mit) + +;; (jao-load-path "geiser/chicken") +;; (use-package geiser-chicken) + +;; (jao-load-path "geiser/chibi") +;; (use-package geiser-chibi) + +;; (jao-load-path "geiser/gambit") +;; (use-package geiser-gambit) + +;; (jao-load-path "geiser/gauche") +;; (use-package geiser-gauche) + +;;;; Haskell +;;;;; packages +;; (jao-load-path "haskell-mode") + +(use-package haskell-mode +  :ensure t +  :custom +  ((inferior-haskell-find-project-root t) +   (haskell-check-remember-last-command-p nil) +   (haskell-completing-read-function 'completing-read) +   (haskell-font-lock-symbols nil) +   (haskell-hoogle-command "hoogle") +   (haskell-interactive-popup-errors t) +   (haskell-process-auto-import-loaded-modules t) +   (haskell-process-log t) +   (haskell-process-suggest-remove-import-lines t) +   (haskell-process-suggest-hoogle-imports t) +   (haskell-process-type 'cabal-repl) +   (haskell-process-use-presentation-mode t) +   (haskell-stylish-on-save nil) +   (haskell-tags-on-save t)) + +  :init +  ;; For use with M-x align +  (require 'align) +  (add-to-list 'align-rules-list +               '(haskell-types +                 (regexp . "\\(\\s-+\\)\\(::\\|∷\\)\\s-+") +                 (modes quote (haskell-mode haskell-literate-mode)))) +  (add-to-list 'align-rules-list +               '(haskell-assignment +                 (regexp . "\\(\\s-+\\)=\\s-+") +                 (modes quote (haskell-mode haskell-literate-mode)))) +  (add-to-list 'align-rules-list +               '(haskell-arrows +                 (regexp . "\\(\\s-+\\)\\(->\\|→\\)\\s-+") +                 (modes quote (haskell-mode haskell-literate-mode)))) +  (add-to-list 'align-rules-list +               '(haskell-left-arrows +                 (regexp . "\\(\\s-+\\)\\(<-\\|←\\)\\s-+") +                 (modes quote (haskell-mode haskell-literate-mode)))) + +  :config +  (defun jao-haskell-hoogle (no-info) +    (interactive "P") +    (haskell-hoogle (format "%s" (haskell-ident-at-point)) (not no-info))) + +  (put 'haskell-process-args-cabal-repl +       'safe-local-variable +       (apply-partially #'seq-every-p #'stringp)) + +  (defun jao-haskell-eldoc (cb) +    (let ((msg (or (haskell-doc-current-info--interaction t) +                   (haskell-doc-sym-doc (haskell-ident-at-point)) +                   ""))) +      (funcall cb (replace-regexp-in-string "[\n ]+" " " msg)))) + +  (setq tags-revert-without-query t) + +  (defun jao-haskell-mode () +    (require 'haskell-doc) +    (setq-local eldoc-documentation-function 'eldoc-documentation-default +                eldoc-documentation-functions '(jao-haskell-eldoc)) +    (eldoc-mode)) + +  (dolist (h '(jao-haskell-mode +               haskell-decl-scan-mode +               haskell-indentation-mode +               interactive-haskell-mode)) +    (add-hook 'haskell-mode-hook h)) + +  (add-hook 'haskell-presentation-mode-hook (lambda () (whitespace-mode -1))) + +  :bind (:map haskell-mode-map +              (("C-c C-d" . jao-haskell-hoogle) +               ("C-c C-s" . haskell-session-change-target) +               ("C-c h" . haskell-hoogle) +               ("C-c t" . haskell-doc-show-type) +               ("C-c C-e" . haskell-command-insert-language-pragma) +               ("C-M-n" . flymake-goto-next-error) +               ("C-M-p" . flymake-goto-prev-error) +               ("<f3>" . haskell-session-kill)))) + +(jao-when-linux + (use-package hlint-refactor +   :ensure t +   :after haskell-mode +   :hook ((haskell-mode . hlint-refactor-mode)) +   :bind (:map haskell-mode-map (("C-M-h" . 'hlint-refactor-refactor-at-point) +                                 ("C-M-S-h" . 'hlint-refactor-refactor-buffer))) +   :diminish) + + (use-package flymake-hlint +   :ensure t +   :after haskell-mode +   :hook ((haskell-mode . flymake-hlint-load)))) + +(use-package consult-hoogle +  :ensure t) + +(require 'haskell) + +(diminish 'interactive-haskell-mode " λ") +(diminish 'haskell-doc-mode) +(diminish 'haskell-decl-scan-mode) + +(jao-define-attached-buffer "\\*hoogle\\*.*") +(jao-define-attached-buffer '(major-mode . haskell-interactive-mode) 0.33) +(jao-define-attached-buffer '(major-mode . haskell-presentation-mode) 0.25) + +;;;;; transient +(jao-transient-major-mode haskell +  ["Imports" +   ("in" "Navigate imports" haskell-navigate-imports) +   ("if" "Format imports" haskell-mode-format-imports) +   ("is" "Sort imports" haskell-sort-imports) +   ("ia" "Align imports" haskell-align-imports)] +  ["Session" +   ("s" "Change the session's target" haskell-session-change-target)] +  ["Code" +   ("e" "insert language pragma" haskell-command-insert-language-pragma) +   ("v" "visit cabal file" haskell-cabal-visit-file) +   ("h" "hoogle" jao-haskell-hoogle) +   ("t" "show type" haskell-doc-show-type)] +  ["Flymake" +   ("n" "next error" flymake-goto-next-error) +   ("p" "previous error" flymake-goto-prev-error)]) + +;;;; Pie +;; (jao-load-path "pie") +;; (use-package pie +;;   :commands (pie-mode)) + +;;;; Prolog +;; (use-package ediprolog :ensure t) + +(use-package prolog +  :disabled t +  :ensure t +  :commands (run-prolog prolog-mode mercury-mode) +  :init (progn +          (setq prolog-system 'swi) +          (add-to-list 'auto-mode-alist '("\\.pl$" . prolog-mode)) +          (setq prolog-consult-string '((t "[%f]."))) +          (setq prolog-program-name +                '(((getenv "EPROLOG") (eval (getenv "EPROLOG"))) +                  (eclipse "eclipse") +                  (mercury nil) +                  (sicstus "sicstus") +                  (swi "swipl") +                  (t "prolog"))))) + +;;;; Python +;; (use-package virtualenvwrapper +;;   :ensure t +;;   :config +;;   (venv-initialize-eshell) +;;   (jao-compilation-env "VIRTUAL_ENV")) + +;;;; Javascript + +(use-package typescript-mode +  :ensure t +  :custom ((typescript-indent-level 2))) +;;;; Applescript + +(jao-when-darwin + (use-package ob-applescript +   :after org +   :ensure t +   :demand t) + + (use-package apples-mode +   :ensure t +   :init +   (add-to-list 'auto-mode-alist +                '("\\.\\(applescri\\|sc\\)pt\\'" . apples-mode)))) + +;;; - +(provide 'jao-custom-programming) diff --git a/custom/jao-custom-shells.el b/custom/jao-custom-shells.el new file mode 100644 index 0000000..eaae13c --- /dev/null +++ b/custom/jao-custom-shells.el @@ -0,0 +1,6 @@ +;; -*- lexical-binding: t -*- + + + + +(provide 'jao-custom-shells) diff --git a/custom/jao-custom-w3m.el b/custom/jao-custom-w3m.el new file mode 100644 index 0000000..f532e8b --- /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-r2e-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) diff --git a/custom/jao-custom-x11.el b/custom/jao-custom-x11.el new file mode 100644 index 0000000..3311668 --- /dev/null +++ b/custom/jao-custom-x11.el @@ -0,0 +1,192 @@ +;; -*- lexical-binding: t -*- + +;;; x11 utils +(defun jao-xdotool (arg-or-wait &rest args) +  (apply 'jao-shell-exec* +         (if (stringp arg-or-wait) "xdotool" arg-or-wait) +         (if (stringp arg-or-wait) arg-or-wait "xdotool") +         args)) + +(defsubst jao-xdotool-string (&rest args) +  (apply 'jao-shell-string "xdotool" args)) + +(defsubst jao-x11-focused-id () (jao-xdotool-string "getwindowfocus")) + +(defsubst jao-x11-window-name (&optional wid) +  (jao-xdotool-string "getwindowname" (or wid (jao-x11-focused-id)))) + +(defsubst jao-x11-search-window (title) +  (jao-xdotool-string "search" "--name" title)) + +(defsubst jao-x11-goto-ws (n) (jao-xdotool t "set_desktop" (format "%s" n))) + +;;; exwm +(defun jao-exwm-enable () +  (require 'jao-custom-exwm) +  (setq jao-exwm-enabled t) +  (display-time-mode -1) +  (jao-ednc-setup 95) +  (x-change-window-property "_XMONAD_TRAYPAD" "" nil nil nil nil 0) +  (jao-mode-line-add-to-minibuffer-left 90) +  (jao-xmobar-restart) +  (jao-trisect t)) + +;;; xmonad +(defun jao-xmonad-enable () +  (setq jao-pdf-open-in-emacs (display-graphic-p)) +  (setq jao-mode-line-in-minibuffer nil) +  (display-battery-mode -1) +  (jao-trisect) +  (message "Welcome to xmonad")) + +(when jao-xmonad-enabled +  (add-hook 'after-init-hook #'jao-xmonad-enable)) + +;;; wayland + +(use-package jao-wayland :demand t) + +(defun jao-wayland-enable () +  (interactive) +  (defalias 'x-change-window-property #'ignore) +  (jao-trisect) +  (message "Welcome to wayland")) + +(defun jao-river-enable () +  (jao-wayland-enable) +  (when (jao-shell-running-p "i3bar-river") +    (jao-tracking-set-log "")) +  (message "Welcome to river")) + +(when jao-river-enabled +  (add-hook 'after-init-hook #'jao-river-enable t)) + +(when jao-sway-enabled +  (add-hook 'after-init-hook #'jao-wayland-enable t)) + +;;; wallpaper +(defvar jao-wallpaper-dir "~/.wallpapers/") + +(defvar jao-wallpaper-random-candidates +  '("wallpaper.jpg" "wallpaper2.jpg")) + +(defvar jao-wallpaper-random-candidates-light +  '("wallpaper.jpg" "wallpaper2.jpg")) + +(defvar jao-wallpaper-random-wake t +  "Set to t for getting a new wallpaper on awaking from sleep") + +(defun jao-set-wallpaper (&optional path) +  (interactive) +  (let ((current (format "~/.wallpaper.%s" (jao-colors-scheme)))) +    (when-let ((f (or (and path (expand-file-name path)) +                      (read-file-name "Image: " +                                      jao-wallpaper-dir +                                      (file-symlink-p current) +                                      t)))) +      (make-symbolic-link f current t) +      (cond (jao-river-enabled (jao-river-set-wallpaper f)) +            (jao-sway-enabled (jao-sway-set-wallpaper f)) +            (t (shell-command-to-string (format "xwallpaper --zoom %s" f))))))) + +(defun jao-set-random-wallpaper () +  (interactive) +  (when (or (called-interactively-p 'interactive) +            jao-wallpaper-random-wake) +    (let* ((ws (if (jao-colors-scheme-dark-p) +                   jao-wallpaper-random-candidates +                 jao-wallpaper-random-candidates-light)) +           (f (seq-random-elt ws))) +      (jao-set-wallpaper (expand-file-name f jao-wallpaper-dir)) +      (message "%s" f)))) + +(add-to-list 'jao-sleep-awake-functions #'jao-set-random-wallpaper) + +;;; screensaver and lock +(defun jao-screensaver-enabled () +  (string= (jao-shell-string "xdg-screensaver status") "enabled")) + +(defvar jao-screensaver--wid nil) +(defun jao-screensaver-toggle () +  (interactive) +  (if (jao-screensaver-enabled) +      (let ((wid (jao-x11-focused-id))) +        (setq jao-screensaver--wid wid) +        (jao-shell-exec* t "xdg-screensaver" "suspend" wid)) +    (jao-shell-exec* t "xdg-screensaver" "resume" jao-screensaver--wid) +    (setq jao-screensaver--wid nil)) +  (jao-notify (format "Screensaver %s" +                      (jao-shell-string "xdg-screensaver status")))) + +(jao-shell-def-exec jao-xlock-screen "xdg-screensaver" "activate") +(jao-shell-def-exec jao-suspend "sudo" "systemctl" "suspend") +(jao-shell-def-exec jao-poweroff "sudo" "systemctl" "poweroff") + +(defun jao-lock-screen () +  (interactive) +  (if jao-wayland-enabled +      (shell-command "swaylock -i ~/.lockimage") +    (jao-xlock-screen))) + +(transient-define-prefix jao-transient-sleep () +  ["Sleep" +   ("l" "lock screen" jao-lock-screen) +   ("z" "sleep" jao-suspend) +   ("u" (lambda () +          (if (jao-screensaver-enabled) "suspend screensaver" "resume screensaver")) +    jao-screensaver-toggle) +   ("poof" "power-off" jao-poweroff)]) + +;;; X clipboard +(setq select-enable-clipboard t +      select-enable-primary t +      selection-timeout 100 +      xterm-select-active-regions t) + +(use-package xclip +  :ensure t +  :init (setq xclip-method (if jao-wayland-enabled 'wl-copy 'xclip))) + +(unless (display-graphic-p) (xclip-mode 1)) + +;;; pop-up frames +(defun jao-open-in-x-frame (&optional width height) +  (interactive) +  (make-frame `((window-system . x) +                (name . "emacs popup") +                (width . ,(or width (window-width))) +                (height . ,(or height (window-height))))) +  (define-key (current-local-map) "q" #'delete-frame)) + +;;; xmobar +(defun jao-xmobar-kill () +  (interactive) +  (shell-command "killall xmobar-single")) + +(defun jao-xmobar-restart () +  (interactive) +  (jao-xmobar-kill) +  (start-process "" nil "xmobar-single" "-d")) + +(use-package tab-bar +  :init (setq tab-bar-close-button-show nil +              tab-bar-show (> emacs-major-version 28) +              tab-bar-format ())) + +(use-package xmobar +  :init (setq  xmobar-tab-bar t +               xmobar-tab-split "*" +               xmobar-tab-bar-format +               (if window-system +                   '(xmobar-left-string +                     tab-bar-format-align-right +                     xmobar-right-string) +                 '(xmobar-left-string +                   xmobar-elastic-space +                   xmobar-right-string)) +               xmobar-command +               (if window-system '("xmobar-emacs" "-TAnsi") "xmobar-emacs"))) + + +;;; - provide +(provide 'jao-custom-x11) | 
