Merge from gnus--devo--0
[emacs.git] / lisp / mail / emacsbug.el
blob5582bf95b4fc9ab23444e706ff0c7ce0390140ea
1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
3 ;; Copyright (C) 1985, 1994, 1997, 1998, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: K. Shane Hartman
7 ;; Maintainer: FSF
8 ;; Keywords: maint mail
10 ;; Not fully installed because it can work only on Internet hosts.
11 ;; This file is part of GNU Emacs.
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 3 of the License, or
16 ;; (at your option) any later version.
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.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;; `M-x report-emacs-bug' starts an email note to the Emacs maintainers
29 ;; describing a problem. You need to be able to send mail from Emacs
30 ;; to complete the process. Alternatively, compose the bug report in
31 ;; Emacs then paste it into your normal mail client.
33 ;;; Code:
35 (require 'sendmail)
37 (defgroup emacsbug nil
38 "Sending Emacs bug reports."
39 :group 'maint
40 :group 'mail)
42 (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
43 "Address of mailing list for GNU Emacs bugs."
44 :group 'emacsbug
45 :type 'string)
47 (defcustom report-emacs-bug-pretest-address "emacs-pretest-bug@gnu.org"
48 "Address of mailing list for GNU Emacs pretest bugs."
49 :group 'emacsbug
50 :type 'string)
52 (defcustom report-emacs-bug-no-confirmation nil
53 "If non-nil, suppress the confirmations asked for the sake of novice users."
54 :group 'emacsbug
55 :type 'boolean)
57 (defcustom report-emacs-bug-no-explanations nil
58 "If non-nil, suppress the explanations given for the sake of novice users."
59 :group 'emacsbug
60 :type 'boolean)
62 ;; User options end here.
65 (defvar report-emacs-bug-orig-text nil
66 "The automatically-created initial text of bug report.")
68 ;;;###autoload
69 (defun report-emacs-bug (topic &optional recent-keys)
70 "Report a bug in GNU Emacs.
71 Prompts for bug subject. Leaves you in a mail buffer."
72 ;; This strange form ensures that (recent-keys) is the value before
73 ;; the bug subject string is read.
74 (interactive (reverse (list (recent-keys) (read-string "Bug Subject: "))))
75 ;; The syntax `version;' is preferred to `[version]' because the
76 ;; latter could be mistakenly stripped by mailing software.
77 (if (eq system-type 'ms-dos)
78 (setq topic (concat emacs-version "; " topic))
79 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
80 (setq topic (concat (match-string 1 emacs-version) "; " topic))))
81 ;; If there are four numbers in emacs-version (three for MS-DOS),
82 ;; this is a pretest version.
83 (let* ((pretest-p (string-match (if (eq system-type 'ms-dos)
84 "\\..*\\."
85 "\\..*\\..*\\.")
86 emacs-version))
87 (from-buffer (current-buffer))
88 (reporting-address (if pretest-p
89 report-emacs-bug-pretest-address
90 report-emacs-bug-address))
91 ;; Put these properties on semantically-void text.
92 (prompt-properties '(field emacsbug-prompt
93 intangible but-helpful
94 rear-nonsticky t))
95 user-point message-end-point)
96 (setq message-end-point
97 (with-current-buffer (get-buffer-create "*Messages*")
98 (point-max-marker)))
99 (compose-mail reporting-address
100 topic)
101 ;; The rest of this does not execute
102 ;; if the user was asked to confirm and said no.
103 (rfc822-goto-eoh)
104 (forward-line 1)
106 (let ((signature (buffer-substring (point) (point-max))))
107 (delete-region (point) (point-max))
108 (insert signature)
109 (backward-char (length signature)))
110 (unless report-emacs-bug-no-explanations
111 ;; Insert warnings for novice users.
112 (when (string-match "@gnu\\.org^" reporting-address)
113 (insert "This bug report will be sent to the Free Software Foundation,\n")
114 (let ((pos (point)))
115 (insert "not to your local site managers!")
116 (put-text-property pos (point) 'face 'highlight)))
117 (insert "\nPlease write in ")
118 (let ((pos (point)))
119 (insert "English")
120 (put-text-property pos (point) 'face 'highlight))
121 (insert " if possible, because the Emacs maintainers
122 usually do not have translators to read other languages for them.\n\n")
123 (insert (format "Your bug report will be posted to the %s mailing list"
124 reporting-address))
125 (if pretest-p
126 (insert ".\n\n")
127 (insert ",\nand to the gnu.emacs.bug news group.\n\n")))
129 (insert "Please describe exactly what actions triggered the bug\n"
130 "and the precise symptoms of the bug:\n\n")
131 (add-text-properties (point) (save-excursion (mail-text) (point))
132 prompt-properties)
134 (setq user-point (point))
135 (insert "\n\n")
137 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
138 "please include the output from the following gdb commands:\n"
139 " `bt full' and `xbacktrace'.\n")
141 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
142 (if (file-readable-p debug-file)
143 (insert "If you would like to further debug the crash, please read the file\n"
144 debug-file " for instructions.\n")))
145 (add-text-properties (1+ user-point) (point) prompt-properties)
147 (insert "\n\nIn " (emacs-version) "\n")
148 (if (fboundp 'x-server-vendor)
149 (condition-case nil
150 ;; This is used not only for X11 but also W32 and others.
151 (insert "Windowing system distributor `" (x-server-vendor)
152 "', version "
153 (mapconcat 'number-to-string (x-server-version) ".") "\n")
154 (error t)))
155 (if (and system-configuration-options
156 (not (equal system-configuration-options "")))
157 (insert "configured using `configure "
158 system-configuration-options "'\n\n"))
159 (insert "Important settings:\n")
160 (mapc
161 '(lambda (var)
162 (insert (format " value of $%s: %s\n" var (getenv var))))
163 '("LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
164 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
165 (insert (format " locale-coding-system: %s\n" locale-coding-system))
166 (insert (format " default-enable-multibyte-characters: %s\n"
167 default-enable-multibyte-characters))
168 (insert "\n")
169 (insert (format "Major mode: %s\n"
170 (format-mode-line
171 (buffer-local-value 'mode-name from-buffer)
172 nil nil from-buffer)))
173 (insert "\n")
174 (insert "Minor modes in effect:\n")
175 (dolist (mode minor-mode-list)
176 (and (boundp mode) (buffer-local-value mode from-buffer)
177 (insert (format " %s: %s\n" mode
178 (buffer-local-value mode from-buffer)))))
179 (insert "\n")
180 (insert "Recent input:\n")
181 (let ((before-keys (point)))
182 (insert (mapconcat (lambda (key)
183 (if (or (integerp key)
184 (symbolp key)
185 (listp key))
186 (single-key-description key)
187 (prin1-to-string key nil)))
188 (or recent-keys (recent-keys))
189 " "))
190 (save-restriction
191 (narrow-to-region before-keys (point))
192 (goto-char before-keys)
193 (while (progn (move-to-column 50) (not (eobp)))
194 (search-forward " " nil t)
195 (insert "\n"))))
196 (let ((message-buf (get-buffer "*Messages*")))
197 (if message-buf
198 (let (beg-pos
199 (end-pos message-end-point))
200 (with-current-buffer message-buf
201 (goto-char end-pos)
202 (forward-line -10)
203 (setq beg-pos (point)))
204 (insert "\n\nRecent messages:\n")
205 (insert-buffer-substring message-buf beg-pos end-pos))))
206 ;; This is so the user has to type something
207 ;; in order to send easily.
208 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
209 (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
210 (unless report-emacs-bug-no-explanations
211 (with-output-to-temp-buffer "*Bug Help*"
212 (if (eq mail-user-agent 'sendmail-user-agent)
213 (princ (substitute-command-keys
214 "Type \\[mail-send-and-exit] to send the bug report.\n")))
215 (princ (substitute-command-keys
216 "Type \\[kill-buffer] RET to cancel (don't send it).\n"))
217 (terpri)
218 (princ (substitute-command-keys
219 "Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
220 about when and how to write a bug report,
221 and what information to supply so that the bug can be fixed.
222 Type SPC to scroll through this section and its subsections."))))
223 ;; Make it less likely people will send empty messages.
224 (make-local-variable 'mail-send-hook)
225 (add-hook 'mail-send-hook 'report-emacs-bug-hook)
226 (save-excursion
227 (goto-char (point-max))
228 (skip-chars-backward " \t\n")
229 (make-local-variable 'report-emacs-bug-orig-text)
230 (setq report-emacs-bug-orig-text (buffer-substring (point-min) (point))))
231 (goto-char user-point)))
233 (defun report-emacs-bug-info ()
234 "Go to the Info node on reporting Emacs bugs."
235 (interactive)
236 (info "(emacs)Bugs"))
238 (defun report-emacs-bug-hook ()
239 (save-excursion
240 (save-excursion
241 (goto-char (point-max))
242 (skip-chars-backward " \t\n")
243 (if (and (= (- (point) (point-min))
244 (length report-emacs-bug-orig-text))
245 (equal (buffer-substring (point-min) (point))
246 report-emacs-bug-orig-text))
247 (error "No text entered in bug report")))
249 ;; Check the buffer contents and reject non-English letters.
250 (save-excursion
251 (goto-char (point-min))
252 (skip-chars-forward "\0-\177")
253 (if (not (eobp))
254 (if (or report-emacs-bug-no-confirmation
255 (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
256 (while (progn (skip-chars-forward "\0-\177")
257 (not (eobp)))
258 (let ((ch (following-char)))
259 (delete-char 1)
260 (insert (format "=%02x" ch)))))))
262 ;; The last warning for novice users.
263 (if (or report-emacs-bug-no-confirmation
264 (yes-or-no-p
265 "Send this bug report to the Emacs maintainers? "))
266 ;; Just send the current mail.
268 (goto-char (point-min))
269 (if (search-forward "To: ")
270 (let ((pos (point)))
271 (end-of-line)
272 (delete-region pos (point))))
273 (kill-local-variable 'mail-send-hook)
274 (with-output-to-temp-buffer "*Bug Help*"
275 (princ (substitute-command-keys "\
276 You invoked the command M-x report-emacs-bug,
277 but you decided not to mail the bug report to the Emacs maintainers.
279 If you want to mail it to someone else instead,
280 please insert the proper e-mail address after \"To: \",
281 and send the mail again using \\[mail-send-and-exit].")))
282 (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
284 ;; Unclutter
285 (mail-text)
286 (let ((pos (1- (point))))
287 (while (setq pos (text-property-any pos (point-max)
288 'field 'emacsbug-prompt))
289 (delete-region pos (field-end (1+ pos)))))))
291 (provide 'emacsbug)
293 ;; arch-tag: 248b6523-c3b5-4fec-9a3f-0411fafa7d49
294 ;;; emacsbug.el ends here