Initial Commit
[packages] / xemacs-packages / mew / mew / mew-message.el
1 ;;; mew-message.el --- Message mode for Mew
2
3 ;; Author:  Kazu Yamamoto <Kazu@Mew.org>
4 ;; Created: Oct  2, 1996
5 ;; Revised: Aug 30, 1999
6
7 ;;; Code:
8
9 (defconst mew-message-version "mew-message.el version 0.12")
10
11 (require 'mew)
12 (if mew-xemacs-p (require 'easymenu))
13
14 (defvar mew-message-mode-map nil)
15
16 (defvar mew-message-mode-menu-spec
17   '("Mew/message"
18     ["Next part"    mew-message-next-msg t]
19     ["Prev part"    mew-message-prev-msg t]
20     ["Next page"    mew-message-next-page t]
21     ["Prev page"    mew-message-prev-page t]
22     ["Goto summary" mew-message-goto-summary t]
23     "---"
24     ("Reply/Forward"
25      ["Reply"               mew-message-reply t]
26      ["Reply with citation" mew-message-reply-with-citation t]
27      ["Forward"             mew-message-forward t])))
28
29 (if mew-message-mode-map
30     ()
31   (setq mew-message-mode-map (make-sparse-keymap))
32   (define-key mew-message-mode-map " "    'mew-message-next-page)
33   (define-key mew-message-mode-map "\177" 'mew-message-prev-page)
34   (define-key mew-message-mode-map "n"    'mew-message-next-msg)
35   (define-key mew-message-mode-map "p"    'mew-message-prev-msg)
36   (define-key mew-message-mode-map "h"    'mew-message-goto-summary)
37   (define-key mew-message-mode-map "a"    'mew-message-reply)
38   (define-key mew-message-mode-map "A"    'mew-message-reply-with-citation)
39   (define-key mew-message-mode-map "f"    'mew-message-forward)
40   (define-key mew-message-mode-map "r"    'mew-message-resend)
41   (if mew-temacs-p
42       (easy-menu-define
43        mew-message-mode-menu
44        mew-message-mode-map
45        "Menu used in Message mode."
46        mew-message-mode-menu-spec)))
47
48 ;;;
49 ;;; Message mode
50 ;;;
51
52 (defun mew-message-mode ()
53   "\\<mew-message-mode-map>
54 Mew Message mode:: major mode for display a message.
55 The keys that are defined for this mode are:
56
57 \\[mew-message-next-page]       Scroll up this message.
58 \\[mew-message-prev-page]       Back-scroll this message.
59 \\[mew-message-next-msg]        Display a message or a part below.
60 \\[mew-message-prev-msg]        Display a message or a part above.
61 \\[mew-message-goto-summary]    Get back to Summary mode.
62 \\[mew-message-reply]   Answer to this message. A new draft is prepared in Draft mode. 
63         Mew automatically decides To: and Cc:.
64 \\[mew-message-reply-with-citation]     Answer to this message. A new draft is prepared in Draft mode. 
65         Mew automatically decides To: and Cc: and cites the body.
66 \\[mew-message-forward] Forward this message to a third person. A new draft is prepared in 
67         Draft mode and this message is automatically attached.
68 "
69   (interactive)
70   (setq major-mode 'mew-message-mode)
71   (setq mode-name "Message")
72   (setq mode-line-buffer-identification mew-mode-line-id)
73   (use-local-map mew-message-mode-map)
74   (setq buffer-read-only t)
75   (make-local-variable 'page-delimiter)
76   (setq page-delimiter mew-page-delimiter)
77   (run-hooks 'mew-message-mode-hook))
78
79 (defun mew-message-next-page (&optional lines)
80   "Scroll up this message. Return 'nil' if more pages. Otherwise, return 't'."
81   (interactive)
82   (move-to-window-line -1)
83   (if (save-excursion
84         (end-of-line)
85         (and (pos-visible-in-window-p) (eobp)))
86       ;; Nothing in this page.
87       (if (or (null mew-break-pages)
88               (save-excursion
89                 (save-restriction
90                   (widen) (forward-line) (eobp)))) ;; Real end of buffer?
91           t
92         ;; Go to the next page.
93         (mew-message-narrow-to-page 1)
94         nil)
95     ;; More in this page.
96     (condition-case nil
97         (scroll-up lines)
98       (end-of-buffer
99        (goto-char (point-max))
100        (message "End of buffer")))
101     nil))
102
103 (defun mew-message-prev-page (&optional lines)
104   "Back-scroll this message. Return 'nil' if more pages. 
105 Otherwise, return 't'."
106   (interactive)
107   (move-to-window-line 0)
108   (if (save-excursion
109         (beginning-of-line)
110         (and (pos-visible-in-window-p) (bobp)))
111       ;; Nothing in this page.
112       (if (or (null mew-break-pages)
113               (save-restriction
114                 (widen) (bobp))) ;; Real beginning of buffer?
115           t
116         ;; Go to the previous page.
117         (mew-message-narrow-to-page -1)
118         nil)
119     ;; More in this page.
120     (condition-case nil
121         (scroll-down lines)
122       (beginning-of-buffer
123        (goto-char (point-min))
124        (message "Beginning of buffer")))
125     nil))
126
127 (defun mew-message-narrow-to-page (&optional arg)
128   (interactive "P")
129   (setq arg (if arg (prefix-numeric-value arg) 0))
130   (save-excursion
131     (condition-case nil
132         (forward-page -1) ;; Beginning of the current page.
133       (beginning-of-buffer ()))
134     (forward-char 1)  ;; for compatibility with emacs-19.28 and emacs-19.29
135     (widen)
136     (cond
137      ((> arg 0) (forward-page arg))
138      ((< arg 0) (forward-page (1- arg))))
139     (forward-page)
140     (narrow-to-region
141      (point)
142      (progn
143        (forward-page -1)
144        (if (and (eolp) (not (bobp)))
145            (forward-line))
146        (point)))))
147
148 (defun mew-message-goto-summary ()
149   "Get back to Summary mode."
150   (interactive)
151   (let* ((sum-num (mew-current-get 'message))
152          (sum (car sum-num))
153          (num (cdr sum-num)))
154     (if (not (get-buffer sum))
155         (message "No Summary mode for %s" sum)
156       (mew-pop-to-buffer sum)
157       (if num
158           (mew-summary-jump-message num)))))
159
160 (defun mew-message-reply ()
161   "Answer to this message. A new draft is prepared in Draft mode. 
162 Mew automatically decides To: and Cc:."
163   (interactive)
164   (mew-message-goto-summary)
165   (call-interactively 'mew-summary-reply))
166
167 (defun mew-message-reply-with-citation ()
168   "Answer to this message. A new draft is prepared in Draft mode. 
169 Mew automatically decides To: and Cc: and cites the body."
170   (interactive)
171   (mew-message-goto-summary)
172   (call-interactively 'mew-summary-reply-with-citation))
173
174 (defun mew-message-forward ()
175   "Forward this message to a third person. A new draft is prepared in 
176 Draft mode and this message is automatically attached."
177   (interactive)
178   (mew-message-goto-summary)
179   (call-interactively 'mew-summary-forward))
180
181 (defun mew-message-resend ()
182   "\\<mew-message-mode-map>
183 Resend this message with Resent-To:. It is strongly 
184 discouraged to use this command since beginners are always 
185 confused. Please use '\\[mew-message-forward]' instead."
186   (interactive)
187   (mew-message-goto-summary)
188   (call-interactively 'mew-summary-resend))
189  
190 (defun mew-message-next-msg (&optional arg)
191   "Display a message or a part below."
192   (interactive "p")
193   (let* ((obuf (current-buffer))
194          (buf (window-buffer (previous-window))))
195     (mew-pop-to-buffer buf) ;; for the next forward-line
196     (if (not (or (eq major-mode 'mew-summary-mode)
197                  (eq major-mode 'mew-virtual-mode)))
198         ()
199       (forward-line arg) ;; minus arg results in prev
200       (mew-summary-display 'force))
201     ;; for window config
202     (mew-pop-to-buffer obuf)))
203       
204 (defun mew-message-prev-msg (&optional arg)
205   "Display a message or a part above."
206   (interactive "p")
207   (mew-message-next-msg (- arg)))
208
209 (provide 'mew-message)
210
211 ;;; Copyright Notice:
212
213 ;; Copyright (C) 1996, 1997, 1998, 1999 Mew developing team.
214 ;; All rights reserved.
215
216 ;; Redistribution and use in source and binary forms, with or without
217 ;; modification, are permitted provided that the following conditions
218 ;; are met:
219 ;; 
220 ;; 1. Redistributions of source code must retain the above copyright
221 ;;    notice, this list of conditions and the following disclaimer.
222 ;; 2. Redistributions in binary form must reproduce the above copyright
223 ;;    notice, this list of conditions and the following disclaimer in the
224 ;;    documentation and/or other materials provided with the distribution.
225 ;; 3. Neither the name of the team nor the names of its contributors
226 ;;    may be used to endorse or promote products derived from this software
227 ;;    without specific prior written permission.
228 ;; 
229 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
230 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
232 ;; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
233 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
234 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
235 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
236 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
237 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
238 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
239 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
240
241 ;;; mew-message.el ends here