Debian Codegraph @

mew-virtual.el

raw
1 ;;; mew-virtual.el --- Virtual 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 ;;; Virtual info
13 ;;;
14
15 (defvar mew-vinfo-list
16 '("func" "lra" "top" "db" "column"
17 "mode" ;; 'selection or 'thread
18 "physical-folder"
19 "original-folder")) ;; tt back from Thread
20
21 (mew-blinfo-defun 'mew-vinfo mew-vinfo-list)
22
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;;
25 ;;; Virtual mode
26 ;;;
27
28 (defun mew-virtual-mode ()
29 "A major mode to visualize messages in a virtual folder.
30
31 \\{mew-summary-mode-map}"
32 (interactive)
33 (setq major-mode 'mew-virtual-mode)
34 (setq mode-line-buffer-identification (mew-mode-line-id))
35 (use-local-map mew-summary-mode-map)
36 (setq buffer-read-only t)
37 (setq truncate-lines t)
38 ;;
39 (if (boundp 'bidi-paragraph-direction)
40 (setq bidi-paragraph-direction 'left-to-right))
41 (make-local-variable 'tab-width)
42 (make-local-variable 'search-invisible)
43 (setq search-invisible nil)
44 (unless (mew-thread-p)
45 (jit-lock-register 'mew-summary-cook-region))
46 (mew-sinfo-set-disp-msg t)
47 ;;
48 (mew-summary-mode-name mew-mode-name-virtual)
49 (mew-summary-setup-mode-line)
50 (mew-summary-setup-decoration)
51 (mew-highlight-cursor-line)
52 (mew-run-mode-hooks 'mew-virtual-mode-hook))
53
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 ;;;
56 ;;; Making Virtual mode
57 ;;;
58
59 (defun mew-summary-selection-by-pick (&optional regionp)
60 "Making selection according to a specified pick pattern.
61 'mewl' or 'grep' is called as a picking command. If called with
62 '\\[universal-argument]', the target is the region."
63 (interactive "P")
64 (mew-pickable
65 (mew-summary-with-mewl
66 (let* ((ofolder (mew-summary-folder-name 'ext))
67 (vfolder (mew-folder-to-selection ofolder))
68 (pfolder (mew-summary-physical-folder))
69 (msgs (mew-summary-pick-msgs pfolder regionp))
70 (prompt (format "%s/%s virtual" mew-prog-mewl mew-prog-grep))
71 (prog mew-prog-grep)
72 (opts mew-prog-grep-opts)
73 mew-inherit-pick-mewlp
74 grepp pattern prog-opts-pat
75 rfolder lra)
76 (if (not msgs)
77 (message "No message")
78 (setq pattern (mew-input-pick-pattern prompt))
79 (cond
80 ((string= pattern "")
81 (setq prog-opts-pat (mew-input-pick-command prog opts))
82 (mew-set '(prog opts pattern) prog-opts-pat)
83 (setq grepp t))
84 (t
85 (setq pattern (mew-pick-canonicalize-pattern pattern))
86 (unless mew-inherit-pick-mewlp (setq grepp t))))
87 (if (and grepp (not (mew-which-exec prog)))
88 (message "'%s' not found" prog)
89 (setq rfolder (mew-expand-folder2 pfolder))
90 (setq lra (list (cons rfolder pfolder)))
91 (mew-summary-switch-to-folder vfolder)
92 (when (mew-summary-exclusive-p)
93 (mew-vinfo-set-mode 'selection)
94 (mew-vinfo-set-physical-folder pfolder)
95 (mew-vinfo-set-original-folder ofolder)
96 (cond
97 (grepp
98 (mew-sinfo-set-find-key pattern)
99 (message "Picking messages in %s..." pfolder)
100 (mew-summary-selection-by-pick-with-grep prog opts pattern pfolder msgs rfolder lra))
101 (t
102 (mew-sinfo-set-find-key nil)
103 (message "Picking messages in %s..." pfolder)
104 (mew-summary-selection-by-pick-with-mewl pattern pfolder msgs rfolder lra))))))))))
105
106 (defun mew-summary-selection-by-pick-with-mewl (pattern _folder src-msgs rfolder lra)
107 "Create selection with 'mewl'"
108 (let ((opts (list "-a" "-p" pattern "-b" mew-mail-path))
109 (range (mew-summary-pick-range src-msgs)))
110 (setq rfolder (mew-scan-mewl-folder rfolder))
111 (if range
112 (setq opts (nconc opts (list rfolder range)))
113 (setq opts (nconc opts (list rfolder))))
114 (mew-local-retrieve 'vir opts nil lra)))
115
116 (defun mew-summary-selection-by-pick-with-grep (prog opts pattern _folder msgs rfolder lra)
117 "Create selection with 'grep'"
118 (interactive)
119 (let ((file-rttl (mew-summary-selection-by-pick-with-grep1 prog opts pattern rfolder msgs))
120 file rttl func args)
121 (mew-set '(file rttl) file-rttl)
122 (setq func `(lambda () (mew-delete-file ,file)))
123 (setq args (list "-i" file))
124 (mew-local-retrieve 'vir args func lra nil rttl)))
125
126 (defun mew-summary-selection-by-pick-with-grep1 (prog opts pattern folder msgs)
127 (let ((dir (mew-expand-folder folder))
128 (file (mew-make-temp-name))
129 (rttl 0) nxt)
130 (if (= (length msgs) 1) (setq msgs (cons null-device msgs)))
131 (if pattern (setq pattern (mew-cs-encode-arg pattern)))
132 (with-temp-buffer
133 (mew-set-buffer-multibyte t)
134 (cd dir)
135 (mew-piolet mew-cs-text-for-read mew-cs-text-for-write
136 (mew-alet ;; xxx
137 (while msgs
138 (goto-char (point-max))
139 (setq nxt (nthcdr mew-prog-grep-max-msgs msgs))
140 (if nxt (mew-ntake mew-prog-grep-max-msgs msgs))
141 (apply 'call-process prog nil t nil
142 (append opts (and pattern (list pattern)) msgs))
143 (setq msgs nxt)))
144 (setq msgs nil)
145 (goto-char (point-min))
146 (while (re-search-forward mew-regex-message-files2 nil t)
147 (setq msgs (cons (mew-match-string 1) msgs))
148 (forward-line))
149 (setq msgs (mew-uniq-list msgs))
150 (setq msgs (mapcar 'string-to-number msgs))
151 (setq msgs (sort msgs '<))
152 (setq msgs (mapcar 'number-to-string msgs)))
153 (mew-erase-buffer)
154 (setq rttl (length msgs))
155 (insert "CD: " folder "\n")
156 (mapc (lambda (x) (insert (mew-msg-get-filename x) "\n")) msgs)
157 (mew-frwlet mew-cs-text-for-read mew-cs-text-for-write
158 (write-region (point-min) (point-max) file nil 'no-msg))
159 (list file rttl))))
160
161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
162 ;;;
163 ;;; mark virtual
164 ;;;
165
166 (defun mew-summary-selection-by-mark (&optional ask-mark)
167 "Making selection for messages marked with '*'.
168 If called with '\\[universal-argument]', you can specify a target mark."
169 (interactive "P")
170 (if (not (mew-pickable))
171 (message "This command cannot be used in this folder")
172 (let* ((ofolder (mew-summary-folder-name 'ext))
173 (vfolder (mew-folder-to-selection ofolder))
174 (pfolder (mew-summary-physical-folder))
175 (mark mew-mark-review)
176 (start (point))
177 (case-fold-search nil)
178 beg line med regex)
179 (if ask-mark (setq mark (mew-input-mark)))
180 (setq regex (mew-mark-regex mark))
181 ;;
182 (mew-summary-switch-to-folder vfolder)
183 (mew-vinfo-set-mode 'selection)
184 (mew-vinfo-set-physical-folder pfolder)
185 (mew-vinfo-set-original-folder ofolder)
186 (mew-erase-buffer)
187 ;;
188 (set-buffer pfolder)
189 (goto-char (point-min))
190 (while (re-search-forward regex nil t)
191 (beginning-of-line)
192 (setq beg (point))
193 (forward-line)
194 ;; This must be buffer-substring
195 (setq line (buffer-substring beg (point)))
196 (with-current-buffer vfolder
197 (mew-elet
198 (insert line)
199 (save-excursion
200 (when (and (search-backward "\r")
201 (setq med (point))
202 (looking-at mew-regex-sumsyn-short))
203 (goto-char (match-beginning 1))
204 (insert pfolder)
205 (put-text-property med (point) 'invisible t))))))
206 (goto-char start)
207 (set-buffer vfolder)
208 (mew-summary-set-count-line)
209 ;; Unmarking in both Summary and Thread
210 (if (char-equal mark mew-mark-review)
211 (mew-mark-undo-mark mark 'no-msg 'virtual-only)))))
212
213 (provide 'mew-virtual)
214
215 ;;; Copyright Notice:
216
217 ;; Copyright (C) 1996-2015 Mew developing team.
218 ;; All rights reserved.
219
220 ;; Redistribution and use in source and binary forms, with or without
221 ;; modification, are permitted provided that the following conditions
222 ;; are met:
223 ;;
224 ;; 1. Redistributions of source code must retain the above copyright
225 ;; notice, this list of conditions and the following disclaimer.
226 ;; 2. Redistributions in binary form must reproduce the above copyright
227 ;; notice, this list of conditions and the following disclaimer in the
228 ;; documentation and/or other materials provided with the distribution.
229 ;; 3. Neither the name of the team nor the names of its contributors
230 ;; may be used to endorse or promote products derived from this software
231 ;; without specific prior written permission.
232 ;;
233 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
234 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
235 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
236 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
237 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
238 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
239 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
240 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
241 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
242 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
243 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
244
245 ;;; mew-virtual.el ends here