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