Commit 141797b6 authored by David Byers's avatar David Byers

Rewrite lyskom-format to handle more types and to generate text properties.

Added group message handling.
Rewrote filtering to compile filter specifications to lisp functions.
Added URL recognition in text bodies.
Fixed some minor bugs.
parent f040e2eb
......@@ -33,14 +33,15 @@ GENERIC-DIST-CLEAN = TAGS
RM = /usr/gnu/bin/rm -vf
# for compiling using emacs 19!
EMACS-BATCH = emacs -batch
EMACS=emacs
EMACS-BATCH = $(EMACS) -batch
# NOTE: lyskom-rest.el must be the last file in PARTS-EL and SRC-ELC.
PARTS-EL = komtypes.el clienttypes.el startup.el \
reading.el \
internal.el parse.el services.el cache.el\
commands1.el commands2.el review.el edit-text.el \
filter.el filter-edit.el \
filter.el filter-edit.el lyskom-buttons.el \
view-text.el async.el completing-read.el \
prioritize.el flags.el \
elib-string.el \
......@@ -55,7 +56,7 @@ SRC-ELC = komtypes.elc clienttypes.elc startup.elc \
reading.elc \
internal.elc parse.elc services.elc cache.elc\
commands1.elc commands2.elc review.elc edit-text.elc \
filter.elc filter-edit.elc \
filter.elc filter-edit.elc lyskom-buttons.elc \
view-text.elc async.elc completing-read.elc \
prioritize.elc flags.elc \
elib-string.elc \
......
......@@ -81,8 +81,10 @@ this function shall be with current-buffer the BUFFER."
(lyskom-save-excursion
(set-buffer buffer)
(if (and lyskom-pers-no (= conf-no lyskom-pers-no))
(lyskom-insert-before-prompt
(lyskom-format 'you-changed-name-to new-name)))
(lyskom-format-insert-before-prompt
'you-changed-name-to
new-name
(lyskom-default-button 'conf conf-no)))
(cache-del-conf-stat conf-no) ;+++Borde {ndra i cachen i st{llet.
(cond
((lyskom-is-in-minibuffer))
......@@ -91,8 +93,11 @@ this function shall be with current-buffer the BUFFER."
old-name new-name))))
(cond
(kom-presence-messages-in-buffer
(lyskom-insert-before-prompt
(lyskom-format 'name-has-changed-to-name-r old-name new-name )))))))
(lyskom-format-insert-before-prompt
'name-has-changed-to-name-r
old-name
new-name
(lyskom-default-button 'conf conf-no)))))))
((eq msg-no 6) ;i_am_on - something is moving
(let ((info (lyskom-parse-who-info)))
......@@ -156,10 +161,19 @@ this function shall be with current-buffer the BUFFER."
(format "emacs-version: %s\nclient-version: %s"
(emacs-version)
lyskom-clientversion)))
(t (initiate-get-conf-stat 'async
'lyskom-show-personal-message sender
recipient
message))))))
(t
(if (zerop recipient)
(initiate-get-conf-stat 'async
'lyskom-show-personal-message
sender
0
message)
(lyskom-collect 'async)
(initiate-get-conf-stat 'async nil sender)
(initiate-get-conf-stat 'async nil recipient)
(lyskom-use 'async
'lyskom-show-personal-message
message)))))))
((eq msg-no 13) ; New logout
(let ((pers-no (lyskom-parse-num))
......@@ -191,9 +205,7 @@ this function shall be with current-buffer the BUFFER."
(conf-stat->name conf-stat)))))
(cond
(kom-presence-messages-in-buffer
(lyskom-insert-before-prompt
(lyskom-format 'has-entered-r
(conf-stat->name conf-stat))))))
(lyskom-format-insert-before-prompt 'has-entered-r conf-stat))))
(defun lyskom-show-logged-out-person (conf-stat session-no)
......@@ -205,9 +217,7 @@ this function shall be with current-buffer the BUFFER."
(conf-stat->name conf-stat)))))
(cond
(kom-presence-messages-in-buffer
(lyskom-insert-before-prompt
(lyskom-format 'has-left-r
(conf-stat->name conf-stat))))))
(lyskom-format-insert-before-prompt 'has-left-r conf-stat))))
(defun lyskom-show-changed-person (personconfstat conf-num doing)
......@@ -233,12 +243,11 @@ this function shall be with current-buffer the BUFFER."
(or (= 0 conf-num)
(eq conf-num lyskom-current-conf))
(/= 0 (length doing)))
(lyskom-insert-before-prompt
(concat (conf-stat->name personconfstat)
" "
(concat (char-to-string (downcase (string-to-char doing)))
(substring doing 1))
"\n")))))))
(lyskom-format-insert-before-prompt
"%#1M %#2s\n"
persconfstat
(concat (char-to-string (downcase (string-to-char doing)))
(substring doing 1))))))))
(defun lyskom-is-in-minibuffer ()
......@@ -250,8 +259,8 @@ this function shall be with current-buffer the BUFFER."
"Insert a personal message into the lyskom buffer.
Args: SENDER: conf-stat for the person issuing the broadcast message or a
string that is the sender.
RECIPIENT: 0 if this message is for everybody, otherwise the pers-no
of the user.
RECIPIENT: 0 if this message is for everybody, otherwise the conf-stat
of the recipient.
MESSAGE: A string containing the message."
(lyskom-insert-personal-message sender recipient message)
(setq lyskom-last-personal-message-sender (if (stringp sender) sender
......@@ -268,34 +277,45 @@ MESSAGE is a string containing the message.
INSERT-FUNCTION is a function that given a string inserts it into the
current buffer."
(lyskom-handle-as-personal-message
(if (= recipient 0)
(progn
(if (eq t kom-ding-on-personal-messages)
(beep))
(lyskom-format 'message-broadcast
(cond
((stringp sender) sender)
(sender (conf-stat->name sender))
(t (lyskom-get-string 'unknown)))
message
(substring (current-time-string) 11 19)))
(if kom-ding-on-personal-messages
(beep))
(lyskom-format 'message-from
(cond
((stringp sender) sender)
(sender (conf-stat->name sender))
(t (lyskom-get-string 'unknown)))
message
(substring (current-time-string) 11 19)))
(cond ((eq recipient 0)
(if (eq t kom-ding-on-personal-messages) (beep))
(lyskom-format 'message-broadcast
(cond
((stringp sender) sender)
(sender sender)
(t (lyskom-get-string 'unknown)))
message
(substring (current-time-string) 11 19)))
((= (conf-stat->conf-no recipient) lyskom-pers-no)
(if (memq kom-ding-on-personal-messages '(t personal)) (beep))
(lyskom-format 'message-from
(cond
((stringp sender) sender)
(sender sender)
(t (lyskom-get-string 'unknown)))
message
(substring (current-time-string) 11 19)))
(t
(if (memq kom-ding-on-personal-messages '(t group)) (beep))
(lyskom-format 'message-from-to
message
(cond
((stringp sender) sender)
(sender (conf-stat->name sender))
(t (lyskom-get-string 'unknown)))
(cond
((stringp recipient) recipient)
(recipient (conf-stat->name recipient))
(t (lyskom-get-string 'unknown)))
(substring (current-time-string) 11 19))))
(conf-stat->conf-no sender)))
(defun lyskom-handle-as-personal-message (string from)
"Insert STRING as a personal message and beep if not from me and supposed to.
The buffer, is chosen according to the kom-show-personal-messages-in-buffer
variable value.
The text is converted, before insertion."
"Insert STRING (a format state) as a personal message and beep if
not from me and supposed to. The buffer, is chosen according to the
kom-show-personal-messages-in-buffer variable value. The text is
converted, before insertion."
(lyskom-save-excursion
(cond
((eq kom-show-personal-messages-in-buffer t)
......@@ -305,8 +325,8 @@ The text is converted, before insertion."
(set-buffer (get-buffer-create kom-show-personal-messages-in-buffer))
(goto-char (point-max))
(insert (if kom-emacs-knows-iso-8859-1
string
(iso-8859-1-to-swascii string)))))
string
(iso-8859-1-to-swascii string)))))
(if kom-pop-personal-messages
(display-buffer (current-buffer)))))
......
......@@ -185,13 +185,16 @@ otherwise return nil"
;;; who-info cache
(defun cache-initiate-who-info-buffer (who-info-arr)
(defun cache-initiate-who-info-buffer (who-info-arr kombuf)
"Sets the cache of who-info items."
(setq lyskom-who-info-cache (list 'WHO-INFO-LIST))
(lyskom-save-excursion
(setq lyskom-who-info-buffer
(get-buffer-create (concat (buffer-name) "-who")))
(set-buffer lyskom-who-info-buffer)
(make-local-variable 'kom-buffer)
(setq kom-buffer kombuf)
(local-set-key [mouse-2] 'kom-mouse-2)
(erase-buffer))
(mapcar 'cache-add-who-info
(sort (lyskom-array-to-list who-info-arr)
......@@ -275,10 +278,7 @@ ARG: session-info"
(lyskom-print-who-info pers-conf-stat conf-conf-stat who-info sesno
(function
(lambda (string)
(insert
(if kom-emacs-knows-iso-8859-1
string
(iso-8859-1-to-swascii string))))))
(insert string))))
(setq max (point-max-marker))
(goto-char (point-max)))
(delete-char 1))
......
......@@ -493,3 +493,71 @@ The element last pushed is first in the list."
;;; ================================================================
;;; format-props
(defun make-format-props (arg propl)
(cons 'format-props (vector arg propl)))
(defsubst format-props-p (arg)
(eq 'format-props (car-safe arg)))
(defsubst format-props->arg (arg)
(elt (cdr arg) 0))
(defsubst format-props->propl (arg)
(elt (cdr arg) 1))
;;;
;;; Help functions
;;;
;;; ================================================================
;;; format-state
(defun make-format-state (format-string
start
argl
result)
(cons 'format-state
(vector format-string start argl (length argl) result nil)))
(defsubst format-state-p (arg)
(eq 'format-state (car-safe arg)))
(defsubst format-state->format-string (arg)
(elt (cdr arg) 0))
(defsubst set-format-state->format-string (arg str)
(aset (cdr arg) 0 str))
(defsubst format-state->start (arg)
(elt (cdr arg) 1))
(defsubst set-format-state->start (arg pos)
(aset (cdr arg) 1 pos))
(defsubst format-state->args (arg)
(elt (cdr arg) 2))
(defsubst set-format-state->args (arg argl)
(aset (cdr arg) 2 argl)
(aset (cdr arg) 3 (length argl)))
(defsubst format-state->args-length (arg)
(elt (cdr arg) 3))
(defsubst format-state->result (arg)
(elt (cdr arg) 4))
(defsubst set-format-state->result (arg output-list)
(aset (cdr arg) 4 output-list))
(defsubst format-state->delayed-propl (arg)
(elt (cdr arg) 5))
(defsubst set-format-state->delayed-propl (arg propl)
(aset (cdr arg) 5 propl))
;;; ================================================================
......@@ -91,7 +91,7 @@
(lyskom-format-insert 'conf-is-deleted
(conf-stat->name conf-stat))
(lyskom-format-insert 'you-could-not-delete
(conf-stat->name conf-stat)))
conf-stat))
(lyskom-insert-string 'deletion-not-confirmed))
(lyskom-insert-string 'somebody-else-deleted-that-conf)))
(lyskom-end-of-command)))
......@@ -138,11 +138,11 @@
(if (null conf-stat)
(lyskom-insert-string 'somebody-deleted-that-conf)
(lyskom-format-insert 'review-presentation-of
(conf-stat->name conf-stat))
conf-stat)
(if (/= (conf-stat->presentation conf-stat) 0)
(lyskom-view-text (conf-stat->presentation conf-stat))
(lyskom-format-insert 'has-no-presentation
(conf-stat->name conf-stat)))))
conf-stat))))
(if end-of-command-taken-care-of
nil
(lyskom-end-of-command)))))
......@@ -191,7 +191,8 @@ text is shown and a REVIEW list is built to shown the other ones."
misc-infos))))
(if text-nos
(progn
(lyskom-format-insert 'review-text-no (car text-nos))
(lyskom-format-insert 'review-text-no
(car text-nos))
(if (cdr text-nos)
(read-list-enter-read-info
(lyskom-create-read-info
......@@ -234,7 +235,8 @@ as TYPE. If no such misc-info, return NIL"
t
(progn
(recenter 0)
(lyskom-format-insert 'has-motd (conf-stat->name conf-stat))
(lyskom-format-insert 'has-motd
conf-stat)
(lyskom-view-text (conf-stat->msg-of-day conf-stat))
(if (lyskom-j-or-n-p (lyskom-get-string 'motd-persist-q))
t
......@@ -354,10 +356,10 @@ Returns t if it was possible, otherwise nil."
(if (= (conf-stat->conf-no pers-conf-stat)
lyskom-pers-no)
(lyskom-format-insert 'member-in-conf
(conf-stat->name conf-conf-stat))
conf-conf-stat)
(lyskom-format-insert 'add-member-in
(conf-stat->name pers-conf-stat)
(conf-stat->name conf-conf-stat)))
pers-conf-stat
conf-conf-stat))
(blocking-do 'add-member
(conf-stat->conf-no conf-conf-stat)
(conf-stat->conf-no pers-conf-stat)
......@@ -392,10 +394,10 @@ Returns t if it was possible, otherwise nil."
"Suggests that we contact the supervisor to become a member."
(if (not supervisorconf)
(lyskom-format-insert 'cant-find-supervisor
(conf-stat->name conf-conf-stat))
conf-conf-stat)
(lyskom-format-insert 'is-read-protected-contact-supervisor
(conf-stat->name conf-conf-stat)
(conf-stat->name supervisorconf))))
conf-conf-stat
supervisorconf)))
......@@ -508,29 +510,29 @@ user so instead."
(if (= (conf-stat->conf-no pers-conf-stat)
lyskom-pers-no)
(lyskom-format-insert 'unsubscribe-to
(conf-stat->name conf-conf-stat))
conf-conf-stat)
(lyskom-format-insert 'exclude-from
(conf-stat->name pers-conf-stat)
(conf-stat->name conf-conf-stat)))
(initiate-sub-member 'main 'lyskom-sub-member-answer
(conf-stat->conf-no conf-conf-stat)
(conf-stat->conf-no pers-conf-stat)
conf-conf-stat pers-conf-stat)
(if (= (conf-stat->conf-no pers-conf-stat) lyskom-pers-no)
(initiate-get-membership 'main 'lyskom-set-membership
(conf-stat->conf-no
pers-conf-stat))))))
pers-conf-stat
conf-conf-stat)
(initiate-sub-member 'main 'lyskom-sub-member-answer
(conf-stat->conf-no conf-conf-stat)
(conf-stat->conf-no pers-conf-stat)
conf-conf-stat pers-conf-stat)
(if (= (conf-stat->conf-no pers-conf-stat) lyskom-pers-no)
(initiate-get-membership 'main 'lyskom-set-membership
(conf-stat->conf-no
pers-conf-stat)))))))
(defun lyskom-sub-member-answer (answer conf-conf-stat pers-conf-stat)
"Handles the answer after the unsubscribe call to the server."
(if (not answer)
(lyskom-insert
(lyskom-format 'unsubscribe-failed
(if (= (conf-stat->conf-no pers-conf-stat) lyskom-pers-no)
(lyskom-get-string 'You)
(conf-stat->name pers-conf-stat))
(conf-stat->name conf-conf-stat)))
(lyskom-format-insert
'unsubscribe-failed
(if (= (conf-stat->conf-no pers-conf-stat) lyskom-pers-no)
(lyskom-get-string 'You)
pers-conf-stat)
conf-conf-stat)
(lyskom-insert-string 'done)
(if (and (= (conf-stat->conf-no pers-conf-stat)
lyskom-pers-no)
......@@ -579,12 +581,16 @@ user so instead."
Add the person creating and execute lyskom-end-of-command."
(if (null conf-no)
(lyskom-format-insert 'could-not-create-conf
conf-name
conf-name
lyskom-errno)
(progn
(lyskom-format-insert 'created-conf-no-name
conf-no
conf-name)
(let ((conf-stat (blocking-do 'get-conf-stat conf-no)))
(lyskom-format-insert 'created-conf-no-name
(or conf-stat conf-no)
(or conf-stat conf-name)
(if conf-stat
(lyskom-default-button 'conf conf-stat)
nil)))
(lyskom-scroll)
(lyskom-add-member-2 conf-no lyskom-pers-no
'lyskom-create-conf-handler-2 conf-no conf-name))))
......@@ -1012,7 +1018,7 @@ TYPE is either 'pres or 'motd, depending on what should be changed."
(conf-stat->conf-no conf-stat)))
(t
(lyskom-format-insert 'not-supervisor-for
(conf-stat->name conf-stat)))))
conf-stat))))
......@@ -1035,12 +1041,12 @@ TYPE is either 'pres or 'motd, depending on what should be changed."
((null conf-stat)
(lyskom-insert-string 'cant-get-conf-stat))
((or lyskom-is-administrator
(lyskom-member-p (conf-stat->supervisor conf)))
(lyskom-member-p (conf-stat->supervisor conf-stat)))
;; This works like a dispatch. No error handling.
(lyskom-set-conf-motd 0 (conf-stat->conf-no conf)))
(lyskom-set-conf-motd 0 (conf-stat->conf-no conf-stat)))
(t
(lyskom-format-insert 'not-supervisor-for
(conf-stat->name conf)))))
conf-stat))))
(lyskom-end-of-command)))
......@@ -1067,17 +1073,17 @@ back on lyskom-to-do-list."
(let ((membership (lyskom-member-p
(conf-stat->conf-no conf))))
(lyskom-format-insert 'go-to-conf
(conf-stat->name conf))
conf)
(cond
(membership
(lyskom-do-go-to-conf conf membership))
((conf-type->letterbox (conf-stat->conf-type conf))
(lyskom-format-insert 'cant-go-to-his-mailbox
(conf-stat->name conf)))
conf))
(t
(progn
(lyskom-format-insert 'not-member-of-conf
(conf-stat->name conf))
conf)
(lyskom-scroll)
(if (lyskom-j-or-n-p (lyskom-get-string 'want-become-member))
(if (lyskom-add-member-2 (conf-stat->conf-no conf)
......@@ -1137,7 +1143,8 @@ Args: CONF-STAT MEMBERSHIP"
"Go to a conference with no unseen messages. Args: CONF-STAT."
(blocking-do 'pepsi (conf-stat->conf-no conf-stat))
(setq lyskom-current-conf (conf-stat->conf-no conf-stat))
(lyskom-format-insert 'conf-all-read (conf-stat->name conf-stat)))
(lyskom-format-insert 'conf-all-read
conf-stat))
......@@ -1192,10 +1199,12 @@ Args: CONF-STAT MEMBERSHIP"
(defun lyskom-list-pers-print (conf-stat)
"Print name of the person in CONF-STAT for kom-list-persons."
(if conf-stat
(lyskom-insert (concat (format "%4d " (conf-stat->conf-no conf-stat))
(conf-stat->name conf-stat)
"\n"))))
(if conf-stat
(lyskom-format-insert "%[%#1@%4#2:p %#3:P%]\n"
(lyskom-default-button 'conf conf-stat)
conf-stat
conf-stat)))
;;; ================================================================
......@@ -1223,14 +1232,13 @@ Those that you are not a member in will be marked with an asterisk."
If you are not member in the conference it will be flagged with an asterisk."
(if (not conf-stat)
nil
(lyskom-insert (concat (format "%4d %c "
(conf-stat->conf-no conf-stat)
(if (lyskom-member-p
(conf-stat->conf-no conf-stat))
32
?*))
(conf-stat->name conf-stat)
"\n"))))
(lyskom-format-insert "%[%#1@%4#2:m %#3c %#4M%]\n"
(lyskom-default-button 'conf conf-stat)
conf-stat
(if (lyskom-member-p (conf-stat->conf-no conf-stat))
32 ?*)
conf-stat)))
;;; ================================================================
;;; [ndra namn - Change name
......@@ -1253,13 +1261,14 @@ If you are not member in the conference it will be flagged with an asterisk."
(lyskom-insert-string 'no-such-conf-or-pers)
(let (name)
(lyskom-format-insert 'about-to-change-name-from
(conf-stat->name conf-stat))
conf-stat)
(lyskom-scroll)
(lyskom-tell-internat 'kom-tell-change-name)
(setq name (lyskom-read-string (lyskom-get-string 'new-name)
(conf-stat->name conf-stat)))
(if (blocking-do 'change-name (conf-stat->conf-no conf-stat) name)
(lyskom-format-insert 'change-name-done name)
(lyskom-format-insert 'change-name-done name
(lyskom-default-button 'conf conf-stat))
(lyskom-format-insert 'change-name-nope name
(lyskom-get-error-text lyskom-errno)
lyskom-errno)))))
......@@ -1288,17 +1297,17 @@ If you are not member in the conference it will be flagged with an asterisk."
(lyskom-get-string 'new-supervisor)
'all)))
(lyskom-format-insert 'change-supervisor-from-to
(conf-stat->name supervisee)
(conf-stat->name supervisor))
supervisee
supervisor)
(if (blocking-do 'set-supervisor
(conf-stat->conf-no supervisee)
(conf-stat->conf-no supervisor))
(progn
(lyskom-insert-string 'done)
(cache-del-conf-stat (conf-stat->conf-no supervisee)))
(lyskom-insert
(lyskom-format 'change-supervisor-nope
(conf-stat->name supervisee)))))))
(lyskom-format-insert
'change-supervisor-nope
supervisee)))))
(lyskom-end-of-command)))
......@@ -1346,8 +1355,10 @@ MARK: A number that is used as the mark."
(lyskom-read-num-range
1 255 (lyskom-get-string 'what-mark) t))))
(if (equal mark 0)
(lyskom-format-insert 'unmarking-textno text-no)
(lyskom-format-insert 'marking-textno text-no))
(lyskom-format-insert 'unmarking-textno
text-no)
(lyskom-format-insert 'marking-textno
text-no))
(if (blocking-do 'mark-text text-no mark)
(progn
......@@ -1525,19 +1536,19 @@ MY-SESSION-NO is the session number of the running session.
insert-function
'lyskom-insert)))
(funcall insertfun
(lyskom-return-who-info-line
(lyskom-return-who-info-line-as-state
(format "%4d%s"
(who-info->connection who-info)
(if (= my-session-no (who-info->connection who-info))
"*"
" "))
(conf-stat->name conf-stat)
conf-stat
(cond
((conf-stat->name working))
((conf-stat->name working) working)
(t (lyskom-get-string 'not-present-anywhere)))))
(if kom-show-where-and-what
(funcall insertfun
(lyskom-return-who-info-line
(lyskom-return-who-info-line-as-state
" "
(lyskom-return-username who-info)
(concat "("
......@@ -1554,6 +1565,31 @@ MY-SESSION-NO is the session number of the running session.
(substring str 0 len))
(defun lyskom-return-who-info-line-as-state (prefix arg1 arg2)
"Return the format state appropriate for the arguments and
the window width."
(let ((formatstring
(concat prefix
"%=-"
(int-to-string (/ (* 37 (- (lyskom-window-width) 7)) 73))
(if (lyskom-conf-stat-p arg1)
(if (conf-type->letterbox
(conf-stat->conf-type arg1))
"#1P"
"#1M")
"#1s")
" %=-"
(int-to-string (/ (* 37 (- (lyskom-window-width) 8)) 73))