diff options
author | Magnus Henoch <mange@freemail.hu> | 2005-02-20 12:21:45 +0000 |
---|---|---|
committer | Kirill A. Korinskiy <catap@catap.ru> | 2005-02-20 12:21:45 +0000 |
commit | 2d55c36fd78e9bf77095c5cc72d9096837564b2e (patch) | |
tree | 321098b77ef15badcec5aaa78ef4ba37efde8c23 /jabber-chatbuffer.el | |
parent | 4d094da83e2734218b12ac1585fdca145b01297b (diff) |
Revision: mange@freemail.hu--2005/emacs-jabber--cvs-head--0--patch-26
Creator: Magnus Henoch <mange@freemail.hu>
Merge message-attachments branch
Patches applied:
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-6
Merge from CVS HEAD
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-7
Start reworking chat functions
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-8
Hacking on chat
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-9
More hacking
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-10
Make jabber-chatting-with buffer-local
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-11
Merge with CVS
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-12
Reintroduce message alert hooks
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-13
Update jabber-activity for textless alert hooks
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-14
Hack MUC into shape
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-15
Create and switch to MUC buffer in jabber-groupchat-join
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-16
Make more MUC things work
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-17
Remove history from jabber-message-hooks
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-18
Add jabber-muc-send
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-19
Reimplement formatted chat prompts
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-20
Readd header line in chat buffers
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-21
Reimplement groupchat prompt formatting
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-22
Reimplement MUC notifications
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-23
Reactivate history
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-24
Reactivate backlog
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-25
Special prompt-data argument to jabber-chat-buffer-display
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-26
Interpret timestamps in backlog and incoming messages
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-27
Record timestamps in incoming messages for history
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-28
Handle everything not MUC in jabber-process-chat
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-29
Start hacking message attachments and body printers
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-30
Add jabber-send-message. Readd chat menu.
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-31
Add subject support
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-32
Add jabber-chat-text-{local,foreign}
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-33
Merge from CVS
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-34
Don't log MUC messages
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-35
Hooks on sent chat messages
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-36
Really declare jabber-chat-mode-hook
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-37
Add id to outgoing messages, and argument to jabber-chat-send-hooks
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-38
Separate backlog insertion
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-39
jabber-history-query has two time limits
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-40
Remove obsolete comment
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-41
Implement time limits for backlogs
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-42
Add jabber-chat-buffer-display-at-point
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-43
Allow unlimited number of days in backlog
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-44
Add jabber-chat-display-more-backlog
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-45
Don't try to use nonexistent backlog
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-46
Fix backlog insertion
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-47
_Really_ fix jabber-chat-buffer-display-at-point
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-48
Remove old jabber-chat.el
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-49
Ensure newline between each part of a chat message
* mange@freemail.hu--2005/emacs-jabber--message-attachments--0--patch-50
Add URl (jabber:x:oob) printing capability
Diffstat (limited to 'jabber-chatbuffer.el')
-rw-r--r-- | jabber-chatbuffer.el | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/jabber-chatbuffer.el b/jabber-chatbuffer.el new file mode 100644 index 0000000..b010abf --- /dev/null +++ b/jabber-chatbuffer.el @@ -0,0 +1,115 @@ +;; jabber-chatbuffer.el - functions common to all chat buffers + +;; Copyright (C) 2005 - Magnus Henoch - mange@freemail.hu + +;; This file is a part of jabber.el. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +(defvar jabber-point-insert nil + "Position where the message being composed starts") + +(defvar jabber-send-function nil + "Function for sending a message from a chat buffer.") + +(defvar jabber-chat-mode-hook nil + "Hook called at the end of `jabber-chat-mode'. +Note that functions in this hook have no way of knowing +what kind of chat buffer is being created.") + +(defun jabber-chat-mode () + "\\{jabber-chat-mode-map}" + (kill-all-local-variables) + ;; Make sure to set this variable somewhere + (make-local-variable 'jabber-send-function) + + (make-local-variable 'scroll-conservatively) + (setq scroll-conservatively 5) + + (make-local-variable 'jabber-point-insert) + (setq jabber-point-insert (point-min)) + + ;;(setq header-line-format jabber-chat-header-line-format) + + (setq major-mode 'jabber-chat-mode + mode-name "jabber-chat") + (use-local-map jabber-chat-mode-map) + + (if (fboundp 'run-mode-hooks) + (run-mode-hooks 'jabber-chat-mode-hook) + (run-hooks 'jabber-chat-mode-hook))) + +(put 'jabber-chat-mode 'mode-class 'special) + +(defvar jabber-chat-mode-map (copy-keymap jabber-common-keymap)) + +(define-key jabber-chat-mode-map "\r" 'jabber-chat-buffer-send) + +(defun jabber-chat-buffer-send () + (interactive) + (let ((body (delete-and-extract-region jabber-point-insert (point-max)))) + ;; If user accidentally hits RET without writing anything, + ;; delete-and-extract-region returns "". In that case, + ;; no message should be sent. + (unless (zerop (length body)) + (funcall jabber-send-function body)))) + +(defun jabber-chat-buffer-display (prompt-function prompt-data output-functions output-data) + "Display a message in current buffer. +PROMPT-FUNCTION is a function that prints the correct prompt at +point. It is called with PROMPT-DATA as argument. +OUTPUT-FUNCTIONS is a list of functions that may or may not print something +at point. They are called in order with OUTPUT-DATA as argument. +If the OUTPUT-FUNCTIONS produce any output, PROMPT-FUNCTION is called +with point before that output. If there is no output, there is +no prompt. + +If point is at or after jabber-point-insert, it is advanced. +If point is before jabber-point-insert, it is not moved." + (let ((at-insert-point (eq (point) jabber-point-insert))) + (save-excursion + (goto-char jabber-point-insert) + (jabber-chat-buffer-display-at-point prompt-function prompt-data output-functions output-data) + (setq jabber-point-insert (point)) + (set-text-properties jabber-point-insert (point-max) nil)) + + (when at-insert-point + (goto-char jabber-point-insert)))) + +(defun jabber-chat-buffer-display-at-point (prompt-function prompt-data output-functions output-data) + "Display a message at point. +Arguments are as to `jabber-chat-buffer-display'." + (let ((inhibit-read-only t) + (beg (point)) + (point-insert (set-marker (make-marker) jabber-point-insert))) + (set-marker-insertion-type point-insert t) + + (dolist (printer output-functions) + (funcall printer output-data) + (unless (bolp) + (insert "\n"))) + + (unless (eq (point) beg) + (let ((end (point-marker))) + (goto-char beg) + (funcall prompt-function prompt-data) + (goto-char end) + (put-text-property beg end 'read-only t) + (put-text-property beg end 'front-sticky t) + (put-text-property beg end 'rear-nonsticky t) + (setq jabber-point-insert (marker-position point-insert)))))) + +(provide 'jabber-chatbuffer) +;; arch-tag: 917e5b60-5894-4c49-b3bc-12e1f97ffdc6 |