]> code.delx.au - gnu-emacs/blob - lisp/mail/emacsbug.el
(math-read-angle-bracket): Use declared variables math-exp-pos,
[gnu-emacs] / lisp / mail / emacsbug.el
1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
2
3 ;; Copyright (C) 1985, 1994, 1997, 1998, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: K. Shane Hartman
7 ;; Maintainer: FSF
8 ;; Keywords: maint mail
9
10 ;; Not fully installed because it can work only on Internet hosts.
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30 ;; `M-x report-emacs-bug' starts an email note to the Emacs maintainers
31 ;; describing a problem. Here's how it's done...
32
33 ;;; Code:
34
35 ;; >> This should be an address which is accessible to your machine,
36 ;; >> otherwise you can't use this file. It will only work on the
37 ;; >> internet with this address.
38
39 (require 'sendmail)
40
41 (defgroup emacsbug nil
42 "Sending Emacs bug reports."
43 :group 'maint
44 :group 'mail)
45
46 (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
47 "*Address of mailing list for GNU Emacs bugs."
48 :group 'emacsbug
49 :type 'string)
50
51 (defcustom report-emacs-bug-pretest-address "emacs-pretest-bug@gnu.org"
52 "*Address of mailing list for GNU Emacs pretest bugs."
53 :group 'emacsbug
54 :type 'string)
55
56 (defvar report-emacs-bug-orig-text nil
57 "The automatically-created initial text of bug report.")
58
59 (defvar report-emacs-bug-text-prompt nil
60 "The automatically-created initial prompt of bug report.")
61
62 (defcustom report-emacs-bug-no-confirmation nil
63 "*If non-nil, suppress the confirmations asked for the sake of novice users."
64 :group 'emacsbug
65 :type 'boolean)
66
67 (defcustom report-emacs-bug-no-explanations nil
68 "*If non-nil, suppress the explanations given for the sake of novice users."
69 :group 'emacsbug
70 :type 'boolean)
71
72 ;;;###autoload
73 (defun report-emacs-bug (topic &optional recent-keys)
74 "Report a bug in GNU Emacs.
75 Prompts for bug subject. Leaves you in a mail buffer."
76 ;; This strange form ensures that (recent-keys) is the value before
77 ;; the bug subject string is read.
78 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
79 ;; If there are four numbers in emacs-version, this is a pretest
80 ;; version.
81 (let ((pretest-p (string-match "\\..*\\..*\\." emacs-version))
82 (from-buffer (current-buffer))
83 user-point prompt-beg-point message-end-point)
84 (setq message-end-point
85 (with-current-buffer (get-buffer-create "*Messages*")
86 (point-max-marker)))
87 (compose-mail (if pretest-p
88 report-emacs-bug-pretest-address
89 report-emacs-bug-address)
90 topic)
91 ;; The rest of this does not execute
92 ;; if the user was asked to confirm and said no.
93 (rfc822-goto-eoh)
94 (forward-line 1)
95
96 (let ((signature (buffer-substring (point) (point-max))))
97 (delete-region (point) (point-max))
98 (insert signature)
99 (backward-char (length signature)))
100 (setq prompt-beg-point (point))
101 (unless report-emacs-bug-no-explanations
102 ;; Insert warnings for novice users.
103 (insert "This bug report will be sent to the Free Software Foundation,\n")
104 (let ((pos (point)))
105 (insert "not to your local site managers!")
106 (put-text-property pos (point) 'face 'highlight))
107 (insert "\nPlease write in ")
108 (let ((pos (point)))
109 (insert "English")
110 (put-text-property pos (point) 'face 'highlight))
111 (insert " if possible, because the Emacs maintainers
112 usually do not have translators to read other languages for them.\n\n")
113 (insert (format "Your bug report will be posted to the %s mailing list"
114 (if pretest-p
115 report-emacs-bug-pretest-address
116 report-emacs-bug-address)))
117 (if pretest-p
118 (insert ".\n\n")
119 (insert ",\nand to the gnu.emacs.bug news group.\n\n")))
120
121 (insert "Please describe exactly what actions triggered the bug\n"
122 "and the precise symptoms of the bug:")
123 (setq report-emacs-bug-text-prompt
124 (buffer-substring prompt-beg-point (point)))
125
126 (insert "\n\n")
127 (setq user-point (point))
128 (insert "\n\n\n")
129
130 (insert "In " (emacs-version) "\n")
131 (if (fboundp 'x-server-vendor)
132 (insert "Distributor `" (x-server-vendor) "', version "
133 (mapconcat 'number-to-string (x-server-version) ".") "\n"))
134 (if (and system-configuration-options
135 (not (equal system-configuration-options "")))
136 (insert "configured using `configure "
137 system-configuration-options "'\n\n"))
138 (insert "Important settings:\n")
139 (mapcar
140 '(lambda (var)
141 (insert (format " value of $%s: %s\n" var (getenv var))))
142 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
143 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG"))
144 (insert (format " locale-coding-system: %s\n" locale-coding-system))
145 (insert (format " default-enable-multibyte-characters: %s\n"
146 default-enable-multibyte-characters))
147 (insert "\n")
148 (insert (format "Major mode: %s\n"
149 (buffer-local-value 'mode-name from-buffer)))
150 (insert "\n")
151 (insert "Minor modes in effect:\n")
152 (dolist (mode minor-mode-list)
153 (and (boundp mode) (buffer-local-value mode from-buffer)
154 (insert (format " %s: %s\n" mode
155 (buffer-local-value mode from-buffer)))))
156 (insert "\n")
157 (insert "Recent input:\n")
158 (let ((before-keys (point)))
159 (insert (mapconcat (lambda (key)
160 (if (or (integerp key)
161 (symbolp key)
162 (listp key))
163 (single-key-description key)
164 (prin1-to-string key nil)))
165 (or recent-keys (recent-keys))
166 " "))
167 (save-restriction
168 (narrow-to-region before-keys (point))
169 (goto-char before-keys)
170 (while (progn (move-to-column 50) (not (eobp)))
171 (search-forward " " nil t)
172 (insert "\n"))))
173 (let ((message-buf (get-buffer "*Messages*")))
174 (if message-buf
175 (let (beg-pos
176 (end-pos message-end-point))
177 (with-current-buffer message-buf
178 (goto-char end-pos)
179 (forward-line -10)
180 (setq beg-pos (point)))
181 (insert "\n\nRecent messages:\n")
182 (insert-buffer-substring message-buf beg-pos end-pos))))
183 ;; This is so the user has to type something
184 ;; in order to send easily.
185 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
186 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
187 (unless report-emacs-bug-no-explanations
188 (with-output-to-temp-buffer "*Bug Help*"
189 (if (eq mail-user-agent 'sendmail-user-agent)
190 (princ (substitute-command-keys
191 "Type \\[mail-send-and-exit] to send the bug report.\n")))
192 (princ (substitute-command-keys
193 "Type \\[kill-buffer] RET to cancel (don't send it).\n"))
194 (terpri)
195 (princ (substitute-command-keys
196 "Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
197 about when and how to write a bug report,
198 and what information to supply so that the bug can be fixed.
199 Type SPC to scroll through this section and its subsections."))))
200 ;; Make it less likely people will send empty messages.
201 (make-local-variable 'mail-send-hook)
202 (add-hook 'mail-send-hook 'report-emacs-bug-hook)
203 (save-excursion
204 (goto-char (point-max))
205 (skip-chars-backward " \t\n")
206 (make-local-variable 'report-emacs-bug-orig-text)
207 (setq report-emacs-bug-orig-text (buffer-substring (point-min) (point))))
208 (goto-char user-point)))
209
210 (defun report-emacs-bug-info ()
211 "Go to the Info node on reporting Emacs bugs."
212 (interactive)
213 (info)
214 (Info-directory)
215 (Info-menu "emacs")
216 (Info-goto-node "Bugs"))
217
218 (defun report-emacs-bug-hook ()
219 (save-excursion
220 (save-excursion
221 (goto-char (point-max))
222 (skip-chars-backward " \t\n")
223 (if (and (= (- (point) (point-min))
224 (length report-emacs-bug-orig-text))
225 (equal (buffer-substring (point-min) (point))
226 report-emacs-bug-orig-text))
227 (error "No text entered in bug report")))
228
229 ;; Check the buffer contents and reject non-English letters.
230 (save-excursion
231 (goto-char (point-min))
232 (skip-chars-forward "\0-\177")
233 (if (not (eobp))
234 (if (or report-emacs-bug-no-confirmation
235 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
236 (while (progn (skip-chars-forward "\0-\177")
237 (not (eobp)))
238 (let ((ch (following-char)))
239 (delete-char 1)
240 (insert (format "=%02x" ch)))))))
241
242 ;; The last warning for novice users.
243 (if (or report-emacs-bug-no-confirmation
244 (yes-or-no-p
245 "Send this bug report to the Emacs maintainers? "))
246 ;; Just send the current mail.
247 nil
248 (goto-char (point-min))
249 (if (search-forward "To: ")
250 (let ((pos (point)))
251 (end-of-line)
252 (delete-region pos (point))))
253 (kill-local-variable 'mail-send-hook)
254 (with-output-to-temp-buffer "*Bug Help*"
255 (princ (substitute-command-keys "\
256 You invoked the command M-x report-emacs-bug,
257 but you decided not to mail the bug report to the Emacs maintainers.
258
259 If you want to mail it to someone else instead,
260 please insert the proper e-mail address after \"To: \",
261 and send the mail again using \\[mail-send-and-exit].")))
262 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
263
264 ;; Unclutter
265 (mail-text)
266 (if (looking-at report-emacs-bug-text-prompt)
267 (replace-match "Symptoms:"))))
268
269 (provide 'emacsbug)
270
271 ;;; arch-tag: 248b6523-c3b5-4fec-9a3f-0411fafa7d49
272 ;;; emacsbug.el ends here