From 79fee39ab74d0ebb89a559d7d1b8fdb6222e4a41 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 15 Sep 2025 03:01:58 +0100 Subject: macos compatibility --- custom/jao-custom-chats.el | 344 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 344 insertions(+) create mode 100644 custom/jao-custom-chats.el (limited to 'custom/jao-custom-chats.el') diff --git a/custom/jao-custom-chats.el b/custom/jao-custom-chats.el new file mode 100644 index 0000000..7f5bfe4 --- /dev/null +++ b/custom/jao-custom-chats.el @@ -0,0 +1,344 @@ +;; -*- 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")) + +;;;; mastodon +(use-package mastodon + :ensure t + :init + (setq mastodon-instance-url "https://fosstodon.org" + mastodon-active-user "jao@gnu.org" + mastodon-group-notifications t + mastodon-images-in-notifs t + mastodon-tl-position-after-update nil + mastodon-toot-display-orig-in-reply-buffer t + mastodon-media--hide-sensitive-media nil) + :config + ;; (defun jao-mastodon--setup () + ;; (setq-local scroll-margin 12)) + + ;; (add-hook 'mastodon-mode-hook #'jao-mastodon--setup) + (with-eval-after-load "ewww" + (define-key eww-mode-map (kbd "T") #'jao-mastodon-toot-url))) + +(defun jao-mastodon-toot-url () + (interactive) + (when-let (url (jao-url-around-point t)) + (jao-tracking-go-to-chats) + (mastodon-toot--compose-buffer nil nil nil url))) + +(defun jao-mastodon () + (interactive) + (jao-afio-goto-chats) + (mastodon)) + +;; https://0x0.st/XJ14.txt +(jao-transient-major-mode mastodon + ["Timelines" + ("H" "home" mastodon-tl--get-home-timeline) + ("L" "local" mastodon-tl--get-local-timeline) + ("F" "federated" mastodon-tl--get-federated-timeline) + ("K" "bookmarks" mastodon-profile--view-bookmarks) + ("V" "favorites" mastodon-profile--view-favourites) + ("'" "followed tags" mastodon-tl--followed-tags-timeline) + ("@" "mentions" mastodon-notifications--get-mentions) + ("N" "notifications" mastodon-notifications-get) + ("\\" "of remote host" mastodon-tl--get-remote-local-timeline)] + + ;; u mastodon-tl--update + + ["Search" + ("s" "search" mastodon-search--query) + ("#" "tagged" mastodon-tl--get-tag-timeline) + ("\"" "followed tags" mastodon-tl--list-followed-tags) + ("I" "filter" mastodon-views--view-filters) + ("X" "lists" mastodon-views--view-lists)] + + ["Toots" + ("n" "next" mastodon-tl--goto-next-item :transient t) + ("p" "prev" mastodon-tl--goto-prev-item :transient t) + ("c" "spoiler" mastodon-tl--toggle-spoiler-text-in-toot :transient t) + ("T" "thread" mastodon-tl--thread) + ("b" "(un)boost" mastodon-toot--toggle-boost :transient t) + ("f" "(un)fav" mastodon-toot--toggle-favourite :transient t) + ("i" "(un)pin" mastodon-toot--pin-toot-toggle :transient t) + ("k" "(un)bookmark" mastodon-toot--toggle-bookmark :transient t) + ("v" "vote" mastodon-tl--poll-vote)] + + ;; Z mastodon-tl--report-to-mods + ;; o mastodon-toot--open-toot-url + + ["Own Toots" + ("r" "replay" mastodon-toot--reply) + ("t" "write" mastodon-toot) + ("e" "edit" mastodon-toot--edit-toot-at-point) + ("d" "delete" mastodon-toot--delete-toot) + ("D" "del & redraft" mastodon-toot--delete-and-redraft-toot) + ("E" "show edits" mastodon-toot--view-toot-edits)] + + ;; S mastodon-views--view-scheduled-toots + + ["Users" + ("W" "follow" mastodon-tl--follow-user) + ("R" "follow req" mastodon-views--view-follow-requests) + ("G" "suggestions" mastodon-views--view-follow-suggestions) + ("M" "mute user" mastodon-tl--mute-user) + ("B" "block user" mastodon-tl--block-user) + ("m" "message user" mastodon-tl--dm-user) + ;; "" + ;; ("," "favouriters" mastodon-toot--list-toot-favouriters) + ;; ("." "boosters" mastodon-toot--list-toot-boosters) + ] + + ;; S-RET mastodon-tl--unmute-user + ;; C-S-b mastodon-tl--unblock-user + + ["Profiles" + ("A" "author" mastodon-profile--get-toot-author) + ("P" "any user" mastodon-profile--show-user) + ("O" "own" mastodon-profile--my-profile) + ("U" "update own" mastodon-profile--update-user-profile-note)] + + ["Misc" + ("C" "copy URL" mastodon-toot--copy-toot-url) + ("?" "help" describe-mode) + ("q" "quit" transient-quit-one)]) + +;;;; 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) -- cgit v1.2.3