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