annotate lisp/mail/mh-utils.el @ 43247:4c5a2e2ddf43

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