Initial Commit
[packages] / xemacs-packages / ecb / ecb-help.el
1 ;;; ecb-help.el --- online help for ECB and bug reporting
2
3 ;; Copyright (C) 2000 - 2003 Jesper Nordenberg,
4 ;;                           Klaus Berndl,
5 ;;                           Kevin A. Burton,
6 ;;                           Free Software Foundation, Inc.
7
8 ;; Author: Jesper Nordenberg <mayhem@home.se>
9 ;;         Klaus Berndl <klaus.berndl@sdm.de>
10 ;;         Kevin A. Burton <burton@openprivacy.org>
11 ;; Maintainer: Klaus Berndl <klaus.berndl@sdm.de>
12 ;;             Kevin A. Burton <burton@openprivacy.org>
13 ;; Keywords: browser, code, programming, tools
14 ;; Created: 2001
15
16 ;; This program is free software; you can redistribute it and/or modify it under
17 ;; the terms of the GNU General Public License as published by the Free Software
18 ;; Foundation; either version 2, or (at your option) any later version.
19
20 ;; This program is distributed in the hope that it will be useful, but WITHOUT
21 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 ;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
23 ;; details.
24
25 ;; You should have received a copy of the GNU General Public License along with
26 ;; GNU Emacs; see the file COPYING.  If not, write to the Free Software
27 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
29 ;; $Id: ecb-help.el,v 1.109 2004/11/17 17:28:38 berndl Exp $
30
31 ;;; Commentary:
32 ;;
33 ;; Contains all online-help for ECB (stolen something from recentf.el)
34
35 ;;; History
36 ;;
37 ;; For the ChangeLog of this file see the CVS-repository. For a complete
38 ;; history of the ECB-package see the file NEWS.
39
40 ;;; Code
41
42 (eval-when-compile
43   (require 'silentcomp))
44
45 (require 'ecb-layout)
46 (require 'ecb-util)
47
48 ;; XEmacs and Emacs 20.X
49 (silentcomp-defvar browse-url-new-window-p)
50 (silentcomp-defun browse-url)
51 ;; Emacs 21
52 (silentcomp-defvar browse-url-new-window-flag)
53 ;; JDE
54 (silentcomp-defvar jde-version)
55 ;; mail and reporter
56 (silentcomp-defun mail-subject)
57 (silentcomp-defun mail-text)
58 (silentcomp-defun reporter-submit-bug-report)
59
60 (defconst ecb-help-info-start-file "ecb.info")
61 (defconst ecb-help-html-start-file "ecb.html")
62 (defconst ecb-help-info-subdir "./info-help/")
63 (defconst ecb-help-html-subdir "./html-help/")
64
65 (defgroup ecb-help nil
66   "Settings for the ECB online help"
67   :group 'ecb)
68
69 (defcustom ecb-show-help-format 'info
70   "*The format `ecb-show-help' shows its online help.
71 Allowed values are 'info \(for the Info format) and 'html \(for HTML format).
72 If the value is 'html then `browse-url-browser-function' says which browser is
73 used.
74
75 Note: If you got ECB as a standard XEmacs-package maybe the
76 HTML-online-documentation is not included."
77   :group 'ecb-help
78   :group 'ecb-most-important
79   :type '(choice :tag "Online-help format" :menu-tag "Online-help format"
80                  (const :tag "Info" :value info)
81                  (const :tag "Html" :value html)))
82
83
84 (defcustom ecb-help-info-path (concat
85                                (if ecb-running-xemacs
86                                    (if (file-exists-p
87                                         (concat ecb-ecb-dir
88                                                 ecb-help-info-subdir
89                                                 ecb-help-info-start-file))
90                                        ecb-help-info-subdir
91                                      "../../info/")
92                                  ecb-help-info-subdir)
93                                ecb-help-info-start-file)
94   "*Path where the ECB online help in info format resides.
95 This must be the location of the file \"ecb.info\" which comes with the ECB
96 distribution. If is installed by unpacking the archive available on the ECB
97 web-site then this is the subdir `ecb-help-info-subdir' of the installation
98 directory of ECB. If it is installed as XEmacs-package \(e.g. via the package
99 manager of XEmacs) then this is probably the directory \"../../info/\"
100 \(relativ to the Elisp directory of ECB).
101
102 The path can either be an absolute path or a path relative to the directory
103 where the Elisp files of ECB are.
104
105 Normally there should be no need to change this option!"
106   :group 'ecb-help
107   :type 'file)
108
109 (defcustom ecb-help-html-path
110   (if (not ecb-running-xemacs)
111       (concat ecb-help-html-subdir ecb-help-html-start-file)
112     (cond ((file-exists-p
113             (concat ecb-ecb-dir
114                     ecb-help-html-subdir
115                     ecb-help-html-start-file))
116            (concat ecb-help-html-subdir ecb-help-html-start-file))
117           ((file-exists-p
118             (concat ecb-ecb-dir
119                     "../../html/"
120                     ecb-help-html-start-file))
121            (concat "../../html/" ecb-help-html-start-file))
122           ((file-exists-p
123             (concat ecb-ecb-dir
124                     "../../html/ecb/index.html"))
125            "../../html/ecb/index.html")
126           (t
127            (concat "../../etc/ecb/html/" ecb-help-html-start-file))))
128   "*Path where the ECB online help in HTML format resides.
129 This must be the location of the file \"index.html\" which comes with the ECB
130 distribution. If is installed by unpacking the archive available on the ECB
131 web-site then this is the subdir `ecb-help-html-subdir' of the installation
132 directory of ECB. If it is installed as XEmacs-package \(e.g. via the package
133 manager of XEmacs) then this is probably either the directory \"../../html/\" or
134 \"../../etc/ecb/html/\" \(both relative to the Elisp directory of ECB).
135
136 The path can either be an absolute path or a path relative to the directory
137 where the Elisp files of ECB are.
138
139 Normally there should be no need to change this option!"
140   :group 'ecb-help
141   :type 'file)
142
143
144 (defun ecb-info (info-file &optional no-file-not-exist-err)
145   "Starts `info' with INFO-FILE. If INFO-FILE does not exists then nil is
146 returned otherwise true. If NO-FILE-NOT-EXIST-ERR is not nil then just nil is
147 returned if INFO-FILE does not exist otherwise an error is reported."
148   (if (file-exists-p info-file)
149       (prog1 t
150         (info info-file))
151     (unless no-file-not-exist-err
152       (ecb-error "Info file %s does not exists!" info-file))
153     nil))
154
155 (defun ecb-browse-html-file (html-file &optional no-file-not-exist-err)
156   "Opens HTML-FILE in the standard-webbrowser with `browse-url'. If INFO-FILE
157 does not exists then nil is returned otherwise true. If NO-FILE-NOT-EXIST-ERR
158 is not nil then just nil is returned if HTML-FILE does not exist otherwise an
159 error is reported."
160   (if (file-exists-p html-file)
161       (prog1 t
162         (if (and (locate-library "browse-url")
163                  (require 'browse-url)
164                  (fboundp 'browse-url))
165             (browse-url (concat "file://" html-file)
166                         (if (boundp 'browse-url-new-window-flag)
167                             browse-url-new-window-flag
168                           browse-url-new-window-p))
169           (ecb-error "Function 'browse-url needed for displaying HTML!")))
170     (unless no-file-not-exist-err
171       (ecb-error "HTML file %s does not exists!" html-file))
172     nil))
173
174 ;;;###autoload
175 (defun ecb-show-help (&optional format)
176   "Shows the online help of ECB in Info or HTML-format.
177 The format depends on the setting in `ecb-show-help-format'. If called with
178 prefix argument, i.e. if FORMAT is not nil then the user is prompted to choose
179 the format of the help \(Info or Html).
180
181 If an error about not finding the needed help-file occurs please take a look
182 at the options `ecb-help-info-start-file' and `ecb-help-html-start-file'!
183
184 Note: If you got ECB as a standard XEmacs-package maybe the
185 HTML-online-documentation is not included."
186   (interactive "P")
187   (let ((f (if format
188                (intern (ecb-query-string "Choose format of online-help:"
189                                          (if (equal 'ecb-show-help-format
190                                                     'html)
191                                              '("info" "html")
192                                            '("html" "info"))))
193              ecb-show-help-format))
194         (info-path-abs (expand-file-name
195                         (if (or (string-match "^\\." ecb-help-info-path)
196                                 (string-match (concat "^"
197                                                       (regexp-quote
198                                                        ecb-help-info-start-file))
199                                               ecb-help-info-path))
200                             (concat ecb-ecb-dir ecb-help-info-path)
201                           ecb-help-info-path)))
202         (html-path-abs (expand-file-name
203                         (if (or (string-match "^\\." ecb-help-html-path)
204                                 (string-match (concat "^"
205                                                       (regexp-quote
206                                                        ecb-help-html-start-file))
207                                               ecb-help-html-path))
208                             (concat ecb-ecb-dir ecb-help-html-path)
209                           ecb-help-html-path))))
210     (if (equal f 'info)
211         (ecb-info info-path-abs)
212       (message "Opening ECB online-help in a web-browser...")
213       (ecb-browse-html-file html-path-abs))))
214
215
216 ;;
217 ;; Problem reporting functions stolen from JDEE
218 ;;
219 (defvar ecb-problem-report-mail-address "ecb-list@lists.sourceforge.net" )
220
221 (defconst ecb-problem-report-message
222   "Please enter the details of your bug report here")
223
224 (defun ecb-submit-problem-report()
225   "Submit a problem report for the ECB to the ECB mailing-list.
226 This command generates in the edit-window a problem-report which contains
227 already the current values of all ECB options, the current backtrace-buffer if
228 there is any and the current message-buffer. You will be asked for a
229 problem-report subject and then you must insert a description of the problem.
230 Please describe the problem as detailed as possible!
231
232 *IMPORTANT*: Cause of extra appearance of SPAM in the mailing-lists,
233 SourceForge has changed its policy: Now it is only possible to post to the
234 mailing-list for users who have subscribed this mailing-list. So please be
235 aware you will not be able to send comments, bug reports and improvement
236 suggestions before you have subscribed the ECB-mailing-list. See the section
237 \"Mailing-list\" at the ECB-website at http://ecb.sourceforge.net how to do
238 this."
239
240   (interactive)
241   (when (or ecb-minor-mode
242             (y-or-n-p "ECB should be active when submitting a problem-report. Force report? "))
243     (if (and (equal ecb-frame (selected-frame))
244              (not (ecb-point-in-edit-window)))
245         (ecb-select-edit-window))
246     (if (not (locate-library "reporter"))
247         (ecb-error "You need the reporter.el package to submit a bugreport for ECB!")
248       (require 'reporter)
249       (progn
250         (message "Preparing problem report...")
251         ;;prepare the basic buffer
252         (reporter-submit-bug-report
253          ecb-problem-report-mail-address
254          (format "ECB: %s, semantic: %s, eieio: %s, speedbar: %s, JDEE: %s"
255                  ecb-version
256                  semantic-version
257                  eieio-version
258                  speedbar-version
259                  (if (boundp 'jde-version)
260                      jde-version
261                    "No JDEE"))
262          (ecb-problem-report-list-all-variables)
263          nil
264          'ecb-problem-report-post-hook
265          ecb-problem-report-message)
266         (if (equal ecb-frame (selected-frame))
267             (ecb-redraw-layout))
268         (mail-subject)
269         (insert (read-string "Problem report subject: "
270                              (format "ECB-%s -- " ecb-version)))
271         (mail-text)
272         (search-forward ecb-problem-report-message)
273         (end-of-line)
274         (message "Preparing bug report...done")))))
275
276 (defun ecb-problem-report-post-hook()
277   "Function run the reporter package done its work. It looks for a message- and
278 a backtrace-buffer and inserts the contents of that."
279   (save-excursion
280     (beginning-of-buffer)
281     ;; if the mail-packages has already inserted a signature we must not go to
282     ;; the buffer-end but just before the signature
283     (if (re-search-forward "^--[ \t]*$" nil t)
284         (progn
285           (beginning-of-line)
286           (insert "\n\n\n")
287           (forward-line -2))
288       (goto-char (point-max))
289       (insert "\n\n"))
290     ;; ecb-faces
291     (let ((ecb-face-list (delq nil (mapcar (function
292                                             (lambda (f)
293                                               (if (string-match "^ecb-"
294                                                                 (symbol-name f))
295                                                   f
296                                                 nil)))
297                                            (face-list)))))
298       (insert "\n\n-----------------------------------------------------\n")
299       (insert "The attributes of the ECB-faces are:\n\n")
300       (dolist (f ecb-face-list)
301         (when f
302           (insert (format "%s: %s\n"
303                           (symbol-name f)
304                           (funcall (if ecb-running-xemacs
305                                        'face-custom-attributes-get
306                                      'custom-face-attributes-get)
307                                    f ecb-frame)))))
308       (insert "\n-----------------------------------------------------\n\n"))
309     (let* ((messages-buffer 
310             (get-buffer
311              (if ecb-running-xemacs " *Message-Log*" "*Messages*")))
312            (backtrace-buffer (get-buffer "*Backtrace*"))
313            (tag-dump-buffer (get-buffer "*ecb-tag-dump*")))
314
315       ;;insert the contents of the tag-dump buffer if it is there. 
316       (insert "\n\n-----------------------------------------------------\n")
317       (if tag-dump-buffer
318           (progn
319             (insert "The contents of the *ecb-tag-dump* buffer were\n\n")
320             (insert-buffer tag-dump-buffer)
321             ;; we must force the mark
322             (goto-char (mark t))
323             (insert "\nEnd Insert *ecb-tag-dump* buffer" ))
324         (insert "There was no *ecb-tag-dump* buffer" ))
325       (insert "\n-----------------------------------------------------\n\n")
326
327       ;;insert the contents of the trace-output buffer if it is there. 
328 ;;       (insert "\n\n-----------------------------------------------------\n")
329 ;;       (if tag-dump-buffer
330 ;;           (progn
331 ;;             (insert "The contents of the *ecb-tag-dump* buffer were\n\n")
332 ;;          (insert-buffer tag-dump-buffer)
333 ;;             ;; we must force the mark
334 ;;          (goto-char (mark t))
335 ;;             (insert "\nEnd Insert *ecb-tag-dump* buffer" ))
336 ;;         (insert "There was no *ecb-tag-dump* buffer" ))
337 ;;       (insert "\n-----------------------------------------------------\n\n")
338
339       ;;insert the contents of the backtrace buffer if it is there. 
340       (insert "\n\n-----------------------------------------------------\n")
341       (if backtrace-buffer
342           (progn
343             (insert "The contents of the *Backtrace* buffer were\n\n")
344             (insert-buffer backtrace-buffer)
345             ;; we must force the mark
346             (goto-char (mark t))
347             (insert "\nEnd Insert *Backtrace* buffer" ))
348         (insert "There was no *Backtrace* buffer" ))
349       (insert "\n-----------------------------------------------------\n\n")
350
351       ;;insert the contents of the messages buffer if it is there. 
352       (insert "-----------------------------------------------------\n")
353       (if messages-buffer
354           (progn
355             (insert "The contents of the *Messages* buffer were\n\n")
356             (insert-buffer messages-buffer)
357             (goto-char (mark t))
358             (insert "\nEnd Insert *Messages* buffer" ))
359         (insert "There was no *Messages* buffer" ))
360       (insert  "\n-----------------------------------------------------\n\n"))))
361
362
363 (defun ecb-problem-report-list-all-variables()
364   "List all variables starting with `ecb-' and some other variables which
365 could be interesting for support."
366   (let ((emacs-vars (sort (delete nil
367                                   `(pre-command-hook
368                                     post-command-hook
369                                     after-save-hook
370                                     help-mode-hook
371                                     compilation-mode-hook
372                                     truncate-partial-width-windows
373                                     truncate-lines
374                                     ,(if (boundp 'compilation-window-height)
375                                          'compilation-window-height)
376                                     ,(if (boundp 'temp-buffer-max-height)
377                                          'temp-buffer-max-height)
378                                     auto-mode-alist
379                                     ,(if (boundp 'c-mode-hook)
380                                          'c-mode-hook)
381                                     ,(if (boundp 'c++-mode-hook)
382                                          'c++-mode-hook)
383                                     ,(if (boundp 'c-mode-common-hook)
384                                          'c-mode-common-hook)
385                                     ,(if (boundp 'java-mode-hook)
386                                          'java-mode-hook)
387                                     ,(if (boundp 'jde-mode-hook)
388                                          'jde-mode-hook)
389                                     system-type
390                                     window-system
391                                     max-specpdl-size
392                                     max-lisp-eval-depth
393                                     ,(if (boundp 'ediff-quit-hook)
394                                          'ediff-quit-hook)))
395                           (function (lambda (l r)
396                                       (ecb-string< (symbol-name l)
397                                                    (symbol-name r))))))
398         (semantic-vars (sort (delete nil
399                                      `(semantic-after-toplevel-cache-change-hook
400                                        semantic-after-partial-cache-change-hook
401                                        ,(if (boundp 'semantic-format-face-alist)
402                                             'semantic-format-face-alist
403                                           'semantic-face-alist)
404                                        semantic-uml-colon-string
405                                        semantic-orphaned-member-metaparent-type))
406                              (function (lambda (l r)
407                                          (ecb-string< (symbol-name l)
408                                                       (symbol-name r))))))
409         (speedbar-vars (sort '(speedbar-dynamic-tags-function-list
410                                speedbar-tag-hierarchy-method
411                                speedbar-tag-group-name-minimum-length
412                                speedbar-tag-split-minimum-length
413                                speedbar-tag-regroup-maximum-length
414                                speedbar-fetch-etags-command
415                                speedbar-fetch-etags-arguments
416                                speedbar-fetch-etags-parse-list)
417                              (function (lambda (l r)
418                                          (ecb-string< (symbol-name l)
419                                                       (symbol-name r))))))
420         (ecb-options (mapcar
421                       'intern
422                       (sort
423                        (let (completion-ignore-case)
424                          (all-completions "ecb-" obarray 'user-variable-p))
425                        'ecb-string<)))
426         (ecb-internal-vars (sort '(ecb-path-selected-directory
427                                    ecb-path-selected-source
428                                    ecb-use-semantic-grouping
429                                    ecb-idle-timer-alist
430                                    ecb-post-command-hooks
431                                    ecb-max-specpdl-size-old
432                                    ecb-max-lisp-eval-depth-old
433                                    ecb-minor-mode
434                                    ecb-last-window-config-before-deactivation
435                                    ecb-edit-area-creators
436                                    ecb-windows-hidden
437                                    ecb-toggle-layout-state
438                                    ecb-current-maximized-ecb-buffer-name
439                                    ecb-special-ecb-buffers-of-current-layout)
440                                  (function (lambda (l r)
441                                              (ecb-string< (symbol-name l)
442                                                           (symbol-name r)))))))
443     (append emacs-vars semantic-vars speedbar-vars
444             ecb-internal-vars ecb-options)))
445
446
447 (silentcomp-provide 'ecb-help)
448
449 ;; ecb-help.el ends here