1 | ;;; $Id: discuss-enter.el,v 1.12 1999-01-22 23:09:43 ghudson Exp $ |
---|
2 | ;;; |
---|
3 | ;;; Emacs lisp code to enter transaction into discuss. Part of the |
---|
4 | ;;; emacs-based interface to the discuss conferencing system. |
---|
5 | ;;; |
---|
6 | ;;; Copyright (c) 1989 by the Massachusetts Institute of Technology. |
---|
7 | ;;; Written by Stan Zanarotti, Bill Sommerfeld and Theodore Ts'o. |
---|
8 | ;;; |
---|
9 | |
---|
10 | (require 'discuss) |
---|
11 | |
---|
12 | (defvar discuss-new-trn-buf nil |
---|
13 | "Name of buffer for new transaction") |
---|
14 | |
---|
15 | (defvar discuss-trn-buffer "*discuss-unprocessed*" |
---|
16 | "Name of buffer for entering new transaction") |
---|
17 | |
---|
18 | (defvar discuss-edit-mode-map nil |
---|
19 | "Keymap used by the edit mode of the discuss subsystem") |
---|
20 | |
---|
21 | (defvar discuss-randrp-trn-info nil |
---|
22 | "Randrom transaction information.") |
---|
23 | |
---|
24 | (defun discuss-temp-file () |
---|
25 | "Return name of temporary buffer to use to transfer transactions." |
---|
26 | (format "/tmp/em.disc%d" |
---|
27 | (process-id discuss-process))) |
---|
28 | |
---|
29 | (defun discuss-talk () |
---|
30 | "Enter a new discuss transaction." |
---|
31 | (interactive) |
---|
32 | (if (not (string-match "w" (nth 10 discuss-current-meeting-info))) |
---|
33 | (error "Insufficient access for talk in %s" |
---|
34 | (nth 1 discuss-current-meeting-info))) |
---|
35 | (discuss-enter discuss-current-meeting 0 "")) |
---|
36 | |
---|
37 | (defun discuss-reply () |
---|
38 | "Reply to an existing discuss transaction." |
---|
39 | (interactive) |
---|
40 | (if (not (string-match "a" (nth 10 discuss-current-meeting-info))) |
---|
41 | (error "Insufficient access for reply in %s" |
---|
42 | (nth 1 discuss-current-meeting-info))) |
---|
43 | (let ((subject (nth 11 discuss-current-transaction-info))) |
---|
44 | ;; Add the Re: field |
---|
45 | (if (and (> (length subject) 3) |
---|
46 | (string-match "[Rr]e: " (substring subject 0 4))) |
---|
47 | nil |
---|
48 | (setq subject (concat "Re: " subject))) |
---|
49 | (discuss-enter discuss-current-meeting discuss-current-transaction |
---|
50 | subject t))) |
---|
51 | |
---|
52 | (defun discuss-randrp () |
---|
53 | "Randrp in a meeting." |
---|
54 | (interactive) |
---|
55 | (if (not (string-match "a" (nth 10 discuss-current-meeting-info))) |
---|
56 | (error "Insufficient access for reply in %s" |
---|
57 | (nth 1 discuss-current-meeting-info))) |
---|
58 | (discuss-send-cmd (format "(grtn %s)\n" discuss-current-meeting) |
---|
59 | 'discuss-randrp-gmi-end 'discuss-read-form)) |
---|
60 | |
---|
61 | (defun discuss-randrp-gmi-end () |
---|
62 | (setq discuss-randrp-trn-info discuss-form) |
---|
63 | (let ((subject (nth 11 discuss-randrp-trn-info)) |
---|
64 | (trn-num (nth 0 discuss-randrp-trn-info))) |
---|
65 | (if (and (> (length subject) 3) |
---|
66 | (string-match "[Rr]e: " (substring subject 0 4))) |
---|
67 | nil |
---|
68 | (setq subject (concat "Re: " subject))) |
---|
69 | (discuss-enter discuss-current-meeting trn-num subject t))) |
---|
70 | |
---|
71 | (defun discuss-enter (mtg-name reply-trn subject &optional reply init-txt) |
---|
72 | (setq discuss-new-trn-buf |
---|
73 | (get-buffer discuss-trn-buffer)) |
---|
74 | (if discuss-new-trn-buf |
---|
75 | (error "Already entering transaction") |
---|
76 | (progn |
---|
77 | (setq discuss-new-trn-buf |
---|
78 | (get-buffer-create discuss-trn-buffer)) |
---|
79 | (if (not (null reply)) |
---|
80 | (let ((pop-up-windows t)) |
---|
81 | (pop-to-buffer discuss-new-trn-buf)) |
---|
82 | (switch-to-buffer discuss-new-trn-buf)) |
---|
83 | (discuss-edit-mode) |
---|
84 | (insert "Subject: " |
---|
85 | subject |
---|
86 | "\n" |
---|
87 | mail-header-separator |
---|
88 | "\n") |
---|
89 | (if init-txt |
---|
90 | (save-excursion |
---|
91 | (goto-char (point-max)) |
---|
92 | (insert init-txt))) |
---|
93 | (setq discuss-reply-trn reply-trn) |
---|
94 | (setq discuss-enter-mtg mtg-name) |
---|
95 | (if (equal subject "") |
---|
96 | (progn |
---|
97 | (goto-char (point-min)) |
---|
98 | (end-of-line)))))) |
---|
99 | |
---|
100 | (defun discuss-edit-mode () |
---|
101 | "Major mode for editing Discuss transactions to be entered. |
---|
102 | Like Text Mode but with these additional commands: |
---|
103 | \\[describe-mode] Display available commands. |
---|
104 | \\[discuss-send] Enter the transaction. |
---|
105 | \\[discuss-abort-edit] Exit without entering transaction." |
---|
106 | (interactive) |
---|
107 | (kill-all-local-variables) |
---|
108 | (make-local-variable 'discuss-reply-trn) |
---|
109 | (setq discuss-reply-trn 0) |
---|
110 | (make-local-variable 'discuss-enter-mtg) |
---|
111 | (setq discuss-enter-mtg nil) |
---|
112 | (set-syntax-table text-mode-syntax-table) |
---|
113 | (use-local-map discuss-edit-mode-map) |
---|
114 | (setq local-abbrev-table text-mode-abbrev-table) |
---|
115 | (setq major-mode 'discuss-edit-mode) |
---|
116 | (setq mode-name "Discuss Edit") |
---|
117 | (setq buffer-offer-save t) |
---|
118 | (auto-save-mode 1) |
---|
119 | (setq paragraph-start (concat "^" mail-header-separator |
---|
120 | "$\\|^[ \t]*[-_][-_][-_]+$\\|" |
---|
121 | paragraph-start)) |
---|
122 | (setq paragraph-separate (concat "^" mail-header-separator |
---|
123 | "$\\|^[ \t]*[-_][-_][-_]+$\\|" |
---|
124 | paragraph-separate)) |
---|
125 | (run-hooks 'text-mode-hook 'discuss-edit-mode-hook)) |
---|
126 | |
---|
127 | (if discuss-edit-mode-map |
---|
128 | nil |
---|
129 | (setq discuss-edit-mode-map (make-sparse-keymap)) |
---|
130 | (define-key discuss-edit-mode-map "\C-c?" 'describe-mode) |
---|
131 | (define-key discuss-edit-mode-map "\C-c\C-c" 'discuss-send) |
---|
132 | (define-key discuss-edit-mode-map "\C-c\C-]" 'discuss-abort-edit)) |
---|
133 | |
---|
134 | |
---|
135 | (defun discuss-send () |
---|
136 | "Enter the current Discuss transaction" |
---|
137 | (interactive) |
---|
138 | (save-excursion |
---|
139 | (run-hooks 'discuss-send-hook) |
---|
140 | ;; Make sure buffer ends with a newline. |
---|
141 | (goto-char (point-max)) |
---|
142 | (if (/= (preceding-char) ?\n) |
---|
143 | (insert "\n")) |
---|
144 | ;; get subject, and find separator |
---|
145 | (goto-char (point-min)) |
---|
146 | (if (not (looking-at "Subject: ")) |
---|
147 | (error "Subject not found.") |
---|
148 | (forward-line 1) |
---|
149 | (let ((subject (buffer-substring 10 (1- (point))))) |
---|
150 | (if (not (re-search-forward |
---|
151 | (concat "^" (regexp-quote mail-header-separator) "\n") |
---|
152 | (point-max) |
---|
153 | t)) |
---|
154 | (error "Text separator not found.") |
---|
155 | (write-region (point) (point-max) (discuss-temp-file)) |
---|
156 | (message "Sending...") |
---|
157 | (discuss-send-cmd (format "(at %d %s %s)\n%s\n" |
---|
158 | discuss-reply-trn |
---|
159 | (discuss-temp-file) |
---|
160 | discuss-enter-mtg |
---|
161 | subject) |
---|
162 | 'discuss-end-of-enter 'discuss-read-form) |
---|
163 | ))))) |
---|
164 | |
---|
165 | (defun discuss-end-of-enter () |
---|
166 | (set-buffer discuss-trn-buffer) |
---|
167 | (message (format "Transaction %s entered in %s meeting." |
---|
168 | (discuss-format-trn-num (car discuss-form)) |
---|
169 | discuss-enter-mtg)) |
---|
170 | (if (not (one-window-p)) (delete-window)) |
---|
171 | (delete-auto-save-file-if-necessary) |
---|
172 | (kill-buffer discuss-trn-buffer) |
---|
173 | (save-excursion |
---|
174 | (set-buffer discuss-cur-mtg-buf) |
---|
175 | (discuss-la-invalidate-relatives discuss-current-transaction) |
---|
176 | (discuss-show-trn discuss-current-transaction))) |
---|
177 | |
---|
178 | (defun discuss-abort-edit () |
---|
179 | "Aborts entering a transaction." |
---|
180 | (interactive) |
---|
181 | (if (not (one-window-p)) (delete-window)) |
---|
182 | (kill-buffer discuss-trn-buffer)) |
---|