Mercurial > emacs
annotate lisp/mail/mh-utils.el @ 24561:6f4ae209bbac
(dumpglyphs): Be sure to fill the whole background of
glyphs.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 05 Apr 1999 06:47:41 +0000 |
parents | 8532b00fb743 |
children | 869c9511ad3c |
rev | line source |
---|---|
6365 | 1 ;;; mh-utils.el --- mh-e code needed for both sending and reading |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
2 ;; Time-stamp: <95/10/22 17:58:16 gildea> |
6365 | 3 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
4 ;; Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc. |
6365 | 5 |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
6 ;; This file is part of mh-e, part of GNU Emacs. |
6365 | 7 |
11333 | 8 ;; GNU Emacs is free software; you can redistribute it and/or modify |
6365 | 9 ;; it under the terms of the GNU General Public License as published by |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
11333 | 13 ;; GNU Emacs is distributed in the hope that it will be useful, |
6365 | 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
14169 | 19 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 ;; Boston, MA 02111-1307, USA. | |
6365 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; Internal support for mh-e package. | |
26 | |
27 ;;; Code: | |
28 | |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
29 ;;; Set for local environment: |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
30 ;;; mh-progs and mh-lib used to be set in paths.el, which tried to |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
31 ;;; figure out at build time which of several possible directories MH |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
32 ;;; was installed into. But if you installed MH after building Emacs, |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
33 ;;; this would almost certainly be wrong, so now we do it at run time. |
6365 | 34 |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
35 (defvar mh-progs nil |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
36 "Directory containing MH commands, such as inc, repl, and rmm.") |
6365 | 37 |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
38 (defvar mh-lib nil |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
39 "Directory containing the MH library. |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
40 This directory contains, among other things, |
24420 | 41 the components file.") |
42 | |
43 (defvar mh-lib-progs nil | |
44 "Directory containing MH helper programs. | |
45 This directory contains, among other things, | |
46 the mhl program.") | |
47 | |
48 (defvar mh-nmh-p nil | |
49 "Non-nil if nmh is installed on this system instead of MH") | |
6365 | 50 |
11331 | 51 ;;;###autoload |
52 (put 'mh-progs 'risky-local-variable t) | |
53 ;;;###autoload | |
54 (put 'mh-lib 'risky-local-variable t) | |
24420 | 55 ;;;###autoload |
56 (put 'mh-lib-progs 'risky-local-variable t) | |
57 ;;;###autoload | |
58 (put 'mh-nmh-p 'risky-local-variable t) | |
11331 | 59 |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
60 ;;; User preferences: |
6365 | 61 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
62 (defgroup mh-buffer nil |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
63 "Layout of MH-E buffers" |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
64 :prefix "mh-" |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
65 :group 'mh) |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
66 |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
67 |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
68 (defcustom mh-auto-folder-collect t |
6365 | 69 "*Whether to start collecting MH folder names immediately in the background. |
70 Non-nil means start a background process collecting the names of all | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
71 folders as soon as mh-e is loaded." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
72 :type 'boolean |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
73 :group 'mh) |
6365 | 74 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
75 (defcustom mh-recursive-folders nil |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
76 "*If non-nil, then commands which operate on folders do so recursively." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
77 :type 'boolean |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
78 :group 'mh) |
6365 | 79 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
80 (defcustom mh-clean-message-header nil |
6365 | 81 "*Non-nil means clean headers of messages that are displayed or inserted. |
82 The variables `mh-visible-headers' and `mh-invisible-headers' control what | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
83 is removed." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
84 :type 'boolean |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
85 :group 'mh-buffer) |
6365 | 86 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
87 (defcustom mh-visible-headers nil |
6365 | 88 "*If non-nil, contains a regexp specifying the headers to keep when cleaning. |
89 Only used if `mh-clean-message-header' is non-nil. Setting this variable | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
90 overrides `mh-invisible-headers'." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
91 :type '(choice (const nil) regexp) |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
92 :group 'mh-buffer) |
6365 | 93 |
94 (defvar mh-invisible-headers | |
11331 | 95 "^Received: \\|^Message-Id: \\|^Remailed-\\|^Via: \\|^Mail-from: \\|^Return-Path: \\|^Delivery-Date: \\|^In-Reply-To: \\|^Resent-" |
6365 | 96 "Regexp matching lines in a message header that are not to be shown. |
97 If `mh-visible-headers' is non-nil, it is used instead to specify what | |
98 to keep.") | |
99 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
100 (defcustom mh-bury-show-buffer t |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
101 "*Non-nil means that the displayed show buffer for a folder is buried." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
102 :type 'boolean |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
103 :group 'mh-buffer) |
6365 | 104 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
105 (defcustom mh-summary-height 4 |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
106 "*Number of lines in MH-Folder window (including the mode line)." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
107 :type 'integer |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
108 :group 'mh-buffer) |
6365 | 109 |
110 (defvar mh-msg-number-regexp "^ *\\([0-9]+\\)" | |
111 "Regexp to find the number of a message in a scan line. | |
112 The message's number must be surrounded with \\( \\)") | |
113 | |
114 (defvar mh-msg-search-regexp "^[^0-9]*%d[^0-9]" | |
115 "Format string containing a regexp matching the scan listing for a message. | |
116 The desired message's number will be an argument to format.") | |
117 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
118 (defcustom mhl-formfile nil |
6365 | 119 "*Name of format file to be used by mhl to show and print messages. |
120 A value of T means use the default format file. | |
121 Nil means don't use mhl to format messages when showing; mhl is still used, | |
122 with the default format file, to format messages when printing them. | |
123 The format used should specify a non-zero value for overflowoffset so | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
124 the message continues to conform to RFC 822 and mh-e can parse the headers." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
125 :type '(choice (const nil) (const t) string) |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17243
diff
changeset
|
126 :group 'mh) |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
127 (put 'mhl-formfile 'info-file "mh-e") |
6365 | 128 |
11331 | 129 (defvar mh-default-folder-for-message-function nil |
130 "Function to select a default folder for refiling or Fcc. | |
131 If set to a function, that function is called with no arguments by | |
132 `\\[mh-refile-msg]' and `\\[mh-to-fcc]' to get a default when | |
133 prompting the user for a folder. The function is called from within a | |
134 save-excursion, with point at the start of the message. It should | |
135 return the folder to offer as the refile or Fcc folder, as a string | |
136 with a leading `+' sign. It can also return an empty string to use no | |
137 default, or NIL to calculate the default the usual way. | |
138 NOTE: This variable is not an ordinary hook; | |
139 It may not be a list of functions.") | |
6365 | 140 |
11331 | 141 (defvar mh-find-path-hook nil |
142 "Invoked by mh-find-path while reading the user's MH profile.") | |
143 | |
144 (defvar mh-folder-list-change-hook nil | |
145 "Invoked whenever the cached folder list `mh-folder-list' is changed.") | |
146 | |
147 (defvar mh-show-buffer-mode-line-buffer-id "{show-%s} %d" | |
148 "Format string to produce `mode-line-buffer-identification' for show buffers. | |
149 First argument is folder name. Second is message number.") | |
6365 | 150 |
151 (defvar mh-cmd-note 4 | |
152 "Offset to insert notation.") | |
153 | |
11331 | 154 (defvar mh-note-seq "%" |
155 "String whose first character is used to notate messages in a sequence.") | |
156 | |
157 ;;; Internal bookkeeping variables: | |
6365 | 158 |
11331 | 159 ;; The value of `mh-folder-list-change-hook' is called whenever |
160 ;; mh-folder-list variable is set. | |
161 (defvar mh-folder-list nil) ;List of folder names for completion. | |
162 | |
163 ;; Cached value of the `Path:' component in the user's MH profile. | |
164 (defvar mh-user-path nil) ;User's mail folder directory. | |
6365 | 165 |
11331 | 166 ;; An mh-draft-folder of NIL means do not use a draft folder. |
167 ;; Cached value of the `Draft-Folder:' component in the user's MH profile. | |
168 (defvar mh-draft-folder nil) ;Name of folder containing draft messages. | |
169 | |
170 ;; Cached value of the `Unseen-Sequence:' component in the user's MH profile. | |
171 (defvar mh-unseen-seq nil) ;Name of the Unseen sequence. | |
6365 | 172 |
11331 | 173 ;; Cached value of the `Previous-Sequence:' component in the user's MH profile. |
174 (defvar mh-previous-seq nil) ;Name of the Previous sequence. | |
6365 | 175 |
11331 | 176 ;; Cached value of the `Inbox:' component in the user's MH profile, |
177 ;; or "+inbox" if no such component. | |
178 (defvar mh-inbox nil) ;Name of the Inbox folder. | |
6365 | 179 |
11331 | 180 (defconst mh-temp-buffer " *mh-temp*") ;Name of mh-e scratch buffer. |
181 | |
182 (defvar mh-previous-window-config nil) ;Window configuration before mh-e command. | |
183 | |
184 ;;; Internal variables local to a folder. | |
6365 | 185 |
11331 | 186 (defvar mh-current-folder nil) ;Name of current folder, a string. |
187 | |
188 (defvar mh-show-buffer nil) ;Buffer that displays message for this folder. | |
6365 | 189 |
11331 | 190 (defvar mh-folder-filename nil) ;Full path of directory for this folder. |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
191 |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
192 (defvar mh-msg-count nil) ;Number of msgs in buffer. |
11331 | 193 |
194 (defvar mh-showing nil) ;If non-nil, show the message in a separate window. | |
6365 | 195 |
11331 | 196 ;;; This holds a documentation string used by describe-mode. |
197 (defun mh-showing () | |
198 "When moving to a new message in the Folder window, | |
199 also show it in a separate Show window." | |
200 nil) | |
6365 | 201 |
11331 | 202 (defvar mh-seq-list nil) ;The sequences of this folder. An alist of (seq . msgs). |
203 | |
204 (defvar mh-seen-list nil) ;List of displayed messages to be removed from the Unseen sequence. | |
6365 | 205 |
11331 | 206 ;; If non-nil, show buffer contains message with all headers. |
207 ;; If nil, show buffer contains message processed normally. | |
208 (defvar mh-showing-with-headers nil) ;Showing message with headers or normally. | |
6365 | 209 |
210 | |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
211 ;;; mh-e macros |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
212 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
213 (defmacro with-mh-folder-updating (save-modification-flag-p &rest body) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
214 ;; Format is (with-mh-folder-updating (SAVE-MODIFICATION-FLAG-P) &body BODY). |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
215 ;; Execute BODY, which can modify the folder buffer without having to |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
216 ;; worry about file locking or the read-only flag, and return its result. |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
217 ;; If SAVE-MODIFICATION-FLAG-P is non-nil, the buffer's modification |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
218 ;; flag is unchanged, otherwise it is cleared. |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
219 (setq save-modification-flag-p (car save-modification-flag-p)) ; CL style |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
220 (` (prog1 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
221 (let ((mh-folder-updating-mod-flag (buffer-modified-p)) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
222 (buffer-read-only nil) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
223 (buffer-file-name nil)) ;don't let the buffer get locked |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
224 (prog1 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
225 (progn |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
226 (,@ body)) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
227 (mh-set-folder-modified-p mh-folder-updating-mod-flag))) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
228 (,@ (if (not save-modification-flag-p) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
229 '((mh-set-folder-modified-p nil))))))) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
230 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
231 (put 'with-mh-folder-updating 'lisp-indent-hook 1) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
232 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
233 (defmacro mh-in-show-buffer (show-buffer &rest body) |
11331 | 234 ;; Format is (mh-in-show-buffer (SHOW-BUFFER) &body BODY). |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
235 ;; Display buffer SHOW-BUFFER in other window and execute BODY in it. |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
236 ;; Stronger than save-excursion, weaker than save-window-excursion. |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
237 (setq show-buffer (car show-buffer)) ; CL style |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
238 (` (let ((mh-in-show-buffer-saved-window (selected-window))) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
239 (switch-to-buffer-other-window (, show-buffer)) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
240 (if mh-bury-show-buffer (bury-buffer (current-buffer))) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
241 (unwind-protect |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
242 (progn |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
243 (,@ body)) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
244 (select-window mh-in-show-buffer-saved-window))))) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
245 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
246 (put 'mh-in-show-buffer 'lisp-indent-hook 1) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
247 |
11331 | 248 (defmacro mh-make-seq (name msgs) (list 'cons name msgs)) |
249 | |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
250 (defmacro mh-seq-name (pair) (list 'car pair)) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
251 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
252 (defmacro mh-seq-msgs (pair) (list 'cdr pair)) |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
253 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
254 |
6365 | 255 ;;; Ensure new buffers won't get this mode if default-major-mode is nil. |
256 (put 'mh-show-mode 'mode-class 'special) | |
257 | |
258 (defun mh-show-mode () | |
259 "Major mode for showing messages in mh-e. | |
260 The value of mh-show-mode-hook is called when a new message is displayed." | |
261 (kill-all-local-variables) | |
262 (setq major-mode 'mh-show-mode) | |
263 (mh-set-mode-name "MH-Show") | |
264 (run-hooks 'mh-show-mode-hook)) | |
265 | |
266 | |
267 (defun mh-maybe-show (&optional msg) | |
268 ;; If in showing mode, then display the message pointed to by the cursor. | |
269 (if mh-showing (mh-show msg))) | |
270 | |
11331 | 271 (defun mh-show (&optional message) |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
272 "Show MESSAGE (default: message at cursor). |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
273 Force a two-window display with the folder window on top (size |
6365 | 274 mh-summary-height) and the show buffer below it. |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
275 If the message is already visible, display the start of the message. |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
276 |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
277 Display of the message is controlled by setting the variables |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
278 `mh-clean-message-header' and `mhl-formfile'. The default behavior is |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
279 to scroll uninteresting headers off the top of the window. |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
280 Type \"\\[mh-header-display]\" to see the message with all its headers." |
6365 | 281 (interactive) |
282 (and mh-showing-with-headers | |
283 (or mhl-formfile mh-clean-message-header) | |
284 (mh-invalidate-show-buffer)) | |
11331 | 285 (mh-show-msg message)) |
6365 | 286 |
287 | |
288 (defun mh-show-msg (msg) | |
289 (if (not msg) | |
290 (setq msg (mh-get-msg-num t))) | |
291 (setq mh-showing t) | |
292 (let ((folder mh-current-folder) | |
293 (clean-message-header mh-clean-message-header) | |
294 (show-window (get-buffer-window mh-show-buffer))) | |
18926
e597d4b325df
Change eql calls to eq.
Richard M. Stallman <rms@gnu.org>
parents:
18901
diff
changeset
|
295 (if (not (eq (next-window (minibuffer-window)) (selected-window))) |
6365 | 296 (delete-other-windows)) ; force ourself to the top window |
297 (mh-in-show-buffer (mh-show-buffer) | |
298 (if (and show-window | |
299 (equal (mh-msg-filename msg folder) buffer-file-name)) | |
300 (progn ;just back up to start | |
301 (goto-char (point-min)) | |
302 (if (not clean-message-header) | |
303 (mh-start-of-uncleaned-message))) | |
304 (mh-display-msg msg folder)))) | |
305 (if (not (= (1+ (window-height)) (screen-height))) ;not horizontally split | |
306 (shrink-window (- (window-height) mh-summary-height))) | |
307 (mh-recenter nil) | |
308 (if (not (memq msg mh-seen-list)) (setq mh-seen-list (cons msg mh-seen-list))) | |
309 (run-hooks 'mh-show-hook)) | |
310 | |
311 | |
312 (defun mh-display-msg (msg-num folder) | |
313 ;; Display message NUMBER of FOLDER. | |
314 ;; Sets the current buffer to the show buffer. | |
315 (set-buffer folder) | |
316 ;; Bind variables in folder buffer in case they are local | |
317 (let ((formfile mhl-formfile) | |
318 (clean-message-header mh-clean-message-header) | |
319 (invisible-headers mh-invisible-headers) | |
320 (visible-headers mh-visible-headers) | |
321 (msg-filename (mh-msg-filename msg-num)) | |
322 (show-buffer mh-show-buffer)) | |
323 (if (not (file-exists-p msg-filename)) | |
324 (error "Message %d does not exist" msg-num)) | |
325 (set-buffer show-buffer) | |
326 (cond ((not (equal msg-filename buffer-file-name)) | |
11331 | 327 (mh-unvisit-file) |
6365 | 328 (erase-buffer) |
11331 | 329 ;; Changing contents, so this hook needs to be reinitialized. |
330 ;; pgp.el uses this. | |
331 (if (boundp 'write-contents-hooks) ;Emacs 19 | |
14118
e7809b53da4d
(mh-display-msg): Use kill-local-variable
Karl Heuer <kwzh@gnu.org>
parents:
13386
diff
changeset
|
332 (kill-local-variable 'write-contents-hooks)) |
6365 | 333 (if formfile |
334 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" | |
335 (if (stringp formfile) | |
336 (list "-form" formfile)) | |
337 msg-filename) | |
338 (insert-file-contents msg-filename)) | |
339 (goto-char (point-min)) | |
340 (cond (clean-message-header | |
341 (mh-clean-msg-header (point-min) | |
342 invisible-headers | |
343 visible-headers) | |
344 (goto-char (point-min))) | |
345 (t | |
346 (mh-start-of-uncleaned-message))) | |
11331 | 347 ;; the parts of visiting we want to do (no locking) |
6365 | 348 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs |
349 (setq buffer-undo-list nil)) | |
11331 | 350 (set-buffer-modified-p nil) |
351 (set-buffer-auto-saved) | |
352 ;; the parts of set-visited-file-name we want to do (no locking) | |
6365 | 353 (setq buffer-file-name msg-filename) |
11331 | 354 (setq buffer-backed-up nil) |
355 (auto-save-mode 1) | |
6365 | 356 (set-mark nil) |
357 (mh-show-mode) | |
358 (setq mode-line-buffer-identification | |
359 (list (format mh-show-buffer-mode-line-buffer-id | |
360 folder msg-num))) | |
361 (set-buffer folder) | |
362 (setq mh-showing-with-headers nil))))) | |
363 | |
364 (defun mh-start-of-uncleaned-message () | |
365 ;; position uninteresting headers off the top of the window | |
366 (let ((case-fold-search t)) | |
367 (re-search-forward | |
11331 | 368 "^To:\\|^Cc:\\|^From:\\|^Subject:\\|^Date:" nil t) |
6365 | 369 (beginning-of-line) |
370 (mh-recenter 0))) | |
371 | |
372 | |
373 (defun mh-invalidate-show-buffer () | |
374 ;; Invalidate the show buffer so we must update it to use it. | |
375 (if (get-buffer mh-show-buffer) | |
376 (save-excursion | |
377 (set-buffer mh-show-buffer) | |
11331 | 378 (mh-unvisit-file)))) |
6365 | 379 |
380 | |
11331 | 381 (defun mh-unvisit-file () |
382 ;; Separate current buffer from the message file it was visiting. | |
383 (or (not (buffer-modified-p)) | |
384 (null buffer-file-name) ;we've been here before | |
385 (yes-or-no-p (format "Message %s modified; flush changes? " | |
386 (file-name-nondirectory buffer-file-name))) | |
387 (error "Flushing changes not confirmed")) | |
388 (clear-visited-file-modtime) | |
389 (unlock-buffer) | |
390 (setq buffer-file-name nil)) | |
391 | |
392 | |
6365 | 393 (defun mh-get-msg-num (error-if-no-message) |
394 ;; Return the message number of the displayed message. If the argument | |
395 ;; ERROR-IF-NO-MESSAGE is non-nil, then complain if the cursor is not | |
396 ;; pointing to a message. | |
397 (save-excursion | |
398 (beginning-of-line) | |
399 (cond ((looking-at mh-msg-number-regexp) | |
400 (string-to-int (buffer-substring (match-beginning 1) | |
401 (match-end 1)))) | |
402 (error-if-no-message | |
403 (error "Cursor not pointing to message")) | |
404 (t nil)))) | |
405 | |
406 | |
407 (defun mh-msg-filename (msg &optional folder) | |
408 ;; Return the file name of MESSAGE in FOLDER (default current folder). | |
409 (expand-file-name (int-to-string msg) | |
410 (if folder | |
411 (mh-expand-file-name folder) | |
412 mh-folder-filename))) | |
413 | |
414 | |
415 (defun mh-clean-msg-header (start invisible-headers visible-headers) | |
416 ;; Flush extraneous lines in a message header, from the given POINT to the | |
417 ;; end of the message header. If VISIBLE-HEADERS is non-nil, it contains a | |
418 ;; regular expression specifying the lines to display, otherwise | |
419 ;; INVISIBLE-HEADERS contains a regular expression specifying lines to | |
420 ;; delete from the header. | |
421 (let ((case-fold-search t)) | |
422 (save-restriction | |
423 (goto-char start) | |
424 (if (search-forward "\n\n" nil 'move) | |
425 (backward-char 1)) | |
426 (narrow-to-region start (point)) | |
427 (goto-char (point-min)) | |
428 (if visible-headers | |
429 (while (< (point) (point-max)) | |
430 (cond ((looking-at visible-headers) | |
431 (forward-line 1) | |
432 (while (looking-at "[ \t]") (forward-line 1))) | |
433 (t | |
434 (mh-delete-line 1) | |
435 (while (looking-at "[ \t]") | |
436 (mh-delete-line 1))))) | |
437 (while (re-search-forward invisible-headers nil t) | |
438 (beginning-of-line) | |
439 (mh-delete-line 1) | |
440 (while (looking-at "[ \t]") | |
441 (mh-delete-line 1)))) | |
442 (unlock-buffer)))) | |
443 | |
444 | |
445 (defun mh-recenter (arg) | |
446 ;; Like recenter but with two improvements: nil arg means recenter, | |
447 ;; and only does anything if the current buffer is in the selected | |
448 ;; window. (Commands like save-some-buffers can make this false.) | |
18926
e597d4b325df
Change eql calls to eq.
Richard M. Stallman <rms@gnu.org>
parents:
18901
diff
changeset
|
449 (if (eq (get-buffer-window (current-buffer)) |
e597d4b325df
Change eql calls to eq.
Richard M. Stallman <rms@gnu.org>
parents:
18901
diff
changeset
|
450 (selected-window)) |
6365 | 451 (recenter (if arg arg '(t))))) |
452 | |
453 | |
454 (defun mh-delete-line (lines) | |
455 ;; Delete version of kill-line. | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
456 (delete-region (point) (progn (forward-line lines) (point)))) |
6365 | 457 |
458 | |
459 (defun mh-notate (msg notation offset) | |
460 ;; Marks MESSAGE with the character NOTATION at position OFFSET. | |
461 ;; Null MESSAGE means the message that the cursor points to. | |
462 (save-excursion | |
463 (if (or (null msg) | |
464 (mh-goto-msg msg t t)) | |
465 (with-mh-folder-updating (t) | |
466 (beginning-of-line) | |
467 (forward-char offset) | |
468 (delete-char 1) | |
469 (insert notation))))) | |
470 | |
471 | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
472 (defun mh-find-msg-get-num (step) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
473 ;; Return the message number of the message on the current scan line |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
474 ;; or one nearby. Jumps over non-message lines, such as inc errors. |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
475 ;; STEP tells whether to search forward or backward if we have to search. |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
476 (or (mh-get-msg-num nil) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
477 (let ((msg-num nil) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
478 (nreverses 0)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
479 (while (and (not msg-num) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
480 (< nreverses 2)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
481 (cond ((eobp) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
482 (setq step -1) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
483 (setq nreverses (1+ nreverses))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
484 ((bobp) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
485 (setq step 1) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
486 (setq nreverses (1+ nreverses)))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
487 (forward-line step) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
488 (setq msg-num (mh-get-msg-num nil))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
489 msg-num))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
490 |
6365 | 491 (defun mh-goto-msg (number &optional no-error-if-no-message dont-show) |
492 "Position the cursor at message NUMBER. | |
11331 | 493 Optional non-nil second argument means return nil instead of |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
494 signaling an error if message does not exist; in this case, |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
495 the cursor is positioned near where the message would have been. |
11331 | 496 Non-nil third argument means not to show the message." |
497 (interactive "NGo to message: ") | |
498 (setq number (prefix-numeric-value number)) ;Emacs 19 | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
499 ;; This basic routine tries to be as fast as possible, |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
500 ;; using a binary search and minimal regexps. |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
501 (let ((cur-msg (mh-find-msg-get-num -1)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
502 (jump-size mh-msg-count)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
503 (while (and (> jump-size 1) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
504 cur-msg |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
505 (not (eq cur-msg number))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
506 (cond ((< cur-msg number) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
507 (setq jump-size (min (- number cur-msg) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
508 (ash (1+ jump-size) -1))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
509 (forward-line jump-size) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
510 (setq cur-msg (mh-find-msg-get-num 1))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
511 (t |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
512 (setq jump-size (min (- cur-msg number) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
513 (ash (1+ jump-size) -1))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
514 (forward-line (- jump-size)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
515 (setq cur-msg (mh-find-msg-get-num -1))))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
516 (if (eq cur-msg number) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
517 (progn |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
518 (beginning-of-line) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
519 (or dont-show |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
520 (mh-maybe-show number) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
521 t)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
522 (if (not no-error-if-no-message) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
523 (error "No message %d" number))))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
524 |
6365 | 525 |
526 (defun mh-msg-search-pat (n) | |
527 ;; Return a search pattern for message N in the scan listing. | |
528 (format mh-msg-search-regexp n)) | |
529 | |
530 | |
11331 | 531 (defun mh-get-profile-field (field) |
532 ;; Find and return the value of FIELD in the current buffer. | |
533 ;; Returns NIL if the field is not in the buffer. | |
534 (let ((case-fold-search t)) | |
535 (goto-char (point-min)) | |
536 (cond ((not (re-search-forward (format "^%s" field) nil t)) nil) | |
537 ((looking-at "[\t ]*$") nil) | |
538 (t | |
539 (re-search-forward "[\t ]*\\([^\t \n].*\\)$" nil t) | |
540 (let ((start (match-beginning 1))) | |
541 (end-of-line) | |
542 (buffer-substring start (point))))))) | |
543 | |
15531
84b8ad02c07c
(mail-user-agent): Replaces mua-paradigm.
Richard M. Stallman <rms@gnu.org>
parents:
14426
diff
changeset
|
544 (defvar mail-user-agent 'mh-e-user-agent) ;from reporter.el 3.2 |
11331 | 545 |
6365 | 546 (defun mh-find-path () |
24420 | 547 ;; Set mh-progs, mh-lib, and mh-libs-progs |
6365 | 548 ;; (This step is necessary if MH was installed after this Emacs was dumped.) |
11331 | 549 ;; From profile file, set mh-user-path, mh-draft-folder, |
550 ;; mh-unseen-seq, mh-previous-seq, mh-inbox. | |
6365 | 551 (mh-find-progs) |
552 (save-excursion | |
553 ;; Be sure profile is fully expanded before switching buffers | |
554 (let ((profile (expand-file-name (or (getenv "MH") "~/.mh_profile")))) | |
11331 | 555 (set-buffer (get-buffer-create mh-temp-buffer)) |
6365 | 556 (setq buffer-offer-save nil) ;for people who set default to t |
557 (erase-buffer) | |
558 (condition-case err | |
559 (insert-file-contents profile) | |
560 (file-error | |
561 (mh-install profile err))) | |
11331 | 562 (setq mh-user-path (mh-get-profile-field "Path:")) |
563 (if (not mh-user-path) | |
6365 | 564 (setq mh-user-path "Mail")) |
565 (setq mh-user-path | |
566 (file-name-as-directory | |
567 (expand-file-name mh-user-path (expand-file-name "~")))) | |
11331 | 568 (setq mh-draft-folder (mh-get-profile-field "Draft-Folder:")) |
569 (if mh-draft-folder | |
570 (progn | |
571 (if (not (mh-folder-name-p mh-draft-folder)) | |
572 (setq mh-draft-folder (format "+%s" mh-draft-folder))) | |
573 (if (not (file-exists-p (mh-expand-file-name mh-draft-folder))) | |
574 (error "Draft folder \"%s\" not found. Create it and try again." | |
575 (mh-expand-file-name mh-draft-folder))))) | |
576 (setq mh-inbox (mh-get-profile-field "Inbox:")) | |
577 (cond ((not mh-inbox) | |
578 (setq mh-inbox "+inbox")) | |
579 ((not (mh-folder-name-p mh-inbox)) | |
580 (setq mh-inbox (format "+%s" mh-inbox)))) | |
581 (setq mh-unseen-seq (mh-get-profile-field "Unseen-Sequence:")) | |
582 (if mh-unseen-seq | |
583 (setq mh-unseen-seq (intern mh-unseen-seq)) | |
584 (setq mh-unseen-seq 'unseen)) ;old MH default? | |
585 (setq mh-previous-seq (mh-get-profile-field "Previous-Sequence:")) | |
586 (if mh-previous-seq | |
587 (setq mh-previous-seq (intern mh-previous-seq))) | |
15531
84b8ad02c07c
(mail-user-agent): Replaces mua-paradigm.
Richard M. Stallman <rms@gnu.org>
parents:
14426
diff
changeset
|
588 (setq mail-user-agent 'mh-e-user-agent) |
18901
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
589 (run-hooks 'mh-find-path-hook))) |
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
590 (and mh-auto-folder-collect |
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
591 (let ((mh-no-install t)) ;only get folders if MH installed |
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
592 (condition-case err |
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
593 (mh-make-folder-list-background) |
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
594 (file-error))))) ;so don't complain if not installed |
6365 | 595 |
17893
ad5fda4d4c36
(mh-file-command-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
596 (defun mh-file-command-p (file) |
ad5fda4d4c36
(mh-file-command-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
597 "Return t if file FILE is the name of a executable regular file." |
ad5fda4d4c36
(mh-file-command-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
598 (and (file-regular-p file) (file-executable-p file))) |
ad5fda4d4c36
(mh-file-command-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
599 |
6365 | 600 (defun mh-find-progs () |
17893
ad5fda4d4c36
(mh-file-command-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
601 "Find the `inc' and `mhl' programs of MH. |
24420 | 602 Set the `mh-progs' and `mh-lib', and `mh-lib-progs' variables to the |
603 directory names." | |
17893
ad5fda4d4c36
(mh-file-command-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
604 (or (and mh-progs (mh-file-command-p (expand-file-name "inc" mh-progs))) |
6365 | 605 (setq mh-progs |
606 (or (mh-path-search exec-path "inc") | |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
607 (mh-path-search '("/usr/local/bin/mh/" |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
608 "/usr/local/mh/" |
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
609 "/usr/bin/mh/" ;Ultrix 4.2 |
6365 | 610 "/usr/new/mh/" ;Ultrix <4.2 |
11331 | 611 "/usr/contrib/mh/bin/" ;BSDI |
24420 | 612 "/usr/pkg/bin/" ; NetBSD |
11331 | 613 "/usr/local/bin/" |
6856
396254137b30
(mh-progs, mh-lib): Move from mh-e.el
Richard M. Stallman <rms@gnu.org>
parents:
6365
diff
changeset
|
614 ) |
17893
ad5fda4d4c36
(mh-file-command-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
615 "inc")))) |
24420 | 616 (or (null mh-progs) |
617 (let ((mh-base mh-progs)) | |
618 (while (let ((dir-name (file-name-nondirectory | |
619 (directory-file-name mh-base)))) | |
620 (or (string= "mh" dir-name) | |
621 (string= "bin" dir-name))) | |
622 (setq mh-base | |
623 (file-name-directory (directory-file-name mh-base)))) | |
624 (or (and mh-lib | |
625 (file-exists-p (expand-file-name "components" mh-lib))) | |
626 (setq mh-lib | |
627 ;; Look for a lib directory roughly parallel to the bin | |
628 ;; directory: Strip any trailing `mh' or `bin' path | |
629 ;; components, then look for lib/mh or mh/lib. | |
630 (or (mh-path-search | |
631 (list (expand-file-name "lib/mh" mh-base) | |
632 (expand-file-name "etc/nmh" mh-base) ; NetBSD | |
633 (expand-file-name "mh/lib" mh-base)) | |
634 "components" | |
635 'file-exists-p)))) | |
636 (or (and mh-lib-progs | |
637 (mh-file-command-p (expand-file-name "mhl" mh-lib-progs))) | |
638 (setq mh-lib-progs | |
639 (or (mh-path-search | |
640 (list (expand-file-name "lib/mh" mh-base) | |
641 (expand-file-name "libexec/nmh" mh-base) ; NetBSD | |
642 (expand-file-name "mh/lib" mh-base)) | |
643 "mhl") | |
644 (mh-path-search '("/usr/local/bin/mh/") "mhl") | |
645 (mh-path-search exec-path "mhl") ;unlikely | |
646 ))))) | |
647 (unless (and mh-progs mh-lib mh-lib-progs) | |
648 (error "Cannot find the commands `inc' and `mhl' and the file `components'")) | |
649 (setq mh-nmh-p (not (null | |
650 (or (string-match "nmh" mh-lib-progs) | |
651 (string-match "nmh" mh-lib)))))) | |
22637
030c40f7d202
(mh-find-progs): Avoid WTA error
Richard M. Stallman <rms@gnu.org>
parents:
21164
diff
changeset
|
652 |
24420 | 653 (defun mh-path-search (path file &optional func-p) |
6365 | 654 ;; Search PATH, a list of directory names, for FILE. |
655 ;; Returns the element of PATH that contains FILE, or nil if not found. | |
656 (while (and path | |
24420 | 657 (not (funcall (or func-p 'mh-file-command-p) |
658 (expand-file-name file (car path))))) | |
6365 | 659 (setq path (cdr path))) |
660 (car path)) | |
661 | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
662 (defvar mh-no-install nil) ;do not run install-mh |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
663 |
6365 | 664 (defun mh-install (profile error-val) |
665 ;; Called to do error recovery if we fail to read the profile file. | |
666 ;; If possible, initialize the MH environment. | |
667 (if (or (getenv "MH") | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
668 (file-exists-p profile) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
669 mh-no-install) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
670 (signal (car error-val) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
671 (list (format "Cannot read MH profile \"%s\"" profile) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
672 (car (cdr (cdr error-val)))))) |
6365 | 673 ;; The "install-mh" command will output a short note which |
674 ;; mh-exec-cmd will display to the user. | |
11331 | 675 ;; The MH 5 version of install-mh might try prompt the user |
676 ;; for information, which would fail here. | |
24420 | 677 (mh-exec-cmd (expand-file-name "install-mh" mh-lib-progs) "-auto") |
6365 | 678 ;; now try again to read the profile file |
679 (erase-buffer) | |
680 (condition-case err | |
681 (insert-file-contents profile) | |
682 (file-error | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
683 (signal (car err) ;re-signal with more specific msg |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
684 (list (format "Cannot read MH profile \"%s\"" profile) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
685 (car (cdr (cdr err)))))))) |
6365 | 686 |
687 | |
688 (defun mh-set-folder-modified-p (flag) | |
11331 | 689 ;; Mark current folder as modified or unmodified according to FLAG. |
6365 | 690 (set-buffer-modified-p flag)) |
691 | |
692 | |
693 (defun mh-find-seq (name) (assoc name mh-seq-list)) | |
694 | |
695 (defun mh-seq-to-msgs (seq) | |
11331 | 696 ;; Return a list of the messages in SEQUENCE. |
6365 | 697 (mh-seq-msgs (mh-find-seq seq))) |
698 | |
699 | |
700 (defun mh-add-msgs-to-seq (msgs seq &optional internal-flag) | |
701 ;; Add MESSAGE(s) to the SEQUENCE. If optional FLAG is non-nil, do not mark | |
702 ;; the message in the scan listing or inform MH of the addition. | |
703 (let ((entry (mh-find-seq seq))) | |
704 (if (and msgs (atom msgs)) (setq msgs (list msgs))) | |
705 (if (null entry) | |
706 (setq mh-seq-list (cons (mh-make-seq seq msgs) mh-seq-list)) | |
11331 | 707 (if msgs (setcdr entry (append msgs (mh-seq-msgs entry))))) |
6365 | 708 (cond ((not internal-flag) |
709 (mh-add-to-sequence seq msgs) | |
11331 | 710 (mh-notate-seq seq mh-note-seq (1+ mh-cmd-note)))))) |
6365 | 711 |
712 (autoload 'mh-add-to-sequence "mh-seq") | |
713 (autoload 'mh-notate-seq "mh-seq") | |
714 (autoload 'mh-read-seq-default "mh-seq") | |
715 (autoload 'mh-map-to-seq-msgs "mh-seq") | |
716 | |
717 | |
718 (defun mh-set-mode-name (mode-name-string) | |
719 ;; Set the mode-name and ensure that the mode line is updated. | |
720 (setq mode-name mode-name-string) | |
11576
f0906608aa63
(mh-set-mode-name): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
11333
diff
changeset
|
721 (force-mode-line-update t)) |
6365 | 722 |
723 | |
724 (defun mh-prompt-for-folder (prompt default can-create) | |
725 ;; Prompt for a folder name with PROMPT. Returns the folder's name as a | |
726 ;; string. DEFAULT is used if the folder exists and the user types return. | |
727 ;; If the CAN-CREATE flag is t, then a non-existent folder is made. | |
728 (if (null default) | |
729 (setq default "")) | |
730 (let* ((prompt (format "%s folder%s" prompt | |
731 (if (equal "" default) | |
732 "? " | |
733 (format " [%s]? " default)))) | |
734 read-name folder-name) | |
735 (if (null mh-folder-list) | |
736 (mh-set-folder-list)) | |
737 (while (and (setq read-name (completing-read prompt mh-folder-list | |
738 nil nil "+")) | |
739 (equal read-name "") | |
740 (equal default ""))) | |
741 (cond ((or (equal read-name "") (equal read-name "+")) | |
742 (setq read-name default)) | |
743 ((not (mh-folder-name-p read-name)) | |
744 (setq read-name (format "+%s" read-name)))) | |
745 (setq folder-name read-name) | |
746 (cond ((and (> (length folder-name) 0) | |
18926
e597d4b325df
Change eql calls to eq.
Richard M. Stallman <rms@gnu.org>
parents:
18901
diff
changeset
|
747 (eq (aref folder-name (1- (length folder-name))) ?/)) |
6365 | 748 (setq folder-name (substring folder-name 0 -1)))) |
749 (let ((new-file-p (not (file-exists-p (mh-expand-file-name folder-name))))) | |
750 (cond ((and new-file-p | |
751 (y-or-n-p | |
752 (format "Folder %s does not exist. Create it? " folder-name))) | |
753 (message "Creating %s" folder-name) | |
754 (call-process "mkdir" nil nil nil (mh-expand-file-name folder-name)) | |
755 (message "Creating %s...done" folder-name) | |
11331 | 756 (setq mh-folder-list (cons (list read-name) mh-folder-list)) |
757 (run-hooks 'mh-folder-list-change-hook)) | |
6365 | 758 (new-file-p |
759 (error "Folder %s is not created" folder-name)) | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
760 ((not (file-directory-p (mh-expand-file-name folder-name))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
761 (error "\"%s\" is not a directory" |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
762 (mh-expand-file-name folder-name))) |
6365 | 763 ((and (null (assoc read-name mh-folder-list)) |
764 (null (assoc (concat read-name "/") mh-folder-list))) | |
11331 | 765 (setq mh-folder-list (cons (list read-name) mh-folder-list)) |
766 (run-hooks 'mh-folder-list-change-hook)))) | |
6365 | 767 folder-name)) |
768 | |
769 | |
11331 | 770 (defvar mh-make-folder-list-process nil) ;The background process collecting the folder list. |
6365 | 771 |
11331 | 772 (defvar mh-folder-list-temp nil) ;mh-folder-list as it is being built. |
6365 | 773 |
11331 | 774 (defvar mh-folder-list-partial-line "") ;Start of last incomplete line from folder process. |
6365 | 775 |
776 (defun mh-set-folder-list () | |
11331 | 777 ;; Sets mh-folder-list correctly. |
778 ;; A useful function for the command line or for when you need to | |
779 ;; sync by hand. Format is in a form suitable for completing read. | |
6365 | 780 (message "Collecting folder names...") |
781 (if (not mh-make-folder-list-process) | |
782 (mh-make-folder-list-background)) | |
783 (while (eq (process-status mh-make-folder-list-process) 'run) | |
784 (accept-process-output mh-make-folder-list-process)) | |
785 (setq mh-folder-list mh-folder-list-temp) | |
11331 | 786 (run-hooks 'mh-folder-list-change-hook) |
6365 | 787 (setq mh-folder-list-temp nil) |
788 (delete-process mh-make-folder-list-process) | |
789 (setq mh-make-folder-list-process nil) | |
790 (message "Collecting folder names...done")) | |
791 | |
792 (defun mh-make-folder-list-background () | |
11331 | 793 ;; Start a background process to compute a list of the user's folders. |
794 ;; Call mh-set-folder-list to wait for the result. | |
6365 | 795 (cond |
796 ((not mh-make-folder-list-process) | |
18901
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
797 (unless mh-inbox |
b9b03935853a
(mh-make-folder-list-background):
Richard M. Stallman <rms@gnu.org>
parents:
18889
diff
changeset
|
798 (mh-find-path)) |
6365 | 799 (let ((process-connection-type nil)) |
800 (setq mh-make-folder-list-process | |
801 (start-process "folders" nil (expand-file-name "folders" mh-progs) | |
802 "-fast" | |
803 (if mh-recursive-folders | |
804 "-recurse" | |
805 "-norecurse"))) | |
806 (set-process-filter mh-make-folder-list-process | |
807 'mh-make-folder-list-filter) | |
808 (process-kill-without-query mh-make-folder-list-process))))) | |
809 | |
810 (defun mh-make-folder-list-filter (process output) | |
811 ;; parse output from "folders -fast" | |
812 (let ((position 0) | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
813 line-end |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
814 new-folder |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
815 (prevailing-match-data (match-data))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
816 (unwind-protect |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
817 ;; make sure got complete line |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
818 (while (setq line-end (string-match "\n" output position)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
819 (setq new-folder (format "+%s%s" |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
820 mh-folder-list-partial-line |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
821 (substring output position line-end))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
822 (setq mh-folder-list-partial-line "") |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
823 ;; is new folder a subfolder of previous? |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
824 (if (and mh-folder-list-temp |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
825 (string-match |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
826 (regexp-quote |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
827 (concat (car (car mh-folder-list-temp)) "/")) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
828 new-folder)) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
829 ;; append slash to parent folder for better completion |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
830 ;; (undone by mh-prompt-for-folder) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
831 (setq mh-folder-list-temp |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
832 (cons |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
833 (list new-folder) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
834 (cons |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
835 (list (concat (car (car mh-folder-list-temp)) "/")) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
836 (cdr mh-folder-list-temp)))) |
6365 | 837 (setq mh-folder-list-temp |
838 (cons (list new-folder) | |
13386
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
839 mh-folder-list-temp))) |
78c7ebcbd9fe
(mh-goto-msg): binary search (much faster!).
Karl Heuer <kwzh@gnu.org>
parents:
11576
diff
changeset
|
840 (setq position (1+ line-end))) |
21164
966308b754da
(mh-make-folder-list-filter): store-match-data => set-match-data.
Richard M. Stallman <rms@gnu.org>
parents:
18926
diff
changeset
|
841 (set-match-data prevailing-match-data)) |
6365 | 842 (setq mh-folder-list-partial-line (substring output position)))) |
843 | |
844 | |
845 (defun mh-folder-name-p (name) | |
846 ;; Return non-NIL if NAME is possibly the name of a folder. | |
847 ;; A name (a string or symbol) can be a folder name if it begins with "+". | |
848 (if (symbolp name) | |
18926
e597d4b325df
Change eql calls to eq.
Richard M. Stallman <rms@gnu.org>
parents:
18901
diff
changeset
|
849 (eq (aref (symbol-name name) 0) ?+) |
6365 | 850 (and (> (length name) 0) |
18926
e597d4b325df
Change eql calls to eq.
Richard M. Stallman <rms@gnu.org>
parents:
18901
diff
changeset
|
851 (eq (aref name 0) ?+)))) |
6365 | 852 |
853 | |
854 ;;; Issue commands to MH. | |
855 | |
856 | |
857 (defun mh-exec-cmd (command &rest args) | |
858 ;; Execute mh-command COMMAND with ARGS. | |
11331 | 859 ;; The side effects are what is desired. |
6365 | 860 ;; Any output is assumed to be an error and is shown to the user. |
11331 | 861 ;; The output is not read or parsed by mh-e. |
6365 | 862 (save-excursion |
11331 | 863 (set-buffer (get-buffer-create mh-temp-buffer)) |
6365 | 864 (erase-buffer) |
865 (apply 'call-process | |
866 (expand-file-name command mh-progs) nil t nil | |
867 (mh-list-to-string args)) | |
868 (if (> (buffer-size) 0) | |
869 (save-window-excursion | |
11331 | 870 (switch-to-buffer-other-window mh-temp-buffer) |
6365 | 871 (sit-for 5))))) |
872 | |
873 | |
874 (defun mh-exec-cmd-error (env command &rest args) | |
875 ;; In environment ENV, execute mh-command COMMAND with args ARGS. | |
876 ;; ENV is nil or a string of space-separated "var=value" elements. | |
877 ;; Signals an error if process does not complete successfully. | |
878 (save-excursion | |
11331 | 879 (set-buffer (get-buffer-create mh-temp-buffer)) |
6365 | 880 (erase-buffer) |
881 (let ((status | |
882 (if env | |
883 ;; the shell hacks necessary here shows just how broken Unix is | |
884 (apply 'call-process "/bin/sh" nil t nil "-c" | |
885 (format "%s %s ${1+\"$@\"}" | |
886 env | |
887 (expand-file-name command mh-progs)) | |
888 command | |
889 (mh-list-to-string args)) | |
890 (apply 'call-process | |
891 (expand-file-name command mh-progs) nil t nil | |
892 (mh-list-to-string args))))) | |
893 (mh-handle-process-error command status)))) | |
894 | |
895 | |
896 (defun mh-exec-cmd-daemon (command &rest args) | |
11331 | 897 ;; Execute MH command COMMAND with ARGS in the background. |
898 ;; Any output from command is displayed in an asynchronous pop-up window. | |
6365 | 899 (save-excursion |
11331 | 900 (set-buffer (get-buffer-create mh-temp-buffer)) |
6365 | 901 (erase-buffer)) |
902 (let* ((process-connection-type nil) | |
903 (process (apply 'start-process | |
904 command nil | |
905 (expand-file-name command mh-progs) | |
906 (mh-list-to-string args)))) | |
907 (set-process-filter process 'mh-process-daemon))) | |
908 | |
909 (defun mh-process-daemon (process output) | |
910 ;; Process daemon that puts output into a temporary buffer. | |
11331 | 911 (set-buffer (get-buffer-create mh-temp-buffer)) |
6365 | 912 (insert-before-markers output) |
11331 | 913 (display-buffer mh-temp-buffer)) |
6365 | 914 |
915 | |
916 (defun mh-exec-cmd-quiet (raise-error command &rest args) | |
917 ;; Args are RAISE-ERROR, COMMANDS, ARGS.... | |
918 ;; Execute MH command COMMAND with ARGS. ARGS is a list of strings. | |
919 ;; Return at start of mh-temp buffer, where output can be parsed and used. | |
920 ;; Returns value of call-process, which is 0 for success, | |
921 ;; unless RAISE-ERROR is non-nil, in which case an error is signaled | |
922 ;; if call-process returns non-0. | |
11331 | 923 (set-buffer (get-buffer-create mh-temp-buffer)) |
6365 | 924 (erase-buffer) |
925 (let ((value | |
926 (apply 'call-process | |
927 (expand-file-name command mh-progs) nil t nil | |
928 args))) | |
929 (goto-char (point-min)) | |
930 (if raise-error | |
931 (mh-handle-process-error command value) | |
932 value))) | |
933 | |
934 | |
935 (defun mh-exec-cmd-output (command display &rest args) | |
936 ;; Execute MH command COMMAND with DISPLAY flag and ARGS. | |
937 ;; Put the output into buffer after point. Set mark after inserted text. | |
11331 | 938 ;; Output is expected to be shown to user, not parsed by mh-e. |
6365 | 939 (push-mark (point) t) |
940 (apply 'call-process | |
941 (expand-file-name command mh-progs) nil t display | |
942 (mh-list-to-string args)) | |
943 (exchange-point-and-mark)) | |
944 | |
945 | |
946 (defun mh-exec-lib-cmd-output (command &rest args) | |
947 ;; Execute MH library command COMMAND with ARGS. | |
948 ;; Put the output into buffer after point. Set mark after inserted text. | |
24420 | 949 (apply 'mh-exec-cmd-output (expand-file-name command mh-lib-progs) nil args)) |
6365 | 950 |
951 | |
952 (defun mh-handle-process-error (command status) | |
953 ;; Raise error if COMMAND returned non-0 STATUS, otherwise return STATUS. | |
954 ;; STATUS is return value from call-process. | |
955 ;; Program output is in current buffer. | |
11331 | 956 ;; If output is too long to include in error message, display the buffer. |
18926
e597d4b325df
Change eql calls to eq.
Richard M. Stallman <rms@gnu.org>
parents:
18901
diff
changeset
|
957 (cond ((eq status 0) ;success |
6365 | 958 status) |
959 ((stringp status) ;kill string | |
14426
9f18c1b097ce
(mh-handle-process-error): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
960 (error "%s: %s" command status)) |
6365 | 961 (t ;exit code |
962 (cond | |
963 ((= (buffer-size) 0) ;program produced no error message | |
14426
9f18c1b097ce
(mh-handle-process-error): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
964 (error "%s: exit code %d" command status)) |
6365 | 965 (t |
966 ;; will error message fit on one line? | |
967 (goto-line 2) | |
968 (if (and (< (buffer-size) (screen-width)) | |
969 (eobp)) | |
14426
9f18c1b097ce
(mh-handle-process-error): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
970 (error "%s" |
9f18c1b097ce
(mh-handle-process-error): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
971 (buffer-substring 1 (progn (goto-char 1) |
6365 | 972 (end-of-line) |
973 (point)))) | |
974 (display-buffer (current-buffer)) | |
14426
9f18c1b097ce
(mh-handle-process-error): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
975 (error "%s failed with status %d. See error message in other window." |
9f18c1b097ce
(mh-handle-process-error): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
976 command status))))))) |
6365 | 977 |
978 | |
979 (defun mh-expand-file-name (filename &optional default) | |
11331 | 980 ;; Just like `expand-file-name', but also handles MH folder names. |
981 ;; Assumes that any filename that starts with '+' is a folder name. | |
6365 | 982 (if (mh-folder-name-p filename) |
983 (expand-file-name (substring filename 1) mh-user-path) | |
984 (expand-file-name filename default))) | |
985 | |
986 | |
987 (defun mh-list-to-string (l) | |
988 ;; Flattens the list L and makes every element of the new list into a string. | |
989 (nreverse (mh-list-to-string-1 l))) | |
990 | |
991 (defun mh-list-to-string-1 (l) | |
992 (let ((new-list nil)) | |
993 (while l | |
994 (cond ((null (car l))) | |
995 ((symbolp (car l)) | |
996 (setq new-list (cons (symbol-name (car l)) new-list))) | |
997 ((numberp (car l)) | |
998 (setq new-list (cons (int-to-string (car l)) new-list))) | |
999 ((equal (car l) "")) | |
1000 ((stringp (car l)) (setq new-list (cons (car l) new-list))) | |
1001 ((listp (car l)) | |
1002 (setq new-list (nconc (mh-list-to-string-1 (car l)) | |
1003 new-list))) | |
1004 (t (error "Bad element in mh-list-to-string: %s" (car l)))) | |
1005 (setq l (cdr l))) | |
1006 new-list)) | |
1007 | |
1008 (provide 'mh-utils) | |
1009 | |
1010 ;;; mh-utils.el ends here |