summaryrefslogtreecommitdiffstats
path: root/.emacs.d/site-lisp/jabber-init.el
blob: 810cc40baef6277bcc9e81f4d057a473c97820d8 (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
;;; jabber-initel --- Jabber.el initialization
;;; Commentary:
;;; Code:

(require 'init (locate-user-emacs-file "init.elc" "init.el"))
(require 'jabber)

;; (autoload 'jabber-message-libnotify "jabber-libnotify")
;; (autoload 'jabber-muc-libnotify "jabber-libnotify")

(defun jabber-init-roster-mode-func ()
  "Function for `jabber-roster-mode-hook'."
  (setq mode-line-format
        (list (propertize " %m" 'face 'mode-line-buffer-id))))

(defun jabber-init-show-status-in-buffer (who oldstatus newstatus
                                              statustext proposed-alert)
  "Check to see if WHO has a buffer and if so print his new status.

OLDSTATUS, NEWSTATUS and STATUSTEXT are ignored.

Insert PROPOSED-ALERT in the buffer if it is non-nil."
  (let ((buffer (get-buffer (jabber-chat-get-buffer (symbol-name who)))))
    (when (and buffer proposed-alert)
      (with-current-buffer buffer
        (ewoc-enter-last jabber-chat-ewoc (list :notice proposed-alert
                                                :time (current-time)))))))

(defun jabber-init-stumpwm-echo (from buffer text title)
  "Use stumpwm to echo a message has arrived."
  (oni:stumpwm-echo title))

(defun jabber-init-stumpwm-echo-muc (nick group buffer text title)
  "Use stumpwm to echo a message has arrived."
  (oni:stumpwm-echo title))

(setq jabber-account-list
      (append (mapcar (lambda (str) (list (concat str "/" system-name)))
                      '("tom@ryuslash.org" "ryuslash@ninthfloor.org"))
              '("ryuslash@gmail.com"
                (:network-server . "talk.google.com")
                (:port . 443)
                (:connection-type . ssl)))

      jabber-avatar-cache-directory     "~/.emacs.d/jabber-avatars/"
      jabber-chat-buffer-format         "+%n"
      jabber-chat-foreign-prompt-format "%t %u/%r"
      jabber-chat-local-prompt-format   "%t %u/%r"
      jabber-chat-buffer-show-avatar    nil
      jabber-chat-fill-long-lines       nil
      jabber-chat-delayed-time-format   "%H:%M"

      jabber-chatstates-confirm nil

      jabber-muc-colorize-local   t
      jabber-muc-colorize-foreign t

      jabber-history-enabled    t
      jabber-use-global-history nil
      jabber-history-dir        "~/.emacs.d/jabber-hist"

      jabber-groupchat-buffer-format "++%n"
      jabber-groupchat-prompt-format "%t %u"

      jabber-roster-show-bindings  nil
      jabber-show-offline-contacts nil

      jabber-vcard-avatars-publish  nil
      jabber-vcard-avatars-retrieve nil)
(add-to-list 'jabber-account-list
             `(,(concat "thomas@aethon.nl/" system-name)
               (:network-server . "talk.google.com")
               (:connection-type . ssl)))

;; (add-hook 'jabber-alert-message-hooks  #'jabber-message-libnotify)
;; (add-hook 'jabber-alert-muc-hooks      #'jabber-muc-libnotify)
(add-hook 'jabber-alert-message-hooks #'jabber-init-stumpwm-echo)
(add-hook 'jabber-alert-muc-hooks #'jabber-init-stumpwm-echo)
(add-hook 'jabber-chat-mode-hook       #'visual-line-mode)
(add-hook 'jabber-roster-mode-hook     #'jabber-init-roster-mode-func)
(add-hook 'jabber-alert-presence-hooks
          #'jabber-init-show-status-in-buffer)

(remove-hook 'jabber-alert-presence-hooks #'jabber-presence-echo)

(global-set-key (kbd "<f6>") 'jabber-switch-to-roster-buffer)


;;; Ugly, but works

(defvar *longest-prompt* 0)
(make-variable-buffer-local '*longest-prompt*)

(defun update-margins (prompt-length)
  (when (> prompt-length *longest-prompt*)
    (let ((window (get-buffer-window (current-buffer))))
      (when (equal window (selected-window))
        (set-window-margins window prompt-length))
      (setq left-margin-width prompt-length
            *longest-prompt* prompt-length))))


(defun jabber-chat-self-prompt (timestamp delayed dont-print-nick-p)
  "Print prompt for sent message.
TIMESTAMP is the timestamp to print, or nil for now.
If DELAYED is true, print long timestamp
\(`jabber-chat-delayed-time-format' as opposed to
`jabber-chat-time-format').
If DONT-PRINT-NICK-P is true, don't include nickname."
  (let* ((state-data (fsm-get-state-data jabber-buffer-connection))
         (username (plist-get state-data :username))
         (server (plist-get state-data :server))
         (resource (plist-get state-data :resource))
         (nickname username)
         (prompt (format-spec jabber-chat-local-prompt-format
                              (list
                               (cons ?t (format-time-string
                                         (if delayed
                                             jabber-chat-delayed-time-format
                                           jabber-chat-time-format)
                                         timestamp))
                               (cons ?n (if dont-print-nick-p "" nickname))
                               (cons ?u username)
                               (cons ?r resource)
                               (cons ?j (concat username "@" server))))))
    (insert (jabber-propertize
             " "
             'display (list '(margin left-margin) prompt)
             'face 'jabber-chat-prompt-local
             'help-echo
             (concat (format-time-string "On %Y-%m-%d %H:%M:%S" timestamp) " from you")))
    (update-margins (length prompt))))

(defun jabber-chat-print-prompt (xml-data timestamp delayed dont-print-nick-p)
  "Print prompt for received message in XML-DATA.
TIMESTAMP is the timestamp to print, or nil to get it
from a jabber:x:delay element.
If DELAYED is true, print long timestamp
\(`jabber-chat-delayed-time-format' as opposed to
`jabber-chat-time-format').
If DONT-PRINT-NICK-P is true, don't include nickname."
  (let* ((from (jabber-xml-get-attribute xml-data 'from))
         (timestamp (or timestamp
                        (car (delq nil (mapcar 'jabber-x-delay (jabber-xml-get-children xml-data 'x))))))
         (prompt (format-spec jabber-chat-foreign-prompt-format
                              (list
                               (cons ?t (format-time-string
                                         (if delayed
                                             jabber-chat-delayed-time-format
                                           jabber-chat-time-format)
                                         timestamp))
                               (cons ?n (if dont-print-nick-p "" (jabber-jid-displayname from)))
                               (cons ?u (or (jabber-jid-username from) from))
                               (cons ?r (jabber-jid-resource from))
                               (cons ?j (jabber-jid-user from))))))
    (insert (jabber-propertize
             " "
             'display (list '(margin left-margin) prompt)
             'face 'jabber-chat-prompt-foreign
             'help-echo
             (concat (format-time-string "On %Y-%m-%d %H:%M:%S" timestamp) " from " from)))
    (update-margins (length prompt))))

(defun jabber-muc-print-prompt (xml-data &optional local dont-print-nick-p)
  "Print MUC prompt for message in XML-DATA."
  (let* ((nick (jabber-jid-resource (jabber-xml-get-attribute xml-data 'from)))
         (timestamp (car (delq nil (mapcar 'jabber-x-delay (jabber-xml-get-children xml-data 'x)))))
         (prompt (format-spec jabber-groupchat-prompt-format
                              (list
                               (cons ?t (format-time-string
                                         (if timestamp
                                             jabber-chat-delayed-time-format
                                           jabber-chat-time-format)
                                         timestamp))
                               (cons ?n (if dont-print-nick-p "" nick))
                               (cons ?u nick)
                               (cons ?r nick)
                               (cons ?j (concat jabber-group "/" nick))))))
    (if (stringp nick)
        (insert (jabber-propertize
                 " "
                 'display (list '(margin left-margin) prompt)
                 'face (if local        ;Message from you.
                           (if jabber-muc-colorize-local ;; If colorization enable...
                               ;; ...colorize nick
                               (list ':foreground (jabber-muc-nick-get-color nick))
                             ;; otherwise, use default face.
                             'jabber-chat-prompt-local)
                         ;; Message from other participant.
                         (if jabber-muc-colorize-foreign ;If colorization enable...
                             ;; ... colorize nick
                             (list ':foreground (jabber-muc-nick-get-color nick))
                           ;; otherwise, use default face.
                           'jabber-chat-prompt-foreign))
                 'help-echo (concat (format-time-string "On %Y-%m-%d %H:%M:%S" timestamp) " from " nick " in " jabber-group)))
      (jabber-muc-system-prompt))
    (update-margins (length prompt))))

(provide 'jabber-init)
;;; jabber-init.el ends here