Skip to content

Commit

Permalink
emacs: more lazy loading & termux
Browse files Browse the repository at this point in the history
  • Loading branch information
SqrtMinusOne committed Jul 10, 2024
1 parent 10429c4 commit 4a65300
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 142 deletions.
18 changes: 15 additions & 3 deletions .emacs.d/init.el
Original file line number Diff line number Diff line change
Expand Up @@ -2684,9 +2684,13 @@ Returns (<buffer> . <workspace-index>) or nil."

(use-package flycheck-package
:straight t
:after flycheck
:config
(flycheck-package-setup))
:defer t
:init
(defun my/flycheck-package-setup ()
(require 'flycheck-package)
(flycheck-package-setup)
(remove-hook 'emacs-lisp-mode-hook #'my/flycheck-package-setup))
(add-hook 'emacs-lisp-mode-hook #'my/flycheck-package-setup))

(add-hook 'emacs-lisp-mode-hook #'aggressive-indent-mode)
;; (add-hook 'emacs-lisp-mode-hook #'smartparens-strict-mode)
Expand Down Expand Up @@ -7742,6 +7746,14 @@ base toot."

(use-package devdocs-browser
:straight t
:commands (devdocs-browser-open
devdocs-browser-open-in
devdocs-browser-install-doc
devdocs-browser-uninstall-doc
devdocs-browser-download-offline-data
devdocs-browser-remove-offline-data
devdocs-browser-upgrade-all-docs
devdocs-browser-update-docs)
:init
(my-leader-def
:infix "hd"
Expand Down
131 changes: 1 addition & 130 deletions .emacs.d/mail.el
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
(setq user-mail-address "[email protected]")
(setq user-full-name "Pavel Korytov")

(let ((dir "/home/pavel/.guix-extra-profiles/mail/mail/share/emacs/site-lisp"))
(when (file-directory-p dir)
(let ((default-directory dir))
(normal-top-level-add-subdirs-to-load-path))))

(use-package notmuch
:straight t
:if my/is-termux)

(defun my/notmuch-toggle-trash ()
(interactive)
(evil-collection-notmuch-toggle-tag "trash" "search" #'ignore))

(defun my/notmuch-toggle-inbox ()
(interactive)
(evil-collection-notmuch-toggle-tag "inbox" "search" #'ignore))

(defun my/notmuch-toggle-unread ()
(interactive)
(evil-collection-notmuch-toggle-tag "unread" "search" #'ignore))

(use-package notmuch
:if (not my/is-termux)
;; :ensure nil
:commands (notmuch notmuch-search)
:init
Expand All @@ -49,109 +26,3 @@
(setq notmuch-address-command 'as-is)
(add-hook 'notmuch-hello-mode-hook
(lambda () (display-line-numbers-mode 0))))

(my-leader-def
"am" (my/command-in-persp "notmuch" "mail" 0 (notmuch)))

(my/persp-add-rule
notmuch-hello-mode 0 "mail"
notmuch-search-mode 0 "mail"
notmuch-tree-mode 0 "mail"
notmuch-message-mode 0 "mail")

(setq notmuch-saved-searches
'((:name "drafts" :query "tag:draft" :key "d")
(:name "main (inbox)" :query "tag:main AND tag:inbox" :key "mi")
(:name "main (unread)" :query "tag:main AND tag:unread" :key "mu")
(:name "main (sent)" :query "tag:main AND tag:sent" :key "ms")
(:name "main (all mail)" :query "tag:main" :key "ma")
(:name "progin (inbox)" :query "tag:progin AND tag:inbox" :key "pi")
(:name "progin (unread)" :query "tag:progin AND tag:unread" :key "pu")
(:name "progin (sent)" :query "tag:progin AND tag:sent" :key "ps")
(:name "progin (all mail)" :query "tag:progin" :key "pa")
(:name "pvkorytov (inbox)" :query "tag:pvkorytov AND tag:inbox" :key "vi")
(:name "pvkorytov (unread)" :query "tag:pvkorytov AND tag:unread" :key "vu")
(:name "pvkorytov (sent)" :query "tag:pvkorytov AND tag:sent" :key "vs")
(:name "pvkorytov (all mail)" :query "tag:pvkorytov" :key "va")))
(setq notmuch-show-empty-saved-searches nil)

(general-define-key
:states '(normal visual)
:keymaps '(notmuch-hello-mode-map)
"f" #'notmuch-jump-search)

(with-eval-after-load 'notmuch
(add-hook 'message-setup-hook 'mml-secure-sign-pgpmime))

(setq mml-secure-key-preferences
'((OpenPGP
(sign
("[email protected]" "914472A1FD6775C166F96EBEED739ADF81C78160"))
(encrypt))
(CMS
(sign)
(encrypt))))

(defun my/message-insert-signature-need-on-top ()
t)

(defun my/message-maybe-fix-signature (&rest _)
(when (my/message-insert-signature-need-on-top)
(save-excursion
(goto-char (point-min))
(when (re-search-forward message-signature-separator nil t)
(move-beginning-of-line 0)
(kill-region (point) (point-max)))
(message-goto-body)
(when (re-search-forward (rx "sign=pgpmime") nil t)
(forward-line))
(insert (current-kill 0))
(insert "\n\n")
(set-buffer-modified-p nil))))

(with-eval-after-load 'notmuch-mua
(advice-add #'notmuch-mua-reply :after #'my/message-maybe-fix-signature))

(defun my/message-ensure-subject ()
(unless (or (message-field-value "Subject")
(y-or-n-p "No subject. Send? "))
(user-error "Aborting.")))

(add-hook 'notmuch-mua-send-hook #'my/message-ensure-subject)

(defvar my/ru-formal-pronous
'("вы" "вас" "вам" "вами" "ваш" "ваша" "ваше" "ваши" "вашего"
"вашей" "вашему" "вашим" "вашем" "вашеми"))

(defvar my/ru-formal-pronous-regex
(regexp-opt
(mapcar (lambda (p) (format " %s " p)) my/ru-formal-pronous) 'words))

(defun my/message-ensure-capitalized-formal-pronouns ()
(interactive)
(save-excursion
(message-goto-body)
(cl-block nil
(let ((case-fold-search nil)
confirmed)
(while (re-search-forward my/ru-formal-pronous-regex nil t)
(let* ((match (match-string 0))
(capitalized (capitalize match))
(beg (match-beginning 0))
(end (match-end 0)))
(if (or confirmed
(y-or-n-p (format "Replace %s with %s? "
match capitalized)))
(progn
(delete-region beg end)
(insert capitalized)
(setq confirmed t))
(cl-return))))))))

(add-hook 'notmuch-mua-send-hook #'my/message-ensure-capitalized-formal-pronouns)

(defun my/ensure-password ()
(interactive)
(my/password-store-get "Job/Digital/Email/[email protected]"))

(add-hook 'notmuch-mua-send-hook #'my/ensure-password)
18 changes: 15 additions & 3 deletions Emacs.org
Original file line number Diff line number Diff line change
Expand Up @@ -3672,9 +3672,13 @@ A package that checks for the metadata in Emacs Lisp packages.
#+begin_src emacs-lisp
(use-package flycheck-package
:straight t
:after flycheck
:config
(flycheck-package-setup))
:defer t
:init
(defun my/flycheck-package-setup ()
(require 'flycheck-package)
(flycheck-package-setup)
(remove-hook 'emacs-lisp-mode-hook #'my/flycheck-package-setup))
(add-hook 'emacs-lisp-mode-hook #'my/flycheck-package-setup))
#+end_src
**** General settings
#+begin_src emacs-lisp
Expand Down Expand Up @@ -10681,6 +10685,14 @@ There is a package called =devdocs= that does more or less the same, but I like
#+begin_src emacs-lisp
(use-package devdocs-browser
:straight t
:commands (devdocs-browser-open
devdocs-browser-open-in
devdocs-browser-install-doc
devdocs-browser-uninstall-doc
devdocs-browser-download-offline-data
devdocs-browser-remove-offline-data
devdocs-browser-upgrade-all-docs
devdocs-browser-update-docs)
:init
(my-leader-def
:infix "hd"
Expand Down
8 changes: 2 additions & 6 deletions Mail.org
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,7 @@ Then, the problem with my Guix setup is that Emacs by default doesn't see the el
(normal-top-level-add-subdirs-to-load-path))))
#+end_src

On termux the above doesn't work so...
#+begin_src emacs-lisp
(use-package notmuch
:straight t
:if my/is-termux)
#+end_src
On termux the above doesn't work, and I don't need it here anyway.

Some functions to toggle tags:
#+begin_src emacs-lisp
Expand All @@ -415,6 +410,7 @@ Some functions to toggle tags:
And notmuch settings:
#+begin_src emacs-lisp
(use-package notmuch
:if (not my/is-termux)
;; :ensure nil
:commands (notmuch notmuch-search)
:init
Expand Down

0 comments on commit 4a65300

Please sign in to comment.