1 ;;; xwem-help.el --- Getting help in XWEM.
3 ;; Copyright (C) 2003-2005 by XWEM Org.
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
7 ;; Keywords: xlib, xwem
8 ;; X-CVS: $Id: xwem-help.el,v 1.8 2005-04-04 19:54:12 lg Exp $
10 ;; This file is part of XWEM.
12 ;; XWEM is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 ;; License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 ;;; Synched up with: Not in FSF
31 ;; Help subsystem. Entry point is `H-h'.
38 (defmacro xwem-help-display (title &rest forms)
39 "Evaluate FORMS in special emacs frame and xwem help buffer."
40 `(let ((temp-buffer-show-function 'xwem-special-popup-frame))
41 (with-displaying-help-buffer
43 (set-buffer standard-output)
45 (format "xwem %s" (or ,title "")))))
46 (put 'xwem-help-display 'lisp-indent-function 'defun)
50 (defun xwem-logo-string ()
51 "Return textified XWEM's logo string."
52 (concat (xwem-str-with-faces "X" (list 'bold-italic))
53 (xwem-str-with-faces "W" (list 'bold-italic 'red))
54 (xwem-str-with-faces "E" (list 'bold-italic 'green))
55 (xwem-str-with-faces "M" (list 'bold-italic 'blue))))
57 ;;;###autoload(autoload 'xwem-help "xwem-help" "" t)
58 (define-xwem-command xwem-help ()
59 "Display some help info."
62 (xwem-help-display nil
63 (insert "Hello, this is help for ")
64 (insert (xwem-logo-string))
67 (insert "TODO: here is some description for ")
68 (insert (xwem-logo-string))
73 (insert "---=== Frames Info ===---\n\n")
74 (insert (format "You have %d frames now and [%d] frame is selected.\n"
75 (length xwem-frames-list)
76 (xwem-frame-num (xwem-frame-selected))))
80 ;; Maybe use tree-widget package to display this info?
81 (let ((curr-classn "")
83 (insert "---=== Clients Info ===---\n")
86 (let ((clclass (xwem-hints-wm-class (xwem-cl-hints el)))
87 (clgeom (xwem-cl-xgeom el)))
88 (when (not (string= curr-classn (cdr clclass)))
89 (setq curr-classn (cadr clclass))
90 (insert (format "\n= Begin for class name: <%s> =\n"
92 (when (not (string= curr-classi (car clclass)))
93 (setq curr-classi (car clclass))
94 (insert (format "\n- Class instance: <%s> -\n" curr-classi)))
95 (insert (format "WM-NAME: <%s>, Geom: %dx%d+%d+%d\n"
96 (xwem-hints-wm-name (xwem-cl-hints el))
98 (X-Geom-height clgeom)
100 (X-Geom-y clgeom)))))
101 (sort (copy-list xwem-clients)
103 (let ((cl1-clas (xwem-hints-wm-class (xwem-cl-hints el1)))
104 (cl1-name (xwem-hints-wm-name (xwem-cl-hints el1)))
105 (cl2-clas (xwem-hints-wm-class (xwem-cl-hints el2)))
106 (cl2-name (xwem-hints-wm-name (xwem-cl-hints el2))))
107 ;; Sort by class name, than by class
108 ;; instance, than by wm-name.
109 (or (string-lessp (cdr cl1-clas) (cdr cl2-clas))
110 (and (string= (cdr cl1-clas) (cdr cl2-clas))
111 (string-lessp (car cl1-clas) (car cl2-clas)))
112 (and (string= (car cl1-clas) (car cl2-clas))
113 (string-lessp cl1-name cl2-name)))))))
117 (insert "---=== Bindings for `")
118 (insert (xwem-str-with-faces "xwem-global-map" 'font-lock-keyword-face))
119 (insert "' ===---\n")
120 (describe-bindings-internal xwem-global-map)))
122 ;;;###autoload(autoload 'xwem-help-for-help "xwem-help" "" t)
123 (define-xwem-command xwem-help-for-help ()
124 "Help for XWEM's help system."
127 (xwem-help-display "help-for-help"
128 (let ((heading "key binding\n--- -------\n"))
129 (insert "Here should be Help-for-Help!\n\n")
131 (insert (format "Help prefix is %s, keys are:\n"
132 (substitute-command-keys
133 "\\<xwem-global-map>\\[xwem-help-prefix]"))
135 (describe-bindings-internal 'xwem-help-prefix))
138 (defun xwem-describe-prefix-bindings-1 (map keys title)
139 "For keymap MAP describe prefix KEYS.
140 If KEYS is nil describe all keymap."
141 (setq map (xwem-kbd-fixup-keymap map))
142 (when (and (keymapp map)
144 (lookup-key map keys t)))
145 (let ((heading "key binding\n--- -------\n"))
146 (insert title "\n" heading)
147 (describe-bindings-internal map nil nil keys))))
148 (put 'xwem-describe-prefix-bindings-1 'lisp-indent-function 2)
150 ;;;###autoload(autoload 'xwem-describe-prefix-bindings "xwem-help" "" t)
151 (define-xwem-command xwem-describe-prefix-bindings (prefix)
152 "Describe the bindings of the PREFIX used to reach this command."
153 (xwem-interactive (list xwem-this-command-keys))
155 ;; Adjust prefix, cut last key
157 (setq prefix (vconcat (butlast (append prefix nil)))))
159 (xwem-help-display (format "%s prefix" (key-description prefix))
161 (insert (format "Key bindings starting with `%s':\n"
162 (key-description prefix))))
164 ;; Minor modes bindings
165 (mapc #'(lambda (mimap)
166 (when (eval (car mimap))
167 (xwem-describe-prefix-bindings-1 (eval (cdr mimap)) prefix
168 (format "\nMinor mode bindings for `%S':" (car mimap)))))
169 xwem-minor-mode-map-alist)
172 (xwem-describe-prefix-bindings-1 (xwem-local-map xwem-event-client) prefix
173 (format "\n%s major mode bindings:"
174 (upcase (symbol-name (xwem-cl-manage-type xwem-event-client)))))
176 ;; Finally global bindings
177 (xwem-describe-prefix-bindings-1 xwem-global-map prefix
178 (format "\nGlobal bindings:"))
181 (xwem-describe-prefix-bindings-1 'xwem-frame-prefix prefix
182 (format "\nFrame bindings:"))
184 ;; Root bindings. Really need?
185 (xwem-describe-prefix-bindings-1 'xwem-root-prefix prefix
186 (format "\nRoot bindings:"))
189 ;;;###autoload(autoload 'xwem-help-describe-bindings "xwem-help" "" t)
190 (define-xwem-command xwem-help-describe-bindings ()
191 "Describe all current bindings."
193 (xwem-describe-prefix-bindings nil))
195 ;;;###autoload(autoload 'xwem-help-describe-key1 "xwem-help" "" t)
196 (define-xwem-command xwem-help-describe-key1 (key)
198 (xwem-interactive (list xwem-this-command-keys))
200 (let ((dfn (xwem-kbd-get-binding key))
201 (keystr (key-description key)))
203 (if (or (null dfn) (integerp dfn))
204 (xwem-message 'info "%s is undefined." keystr)
205 (xwem-help-display (format "key `%s'" keystr)
209 (insert (format "`%S'" dfn))
210 (insert (format "%S" dfn)))
212 (cond ((or (stringp dfn) (vectorp dfn))
213 (let ((cmd (xwem-kbd-get-binding dfn)))
215 (insert "a keyboard macro")
216 (insert "a keyboard macro which runs the command\n")
217 (insert (format "`%S'" cmd))
219 (when (documentation cmd)
220 (insert (documentation cmd))))))
221 ((and (consp dfn) (not (eq 'lambda (car-safe dfn))))
222 (let ((describe-function-show-arglist nil))
223 (describe-function-1 (car dfn))))
225 (describe-function-1 dfn))
227 (insert (documentation dfn)))
228 (t (insert "not documented"))))
231 ;;;###autoload(autoload 'xwem-help-mode "xwem-help" "" t)
232 (define-xwem-command xwem-help-mode (client)
233 "Describe client mode."
234 (xwem-interactive (list (xwem-cl-selected)))
236 (xwem-help-display (format "%S" (xwem-cl-manage-type client))
237 (insert (format "%s mode:\n" (upcase (symbol-name (xwem-cl-manage-type client)))))
238 (insert (function-documentation
239 (get 'manage (xwem-cl-manage-type client))))
240 (insert "\nCommands:\n")
241 ;; Minor modes bindings
242 (mapc #'(lambda (mimap)
243 (when (eval (car mimap))
244 (xwem-describe-prefix-bindings-1 (eval (cdr mimap)) nil
245 (format "\nMinor mode bindings for `%S':" (car mimap)))))
246 xwem-minor-mode-map-alist)
249 ;;;###autoload(autoload 'xwem-help-describe-key "xwem-help" "" t)
250 (define-xwem-command xwem-help-describe-key (keys)
251 "Describe keysequence."
252 (xwem-interactive "KDescribe key: ")
254 (xwem-help-describe-key1 keys))
256 ;;;###autoload(autoload 'xwem-help-frames "xwem-help" "" t)
257 (define-xwem-command xwem-help-frames ()
258 "Help for XWEM's frames."
261 (xwem-message 'todo "`xwem-help-frames' is not written yet.")
264 ;;;###autoload(autoload 'xwem-help-wins "xwem-help" "" t)
265 (define-xwem-command xwem-help-wins ()
266 "Help for XWEM's windows."
269 (xwem-message 'todo "`xwem-help-wins' is not written yet.")
272 ;; TODO: we should write something similar to ibuffer or
273 ;; electric-buffer-list to operate on cliets, switching, getting stat,
275 ;;;###autoload(autoload 'xwem-help-clients "xwem-help" "" t)
276 (define-xwem-command xwem-help-clients ()
277 "Help for XWEM's clients."
280 (xwem-message 'todo "`xwem-help-clients' is not written yet.")
283 ;;;###autoload(autoload 'xwem-help-where-is "xwem-help" "" t)
284 (define-xwem-command xwem-help-where-is (dfn &optional paste)
286 (xwem-interactive "CXWEM where is command: \nP")
288 (let* ((keys (where-is-internal dfn (list xwem-global-map)))
289 (msg (if keys (format "%s is on %s"
290 dfn (sorted-key-descriptions keys))
291 (format "%s is not on any keys" dfn))))
293 (xwem-kbd-add-pending-keys msg)
294 (xwem-message 'info msg))))
299 ;;; xwem-help.el ends here