feat(emacs): ement.el

This commit is contained in:
Pavel Korytov 2023-05-21 23:05:45 +03:00
parent c78097f9a6
commit 4e0583c103
2 changed files with 151 additions and 13 deletions

View file

@ -1157,8 +1157,12 @@ influence of C1 on the result."
(setq my/perspective-assign-alist '())
(defvar my/perspective-assign-ignore nil
"If non-nil, ignore `my/perspective-assign'")
(defun my/perspective-assign ()
(when-let* ((rule (alist-get major-mode my/perspective-assign-alist)))
(when-let* ((_ (not my/perspective-assign-ignore))
(rule (alist-get major-mode my/perspective-assign-alist)))
(let ((workspace-index (car rule))
(persp-name (cadr rule))
(buffer (current-buffer)))
@ -1175,6 +1179,10 @@ influence of C1 on the result."
(persp-set-buffer buffer))
(persp-switch-to-buffer buffer)))))
(defun my/perspective-assign-ignore-advice (fun &rest args)
(let ((my/perspective-assign-ignore t))
(apply fun args)))
(add-hook 'after-change-major-mode-hook #'my/perspective-assign)
(defmacro my/persp-add-rule (&rest body)
@ -5611,7 +5619,7 @@ ENTRY is an instance of `elfeed-entry'."
(erc-update-modules)
(setq erc-autojoin-channels-alist
`((,(rx "libera.chat")
"#systemcrafters")))
"#systemcrafters" "#systemcrafters-emacs")))
(setq erc-kill-buffer-on-part t)
(setq erc-track-shorten-start 8))
@ -5635,7 +5643,7 @@ ENTRY is an instance of `elfeed-entry'."
:straight t
:commands (znc-erc)
:init
(my-leader-def "ai" #'znc-erc)
;; (my-leader-def "ai" #'znc-erc)
(my/persp-add-rule
erc-mode 3 "ERC")
:config
@ -5694,6 +5702,12 @@ ENTRY is an instance of `elfeed-entry'."
(add-hook 'mastodon-mode-hook #'my/mastodon-configure)
(defun my/mastodon-reset ()
(interactive)
(cl-loop for process in (process-list)
if (string-match-p "emacs.ch" (process-name process))
do (delete-process process)))
(with-eval-after-load 'mastodon
(general-define-key
:states '(normal motion)
@ -5960,8 +5974,59 @@ base toot."
:straight (:host github :repo "alphapapa/plz.el")
:defer t)
(defun my/ement ()
(interactive)
(ement-connect
:user-id "@sqrtminusone:matrix.org"
:password (my/password-store-get "My_Online/Accounts/matrix")))
(defun my/ement-room-setup ()
(display-line-numbers-mode 1))
(use-package ement
:straight (:host github :repo "alphapapa/ement.el"))
:straight (:host github :repo "alphapapa/ement.el")
:init
(my-leader-def "ai" #'my/ement)
:config
(setq ement-room-list-auto-update t)
(setq ement-room-mark-rooms-read 'send)
(setq ement-room-message-format-spec "%S> %W%B%r%R[%t]")
(setq ement-room-left-margin-width 0)
(setq ement-room-right-margin-width 10)
(setq ement-room-sender-in-left-margin nil)
(setq ement-room-sender-headers nil)
(setq ement-room-sender-in-headers nil)
(set-face-attribute 'ement-room-reactions nil :height 'unspecified)
(set-face-attribute 'ement-room-reactions-key nil :height 'unspecified)
(set-face-attribute 'ement-room-timestamp nil :inherit 'font-lock-function-name-face)
(set-face-attribute 'ement-room-membership nil :height 0.9
:inherit 'font-lock-warning-face)
(set-face-attribute 'ement-room-wrap-prefix nil :inherit 'unspecified)
(set-face-attribute 'ement-room-timestamp-header nil :height 'unspecified)
(set-face-attribute 'ement-room-wrap-prefix nil :inherit 'unspecified)
(setq ement-room-wrap-prefix "-> ")
(setq ement-notify-notification-predicates
'(ement-notify--event-mentions-session-user-p
ement-notify--event-mentions-room-p
ement-notify--room-unread-p))
(advice-add #'ement-room-list-revert :around #'my/perspective-assign-ignore-advice)
(add-hook 'ement-room-mode-hook #'my/ement-room-setup)
(my/persp-add-rule
ement-room-mode 3 "ement"
ement-describe-room-mode 3 "ement"
ement-room-occur-mode 3 "ement"
ement-room-list-mode 3 "ement"))
(with-eval-after-load 'ement-room-list
(general-define-key
:states '(normal visual)
:keymaps '(ement-room-list-mode-map)
"<tab>" #'magit-section-toggle
"C-j" #'magit-section-forward
"C-k" #'magit-section-backward
"q" #'quit-window
"gr" #'revert-buffer
"RET" #'ement-room-list-RET))
(use-package telega
:straight t
@ -6029,9 +6094,6 @@ base toot."
(setq telega-online-status-function #'my/telega-online-status)
(use-package reddigg
:straight t)
(use-package google-translate
:straight t
:if (not my/remote-server)

View file

@ -1845,8 +1845,12 @@ One rule looks as follows:
And a function to act on these rules.
#+begin_src emacs-lisp
(defvar my/perspective-assign-ignore nil
"If non-nil, ignore `my/perspective-assign'")
(defun my/perspective-assign ()
(when-let* ((rule (alist-get major-mode my/perspective-assign-alist)))
(when-let* ((_ (not my/perspective-assign-ignore))
(rule (alist-get major-mode my/perspective-assign-alist)))
(let ((workspace-index (car rule))
(persp-name (cadr rule))
(buffer (current-buffer)))
@ -1864,6 +1868,13 @@ And a function to act on these rules.
(persp-switch-to-buffer buffer)))))
#+end_src
Also advise to ignore the assignment:
#+begin_src emacs-lisp
(defun my/perspective-assign-ignore-advice (fun &rest args)
(let ((my/perspective-assign-ignore t))
(apply fun args)))
#+end_src
If EXWM is available, then so is mine =perspective-exwm= package, which features a convenient procedure called =perspective-exwm-assign-window=. Otherwise, we just work with perspectives.
Now, we have to put this function somewhere, and =after-change-major-mode-hook= seems like a perfect place for it.
@ -7936,7 +7947,7 @@ ERC is a built-it Emacs IRC client.
(erc-update-modules)
(setq erc-autojoin-channels-alist
`((,(rx "libera.chat")
"#systemcrafters")))
"#systemcrafters" "#systemcrafters-emacs")))
(setq erc-kill-buffer-on-part t)
(setq erc-track-shorten-start 8))
#+end_src
@ -7969,7 +7980,7 @@ ZNC support. Seems to provide a few nice features for ZNC.
:straight t
:commands (znc-erc)
:init
(my-leader-def "ai" #'znc-erc)
;; (my-leader-def "ai" #'znc-erc)
(my/persp-add-rule
erc-mode 3 "ERC")
:config
@ -8046,6 +8057,16 @@ The default UI is a bit rough, but Nicolas Rougier's [[https://github.com/rougie
(add-hook 'mastodon-mode-hook #'my/mastodon-configure)
#+end_src
Kill processes. Useful when the package stops working due to unstable connection.
#+begin_src emacs-lisp
(defun my/mastodon-reset ()
(interactive)
(cl-loop for process in (process-list)
if (string-match-p "emacs.ch" (process-name process))
do (delete-process process)))
#+end_src
The package also doesn't have evil bindings. I implement a few basic bindings here:
#+begin_src emacs-lisp
(with-eval-after-load 'mastodon
@ -8344,8 +8365,62 @@ And the prefix itself:
:straight (:host github :repo "alphapapa/plz.el")
:defer t)
(defun my/ement ()
(interactive)
(ement-connect
:user-id "@sqrtminusone:matrix.org"
:password (my/password-store-get "My_Online/Accounts/matrix")))
(defun my/ement-room-setup ()
(display-line-numbers-mode 1))
(use-package ement
:straight (:host github :repo "alphapapa/ement.el"))
:straight (:host github :repo "alphapapa/ement.el")
:init
(my-leader-def "ai" #'my/ement)
:config
(setq ement-room-list-auto-update t)
(setq ement-room-mark-rooms-read 'send)
(setq ement-room-message-format-spec "%S> %W%B%r%R[%t]")
(setq ement-room-left-margin-width 0)
(setq ement-room-right-margin-width 10)
(setq ement-room-sender-in-left-margin nil)
(setq ement-room-sender-headers nil)
(setq ement-room-sender-in-headers nil)
(set-face-attribute 'ement-room-reactions nil :height 'unspecified)
(set-face-attribute 'ement-room-reactions-key nil :height 'unspecified)
(set-face-attribute 'ement-room-timestamp nil :inherit 'font-lock-function-name-face)
(set-face-attribute 'ement-room-membership nil :height 0.9
:inherit 'font-lock-warning-face)
(set-face-attribute 'ement-room-wrap-prefix nil :inherit 'unspecified)
(set-face-attribute 'ement-room-timestamp-header nil :height 'unspecified)
(set-face-attribute 'ement-room-wrap-prefix nil :inherit 'unspecified)
(setq ement-room-wrap-prefix "-> ")
(setq ement-notify-notification-predicates
'(ement-notify--event-mentions-session-user-p
ement-notify--event-mentions-room-p
ement-notify--room-unread-p))
(advice-add #'ement-room-list-revert :around #'my/perspective-assign-ignore-advice)
(add-hook 'ement-room-mode-hook #'my/ement-room-setup)
(my/persp-add-rule
ement-room-mode 3 "ement"
ement-describe-room-mode 3 "ement"
ement-room-occur-mode 3 "ement"
ement-room-list-mode 3 "ement"))
#+end_src
Some custom keymaps:
#+begin_src emacs-lisp
(with-eval-after-load 'ement-room-list
(general-define-key
:states '(normal visual)
:keymaps '(ement-room-list-mode-map)
"<tab>" #'magit-section-toggle
"C-j" #'magit-section-forward
"C-k" #'magit-section-backward
"q" #'quit-window
"gr" #'revert-buffer
"RET" #'ement-room-list-RET))
#+end_src
*** Telega
[[https://github.com/zevlg/telega.el/][telega.el]] is a Telegam client for Emacs.
@ -8435,13 +8510,14 @@ And custom online status. By default it marks you online when the Emacs frame is
(setq telega-online-status-function #'my/telega-online-status)
#+end_src
*** Reddit
*** OFF Reddit
[[https://github.com/thanhvg/emacs-reddigg][reddigg]] allows to view reddit in org-mode.
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package reddigg
:straight t)
#+end_src
*** Google Translate
Emacs interface to Google Translate.