Debian Codegraph @

mew-mark.el

raw
1 ;;; mew-mark.el --- Marking for Mew Summary and Virtual mode
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Mar 2, 1997
5
6 ;;; Code:
7
8 (require 'mew)
9
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ;;;
12 ;;; undo-func
13 ;;;
14
15 (defun mew-mark-unrefile (fld msg)
16 "Delete refile state and delete the mark."
17 (mew-summary-refile-remove-body)
18 (unless (mew-virtual-p)
19 (mew-refile-reset msg)
20 (mew-summary-refile-unlog fld)))
21
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;;;
24 ;;; Undo
25 ;;;
26
27 (defun mew-mark-unmark ()
28 (save-excursion
29 (mew-summary-goto-mark)
30 (when (looking-at mew-regex-mark)
31 (mew-mark-remove))))
32
33 (defun mew-summary-undo (&optional count)
34 "Cancel the mark in COUNT times."
35 (interactive "P")
36 (mew-mark-put-mark-loop 'mew-summary-undo-one count 'stayp))
37
38 (defun mew-summary-undo-one (&optional no-msg)
39 "Cancel the mark on this message."
40 (if (eobp)
41 (or no-msg (message "No message"))
42 (let (mark func fld msg)
43 (save-excursion
44 (mew-summary-goto-message)
45 (setq mark (mew-summary-get-mark))
46 (if (null mark)
47 (or no-msg (message "No mark"))
48 (setq func (mew-markdb-func-undo mark))
49 (or (fboundp func) (setq func nil))
50 (setq fld (mew-summary-folder-name))
51 (setq msg (mew-summary-message-number))
52 (mew-mark-unmark)
53 (if func (funcall func fld msg))
54 (if (mew-virtual-for-one-summary)
55 (mew-summary-unmark-in-physical fld msg func)))))))
56
57 ;;
58
59 (defun mew-summary-undo-all ()
60 "Cancel all marks according to what you input."
61 (interactive)
62 (let ((char (mew-input-mark)))
63 (if char (mew-mark-undo-mark char))))
64
65 (defun mew-mark-undo-mark (mark &optional no-msg virtual-only)
66 "Undo MARK on the entire buffer.
67 If optional argument NO-MSG is non-nil, no message is displayed."
68 (or no-msg (message "Unmarking..."))
69 (mew-decode-syntax-delete)
70 (let* ((regex (mew-mark-regex mark))
71 (func (mew-markdb-func-undo mark))
72 (case-fold-search nil)
73 (reviewp (char-equal mark mew-mark-review))
74 (one-summary (and (not virtual-only) (mew-virtual-for-one-summary)))
75 alist fld msg reviews)
76 (or (fboundp func) (setq func nil))
77 (save-excursion
78 (goto-char (point-min))
79 (while (re-search-forward regex nil t)
80 (setq fld (mew-summary-folder-name))
81 (setq msg (mew-summary-message-number))
82 (mew-mark-remove)
83 (if one-summary (mew-mark-alist-set alist fld msg))
84 (when reviewp (setq reviews (cons msg reviews)))
85 (if func (funcall func fld msg))
86 (forward-line))
87 (set-buffer-modified-p nil)
88 (mew-sinfo-set-mark-review (nreverse reviews))
89 (if one-summary (mew-summary-unmark-in-physical-alist alist func))))
90 (or no-msg (message "Unmarking...done")))
91
92 ;;
93
94 (defun mew-summary-mark-undo-all ()
95 "Unmark all message marked with 'o' or 'D' or 'X'."
96 (interactive)
97 (message "Unmarking...")
98 (dolist (mark mew-summary-mark-undo-marks)
99 (mew-mark-undo-mark mark 'no-msg))
100 (message "Unmarking...done"))
101
102 ;;
103
104 (defun mew-summary-redo ()
105 "\\<mew-summary-mode-map>Recover the `*' marks which are canceled by the last `\\[mew-summary-undo-all]*'."
106 (interactive)
107 (let ((mark mew-mark-review)
108 (reviews (mew-sinfo-get-mark-review)))
109 (save-excursion
110 (mew-mark-undo-mark mark 'no-msg)
111 (goto-char (point-min))
112 (dolist (msg reviews)
113 (when (re-search-forward (mew-regex-sumsyn-msg msg) nil t)
114 (mew-mark-put mark)
115 (forward-line))))
116 (set-buffer-modified-p nil)))
117
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;;;
120 ;;; Basic functions and macros for mark
121 ;;;
122
123 (defun mew-summary-get-mark ()
124 "Get a mark on the current message."
125 (save-excursion
126 (mew-summary-goto-mark)
127 (when (looking-at mew-regex-mark)
128 (mew-sumsyn-mark)))) ;; return char
129
130 (defun mew-summary-markable ()
131 (let ((mark (mew-summary-get-mark))
132 (case-fold-search nil))
133 (or (null mark) (char-equal mark mew-mark-unread))))
134
135 (defun mew-summary-mark-as (mark)
136 "Mark this message with MARK if possible."
137 (when (mew-summary-markable)
138 (mew-mark-put mark)))
139
140 (defun mew-mark-put (mark)
141 (save-excursion
142 (mew-summary-goto-mark)
143 (let* ((beg (point)) (end (1+ beg)))
144 (mew-elet
145 ;; This code is awkward but for invisible.
146 (forward-char 1)
147 (insert-and-inherit (char-to-string mark)) ;; inherit highlight
148 (forward-char -2)
149 (delete-char 1)
150 (mew-front-nonsticky beg end)
151 (mew-highlight-mark-line mark))
152 (mew-mark-hist-set (mew-summary-message-number) mark))))
153
154 (defun mew-mark-remove ()
155 (save-excursion
156 (mew-summary-goto-mark)
157 (let* ((mark mew-mark-read)
158 (beg (point)) (end (1+ beg)))
159 (mew-elet
160 ;; This code is awkward but for invisible.
161 (forward-char 1)
162 (insert-and-inherit (char-to-string mark)) ;; inherit highlight
163 (forward-char -2)
164 (delete-char 1)
165 (mew-front-nonsticky beg end)
166 (mew-highlight-unmark-line))
167 (mew-mark-hist-set (mew-summary-message-number) mark))))
168
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170 ;;;
171 ;;; Entire buffer
172 ;;;
173
174 (defun mew-summary-mark-exist-p (mark-list)
175 "See if this Summary mode has one or more marked messages."
176 (let ((regex (mew-mark-list-regex mark-list)))
177 (save-excursion
178 (goto-char (point-min))
179 (re-search-forward regex nil t))))
180
181 (defun mew-summary-mark-collect (mark &optional begin end)
182 "This function returns a list of message number."
183 (save-excursion
184 (let ((regex (mew-mark-regex mark))
185 (msglist nil)
186 (case-fold-search nil))
187 (goto-char (if begin begin (point-min)))
188 (while (re-search-forward regex end t)
189 (setq msglist (cons (mew-summary-message-number) msglist)))
190 (nreverse msglist))))
191
192 (defun mew-summary-mark-collect2 (mark)
193 "For Virtual mode, this function returns a list of
194 cons pairs of folder name and message number."
195 (save-excursion
196 (let ((regex (mew-mark-regex mark))
197 (msglist nil)
198 (case-fold-search nil))
199 (goto-char (point-min))
200 (while (re-search-forward regex nil t)
201 (setq msglist (cons
202 (cons
203 (mew-summary-folder-name)
204 (mew-summary-message-number))
205 msglist)))
206 (nreverse msglist))))
207
208 (defun mew-summary-mark-collect4 ()
209 (save-excursion
210 (let (ret mrk msg)
211 (goto-char (point-min))
212 (while (re-search-forward mew-regex-mark nil t)
213 (setq mrk (mew-sumsyn-mark))
214 (setq msg (mew-summary-message-number))
215 (setq ret (cons (list msg mrk) ret))
216 (forward-line))
217 (nreverse ret))))
218
219 (defun mew-summary-mark-collect5 ()
220 (save-excursion
221 (let ((beg (mew-net-invalid-cache-start))
222 ret mrk msg)
223 (when beg
224 (goto-char beg)
225 (while (re-search-forward mew-regex-mark nil t)
226 (setq mrk (mew-sumsyn-mark))
227 (setq msg (mew-summary-message-number))
228 (setq msg (number-to-string (string-to-number msg)))
229 (setq ret (cons (list msg mrk) ret))
230 (forward-line))
231 (nreverse ret)))))
232
233 (defun mew-summary-mark-recover (mdb &optional refdb refs)
234 (let ((opos (point))
235 (case-fold-search nil)
236 msg mrk new-ref ref-ent)
237 (goto-char (point-min))
238 (dolist (ent mdb)
239 (mew-set '(msg mrk) ent)
240 (when (re-search-forward (mew-regex-sumsyn-msg msg) nil t)
241 (if (or (not (char-equal mrk mew-mark-refile)) (null refdb))
242 (mew-mark-put mrk)
243 (when (setq ref-ent (assoc msg refdb))
244 (mew-mark-put mrk)
245 (setq new-ref (cons ref-ent new-ref))))
246 (forward-line)))
247 (dolist (ref refs)
248 (when (setq ref-ent (assoc ref refdb))
249 (setq new-ref (cons ref-ent new-ref))))
250 (goto-char opos)
251 (nreverse new-ref)))
252
253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254 ;;;
255 ;;; Base function
256 ;;;
257
258 (defun mew-mark-afterstep (mark case)
259 "Move the cursor after marking according to MARK's CASE.
260 See also mew-mark-afterstep-spec."
261 (let ((action (mew-markas-nth mark case)))
262 (cond
263 ((eq action 0)
264 ()) ;; stay
265 ((eq action 1)
266 (mew-summary-goto-message)
267 (mew-decode-syntax-delete)
268 (cond
269 ((eq mew-summary-mark-direction 'up)
270 (forward-line -1))
271 ((eq mew-summary-mark-direction 'down)
272 (forward-line))
273 ((eq mew-summary-mark-direction 'next)
274 (if (eq (mew-sinfo-get-direction) 'up)
275 (forward-line -1)
276 (forward-line)))))
277 ((eq action 2)
278 (mew-summary-goto-message)
279 (mew-decode-syntax-delete)
280 (beginning-of-line)
281 (mew-push-mark)
282 (let ((mew-inherit-after-marking t))
283 (mew-summary-display-after mew-summary-mark-direction))))))
284
285 (mew-defstruct mark-hist msg mark)
286
287 (defun mew-mark-hist-set (msg mark)
288 (let* ((hist (mew-sinfo-get-mark-hist))
289 (ent (assoc msg hist))
290 (num (string-to-number msg))
291 curr prev)
292 (cond
293 (ent
294 (if mark (setcar (nthcdr 1 ent) mark)))
295 (t
296 (setq ent (mew-make-mark-hist :msg msg :mark mark))
297 (setq curr hist)
298 (catch 'loop
299 (while curr
300 (if (> (string-to-number (nth 0 (car curr))) num)
301 (progn
302 (if (null prev)
303 (setq hist (cons ent hist))
304 (setcdr prev (cons ent (cdr prev))))
305 (throw 'loop nil)))
306 (setq prev curr)
307 (setq curr (cdr curr)))
308 (setq hist (nconc hist (list ent))))
309 (mew-sinfo-set-mark-hist hist)))))
310
311 (defun mew-mark-put-mark (newmark &optional no-msg valid-only)
312 "Put the NEWMARK on the current line if possible.
313 If NO-MSG is non-nil, no message is displayed.
314 NO-MSG also means that this function is being called in loop."
315 (mew-summary-msg-or-part
316 (let (oldmark oldlevel oldname newlevel newname case msg fld marked validp)
317 (save-excursion
318 (mew-summary-goto-message)
319 (when (mew-sumsyn-match mew-regex-sumsyn-short)
320 (setq msg (mew-sumsyn-message-number))
321 (setq fld (mew-sumsyn-folder-name))
322 (setq validp (or (not valid-only) (mew-msg-validp msg))))
323 (if (not validp)
324 (unless no-msg (message "Cannot mark this invalid message with '%c'" newmark))
325 (setq oldmark (mew-summary-get-mark))
326 (setq oldlevel (mew-markdb-level oldmark))
327 (setq oldname (mew-markdb-name oldmark))
328 (setq newlevel (mew-markdb-level newmark))
329 (setq newname (mew-markdb-name newmark))
330 (cond
331 ((null oldmark);; no mark
332 (setq case 1)
333 (mew-mark-put newmark)
334 (setq marked t))
335 ((eq oldmark newmark)
336 (setq case 2)
337 (or no-msg
338 (mew-markdb-statefullp oldmark)
339 (message "Already marked as '%s'" oldname)))
340 ((< oldlevel newlevel)
341 (setq case 3)
342 (mew-summary-undo-one no-msg)
343 (mew-mark-put newmark)
344 (setq marked t))
345 ((= oldlevel newlevel)
346 (cond
347 ((mew-markdb-statefullp oldmark)
348 (if (or no-msg
349 (y-or-n-p (format "Already marked as '%s'. %s it? "
350 oldname (mew-capitalize newname))))
351 (progn
352 (setq case 4)
353 (mew-summary-undo-one no-msg)
354 (mew-mark-put newmark)
355 (setq marked t))
356 (setq case 5)))
357 (t
358 (setq case 6)
359 (mew-summary-undo-one no-msg)
360 (mew-mark-put newmark)
361 (setq marked t))))
362 (t ;; > oldlevel newlevel
363 (setq case 7)
364 (message "Cannot mark here because '%s' is stronger than '%s'"
365 oldname newname)))))
366 (when validp
367 (if (and marked (mew-virtual-for-one-summary))
368 (mew-summary-mark-in-physical fld msg newmark))
369 (or no-msg (mew-mark-afterstep newmark case))
370 (set-buffer-modified-p nil)))))
371
372 (defun mew-mark-put-mark-loop (func count stayp)
373 "Unless COUNT is numeric, just call FUNC once.
374 The cursor moves forward. STAYP has no effect.
375 If COUNT is positive, call FUNC in COUNT times moving the cursor forward.
376 If COUNT is negative, call FUNC in COUNT times moving the cursor backward.
377 If COUNT is numeric and STAYP is non-nil, the cursor stays in the
378 original position."
379 (if (and (not (integerp count)) (mew-mark-active-p))
380 (let ((begend (mew-summary-get-region)))
381 (goto-char (car begend))
382 (setq stayp nil)
383 (setq count (count-lines (point) (cdr begend)))
384 (mew-mark-put-mark-loop1 func count stayp))
385 (mew-mark-put-mark-loop1 func count stayp)))
386
387 (defun mew-mark-put-mark-loop1 (func count stayp)
388 (when (and func (fboundp func))
389 (mew-summary-msg-or-part
390 (if (integerp count)
391 (let ((start (point)))
392 (mew-decode-syntax-delete)
393 ;; positive loop
394 (while (and (> count 0) (not (eobp)))
395 (setq count (1- count))
396 (funcall func 'no-msg)
397 (forward-line))
398 ;; negative loop
399 (while (< count 0)
400 (if (bobp)
401 ;; need to call the func
402 (setq count 0)
403 (setq count (1+ count)))
404 (funcall func 'no-msg)
405 (forward-line -1))
406 (and stayp (goto-char start)))
407 ;; just one
408 (funcall func))
409 (set-buffer-modified-p nil))))
410
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412 ;;;
413 ;;; Physical
414 ;;;
415
416 (defun mew-summary-mark-in-physical (fld msg new-mark)
417 (save-excursion
418 (when (get-buffer fld)
419 (set-buffer fld)
420 (save-excursion
421 (when (mew-summary-search-msg msg)
422 (mew-mark-put new-mark)
423 (set-buffer-modified-p nil))))))
424
425 (defun mew-summary-unmark-in-physical (fld msg &optional func)
426 (save-excursion
427 (when (get-buffer fld)
428 (set-buffer fld)
429 (save-excursion
430 (when (mew-summary-search-msg msg)
431 (mew-mark-remove)
432 (if func (funcall func fld msg))
433 (set-buffer-modified-p nil))))))
434
435 (defmacro mew-mark-alist-set (alist fld msg)
436 `(let ((imsg (string-to-number ,msg))
437 (fld-msgs (assoc ,fld ,alist)))
438 (if fld-msgs
439 (nconc fld-msgs (list imsg))
440 (setq ,alist (cons (list ,fld imsg) ,alist)))))
441
442 (defun mew-summary-mark-in-physical-alist (alist mark &optional func)
443 (save-excursion
444 (let (fld msg msgs)
445 (dolist (ent alist)
446 (setq fld (car ent))
447 (setq msgs (sort (copy-sequence (cdr ent)) '<)) ;; sort has side effect
448 (when (get-buffer fld)
449 (set-buffer fld)
450 (save-excursion
451 (goto-char (point-min))
452 (dolist (m msgs)
453 (setq msg (number-to-string m))
454 (when (re-search-forward (mew-regex-sumsyn-msg msg) nil t)
455 (if func (funcall func))
456 (mew-mark-put mark)
457 (forward-line)))
458 (set-buffer-modified-p nil)))))))
459
460 (defun mew-summary-unmark-in-physical-alist (alist func)
461 (save-excursion
462 (let (fld msg msgs)
463 (dolist (ent alist)
464 (setq fld (car ent))
465 (setq msgs (sort (copy-sequence (cdr ent)) '<)) ;; sort has side effect
466 (when (get-buffer fld)
467 (set-buffer fld)
468 (save-excursion
469 (goto-char (point-min))
470 (dolist (m msgs)
471 (setq msg (number-to-string m))
472 (when (re-search-forward (mew-regex-sumsyn-msg msg) nil t)
473 (mew-mark-remove)
474 (if func (funcall func fld msg))
475 (forward-line)))
476 (set-buffer-modified-p nil)))))))
477
478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
479 ;;;
480 ;;; Review: "*" in Summary mode
481 ;;;
482
483 (defun mew-summary-review (&optional count)
484 "\\<mew-summary-mode-map>
485 Put the review mark (default is '*') in COUNT times.
486 Use '\\[mew-summary-display-review-down]' or '\\[mew-summary-display-review-up]' to jump to a message marked with '*'.
487 See also '\\[mew-summary-mark-refile]', '\\[mew-summary-mark-delete]', '\\[mew-summary-mark-regexp]', and '\\[mew-summary-mark-all]'."
488 (interactive "P")
489 (mew-mark-put-mark-loop 'mew-summary-review-one count nil))
490
491 (defun mew-summary-review-one (&optional no-msg)
492 "Put the review mark (default is '*') on this message."
493 (mew-mark-put-mark mew-mark-review no-msg))
494
495 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
496 ;;;
497 ;;; Escape: "$" in Summary mode
498 ;;;
499
500 (defun mew-summary-escape (&optional count)
501 "\\<mew-summary-mode-map>
502 Put the escape mark (default is '$') in COUNT times."
503 (interactive "P")
504 (mew-mark-put-mark-loop 'mew-summary-escape-one count nil))
505
506 (defun mew-summary-escape-one (&optional no-msg)
507 "Put the escape mark (default is '$') on this message."
508 (mew-mark-put-mark mew-mark-escape no-msg))
509
510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
511 ;;;
512 ;;; Delete: "D" in Summary mode
513 ;;;
514
515 (defun mew-summary-delete (&optional count)
516 "Put the delete mark (default is 'D') in COUNT times."
517 (interactive "P")
518 (mew-summary-not-in-nntp
519 (mew-mark-put-mark-loop 'mew-summary-delete-one count nil)))
520
521 (defun mew-summary-delete-one (&optional no-msg)
522 "Put the delete mark (default is 'D') on this message."
523 (mew-mark-put-mark mew-mark-delete no-msg 'valid-only))
524
525 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
526 ;;;
527 ;;; Unlink: "X" in Summary mode
528 ;;;
529
530 (defun mew-summary-unlink (&optional count)
531 "Put the unlink mark (default is 'X') in COUNT times."
532 (interactive "P")
533 (mew-summary-not-in-nntp
534 (mew-mark-put-mark-loop 'mew-summary-unlink-one count nil)))
535
536 (defun mew-summary-unlink-one (&optional no-msg)
537 "Put the unlink mark (default is 'X') on this message."
538 (mew-mark-put-mark mew-mark-unlink no-msg 'valid-only))
539
540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
541 ;;;
542 ;;; Unread: "U" in Summary mode
543 ;;;
544
545 (defun mew-summary-unread (&optional count)
546 "\\<mew-summary-mode-map>
547 Put the unread mark (default is 'U') in COUNT times."
548 (interactive "P")
549 (mew-mark-put-mark-loop 'mew-summary-unread-one count nil))
550
551 (defun mew-summary-unread-one (&optional no-msg)
552 "Put the unread mark (default is 'U') on this message."
553 (mew-mark-put-mark mew-mark-unread no-msg))
554
555 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
556 ;;;
557 ;;; All messages
558 ;;;
559
560 (defun mew-summary-mark-all (&optional arg)
561 "Put the '*' mark onto all messages which are not marked."
562 (interactive "P")
563 (mew-decode-syntax-delete)
564 (if (mew-mark-active-p) (setq arg t))
565 (if arg
566 (let ((begend (mew-summary-get-region)))
567 (mew-summary-mark-all-region (car begend) (cdr begend)))
568 (mew-summary-mark-all-region (point-min) (point-max))))
569
570 (defun mew-summary-mark-all-region (beg end)
571 "Put the '*' mark onto all messages which are not marked between
572 BEG and END."
573 (interactive "r")
574 (let ((regex (mew-mark-regex mew-sp)) ;; not marked
575 (mark mew-mark-review) ;; someday ...
576 (one-summary (mew-virtual-for-one-summary))
577 fld msg alist)
578 (save-excursion
579 (goto-char beg)
580 (while (re-search-forward regex end t)
581 (mew-summary-mark-as mark)
582 (when one-summary
583 (setq fld (mew-summary-folder-name))
584 (setq msg (mew-summary-message-number))
585 (mew-mark-alist-set alist fld msg))
586 (forward-line))
587 (set-buffer-modified-p nil))
588 (if one-summary (mew-summary-mark-in-physical-alist alist mark))))
589
590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
591 ;;;
592 ;;; Regex
593 ;;;
594
595 (defun mew-summary-search-regexp-visible (regex)
596 (catch 'loop
597 (while (re-search-forward regex nil t)
598 (beginning-of-line)
599 (unless (search-forward "\r" (match-end 0) t)
600 (throw 'loop t))
601 (forward-line))))
602
603 (defun mew-summary-mark-regexp (&optional args)
604 "Put the '*' mark onto all messages matched to a regular expression."
605 (interactive "P")
606 (mew-decode-syntax-delete)
607 (let ((regex (read-string "Regexp: "))
608 (mark mew-mark-review) ;; someday ...
609 (one-summary (mew-virtual-for-one-summary))
610 (n 0)
611 fld msg alist)
612 (while (string= regex "")
613 (setq regex (read-string "Regexp: ")))
614 (save-excursion
615 (goto-char (point-min))
616 (while (if args
617 (re-search-forward regex nil t)
618 (mew-summary-search-regexp-visible regex))
619 (when (and (mew-summary-markable)
620 (mew-sumsyn-match mew-regex-sumsyn-short))
621 (when one-summary
622 (setq fld (mew-sumsyn-folder-name))
623 (setq msg (mew-sumsyn-message-number))
624 (mew-mark-alist-set alist fld msg))
625 (mew-mark-put mark)
626 (setq n (1+ n)))
627 (forward-line))
628 (set-buffer-modified-p nil))
629 (if one-summary (mew-summary-mark-in-physical-alist alist mark))
630 (cond
631 ((= n 1)
632 (message "1 message marked"))
633 ((> n 1)
634 (message "%d messages marked" n))
635 (t
636 (message "No message to be marked")))))
637
638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
639 ;;;
640 ;;; Exchange
641 ;;;
642
643 (defun mew-summary-exchange-mark (oldmark newmark &optional valid-only)
644 (let ((regex (mew-mark-regex oldmark))
645 (case-fold-search nil)
646 (one-summary (mew-virtual-for-one-summary))
647 (i 0)
648 fld msg alist)
649 (save-excursion
650 (goto-char (point-min))
651 (while (re-search-forward regex nil t)
652 (when (mew-sumsyn-match mew-regex-sumsyn-short)
653 (setq fld (mew-sumsyn-folder-name))
654 (setq msg (mew-sumsyn-message-number))
655 (when (or (not valid-only) (mew-msg-validp msg))
656 (mew-mark-put newmark)
657 (if one-summary (mew-mark-alist-set alist fld msg))))
658 (forward-line)
659 (setq i (1+ i))))
660 (if (= i 0)
661 (message "No marked messages")
662 (set-buffer-modified-p nil)
663 (if one-summary (mew-summary-mark-in-physical-alist alist newmark)))))
664
665 (defun mew-summary-mark-delete () ;; * -> D
666 "Put the delete mark onto all messages marked with '*'."
667 (interactive)
668 (mew-summary-not-in-nntp
669 (mew-summary-exchange-mark mew-mark-review mew-mark-delete 'valid-only)))
670
671 (defun mew-summary-mark-unlink () ;; * -> X
672 "Put the delete mark onto all messages marked with '*'."
673 (interactive)
674 (mew-summary-exchange-mark mew-mark-review mew-mark-unlink 'valid-only))
675
676 (defun mew-summary-mark-escape () ;; * -> $
677 "Change the '*' mark into the '$' mark."
678 (interactive)
679 (mew-summary-exchange-mark mew-mark-review mew-mark-escape))
680
681 (defun mew-summary-mark-review () ;; $ -> *
682 "Change the '$' mark into the '*' mark."
683 (interactive)
684 (mew-summary-exchange-mark mew-mark-escape mew-mark-review))
685
686 (defun mew-summary-mark-unread () ;; * -> U
687 "Change the '*' mark into the 'U' mark."
688 (interactive)
689 (mew-summary-exchange-mark mew-mark-review mew-mark-unread))
690
691 (defun mew-summary-mark-swap () ;; $ <-> *
692 "Swap the '$' mark and the '*' mark."
693 (interactive)
694 (mew-summary-exchange-mark mew-mark-escape mew-mark-tmp)
695 (mew-summary-exchange-mark mew-mark-review mew-mark-escape)
696 (mew-summary-exchange-mark mew-mark-tmp mew-mark-review))
697
698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
699 ;;;
700 ;;; Marking duplicated messages
701 ;;;
702
703 (defun mew-summary-mark-duplicated (&optional arg)
704 "Put the mark specified by 'mew-mark-duplicated' on duplicated
705 messages. If called with '\\[universal-argument]', process in the
706 region."
707 (interactive "P")
708 (mew-summary-not-in-queue
709 (mew-summary-not-in-draft
710 (if (and (or (eq mew-mark-duplicated mew-mark-delete)
711 (eq mew-mark-duplicated mew-mark-unlink))
712 (eq mew-summary-mark-duplicated-skip nil))
713 (message "Cannot mark because messages may lost by this setting")
714 (let ((reversep (eq mew-summary-mark-duplicated-skip 'last))
715 (count 0) my-id dup-id size ids beg end region)
716 (if (mew-mark-active-p) (setq arg t))
717 (cond
718 (arg
719 (setq region (mew-summary-get-region))
720 (setq beg (car region))
721 (setq end (cdr region)))
722 (t
723 (setq beg (point-min))
724 (setq end (point-max))))
725 (message "Marking duplications...")
726 (save-excursion
727 ;; from mew-summary-thread-region in mew-threaed.el
728 (setq size (count-lines beg end))
729 (cond
730 ((<= size 211)
731 (setq size 211))
732 ((<= size 1511)
733 (setq size 1511))
734 ((<= size 7211)
735 (setq size 7211))
736 (t
737 (setq size 18211)))
738 (setq ids (make-vector size 0)) ;; hash
739 (save-restriction
740 (narrow-to-region beg end)
741 (goto-char (if reversep (point-max) (point-min)))
742 (catch 'loop
743 (while t
744 (when (and (mew-summary-message-number)
745 (mew-summary-markable))
746 (setq my-id (mew-summary-my-id))
747 (when (> (length my-id) 0)
748 (setq dup-id (intern-soft my-id ids))
749 (if (null dup-id)
750 ;; first time (no duplication)
751 (set (intern my-id ids) t)
752 (when (symbol-value dup-id)
753 ;; second time (first duplication)
754 (unless mew-summary-mark-duplicated-skip
755 (save-excursion
756 (when (re-search-backward
757 (mew-regex-sumsyn-my-id my-id) nil t)
758 (mew-mark-put-mark mew-mark-duplicated 'no-msg)
759 (setq count (1+ count))))
760 (set (intern my-id ids) nil)))
761 (mew-mark-put-mark mew-mark-duplicated 'no-msg)
762 (setq count (1+ count)))))
763 (cond
764 (reversep
765 (beginning-of-line)
766 (if (bobp)
767 (throw 'loop t)
768 (forward-line -1)))
769 (t
770 (forward-line 1)
771 (if (eobp)
772 (throw 'loop t))))))))
773 (cond
774 ((= count 0)
775 (message "Marking duplications...done (no duplication)"))
776 ((= count 1)
777 (message "Marking duplications...done (1 msg is marked)"))
778 (t
779 (message "Marking duplications...done (%d msgs are marked)" count))))))))
780
781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
782 ;;;
783 ;;; Reviewing
784 ;;;
785
786 (defun mew-summary-set-walk-mark ()
787 (let* ((msg (format "Input mark(%c): " mew-mark-default-walk))
788 (mew-mark-spec (cons (list 13) mew-mark-spec)) ;; adding \r
789 (char (mew-input-mark msg)))
790 (cond
791 ((null char)
792 ;; mew-input-mark displays a message.
793 )
794 ((char-equal char ?\r)
795 (setq mew-mark-walk mew-mark-default-walk)
796 (message "Target mark was set to '%c'" mew-mark-walk))
797 (char
798 (setq mew-mark-walk char)
799 (message "Target mark was set to '%c'" mew-mark-walk)))))
800
801 (defun mew-summary-down-mark (mark)
802 (let ((case-fold-search nil))
803 (forward-line)
804 (cond
805 ((re-search-forward (mew-mark-regex mark) nil t)
806 (beginning-of-line)
807 t)
808 (t
809 (forward-line -1)
810 (message "No more marked messages")
811 nil))))
812
813 (defun mew-summary-display-review-down (&optional arg)
814 "Jump to the message marked with '*' below.
815 If called with '\\[universal-argument]', you can change the target mark.
816 After that, this command jumps to the message marked with
817 the specified mark."
818 (interactive "P")
819 (if arg
820 (mew-summary-set-walk-mark)
821 (if (mew-summary-down-mark mew-mark-walk)
822 (mew-summary-display))))
823
824 (defun mew-summary-up-mark (mark)
825 (let ((case-fold-search nil))
826 (cond
827 ((re-search-backward (mew-mark-regex mark) nil t)
828 t)
829 (t
830 (message "No more marked messages")
831 nil))))
832
833 (defun mew-summary-display-review-up (&optional arg)
834 "Jump to the message marked with '*' above.
835 If called with '\\[universal-argument]', you can change the target mark.
836 After that, this command jumps to the message marked with
837 the specified mark."
838 (interactive "P")
839 (if arg
840 (mew-summary-set-walk-mark)
841 (if (mew-summary-up-mark mew-mark-walk)
842 (mew-summary-display))))
843
844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
845 ;;;
846 ;;; Mark exchange
847 ;;;
848
849 (defun mew-summary-input-exchangeable-mark (msg)
850 (let (mark)
851 (catch 'loop
852 (while t
853 (setq mark (mew-input-mark msg))
854 (cond
855 ((null mark)
856 (message "That is not a mark")
857 (mew-let-user-read))
858 ((mew-markdb-statefullp mark)
859 (message "'%c' cannot be exchanged" mark)
860 (mew-let-user-read))
861 (t
862 (throw 'loop mark)))))))
863
864 (defun mew-summary-exchange-marks ()
865 "Exchange the first input mark to the second one.
866 The 'o' mark is not exchangeable."
867 (interactive)
868 (let* ((from (mew-summary-input-exchangeable-mark "Input mark from: "))
869 (to (mew-summary-input-exchangeable-mark "Input mark to: "))
870 (regex (mew-mark-regex from))
871 (case-fold-search nil))
872 (unless (char-equal from to)
873 (save-excursion
874 (goto-char (point-min))
875 (while (re-search-forward regex nil t)
876 (mew-summary-undo-one 'nomsg)
877 (mew-mark-put-mark to 'nomsg))
878 (forward-line)))))
879
880 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
881 ;;;
882 ;;; Clean up marks!
883 ;;;
884
885 (defun mew-mark-init ()
886 (add-hook 'kill-emacs-hook 'mew-sinfo-clean-up))
887
888 (defun mew-sinfo-clean-up ()
889 "Saving marks. Typically called by kill-emacs-hook."
890 (remove-hook 'kill-emacs-hook 'mew-sinfo-clean-up)
891 (mew-decode-syntax-delete)
892 (save-excursion
893 (dolist (buf mew-buffers)
894 (when (bufferp (get-buffer buf))
895 (set-buffer buf)
896 (when (mew-summary-p)
897 (mew-sinfo-save))))))
898
899 (provide 'mew-mark)
900
901 ;;; Copyright Notice:
902
903 ;; Copyright (C) 1997-2015 Mew developing team.
904 ;; All rights reserved.
905
906 ;; Redistribution and use in source and binary forms, with or without
907 ;; modification, are permitted provided that the following conditions
908 ;; are met:
909 ;;
910 ;; 1. Redistributions of source code must retain the above copyright
911 ;; notice, this list of conditions and the following disclaimer.
912 ;; 2. Redistributions in binary form must reproduce the above copyright
913 ;; notice, this list of conditions and the following disclaimer in the
914 ;; documentation and/or other materials provided with the distribution.
915 ;; 3. Neither the name of the team nor the names of its contributors
916 ;; may be used to endorse or promote products derived from this software
917 ;; without specific prior written permission.
918 ;;
919 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
920 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
921 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
922 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
923 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
924 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
925 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
926 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
927 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
928 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
929 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
930
931 ;;; mew-mark.el ends here