Debian Codegraph @

mew-summary.el

raw
1 ;;; mew-summary.el --- Summary mode for Mew
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Oct 2, 1996
5
6 ;;; Code:
7
8 (require 'mew)
9
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ;;;
12 ;;; Summary info
13 ;;;
14
15 (defvar mew-sinfo-list
16 '(;; parameters to be saved
17 "refile" "mark-hist"
18 ;; parameters used internally
19 "scan-id" "scan-md5" "find-key" "cursor-line" "direction" "start-point"
20 "cache-time" "summary-form" "summary-column" "unread-mark" "refile-back"
21 "disp-msg" "case" "folder" "proto" "mid-marker" "mid-line" "ttl-line"
22 "mark-review" "ret-pos" "inboxp" "column"))
23
24 (mew-blinfo-defun 'mew-sinfo mew-sinfo-list)
25
26 (defvar mew-sinfo-list-save-length 2)
27 (defvar mew-sinfo-file ".mew-sinfo")
28
29 (defun mew-sinfo-save ()
30 (when (mew-summary-p)
31 (let* ((n mew-sinfo-list-save-length)
32 (data (make-vector n nil))
33 (bnm (mew-summary-folder-name 'ext))
34 (file (mew-expand-file bnm mew-sinfo-file)))
35 (dotimes (i n)
36 (aset data i (aref mew-sinfo i)))
37 (mew-lisp-save file data nil 'unlimit))))
38
39 (defun mew-sinfo-load ()
40 (when (mew-summary-p)
41 (let* ((n mew-sinfo-list-save-length)
42 (bnm (mew-summary-folder-name 'ext))
43 (file (mew-expand-file bnm mew-sinfo-file))
44 data)
45 (setq data (mew-lisp-load file))
46 (when data
47 (dotimes (i n)
48 (aset mew-sinfo i (aref data i)))))))
49
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 ;;;
52 ;;; Macros
53 ;;;
54
55 (defmacro mew-summary-msg-or-part (&rest body)
56 "See if the cursor is on a message or a part."
57 (declare (debug (&rest form)))
58 `(cond
59 ((eobp) (message "No message"))
60 ((not (or (mew-summary-message-number) (mew-syntax-number)))
61 (message "No message"))
62 (t ,@body)))
63
64 (defmacro mew-summary-msg (&rest body)
65 "See if the cursor is on a message."
66 (declare (debug (&rest form)))
67 `(cond
68 ((eobp) (message "No message"))
69 ((not (mew-summary-message-number))
70 (message "Please use this command on a message, not a part"))
71 (t ,@body)))
72
73 (defmacro mew-summary-part (&rest body)
74 "See if the cursor is on a part."
75 (declare (debug (&rest form)))
76 `(cond
77 ((eobp) (message "No part"))
78 ((not (mew-syntax-number))
79 (message "Please use this command on a part, not a message"))
80 (t ,@body)))
81
82 (defmacro mew-summary-multi-msgs (&rest body)
83 "Collect messages marked with '*' and set their corresponding
84 files to FILES."
85 (declare (debug (&rest form)))
86 `(let* ((FLD-MSGS (mew-summary-mark-collect2 mew-mark-review))
87 (FLD-MSG-LIST FLD-MSGS) ;; may be used in body
88 FILES) ;; may be used in body
89 (cond
90 ((null FLD-MSGS)
91 (message "No %c marks" mew-mark-review))
92 (t
93 ;; a little bit complicated because of Virtual mode
94 (dolist (fld-msg FLD-MSGS)
95 (setq FILES (cons (mew-expand-msg (car fld-msg) (cdr fld-msg))
96 FILES)))
97 (setq FILES (nreverse FILES))
98 ,@body))))
99
100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
101 ;;;
102 ;;; Subfunctions
103 ;;;
104
105 (defun mew-summary-local-p ()
106 (mew-folder-localp (mew-summary-folder-name 'ext)))
107
108 (defun mew-summary-draft-p ()
109 (mew-folder-draftp (mew-summary-folder-name 'ext)))
110
111 (defun mew-summary-queue-p ()
112 (or (mew-folder-queuep (mew-summary-folder-name 'ext))
113 (mew-folder-postqp (mew-summary-folder-name 'ext))))
114
115 (defun mew-summary-pop-p ()
116 (mew-folder-popp (mew-summary-folder-name 'ext)))
117
118 (defun mew-summary-case1 ()
119 (and (mew-summary-or-virtual-p) (not (mew-summary-draft-p))))
120
121 (defun mew-summary-case2 ()
122 (and (mew-summary-p) (not (mew-summary-queue-p))))
123
124 (defun mew-summary-case3 ()
125 (and (mew-summary-p) mew-summary-buffer-process))
126
127 (defmacro mew-summary-only (&rest body)
128 "See if the mode of this buffer is Summary mode.
129 This macro is used to prohibit using a command in Virtual mode."
130 (declare (debug (&rest form)))
131 `(cond
132 ((not (mew-summary-p))
133 (message "This command can be used in Summary mode only"))
134 (t ,@body)))
135
136 (defmacro mew-virtual-only (&rest body)
137 "See if the mode of this buffer is Virtual mode.
138 This macro is used to prohibit using a command in Summary mode."
139 `(cond
140 ((not (mew-virtual-p))
141 (message "This command can be used in Virtual mode only"))
142 (t ,@body)))
143
144 (defmacro mew-thread-only (&rest body)
145 "See if this buffer is Thread folder.
146 This macro is used to prohibit using a command in Summary mode."
147 (declare (debug (&rest form)))
148 `(cond
149 ((not (mew-thread-p))
150 (message "This command can be used in Thread folder only"))
151 (t ,@body)))
152
153 (defmacro mew-pickable (&rest body)
154 "See if pick can be used for this folder."
155 (declare (debug (&rest form)))
156 `(cond
157 ((not (mew-pickable-p))
158 (message "This command cannot be used in this folder"))
159 (t ,@body)))
160
161 (defmacro mew-summary-not-in-queue (&rest body)
162 "See if this folder is not +queue."
163 (declare (debug (&rest form)))
164 `(cond
165 ((not (mew-summary-or-virtual-p))
166 (message "This command cannot be used in this mode"))
167 ((mew-summary-queue-p)
168 (message "This command cannot be used in %s" (mew-summary-folder-name)))
169 (t ,@body)))
170
171 (defmacro mew-summary-not-in-draft (&rest body)
172 "See if this folder is not +draft."
173 (declare (debug (&rest form)))
174 `(cond
175 ((not (mew-summary-or-virtual-p))
176 (message "This command cannot be used in this mode"))
177 ((mew-summary-draft-p)
178 (message "This command cannot be used in %s" (mew-summary-folder-name)))
179 (t ,@body)))
180
181 (defmacro mew-summary-not-in-nntp (&rest body)
182 "See if this folder is not NNTP."
183 (declare (debug (&rest form)))
184 `(cond
185 ((mew-folder-nntpp (mew-sinfo-get-folder))
186 (message "This command cannot be used in %s" (mew-summary-folder-name)))
187 (t ,@body)))
188
189 (defmacro mew-summary-local-or-imap (&rest body)
190 "See if this folder is either local or IMAP."
191 (declare (debug (&rest form)))
192 `(cond
193 ((not (mew-summary-or-virtual-p))
194 (message "This command cannot be used in this mode"))
195 ((or (mew-folder-nntpp (mew-sinfo-get-folder))
196 (mew-folder-popp (mew-sinfo-get-folder)))
197 (message "This command cannot be used in %s" (mew-summary-folder-name)))
198 (t ,@body))) ;; local or IMAP
199
200 (defmacro mew-summary-local-only (&rest body)
201 "See if this folder is local."
202 (declare (debug (&rest form)))
203 `(cond
204 ((not (mew-summary-or-virtual-p))
205 (message "This command cannot be used in this mode"))
206 ((not (mew-summary-local-p))
207 (message "This command cannot be used in %s" (mew-summary-folder-name)))
208 (t ,@body)))
209
210 (defmacro mew-summary-with-mewl (&rest body)
211 (declare (debug (&rest form)))
212 `(cond
213 ((not (mew-which-exec mew-prog-mewl))
214 (message "'%s' not found!" mew-prog-mewl))
215 (t ,@body)))
216
217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
218 ;;;
219 ;;; Region
220 ;;;
221
222 (defun mew-summary-get-region ()
223 "Get a region according to 'mew-summary-region-include-cursor-line'
224 and return (beg . end)."
225 (save-excursion
226 (let ((beg (region-beginning))
227 (end (region-end)))
228 (goto-char beg)
229 (beginning-of-line)
230 (setq beg (point))
231 (goto-char end)
232 (cond
233 ((eq mew-summary-region-include-cursor-line t)
234 (forward-line))
235 ((eq mew-summary-region-include-cursor-line 'end)
236 (if (eq (char-after) ?\n)
237 (forward-line)
238 (beginning-of-line)))
239 (t
240 (if (> (current-column) 0)
241 (forward-line)
242 (beginning-of-line))))
243 (cons beg (point)))))
244
245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
246 ;;;
247 ;;; Dialog
248 ;;;
249
250 (defun mew-substitute-for-summary (msg)
251 (substitute-command-keys (concat "\\<mew-summary-mode-map>" msg)))
252
253 (defun mew-message-for-summary (msg)
254 (message "%s" (mew-substitute-for-summary msg)))
255
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 ;;;
258 ;;; Modeline
259 ;;;
260
261 (defvar mew-mode-line-target "%p")
262 (defvar mew-mode-line-format
263 `(""
264 (mew-summary-buffer-left-msgs mew-summary-buffer-left-msgs "L%l")
265 (mew-summary-buffer-raw "*")
266 (mew-summary-buffer-secure-process ,mew-secure-format2)))
267
268 (defvar mew-mode-line-process
269 '((mew-summary-buffer-secure-process mew-secure-format)
270 (mew-summary-buffer-process mew-summary-buffer-process-status)))
271
272 (defun mew-summary-setup-mode-line ()
273 (let ((tgt mew-mode-line-target)
274 target prev pos)
275 (if (boundp 'mode-line-position)
276 (progn
277 (make-local-variable 'mode-line-position) ;; Emacs 21.3.50
278 (setq mode-line-position
279 (copy-sequence (default-value 'mode-line-position)))
280 (setq prev mode-line-position))
281 (setq mode-line-format (copy-sequence (default-value 'mode-line-format)))
282 (setq prev mode-line-format))
283 (setq target (or (rassoc (list tgt) prev) ;; Emacs 21.3.50
284 (rassoc tgt prev)
285 (car (member tgt prev))))
286 (when target
287 (setq pos (- (length prev) (length (member target prev))))
288 (setcar (nthcdr pos prev) mew-mode-line-format))
289 (when (boundp 'line-number-mode)
290 (make-local-variable 'line-number-mode)
291 (setq line-number-mode nil))
292 (or (assq 'mew-summary-buffer-process mode-line-process)
293 (setq mode-line-process
294 (append mew-mode-line-process mode-line-process)))))
295
296 (defun mew-summary-reset-mode-line ()
297 (setq mew-summary-buffer-left-msgs nil))
298
299 (defun mew-summary-mode-name (name)
300 (let ((case (if (mew-case-default-p mew-case) "" mew-case)))
301 (if (string= case "")
302 (setq mode-name name)
303 (setq mode-name (format "%s %s" name case)))
304 (force-mode-line-update)))
305
306 (defun mew-summary-mode-line ()
307 (unless mew-summary-buffer-process
308 (let ((pos (point))
309 (mid-point (marker-position (mew-sinfo-get-mid-marker)))
310 (mid-line (mew-sinfo-get-mid-line))
311 (ttl (mew-sinfo-get-ttl-line))
312 cur left)
313 (if (< pos mid-point)
314 (if (< pos (/ mid-point 2))
315 (setq cur (mew-count-lines (point-min) pos))
316 (setq cur (- mid-line (mew-count-lines pos mid-point))))
317 (if (< pos (+ mid-point (/ mid-point 2)))
318 (setq cur (+ mid-line (mew-count-lines mid-point pos)))
319 (setq cur (- ttl (mew-count-lines pos (point-max))))))
320 (unless (and (mew-decode-syntax-p)
321 (equal (mew-decode-syntax-buffer) (current-buffer))
322 (>= pos (mew-decode-syntax-begin))
323 (<= pos (mew-decode-syntax-end)))
324 (setq cur (1+ cur)))
325 (setq left (- ttl cur))
326 (setq mew-summary-buffer-left-msgs (format "[%d/%d{%d}]" cur ttl left)))
327 (force-mode-line-update)))
328
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
330 ;;;
331 ;;; Locking
332 ;;;
333
334 (defun mew-summary-exclusive-p (&optional no-msg)
335 (cond
336 ((eq mew-summary-buffer-process t)
337 (or no-msg (message "Try again later"))
338 nil) ;; not exclusive
339 ((processp mew-summary-buffer-process)
340 (or no-msg
341 (mew-message-for-summary
342 "Another process is running. Try later or type '\\[mew-summary-kill-subprocess]' to kill it"))
343 nil) ;; not exclusive
344 (t t))) ;; exclusive
345
346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
347 ;;;
348 ;;; Summary mode
349 ;;;
350
351 (defun mew-summary-mode ()
352 "A major mode to show a list of messages in a folder.
353
354 \\{mew-summary-mode-map}"
355 (interactive)
356 (setq major-mode 'mew-summary-mode)
357 (setq mode-line-buffer-identification (mew-mode-line-id))
358 (use-local-map mew-summary-mode-map)
359 (setq buffer-read-only t)
360 (setq truncate-lines t)
361 ;;
362 (if (boundp 'bidi-paragraph-direction)
363 (setq bidi-paragraph-direction 'left-to-right))
364 (make-local-variable 'tab-width)
365 (make-local-variable 'search-invisible)
366 (setq search-invisible nil)
367 (make-local-variable 'line-move-ignore-invisible)
368 (setq line-move-ignore-invisible t)
369 (make-local-variable 'search-invisible)
370 (jit-lock-register 'mew-summary-cook-region)
371 (add-hook 'kill-buffer-hook 'mew-sinfo-save nil 'local)
372 (mew-sinfo-set-disp-msg t)
373 ;;
374 (mew-summary-mode-name mew-mode-name-summary)
375 (mew-summary-setup-mode-line)
376 (mew-summary-setup-decoration)
377 (mew-highlight-cursor-line)
378 (mew-run-mode-hooks 'mew-summary-mode-hook))
379
380 (defun mew-summary-kill ()
381 "Kill this Summary mode."
382 (interactive)
383 (mew-kill-buffer)
384 (when (and mew-use-other-frame-for-summary (> (length (frame-list)) 1))
385 (mew-remove-buffer (mew-buffer-message))
386 (delete-frame)))
387
388 (defun mew-summary-reset ()
389 (mew-unhighlight-cursor-line)
390 (mew-window-configure 'summary)
391 (mew-remove-buffer (mew-buffer-message))
392 (mew-current-set nil nil nil)
393 (mew-summary-reset-mode-line)
394 (mew-decode-syntax-delete))
395
396 (provide 'mew-summary)
397
398 ;;; Copyright Notice:
399
400 ;; Copyright (C) 1996-2015 Mew developing team.
401 ;; All rights reserved.
402
403 ;; Redistribution and use in source and binary forms, with or without
404 ;; modification, are permitted provided that the following conditions
405 ;; are met:
406 ;;
407 ;; 1. Redistributions of source code must retain the above copyright
408 ;; notice, this list of conditions and the following disclaimer.
409 ;; 2. Redistributions in binary form must reproduce the above copyright
410 ;; notice, this list of conditions and the following disclaimer in the
411 ;; documentation and/or other materials provided with the distribution.
412 ;; 3. Neither the name of the team nor the names of its contributors
413 ;; may be used to endorse or promote products derived from this software
414 ;; without specific prior written permission.
415 ;;
416 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
417 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
418 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
419 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
420 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
421 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
422 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
423 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
424 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
425 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
426 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
427
428 ;;; mew-summary.el ends here