summaryrefslogtreecommitdiffstats
path: root/.emacs.d/site-lisp
diff options
context:
space:
mode:
authorGravatar Tom Willemse2014-03-10 11:19:37 +0100
committerGravatar Tom Willemse2014-03-10 11:19:37 +0100
commit5537337a589d97c652b3cb7b19b71b3c895ae6f3 (patch)
tree4051328e283333013cda8f813463764ac798ddef /.emacs.d/site-lisp
parent4ac2f054a67ce8ef9d0019c3f2daf36c5100479e (diff)
downloademacs-5537337a589d97c652b3cb7b19b71b3c895ae6f3.tar.gz
emacs-5537337a589d97c652b3cb7b19b71b3c895ae6f3.zip
Show jabber prompts in buffer margins
Change the various formats accordingly.
Diffstat (limited to '.emacs.d/site-lisp')
-rw-r--r--.emacs.d/site-lisp/jabber-init.el118
1 files changed, 115 insertions, 3 deletions
diff --git a/.emacs.d/site-lisp/jabber-init.el b/.emacs.d/site-lisp/jabber-init.el
index d3d65fd..35831e5 100644
--- a/.emacs.d/site-lisp/jabber-init.el
+++ b/.emacs.d/site-lisp/jabber-init.el
@@ -32,10 +32,11 @@ Insert PROPOSED-ALERT in the buffer if it is non-nil."
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-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
@@ -47,7 +48,7 @@ Insert PROPOSED-ALERT in the buffer if it is non-nil."
jabber-history-dir "~/.emacs.d/jabber-hist"
jabber-groupchat-buffer-format "++%n"
- jabber-groupchat-prompt-format "%t %u --\n"
+ jabber-groupchat-prompt-format "%t %u"
jabber-muc-autojoin '("aethon@muc.ryuslash.org")
jabber-roster-show-bindings nil
@@ -71,5 +72,116 @@ Insert PROPOSED-ALERT in the buffer if it is non-nil."
(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