annotate lisp/mh-e/mh-utils.el @ 2:ac2d302a0011 r19-15b2

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