Skip to content

Configuration snippets

Zajcev Evgeny edited this page Apr 18, 2020 · 6 revisions

Side-by-side window layout by @mojoman

Change widths to your liking and display resolution. This way if you split your frame onto two windows (with rootbuf on the left and some chatbuf on the right), chatbufs will always open on the same window, just like official desktop client works. Also the rootbuf will try to keep itself narrow.

(setq telega-inserter-for-chat-button 'telega-ins--chat-full-2lines)
(setq telega-chat-button-width 15)
(setq telega-root-fill-column (+ 20 telega-chat-button-width))
(put (get 'telega-chat 'button-category-symbol)
    :inserter 'telega-ins--chat-full-2lines)
(setq switch-to-buffer-preserve-window-point t)
(setq telega-chat--display-buffer-action
    '((display-buffer-reuse-window display-buffer-use-some-window)))

Viewing asciinema links in vterm

(defun lg-asciinema-view (url &optional speed)
  (let ((vterm-shell (concat "asciinema play -s "
                             (number-to-string (or speed 2))
                             " " url)))
    (vterm "asciinema")))

(defun lg-maybe-asciinema-view (origfunc url &optional in-web-browser)
  "Maybe open link to asciinema.org in vterm."
  (if (and (not in-web-browser)
           (string-match "https?://asciinema.org" url))
      (lg-asciinema-view url)
    (funcall origfunc url in-web-browser)))

(advice-add 'telega-browse-url :around 'lg-maybe-asciinema-view)

Fancy footer in chatbuf

(setq telega-symbol-underline-bar
      (propertize " " 'face 'telega-webpage-strike-through))

Highlight current line in root buffer

(defun lg-telega-root-mode ()
  (hl-line-mode 1))

(defun lg-telega-chat-update (chat)
  (with-telega-root-buffer
    (hl-line-highlight)))

(add-hook 'telega-chat-update-hook 'lg-telega-chat-update)
(add-hook 'telega-root-mode-hook 'lg-telega-root-mode)

Outline unmuted chats using braces

(setq telega-chat-button-brackets
  (list (list '(and (not unmuted) (type private))
              (propertize "{" 'face 'shadow)
              (propertize "}" 'face 'shadow))
        (list '(and (not unmuted) (type basicgroup))
              (propertize "(" 'face 'shadow)
              (propertize ")" 'face 'shadow))
        (list '(and (not unmuted) (type supergroup))
              (propertize "[" 'face 'shadow)
              (propertize "]" 'face 'shadow))
        (list '(and (not unmuted) (type channel))
              (propertize "<" 'face 'shadow)
              (propertize ">" 'face 'shadow))
        (list '(type private)    "{" "}")
        (list '(type basicgroup) "(" ")")
        (list '(type supergroup) "[" "]")
        (list '(type channel)    "<" ">")
        (list 'all               "[" "]")))

Links to chat/message in org-mode

(defun org-telega-follow-link (link)
  (telega-tme-open-tg (concat "tg:telega:" link)))

(defun org-telega-store-link ()
  (when-let ((link (telega-tme-internal-link-to
                    (or (telega-msg-at (point))
                        (telega-chat-at (point))))))
    ;; NOTE: strip leading "tg:"
    (let ((org-link (substring link 3)))
      (org-link-store-props :type "telega" :link org-link)
      org-link)))

(defun org-telega-complete-link ()
  (let ((chat (telega-completing-read-chat "Chat: ")))
    (concat "telega:" (number-to-string (plist-get chat :id)))))

(org-link-set-parameters "telega"
                         :follow 'org-telega-follow-link
                         :store 'org-telega-store-link
                         :complete 'org-telega-complete-link)