-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelp.lisp.in
204 lines (181 loc) · 8.63 KB
/
help.lisp.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
;; Copyright (C) 2008 Shawn Betts
;; Copyright (C) 2010-2011 Alexander aka CosmonauT Vynnyk
;;
;; This file is part of dswm.
;;
;; dswm is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; dswm is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this software; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;; Boston, MA 02111-1307 USA
;; Commentary:
;;
;; Help and introspection commands
;;
;; Code:
(in-package #:dswm)
;; (export '(*version* version))
;; Version
(defparameter *version*
#.(concat "@PACKAGE_VERSION@" " Compiled On "
(format-expand *time-format-string-alist*
*time-format-string-default*)))
(defcommand version () ()
"Print version information and compilation date."
(message *version*))
(defun columnize (list columns &key col-aligns (pad 1) (char #\Space) (align :left))
"Make conlumns for messages from list"
;; only somewhat nasty
(let* ((rows (ceiling (length list) columns))
(data (loop for i from 0 below (length list) by rows
collect (subseq list i (min (+ i rows) (length list)))))
(max (mapcar (lambda (col)
(reduce 'max col :key 'length :initial-value 0))
data))
(padstr (make-string pad :initial-element char)))
(apply 'mapcar 'concat
;; normalize width
(loop
for i in data
for j in max
for c from 0
collect (loop
for k from 0 below rows
for s = (or (nth k i) "")
for len = (make-string (- j (length s))
:initial-element char)
collect (ecase (or (nth c col-aligns) align)
(:left (format nil "~a~a~a" (if (= c 0) "" padstr) s len))
(:right (format nil "~a~a~a" (if (= c 0) "" padstr) len s))))))))
(defun display-bindings-for-keymaps (key-seq &rest keymaps)
(let* ((screen (current-screen))
(data (mapcan (lambda (map)
(mapcar (lambda (b) (format nil "^5*~5a^n ~a" (print-key (binding-key b)) (binding-command b))) (kmap-bindings map)))
keymaps))
(cols (ceiling (1+ (length data))
(truncate (- (head-height (current-head)) (* 2 (screen-msg-border-width screen)))
(font-height (screen-font screen))))))
(message-no-timeout "Prefix: ~a~%~{~a~^~%~}"
(print-key-seq key-seq)
(columnize data cols))))
(defun first-start (&optional show)
(let ((not-firststart-p (data-dir-file "started" "p"))
(*message-window-gravity* :center)
(firststart-message (format nil
"
^7*Welcome to The ^BD^beep ^BS^bpace ^BW^bindow ^BM^banager!
This is first-start message for quick ^BDSWM^b usage learning
-------------------------------------------------------------
* Press ^5*~a ?^7* for more detail help.
* Your config-file is {HOME}/.dswm or ~a/init.lisp
* Use prefix key ^5*~a^7* with keybindings
Basic keybindings:
+--------------+--------------------------------------------+
| Keybinding | Role |
+--------------+--------------------------------------------+
| ! | Run program by name |
| ; | Run commandline for internal DSWM commands |
| r | Resize frame |
| s | Split frame horizontally |
| S | Splt frame vertically |
| R | Remove split |
| m <N> | Move window to frame with number <N> |
| <N> | Select window with number <N> |
| F<N> | Select group with number <N> |
| g c | Create group |
| g k | Remove group |
+-----------------------------------------------------------+
* Run in internal command ^Bdescribe-key or describe-command^b etc
for describing keybinding or command
* ^BYou can always show this message^b, entering ~a h^b, or throug
internal command ^Bhelp-short^b
Notes:
^BVersion: ~a
License: GNU GPL v.2^b
" (print-key *escape-key*) (data-dir) (print-key *escape-key*) (print-key *escape-key*) *version*)))
(when (or (not (file-exists-p not-firststart-p))
show)
(progn (message-no-timeout firststart-message)
(with-open-file (stream not-firststart-p :if-does-not-exist :create)
t)))))
(defcommand commands () ()
"List all available commands."
(let* ((screen (current-screen))
(data (all-commands))
(*message-window-gravity* :center)
(cols (ceiling (length data)
(truncate (- (head-height (current-head)) (* 2 (screen-msg-border-width screen)))
(font-height (screen-font screen))))))
(message-no-timeout "~{~a~^~%~}"
(columnize data cols))))
(defcommand describe-key (keys) ((:key-seq "Type key to describe: "))
"Either interactively type the key sequence or supply it as text. This
command prints the command bound to the specified key sequence."
(let ((cmd (loop for map in (top-maps)
for cmd = (lookup-key-sequence map keys)
when cmd return cmd))
(*message-window-gravity* :center))
(if cmd
(message "Key ~{~a~^ ~}~%is bound to\"~a\" command." (mapcar 'print-key keys) cmd)
(message "~{~a~^ ~} is not bound." (mapcar 'print-key keys)))))
(defcommand describe-variable (var) ((:variable "Input variable name to describe: "))
"Print the online help associated with the specified variable."
(let ((*message-window-gravity* :center))
(message-no-timeout "~a"
(with-output-to-string (s)
(describe var s)))))
(defcommand describe-function (fn) ((:function "Input function name to describe: "))
"Print the online help associated with the specified function."
(let ((*message-window-gravity* :center))
(message-no-timeout "~a"
(with-output-to-string (s)
(describe fn s)))))
(defcommand describe-command (com) ((:command "Input command to describe: "))
"Print the online help associated with the specified command."
(let* ((deref (dereference-command-symbol com))
(struct (get-command-structure com nil))
(*message-window-gravity* :center))
(cond ((null struct)
(message "Error: Command \"~a\" not found." com))
((eq deref struct)
(message-no-timeout "Command \"~a\":~%~a" (command-name struct)
(documentation (command-name struct) 'function)))
(t
(message-no-timeout "\"~a\" is an alias for the command \"~a\":~%~a" (command-alias-from deref) (command-name struct)
(documentation (command-name struct) 'function))))))
(defcommand where-is (cmd) ((:command "Input command to detect to wat key it bind: "))
"Print the key sequences bound to the specified command."
(let ((bindings (loop for map in (top-maps) append (search-kmap cmd map)))
(*message-window-gravity* :center))
(if bindings
(message-no-timeout "\"~a\" is on ~{~a~^, ~}"
cmd
(mapcar 'print-key-seq bindings))
(message-no-timeout "Command \"~a\" is not currently bound"
cmd))))
(defcommand modifiers () ()
"List the modifiers dswm recognizes and what MOD-X it thinks they're on."
(let ((*message-window-gravity* :center))
(message "~@{~5@a: ~{~(~a~)~^ ~}~%~}"
"Meta" (modifiers-meta *modifiers*)
"Alt" (modifiers-alt *modifiers*)
"Super" (modifiers-super *modifiers*)
"Hyper" (modifiers-hyper *modifiers*)
"AltGr" (modifiers-altgr *modifiers*))))
(defcommand help-short () ()
(first-start t))
;; (defcommand help-license () ()
;; (message-no-timeout (cat (merge-pathnames
;; (string-as-directory "@prefix@/share/dswm/")
;; "COPYING"))))
;; (defcommand help-authors () ()
;; (message-no-timeout (cat (merge-pathnames
;; (string-as-directory "@prefix@/share/dswm/")
;; "AUTHORS"))))