Skip to content

Commit 3ab0439

Browse files
committed
refactor telega config
1 parent 614eb7f commit 3ab0439

File tree

6 files changed

+80
-69
lines changed

6 files changed

+80
-69
lines changed

init.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
+dragndrop ; file drag & drop support
158158
+gnuplot
159159
+hugo
160-
+journal
160+
;;+journal
161161
+pretty
162162
;;+jupyter
163163
+pandoc ; pandoc integration into org's exporter
@@ -201,7 +201,7 @@
201201
:h-cheung
202202
chinese
203203
(telega ; telegram
204-
+auto-method) ; auto toggle input method
204+
+auto-im) ; auto toggle input method
205205
tools
206206
ui
207207
(:if (featurep! :lang cc) cc-extra)

modules/h-cheung/telega/+ivy-telega.el

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,50 @@
55
;;;###autoload
66
(defun ivy-telega-chat-highlight (chat)
77
(let ((unread (funcall (telega--tl-prop :unread_count) chat))
8-
(title (telega-chat-title chat 'with-identity))
8+
(title (telega-chat-title-with-brackets chat 'with-identity))
99
(not-muted-p (not (telega-chat-muted-p chat)))
1010
(mentions (funcall (telega--tl-prop :unread_mention_count) chat)))
11-
1211
(if (and not-muted-p (> (+ unread mentions) 0))
13-
(ivy-append-face (format "%s %d@%d" title unread mentions) 'ivy-highlight-face)
12+
(concat (ivy-append-face (format "%s" title) 'ivy-highlight-face)
13+
"("
14+
(ivy-append-face (format "%d" unread) 'telega-unread-unmuted-modeline)
15+
(when (> mentions 0)
16+
(ivy-append-face (format "@%d" mentions) 'telega-mention-count))
17+
")")
1418
title)))
1519

1620
;;;###autoload
1721
(defun ivy-telega-chat-with ()
1822
"Starts chat with defined peer"
1923
(interactive)
20-
2124
(telega t)
2225
(let ((chats (mapcar
2326
(lambda (x) (cons (ivy-telega-chat-highlight x) x))
24-
(telega-filter-chats telega--ordered-chats 'all))))
25-
(ivy-read "chat: " chats
26-
:action (lambda (x) (telega-chat--pop-to-buffer (cdr x)))
27-
:caller 'ivy-telega-chat-with)))
27+
(telega-filter-chats telega--ordered-chats
28+
(if current-prefix-arg
29+
'(or main archive)
30+
'(and (or mention (and unread unmuted))
31+
(or main archive)))))))
32+
(cond ((null chats)
33+
(user-error "No chats available."))
34+
((= 1 (length chats))
35+
(telega-chat--pop-to-buffer (cdar chats)))
36+
(t
37+
(ivy-read "Chat with: " chats
38+
:action (lambda (x) (telega-chat--pop-to-buffer (cdr x)))
39+
:caller 'ivy-telega-chat-with)))))
2840

2941
(setq telega-completing-read-function 'ivy-completing-read)
3042

3143
(when (fboundp 'ivy--regex-pinyin)
3244
(push '(telega-chat-with . ivy--regex-pinyin) ivy-re-builders-alist)
3345
(push '(ivy-telega-chat-with . ivy--regex-pinyin) ivy-re-builders-alist))
3446

35-
(map! "C-c v" #'ivy-telega-chat-with
36-
"C-M-S-s-c" #'ivy-telega-chat-with)
47+
(map! :desc "Telega important chats"
48+
"C-c v" #'ivy-telega-chat-with
49+
:desc "Telega all chats"
50+
"C-c c" (cmd! (let ((current-prefix-arg '(4)))
51+
(call-interactively #'ivy-telega-chat-with)))
52+
:desc "Telega next important chat"
53+
"C-c C-SPC" (cmd! (let ((current-prefix-arg '(4)))
54+
(call-interactively #'telega-switch-important-chat))))
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
;;; h-cheung/telega/+addition.el -*- lexical-binding: t; -*-
22

33
;; based on cnsunyour's configs
4-
;;
4+
55
;; Highlight current line in root buffer
66
(defun lg-telega-root-mode ()
7-
(hl-line-mode 1))
7+
(hl-line-mode))
88
(defun lg-telega-chat-update (chat)
99
(with-telega-root-buffer
1010
(hl-line-highlight)))
@@ -30,23 +30,3 @@
3030
(list '(type supergroup) "[" "]")
3131
(list '(type channel) "<" ">")
3232
(list 'all "[" "]")))
33-
34-
;; Links to chat/message in org-mode
35-
(after! org
36-
(defun org-telega-follow-link (link)
37-
(telega-tme-open-tg (concat "tg:telega:" link)))
38-
(defun org-telega-store-link ()
39-
(when-let ((link (telega-tme-internal-link-to
40-
(or (telega-msg-at (point))
41-
(telega-chat-at (point))))))
42-
;; NOTE: strip leading "tg:"
43-
(let ((org-link (substring link 3)))
44-
(org-link-store-props :type "telega" :link org-link)
45-
org-link)))
46-
(defun org-telega-complete-link ()
47-
(let ((chat (telega-completing-read-chat "Chat: ")))
48-
(concat "telega:" (number-to-string (plist-get chat :id)))))
49-
(org-link-set-parameters "telega"
50-
:follow 'org-telega-follow-link
51-
:store 'org-telega-store-link
52-
:complete 'org-telega-complete-link))

modules/h-cheung/telega/+telega-auto-method.el renamed to modules/h-cheung/telega/+telega-auto-im.el

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; h-cheung/telega/+auto-method.el -*- lexical-binding: t; -*-
1+
;;; h-cheung/telega/+telega-auto-im.el -*- lexical-binding: t; -*-
22

33
;; based on cnsunyour's configs
44

@@ -56,10 +56,12 @@
5656
(telega-chat-title chat)
5757
"\"] is removed from EN/CN chat list."))))
5858

59-
(defadvice! +toggle-input-method--telega-chat-mode-a (chat &optional no-history-load)
59+
;; Determine the function which has advice is available.
60+
(unless (fboundp 'telega-chat--pop-to-buffer)
61+
(error "Function `telega-chat--pop-to-buffer' is not available."))
62+
(define-advice telega-chat--pop-to-buffer (:after (chat &rest _) toggle-input-method-a)
6063
"在 telega-chat-mode 里根据 chat 名称切换输入法,如果名称包含
6164
中文,则激活中文输入法,否则关闭中文输入法"
62-
:after #'telega-chat--pop-to-buffer
6365
(let ((title (telega-chat-title chat))
6466
(chatid (plist-get chat :id)))
6567
(cond ((member chatid +telega--chat-cn-list) (activate-input-method default-input-method))
@@ -68,7 +70,3 @@
6870
((telega-chat-private-p chat) (activate-input-method default-input-method))
6971
((string-match-p "\\cc" title) (activate-input-method default-input-method))
7072
(t (deactivate-input-method)))))
71-
72-
;; Determine the function which has advice is available.
73-
(unless (fboundp 'telega-chat--pop-to-buffer)
74-
(error "Function `telega-chat--pop-to-buffer' is not available."))

modules/h-cheung/telega/config.el

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,84 @@
44

55
;; telegram client for emacs
66
(use-package! telega
7-
:commands (telega)
87
:defer t
9-
:bind ("C-M-S-s-t" . #'telega)
108
:custom
119
;; (telega-proxies (list '(:server "127.0.0.1" :port 1086 :enable t
1210
;; :type (:@type "proxyTypeSocks5"))))
13-
(telega-chat-reply-prompt "<<< ")
14-
(telega-chat-edit-prompt "+++ ")
11+
(telega-open-file-function 'org-open-file)
12+
(telega-chat-input-prompt '((prompt . ">>> ")
13+
(reply . "<<< ")
14+
(edit . "+++ ")))
15+
(telega-chat-input-anonymous-prompt '((prompt . "Anonymous>>> ")
16+
(reply . "Anonymous<<< ")
17+
(edit . "Anonymous+++ ")))
18+
(telega-chat-input-comment-prompt '((prompt . "Comment>>> ")
19+
(reply . "Comment<<< ")
20+
(edit . "Comment+++ ")))
1521
(telega-sticker-size '(8 . 48))
16-
(telega-chat-use-markdown-version nil)
1722
(telega-animation-play-inline t)
1823
(telega-emoji-use-images nil)
1924
(telega-sticker-set-download t)
20-
;; (telega-use-tracking-for '(or pin (label "⌘")))
2125
(telega-chat-show-deleted-messages-for '(all))
26+
2227
:init
2328
(setq telega-use-images (or (display-graphic-p) (daemonp)))
24-
29+
(define-key global-map (kbd "C-c t") telega-prefix-map)
30+
(which-key-add-keymap-based-replacements global-map
31+
(kbd "C-c t") '("telega"))
2532
(when (featurep! :completion ivy)
2633
(load! "+ivy-telega"))
2734

2835
:hook
2936
(telega-chat-mode . yas-minor-mode-on)
30-
(telega-chat-mode . visual-line-mode)
37+
;; (telega-chat-mode . visual-line-mode)
3138
(telega-chat-mode . (lambda ()
3239
(set-company-backend! 'telega-chat-mode
3340
(append '(telega-company-emoji
3441
telega-company-username
3542
telega-company-hashtag)
3643
(when (telega-chat-bot-p telega-chatbuf--chat)
3744
'(telega-company-botcmd))))))
38-
(telega-chat-pre-message . telega-msg-ignore-blocked-sender)
45+
;(telega-chat-pre-message . telega-msg-ignore-blocked-sender)
46+
(telega-load . telega-mode-line-mode)
47+
(telega-load . global-telega-url-shorten-mode)
48+
(telega-load . global-telega-mnz-mode)
49+
3950
:config
51+
(setq telega-mode-line-string-format
52+
(cl-remove '(:eval (telega-mode-line-icon))
53+
telega-mode-line-string-format
54+
:test #'equal))
55+
(add-hook 'telega-msg-ignore-predicates 'telega-msg-from-blocked-sender-p)
4056

41-
(when (featurep! +auto-method)
42-
(load! "+telega-auto-method"))
57+
(when (featurep! +auto-im)
58+
(load! "+telega-auto-im"))
4359

44-
; (set-evil-initial-state! '(telega-root-mode telega-chat-mode) 'emacs)
60+
; (set-evil-initial-state! '(telega-root-mode telega-chat-mode) 'emacs)
4561
(when (featurep! :editor evil)
4662
(map!
4763
(:map telega-msg-button-map
48-
"J" #'telega-button-forward
49-
"k" nil
50-
"K" #'telega-button-backward
51-
"p" #'telega-msg-redisplay
52-
"l" nil))
64+
"J" #'telega-button-forward
65+
"k" nil
66+
"K" #'telega-button-backward
67+
"p" #'telega-msg-redisplay
68+
"l" nil))
5369
(map!
5470
:map telega-chat-button-map
55-
"h" nil))
71+
"h" nil))
5672

5773
;; use RET to add newline and C-RET to send
5874
(when (featurep! :config default)
5975
(map! :map telega-chat-mode-map
60-
"RET" #'+default/newline-below
61-
"<C-return>" #'telega-chatbuf-input-send))
62-
63-
(pushnew! telega-known-inline-bots
64-
"@vid" "@bing" "@wiki" "@imdb")
76+
"C-c C-t" #'telega-chatbuf-attach-sticker
77+
"RET" nil
78+
"<C-return>" #'telega-chatbuf-input-send))
6579

6680
(set-popup-rule! (regexp-quote telega-root-buffer-name)
6781
:ignore t)
6882
;; (set-popup-rule! "^◀[^◀\[]*[\[({<].+[\])}>]"
6983
;; :side 'right :size 100 :select t :ttl 300 :quit nil :modeline t)
7084

71-
(telega-mode-line-mode 1)
72-
(telega-url-shorten-mode 1)
7385
(when (and IS-LINUX (boundp 'dbus-runtime-version))
7486
(telega-notifications-mode 1))
7587

@@ -84,7 +96,9 @@
8496
:heigt 1.0
8597
:v-adjust -0.2
8698
:face all-the-icons-blue)))
99+
(use-package! telega-stories
100+
:config
101+
(telega-stories-mode 1)
102+
(map! :map telega-root-mode-map "v e" 'telega-view-emacs-stories))
103+
87104
(load! "+telega-addition"))
88-
;; (advice-add 'telega-root--killed :around (lambda ())))
89-
;; (when (daemonp)
90-
;; (telega nil)))

modules/h-cheung/telega/packages.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
;;; h-cheung/telega/packages.el
33

44
(package! telega :recipe (:files (:defaults "contrib/*.el" "etc" "server" "Makefile")))
5+
(package! language-detection)

0 commit comments

Comments
 (0)