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