Commit 3a3219fd authored by David Byers's avatar David Byers
Browse files

Auto-organize for Johan and improvements to insert

parent f1893047
2007-06-30 <David Byers@GULAG>
* lyskom-rest.el (lyskom-do-insert): Support format state directly
within this function.
(lyskom-format-insert-before-prompt): Support deferred insertions.
(lyskom-format-insert-at-point): Simplified.
(lyskom-format-insert): Simplified.
2007-06-26 <David Byers@GULAG>
* utilities.el (lyskom-indirect-assq): If assoc-list is t, then
......
;;;;; -*-coding: iso-8859-1;-*-
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 2007 David Byers <davby@ida.liu.se>
;;;;;
;;;;; This file is part of the LysKOM Emacs LISP client.
;;;;;
;;;;; This 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, or (at your option)
;;;;; any later version.
;;;;;
;;;;; LysKOM 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 LysKOM; see the file COPYING. If not, write to
;;;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
;;;;; MA 02139, USA.
;;;;;
(defvar kom-auto-organize-list nil
"This variable defines how to auto-organize LysKOM conference.
Each element of the list configures auto-organize for a given
conference. Each element of kom-auto-organize-list has the
format (CONF . AUTHORS), where CONF is the conference number to
auto-organize, or t to auto-organize all supervised conferences.
AUTHORS is also a list, where each element has the format
\(AUTHOR . ACTIONS), where AUTHOR is either a number indicating
for which author the ACTIONS apply, or t, to indicate that the
actions apply to all authors.
ACTIONS is also a list, where each element has the format
\(REGEXP . FUNC). REGEXP is matched against every text viewed
in CONF, and if a match is found, then FUNC is called with the
conf-stat of the conference, text-stat and text-mass of the text
to be auto-managed. If the function returns non-nil, no more
actions will be applied.")
(defun kom-auto-organize ()
(let* ((text-stat lyskom-view-text-text-stat)
(text-mass lyskom-view-text-text)
(rcpt-confs (make-collector))
(authors nil))
;; Get the conf-stat for every recipient we supervise
(lyskom-traverse misc (text-stat->misc-info-list text-stat)
(when (memq (misc-info->type misc) '(RECPT BCC-RECPT CC-RECPT))
(initiate-get-conf-stat 'follow
'collector-push
(misc-info->recipient-no misc)
rcpt-confs)))
(lyskom-wait-queue 'follow)
(setq rcpt-confs
(nreverse
(cons t (delq nil (mapcar
(lambda (conf-stat)
(and (lyskom-i-am-supervisor conf-stat t)
conf-stat))
(collector->value rcpt-confs))))))
;; Traverse all recipients, then all authors
(setq authors (list (text-stat->author text-stat) t))
(when (> (length rcpt-confs) 1)
(catch 'kom-auto-organize-done
;; Look for a match for each recuipient
(lyskom-traverse rcpt rcpt-confs
(let ((rcpt-data (assq (if (atom rcpt)
rcpt
(conf-stat->conf-no rcpt))
kom-auto-organize-list)))
;; If a match for the recipient is found, look for
;; a match for the author
(when rcpt-data
(lyskom-traverse author authors
(let ((author-data (assq author (cdr rcpt-data))))
;; If a match for the author is found, look for
;; a match for the action regexp
(when author-data
(lyskom-traverse action (cdr author-data)
(when (and (or (eq t (car action))
(let ((case-fold-search t))
(string-match
(car action)
(text->decoded-text-mass text-mass
text-stat))))
(funcall (cdr action)
rcpt
text-stat
text-mass))
(throw 'kom-auto-organize-done t)))))))))))))
(defun kom-auto-organize-sub-recipient (conf-stat text-stat text-mass)
"Automatically subtract recipient from text (for kom-auto-organize)"
(let ((to-sub (cons (text-stat->text-no text-stat)
(lyskom-get-text-attachments text-stat))))
(lyskom-traverse misc (text-stat->misc-info-list text-stat)
(when (eq (misc-info->type misc) 'FOOTN-IN)
(setq to-sub (cons (misc-info->footn-in misc) footnotes))))
(lyskom-traverse text-no to-sub
(lyskom-format-insert-before-prompt
"Subtraherar text %#1n från %#2M i bakgrunden...%#3D\n"
text-no
conf-stat
(lyskom-create-defer-info
'sub-recipient
(list text-no (conf-stat->conf-no conf-stat))
(lambda (res defer-info)
(message "Hello!")
(if res
(lyskom-replace-deferred defer-info "klart")
(lyskom-replace-deferred defer-info "det gick inte")))
nil nil "%#1s")))))
; (setq kom-auto-organize-list '((3715 (7871 ("See attachment" . kom-auto-organize-sub-recipient)))))
\ No newline at end of file
......@@ -1260,12 +1260,21 @@ back, and works even if from has the property."
(error (lyskom-ignore var))))
(defun lyskom-do-insert (string)
(let ((start (point)))
(insert string)
(lyskom-do-special-inserts start (point) 'lyskom-fill)
(lyskom-do-special-inserts start (point) 'lyskom-overlay)
(lyskom-do-special-inserts start (point) 'special-insert)
))
(if (lyskom-format-state-p string)
(let ((start (point)))
(lyskom-do-insert (lyskom-format-transform-result string))
(lyskom-traverse defer-info (format-state->delayed-content string)
(set-defer-info->pos defer-info
(set-marker (make-marker)
(+ start
(defer-info->pos defer-info))))
(lyskom-defer-insertion defer-info)))
(let ((start (point)))
(insert string)
(lyskom-do-special-inserts start (point) 'lyskom-fill)
(lyskom-do-special-inserts start (point) 'lyskom-overlay)
(lyskom-do-special-inserts start (point) 'special-insert))))
......@@ -1431,46 +1440,21 @@ Args: FORMAT-STRING &rest ARGS"
(defun lyskom-format-insert (format-string &rest argl)
"Format and insert a string according to FORMAT-STRING.
The string is inserted at the end of the buffer with `lyskom-insert'."
(let* ((state (lyskom-do-format format-string argl t))
;; We have to use a marker, because lyskom-insert may trim
;; the buffer size.
(start (point-max-marker))
(deferred (format-state->delayed-content state)))
(lyskom-insert (lyskom-format-transform-result state))
(while deferred
(let ((defer-info (car deferred))
(m (make-marker)))
(set-marker m (+ start (defer-info->pos defer-info)))
(set-defer-info->pos defer-info m)
(lyskom-defer-insertion defer-info)
(setq deferred (cdr deferred))))
(set-marker start nil)))
(lyskom-insert (lyskom-do-format format-string argl t)))
(defun lyskom-format-insert-at-point (format-string &rest argl)
"Format and insert a string according to FORMAT-STRING.
The string is inserted at point."
(let* ((state (lyskom-do-format format-string argl t))
(start (point))
(deferred (format-state->delayed-content state)))
(lyskom-insert-at-point (lyskom-format-transform-result state))
(while deferred
(let ((defer-info (car deferred))
(m (make-marker)))
(set-marker m (+ start (defer-info->pos defer-info)))
(set-defer-info->pos defer-info m)
(lyskom-defer-insertion defer-info)
(setq deferred (cdr deferred))))))
(lyskom-insert-at-point (lyskom-do-format format-string argl t)))
(defun lyskom-format-insert-before-prompt (format-string &rest argl)
"Format and insert a string according to FORMAT-STRING.
The string is inserted just before the prompt, and if the prompt is not
currently visible the text is queued to be inserted when the prompt
reappears.
Deferred insertions are not supported."
reappears."
(lyskom-insert-before-prompt
(lyskom-format-transform-result (lyskom-do-format format-string argl))))
(lyskom-do-format format-string argl t)))
(defun lyskom-do-format (format-string &optional argl allow-defer)
......
......@@ -100,14 +100,19 @@
kom-review-marks-texts-as-read toggled."
(interactive)
(let* ((kom-review-marks-texts-as-read (not kom-review-marks-texts-as-read))
(sequence (read-key-sequence
(format "%s: "
(lyskom-get-string
(if kom-review-marks-texts-as-read
'review-marking-as-read
'review-not-marking-as-read)))))
(command (lookup-key (current-local-map) sequence)))
(when (commandp command)
(sequence (read-key-sequence
(format "%s: "
(lyskom-get-string
(if kom-review-marks-texts-as-read
'review-marking-as-read
'review-not-marking-as-read)))))
(command (or (lookup-key (current-local-map) sequence)
(lookup-key global-map sequence))))
(when (or (null command) (eq command 'kom-mouse-null))
(setq sequence (read-key-sequence ""))
(setq command (or (lookup-key (current-local-map) sequence)
(lookup-key global-map sequence))))
(when (commandp command)
(call-interactively command))))
(defun kom-toggle-cache-prefix ()
......@@ -278,7 +283,8 @@ mark unread performed with `kom-unread-by-to'."
(funcall filter 'description)))
(condition-case arg
(let ((list (lyskom-get-texts-by-to by to count t t filter)))
(let* ((lyskom-last-review-num count)
(list (lyskom-get-texts-by-to by to count t t filter)))
(setq lyskom-last-unread-num
(if (< lyskom-last-unread-num 0)
(- count)
......
......@@ -1800,8 +1800,8 @@ See also `kom-server-aliases' and `kom-builtin-server-aliases'."
(def-kom-var kom-view-text-hook nil
"**Hook that is called before a text is shown.
When the hooks are called, `kom-view-text-text' is bound to the text
mass of the text and `kom-view-text-text-stat' to the text-stat of the
When the hooks are called, `lyskom-view-text-text' is bound to the text
mass of the text and `lyskom-view-text-text-stat' to the text-stat of the
text to be shown."
local-hook)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment