OSDN Git Service

update copyright years
[howm/howm.git] / honest-report.el
1 ;;; honest-report.el --- make bug report with screenshot and keylog
2
3 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017
4 ;;   HIRAOKA Kazuyuki <khi@users.sourceforge.jp>
5 ;; $Id: honest-report.el,v 1.13 2011-12-31 15:07:29 hira Exp $
6 ;;
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
10 ;; any later version.
11 ;;
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; The GNU General Public License is available by anonymouse ftp from
18 ;; prep.ai.mit.edu in pub/gnu/COPYING.  Alternately, you can write to
19 ;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
20 ;; USA.
21
22 ;;; Commentary:
23
24 ;; (For users)
25 ;; This small tool helps you write clear bug report.
26 ;; Just type M-x honest-report to show recent keys and screen shots.
27 ;; Copy them into your bug report.
28
29 ;; (For programmers)
30 ;; Write a wrapper of `honest-report' with your favorite header and footer.
31
32 ;; (Bug)
33 ;; Text properties are ignored in screen shot.
34 ;; In particular, too large region can be copied for outline-mode
35 ;; because all closed items are shown as opened.
36
37 ;;; Code:
38
39 (defun honest-report (&optional header footer)
40   (interactive)
41   (let ((ver (honest-report-version))
42         (key (honest-report-recent-keys))
43         (msg (honest-report-message))
44         (scr (honest-report-screenshot)))
45     (honest-report-setup)
46     (mapc (lambda (a) (apply #'honest-report-insert a))
47           `(
48             ("Header"          ,header)
49             ("Emacs version"   ,ver)
50             ("Recent keys"     ,key)
51             ("Recent messages" ,msg)
52             ("Screen shot"     ,scr)
53             ("Footer"          ,footer)
54             ))
55     (goto-char (point-max))))
56
57 (defun honest-report-insert (title content)
58   (when content
59     (insert "* " title ":\n\n" content "\n\n")))
60
61 ;;;;;;;;;;;;;
62
63 (defun honest-report-setup ()
64   (let ((report-buf (format-time-string "honest-report-%Y%m%d-%H%M%S")))
65     (switch-to-buffer report-buf)))
66
67 ;; snap:///usr/share/emacs/21.4/lisp/mail/emacsbug.el#136:(insert (mapconcat (lambda (key)
68 (defun honest-report-recent-keys ()
69   (mapconcat (lambda (key)
70                (if (or (integerp key)
71                        (symbolp key)
72                        (listp key))
73                    (single-key-description key)
74                  (prin1-to-string key nil)))
75              (recent-keys)
76              " "))
77
78 (defun honest-report-screenshot ()
79   (mapconcat (lambda (w)
80                (with-current-buffer (window-buffer w)
81                  (let ((b (max (window-start w) (point-min)))
82                        (e (min (window-end w t) (point-max))))
83                    (format "--- %s ---\n%s"
84                            w
85                            (buffer-substring-no-properties b e)))))
86              (honest-report-window-list)
87              "\n"))
88
89 (defun honest-report-window-list ()
90   "Mimic `window-list'.
91 This function exists only for emacs20 (and meadow-1.15),
92 which lack `window-list'."
93   (let ((ws nil))
94     (walk-windows (lambda (w) (setq ws (cons w ws))))
95     (reverse ws)))
96
97 (defun honest-report-message ()
98   (with-current-buffer (or (get-buffer "*Messages*")
99                            (get-buffer " *Message-Log*"))
100     (save-excursion
101       (goto-char (point-max))
102       (forward-line -10)
103       (buffer-substring-no-properties (point) (point-max)))))
104
105 (defun honest-report-version ()
106   (mapconcat (lambda (sv) (format "[%s] %s" (car sv) (cdr sv)))
107              (honest-report-version-assoc)
108              "\n"))
109
110 (defun honest-report-version-assoc ()
111   (remove nil
112           `(
113             ("Emacs" . ,(format "%s (%s) of %s"
114                               emacs-version
115                               system-configuration
116                               (honest-report-emacs-build-time)))
117             ("system" . ,system-type)
118             ("window system" . ,window-system)
119             ,(let ((f 'Meadow-version))
120                ;; cheat to avoid warning while byte-compilation.
121                (and (fboundp f)
122                     (cons "Meadow" (funcall f))))
123             ("ENV" . ,(mapconcat (lambda (v) (format "%s=%s" v (getenv v)))
124                                  '("LC_ALL" "LC_CTYPE" "LANGUAGE" "LANG")
125                                  ", "))
126             )))
127
128 (defun honest-report-emacs-build-time ()
129   (if (stringp emacs-build-time)
130       emacs-build-time  ;; xemacs
131     (format-time-string "%Y-%m-%d"
132                         emacs-build-time)))
133
134 ;;;;;;;;;;;;;
135
136 (provide 'honest-report)
137
138 ;;; honest-report.el ends here