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