initial commit
[emacs-init.git] / nxhtml / nxhtml / nxhtml-bug.el
1 ;;; nxhtml-bug.el --- Reporting nXhtml bugs
2 ;;
3 ;; Author: Lennar Borgman
4 ;; Maintainer:
5 ;; Created: Wed Mar 07 15:57:15 2007
6 ;; Version:
7 ;; Lxast-Updated: Wed Mar 07 16:00:22 2007 (3600 +0100)
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Fxeatures that might be required by this library:
12 ;;
13 ;;   None
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;;
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;
23 ;;; Change log:
24 ;;
25 ;;
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;
28 ;; This program is free software; you can redistribute it and/or modify
29 ;; it under the terms of the GNU General Public License as published by
30 ;; the Free Software Foundation; either version 2, or (at your option)
31 ;; any later version.
32 ;;
33 ;; This program is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36 ;; GNU General Public License for more details.
37 ;;
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with this program; see the file COPYING.  If not, write to the
40 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41 ;; Boston, MA 02111-1307, USA.
42 ;;
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;;
45 ;;; Code:
46
47 (eval-when-compile (require 'nxhtml-menu nil t))
48
49 (require 'sendmail)
50
51 ;;(require 'emacsbug)
52 (autoload 'report-emacs-bug-info "emacsbug" "Go to the Info node on reporting Emacs bugs." t)
53
54 (defvar nxhtml-report-bug-orig-text nil
55   "The automatically-created initial text of bug report.")
56
57 (defvar nxhtml-report-bug-no-confirmation nil
58   "*If non-nil, suppress the confirmations asked for the sake of novice users.")
59
60 (defvar nxhtml-report-bug-no-explanations nil
61   "*If non-nil, suppress the explanations given when reporting bugs.")
62
63 ;; (defvar nxhtml-bug-launchpad-mode-map
64 ;;   (let ((map (make-sparse-keymap)))
65 ;;     (define-key map [(control ?c) (control ?c)] 'nxhtml-bug-maybe-to-launchpad)
66 ;;     map))
67
68 ;; (define-minor-mode nxhtml-bug-launchpad-mode
69 ;;   "Changes C-c C-c to ask to report on Launchpad."
70 ;;   nil
71 ;;   :keymap 'nxhtml-bug-launchpad-mode-map
72 ;;   nil)
73
74 ;; (defun nxhtml-bug-maybe-to-launchpad ()
75 ;;   (interactive)
76 ;;   (if (y-or-n-p "Do you want to report bug on Launchad (preferred): ")
77 ;;       (browse-url "https://bugs.launchpad.net/nxhtml")
78 ;;     (mail-send-and-exit)))
79
80 ;;;###autoload
81 (defun nxhtml-report-bug ()
82   "Report a bug in nXhtml."
83   (interactive)
84   (with-output-to-temp-buffer (help-buffer)
85     (help-setup-xref (list #'nxhtml-report-bug) (interactive-p))
86     (with-current-buffer (help-buffer)
87       (let ((here (point)))
88         (insert
89          "A lot of things can interfere with nXhtml/MuMaMo to cause bugs.\n"
90          "Therefore when reporting a bug please try to describe\n"
91          "how to show it without your own Emacs initializations.\n"
92          "To do that start from")
93         (fill-region here (point))
94         (insert "\n\n  M-x `emacs-Q-nxhtml'\n\n")
95         (setq here (point))
96         (insert
97          "If you want to find out if your initialization files interfere\n"
98          "then you can try the both test commands `nxhtmltest-run' and\n"
99          "`nxhtmltest-run-Q' and see if there is any difference.\n\n")
100         (fill-region here (point))
101         (setq here (point))
102         (insert
103          "You may also want to look at the installation part of the ")
104         (insert-text-button "The Quick Guide"
105                             'action (lambda (btn)
106                                       (browse-url
107                                        (concat
108                                         (nxhtml-docfile-url)
109                                         "#qg"))))
110         (insert " or the file ")
111         (insert-text-button
112          "nxhtml/readme.txt"
113          'action (lambda (btn)
114                    (find-file-other-window
115                     (expand-file-name "../readme.txt"
116                                       (file-name-directory
117                                        (symbol-file 'nxhtml-report-bug))))))
118         (insert ".\n\n")
119         (fill-region here (point))
120         (setq here (point))
121         (insert
122          "If you know Emacs lisp and are reporting a bug it would be nice "
123          "if you wrote a new unit test case.\n"
124          "Please see the file ")
125         (insert-text-button "nxhtmltest-suites.el"
126                             'help-echo "Visit file"
127                             'action (lambda (button)
128                                       (find-file (symbol-file 'nxhtmltest-run))))
129         (insert " for examples.\n\n")
130         (fill-region here (point))
131         (setq here (point))
132         (insert
133          "There are several ways to report a bug, use the links below:\n"
134          "- By visiting URL `https://bugs.launchpad.net/nxhtml'.\n")
135         (setq here (point))
136         (insert
137          "- By ")
138         (insert-text-button "email to Launchpad"
139                             'help-echo "Send email to Launchpad bug system"
140                             'action (lambda (button)
141                                       (call-interactively
142                                        'nxhtml-report-bug-by-mail)))
143         (insert
144          ".\n")
145         (insert
146          "  This requires PGP signing the email\n"
147          "  and that you have told your PGP key to Launchpad.\n")
148         (fill-region here (point))
149         (setq here (point))
150         (insert
151          "- The above ways are best since the bug get into the database,\n"
152          "  and it is easy to communicate about it, but if they does\n"
153          "  not work for you please go to \n"
154          "  URL `http://www.emacswiki.org/cgi-bin/wiki/NxhtmlMode'.\n")
155         (fill-region here (point))
156         (setq here (point))
157         )
158       (with-no-warnings (print-help-return-message)))))
159
160 (defun nxhtml-report-bug-by-mail (topic)
161   "Report a bug by mail.
162 Prompts for bug subject.  Leaves you in an Emacs mail
163 buffer. However when you send the bug your normal mail client
164 will take over the job (with your help)."
165   (interactive (list (read-string "nXhtml Bug Subject: ")))
166   ;; If there are four numbers in emacs-version, this is a pretest
167   ;; version.
168   (require 'nxhtml-menu)
169   (let* ((pretest-p (string-match "\\..*\\..*\\." emacs-version))
170         (from-buffer (current-buffer))
171         ;;(reporting-address "lennart.borgman@gmail.com")
172         ;;(reporting-address "emacs-nxml-mode@yahoogroups.com")
173         (reporting-address "new@bugs.launchpad.net")
174         ;; Put these properties on semantically-void text.
175         (prompt-properties '(field nxhtml-bug-prompt
176                                    intangible but-helpful
177                                    rear-nonsticky t))
178         user-point message-end-point)
179     (setq message-end-point
180           (with-current-buffer (get-buffer-create "*Messages*")
181             (point-max-marker)))
182     (compose-mail reporting-address
183                   topic)
184     ;; The rest of this does not execute
185     ;; if the user was asked to confirm and said no.
186     (rfc822-goto-eoh)
187     (forward-line 1)
188
189     (let ((signature (buffer-substring (point) (point-max))))
190       (delete-region (point) (point-max))
191       (insert signature)
192       (backward-char (length signature)))
193     ;;(nxhtml-bug-launchpad-mode 1)
194     (insert
195      "\nThis is a bug report for nXhtml mode.\n")
196     (unless nxhtml-report-bug-no-explanations
197       ;; Insert warnings for novice users.
198       (when (string-match "nxml-mode" reporting-address)
199         (insert "This bug report will be sent to the nXhtml maintainers,\n")
200         (let ((pos (point)))
201           (insert "not to your local site managers!\n")
202           (put-text-property pos (point) 'face 'highlight)))
203       (insert "\nPlease write in ")
204       (let ((pos (point)))
205         (insert "English")
206         (put-text-property pos (point) 'face 'highlight))
207       (insert " if possible, because the nXhtml maintainers
208 usually do not have translators to read other languages for them.\n\n")
209       )
210     (insert "Please describe exactly what actions triggered the bug\n"
211             "and the precise symptoms of the bug, preferrably starting\n"
212             "from `M-x emacs-Q-nxhtml'\n"
213             "(it may also be helpful to include an *EXAMPLE FILE*!).\n\n")
214     (add-text-properties (point) (save-excursion (mail-text) (point))
215                          prompt-properties)
216
217     (setq user-point (point))
218     (insert "\n\n")
219
220     (insert "\n\nnXhtml version " nxhtml-menu:version ", " (emacs-version) "\n\n")
221     (insert (format "Major mode: %s\n"
222                     (buffer-local-value 'mode-name from-buffer)))
223     (insert "\n")
224     (insert "Minor modes in effect:\n")
225     (dolist (mode minor-mode-list)
226       (and (boundp mode) (buffer-local-value mode from-buffer)
227            (insert (format "  %s: %s\n" mode
228                            (buffer-local-value mode from-buffer)))))
229     (insert "\n")
230     (let ((message-buf (get-buffer "*Messages*")))
231       (if message-buf
232           (let (beg-pos
233                 (end-pos message-end-point))
234             (with-current-buffer message-buf
235               (goto-char end-pos)
236               (forward-line -10)
237               (setq beg-pos (point)))
238             (insert "\n\nRecent messages:\n")
239             (insert-buffer-substring message-buf beg-pos end-pos))))
240     ;; This is so the user has to type something
241     ;; in order to send easily.
242     (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
243     (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
244     (unless nxhtml-report-bug-no-explanations
245       (with-output-to-temp-buffer "*Bug Help*"
246         (if (eq mail-user-agent 'sendmail-user-agent)
247             (princ (substitute-command-keys
248                     "Type \\[mail-send-and-exit] to send the bug report.\n")))
249         (princ (substitute-command-keys
250                 "Type \\[kill-buffer] RET to cancel (don't send it).\n"))
251         (terpri)
252         (princ (substitute-command-keys
253                 "Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
254 about when and how to write a bug report,
255 and what information to supply so that the bug can be fixed.
256
257 When there type SPC to scroll through this section and its subsections.
258
259 Please notice that you are now reporting a bug for nXhtml, not
260 Emacs itself, so everyting in that manual section might not
261 apply."))))
262     ;; Make it less likely people will send empty messages.
263     (make-local-variable 'mail-send-hook)
264     (add-hook 'mail-send-hook 'nxhtml-report-bug-hook)
265     (save-excursion
266       (goto-char (point-max))
267       (skip-chars-backward " \t\n")
268       (make-local-variable 'nxhtml-report-bug-orig-text)
269       (setq nxhtml-report-bug-orig-text (buffer-substring (point-min) (point))))
270     (goto-char user-point)))
271
272
273 (defun nxhtml-report-bug-hook ()
274   (save-excursion
275     (save-excursion
276       (goto-char (point-max))
277       (skip-chars-backward " \t\n")
278       (if (and (= (- (point) (point-min))
279                   (length nxhtml-report-bug-orig-text))
280                (equal (buffer-substring (point-min) (point))
281                       nxhtml-report-bug-orig-text))
282           (error "No text entered in bug report")))
283
284     ;; Check the buffer contents and reject non-English letters.
285     (save-excursion
286       (goto-char (point-min))
287       (skip-chars-forward "\0-\177")
288       (if (not (eobp))
289           (if (or nxhtml-report-bug-no-confirmation
290                   (y-or-n-p "Convert non-ASCII letters to hexadecimal? "))
291               (while (progn (skip-chars-forward "\0-\177")
292                             (not (eobp)))
293                 (let ((ch (following-char)))
294                   (delete-char 1)
295                   (insert (format "=%02x" ch)))))))
296
297     ;; The last warning for novice users.
298     (if (or nxhtml-report-bug-no-confirmation
299             (yes-or-no-p
300              "Send this bug report to the nXhtml maintainers? "))
301         ;; Just send the current mail.
302         nil
303       (goto-char (point-min))
304       (if (search-forward "To: ")
305           (let ((pos (point)))
306             (end-of-line)
307             (delete-region pos (point))))
308       (kill-local-variable 'mail-send-hook)
309       (with-output-to-temp-buffer "*Bug Help*"
310         (princ (substitute-command-keys "\
311 You invoked the command nxhtml-report-bug,
312 but you decided not to mail the bug report to the nXhtml maintainer.
313
314 If you want to mail it to someone else instead,
315 please insert the proper e-mail address after \"To: \",
316 and send the mail again using \\[mail-send-and-exit].")))
317       (error "M-x nxhtml-report-bug was cancelled, please read *Bug Help* buffer"))
318
319     ;; Unclutter
320     (mail-text)
321     (insert
322      "Next line tells Launchpad bug system what this is. Don't change it!\n"
323      "  affects nxhtml\n\n")
324     (mail-text)
325     (let ((pos (1- (point))))
326       (while (setq pos (text-property-any pos (point-max)
327                                           'field 'nxhtml-bug-prompt))
328         (delete-region pos (field-end (1+ pos)))))))
329
330 (provide 'nxhtml-bug)
331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
332 ;;; nxhtml-bug.el ends here