summary refs log tree commit diff stats
path: root/lisp/acdw-chat.el
blob: 9294ffe6ec5c0403c35edc3ca0e15b7ef40e1319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
;;; acdw-chat.el --- Chat applications (mostly jabber)  -*- lexical-binding: t; -*-

;;; Code:

(defcustom jabber-prefix-width 10
  "Width of jabber prompts and other prefixes."
  :type 'number
  :group 'jabber)

(defun jabber-ui-setup ()
  "Setup the `jabber' user interface."
  (visual-fill-column-mode)
  (electric-pair-local-mode -1)
  (auto-fill-mode -1)
  (setq-local wrap-prefix (make-string (+ 3 jabber-prefix-width) #x20)
              visual-fill-column-extra-text-width `(,(+ 3 jabber-prefix-width)
                                                    . 1)))

(defcustom jabber-biboumi-server "localhost"
  "Biboumi server for `jabber-biboumi-muc-connect'."
  :type 'string
  :group 'jabber)

(defcustom jabber-biboumi-irc-servers '("irc.libera.chat")
  "IRC servers for the user to choose from with `jabber-biboumi-muc-connect'."
  :type '(repeat string)
  :group 'jabber)

(defcustom jabber-biboumi-default-nick ""
  "Default nick for biboumi rooms."
  :type 'string
  :group 'jabber)

(defun jabber-biboumi-muc-connect (channel server nick &optional biboumi-server)
  "Connect to a biboumi (IRC gateway) server MUC.
CHANNEL, SERVER, NICK, and BIBOUMI-SERVER are passed to
`jabber-muc-join'.  If BIBOUMI-SERVER isn't given,
`jabber-biboumi-server' is used."
  (interactive (list (concat "#" (string-remove-prefix "#" (read-string
                                                            "Channel: ")))
                     (completing-read "Server: " jabber-biboumi-irc-servers)
                     (read-string (format "Nick [%s]: "
                                          jabber-biboumi-default-nick)
                                  nil nil jabber-biboumi-default-nick)))
  (let ((room (format "%s%%%s@%s" channel server (or biboumi-server
                                                     jabber-biboumi-server))))
    (if (assoc room *jabber-active-groupchats*)
        (switch-to-buffer (jabber-muc-get-buffer room))
      (jabber-muc-join (jabber-read-account)
                       room
                       nick
                       'popup))))

(defalias 'jabber-irc-join 'jabber-biboumi-muc-connect)

(defun jabber-connect-all* (&optional arg)
  "Run `jabber-connect-all'.
With a prefix ARG, disconnect first."
  (interactive "p")
  (when arg
    (jabber-disconnect))
  (jabber-connect-all))

(defun jabber-group-yank-join-url ()
  "Yank a url for joining the focused group."
  (interactive)
  (let ((s (format "xmpp:%s?join" jabber-group)))
    (kill-new s)
    (message s)))


;;; Packages

(use-package jabber
  :load-path "~/src/jabber.el/"
  :custom-face
  (jabber-activity-face ((t :inherit jabber-chat-prompt-foreign
                            :foreground unspecified
                            :weight normal)))
  (jabber-activity-personal-face ((t :inherit jabber-chat-prompt-local
                                     :foreground unspecified
                                     :weight bold)))
  (jabber-chat-prompt-local ((t :inherit minibuffer-prompt
                                :foreground unspecified
                                :weight normal
                                :slant italic)))
  (jabber-chat-prompt-foreign ((t :inherit warning
                                  :foreground unspecified
                                  :weight normal)))
  (jabber-chat-prompt-system ((t :inherit font-lock-doc-face
                                 :foreground unspecified)))
  (jabber-rare-time-face ((t :inherit font-lock-comment-face
                             :foreground unspecified
                             :underline nil)))
  :bind-keymap ("C-c j" . jabber-global-keymap)
  :bind (("C-c C-SPC" . jabber-activity-switch-to))
  :config
  (setq jabber-account-list '(("acdw@hmm.st"))
        jabber-auto-reconnect t
        jabber-biboumi-server "irc.hmm.st"
        jabber-biboumi-irc-servers '("irc.libera.chat"
                                     "irc.oftc.net"
                                     "irc.tilde.chat"
                                     "tilde.town"
                                     "m455.casa"
                                     "irc.twitch.tv")
        jabber-biboumi-default-nick "acdw"
        jabber-last-read-marker (make-string fill-column ?.)
        jabber-muc-decorate-presence-patterns
        '(("\\( enters the room ([^)]+)\\| has left the chatroom\\)$" . nil)
          ("Mode #.*" . jabber-muc-presence-dim)
          ("." . jabber-muc-presence-dim))
        jabber-activity-make-strings #'jabber-activity-make-strings-shorten
        jabber-rare-time-format  " - - - - - - %H:%M %F"
        jabber-chat-header-line-format
        '("" (jabber-chat-buffer-show-avatar
              (:eval
               (let ((buddy (jabber-jid-symbol jabber-chatting-with)))
                 (jabber-propertize " "
                                    'display (get buddy 'avatar)))))
          (:eval (replace-regexp-in-string "%" "%%"
                                           (jabber-jid-displayname
                                            jabber-chatting-with)))
          "\t" (:eval (let ((buddy (jabber-jid-symbol jabber-chatting-with)))
                        (propertize
                         (or
                          (cdr (assoc (get buddy 'show) jabber-presence-strings))
                          (get buddy 'show))
                         'face
                         (or (cdr (assoc (get buddy 'show) jabber-presence-faces))
                             'jabber-roster-user-online))))
          "\t" (:eval (jabber-fix-status (get (jabber-jid-symbol jabber-chatting-with) 'status)))
          "\t" jabber-events-message
          "\t" jabber-chatstates-message)
        jabber-muc-header-line-format
        '(" " (:eval (replace-regexp-in-string "%" "%%"
                                               (jabber-jid-displayname
                                                jabber-group)))
          " / " jabber-muc-topic)
        ;; buffer name formats
        jabber-chat-buffer-format "*xmpp* %n"
        jabber-browse-buffer-format "*xmpp-browse* %n"
        jabber-groupchat-buffer-format "*xmpp-muc* %n"
        jabber-muc-private-buffer-format "*xmpp-muc-private* %n"
        ;; "prompt" (speaker) formats
        jabber-groupchat-prompt-format (format "%%>%dn . " jabber-prefix-width)
        jabber-chat-local-prompt-format (format "%%>%dn . " jabber-prefix-width)
        jabber-chat-foreign-prompt-format (format "%%>%dn . " jabber-prefix-width)
        jabber-muc-private-foreign-prompt-format "\n%g/%n . ")
  ;; jabber muc nick coloring
  ;; wgreenhous | I found 1.5 ok for saturation and 2.0 for value (modus)
  ;; (setopt jabber-muc-nick-value 1.0
  ;;         jabber-muc-nick-saturation 1.0
  ;;         jabber-muc-colorize-local t
  ;;         jabber-muc-colorize-foreign t)
  ;; When changing the above values, make sure to
  ;; (setq jabber-muc-participant-colors nil)
  (add-hook 'jabber-chat-mode-hook #'jabber-ui-setup)
  (keymap-global-set "C-x C-j" #'dired-jump)  ; Extremely annoying fix
  ;; For each binding in `jabber-global-keymap', also bind the non-control
  ;; character (lowercase)
  (map-keymap (lambda (key command)
                (define-key jabber-global-keymap (vector (+ key #x60)) command))
              jabber-global-keymap)
  (define-key jabber-global-keymap "c" #'jabber-connect-all*)
  (require 'jabber-httpupload nil t)
  (add-hook 'jabber-post-connect-hooks #'jabber-enable-carbons)
  (remove-hook 'jabber-alert-muc-hooks 'jabber-muc-echo)
  (remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo)
  (add-hook 'jabber-alert-muc-hooks
            (defun jabber@highlight-acdw (&optional _ _ buf _ _)
              (when buf
                (with-current-buffer buf
                  (let ((regexp (rx word-boundary
                                    "acdw" ; maybe get from the config?
                                    word-boundary)))
                    (hi-lock-unface-buffer regexp)
                    (highlight-regexp regexp 'jabber-chat-prompt-local))))))
  (add-hook 'jabber-chat-mode-hook
            (defun jabber-chat@leave-when-kill ()
              (add-hook 'kill-buffer-hook
                        (defun @jabber-leave@kill ()
                          (ignore-errors
                            (apply #'jabber-muc-leave (jabber-muc-argument-list))))
                        nil :local)))
  (when (fboundp 'jabber-chat-update-focus)
    (add-hook 'window-configuration-change-hook #'jabber-chat-update-focus))
  (with-eval-after-load 'consult
    (defvar jabber-chat-buffer-source
      `( :name "Jabber"
         :hidden nil
         :narrow ?j
         :category buffer
         :state ,#'consult--buffer-state
         :items ,(lambda ()
                   (mapcar #'buffer-name
                           (seq-filter (lambda (buf)
                                         (with-current-buffer buf
                                           (eq major-mode 'jabber-chat-mode)))
                                       (buffer-list))))))
    (add-to-list 'consult-buffer-sources 'jabber-chat-buffer-source :append)
    (consult-customize
     consult-buffer :preview-key "M-.")))

(provide 'acdw-chat)
;;; acdw-chat.el ends here