add command move-end-of-line
[lice.git] / src / commands.lisp
blobbd10c3c19d5a42a7b9273554d69c60358d852c7c
1 ;; Command related functions
3 (in-package "LICE")
5 (defclass command ()
6 ((name :type symbol :initarg :name :accessor command-name)
7 (args :type list :initarg :args :accessor command-args)
8 (fn :type function :initarg :fn :accessor command-fn)
9 (doc :type (or null string) :initarg :doc :accessor command-doc))
10 (:documentation "An interactive command."))
12 (defvar *commands* (make-hash-table)
13 "A hash table of interactive commands")
15 (defmacro defcommand (name (&optional args &rest interactive-args) &body body)
16 "Create an interactive command named NAME."
17 (let ((tmp (gensym)))
18 `(progn
19 (defun ,name ,args
20 ,@body)
21 (setf (gethash ',name *commands*)
22 (make-instance
23 'command
24 :name ',name
25 :args ',interactive-args
26 :doc ,(when (typep (first body) 'string) (first body))
27 :fn #',name)))))
29 (defgeneric lookup-command (name)
30 (:documentation "lookup the command named NAME."))
32 (defmethod lookup-command ((name symbol))
33 (gethash name *commands*))
35 (defmethod lookup-command ((name string))
36 ;; FIXME: this can fill the keyword package with lots of junk
37 ;; symbols.
38 (gethash (intern (string-upcase name) "KEYWORD") *commands*))
40 (defvar *command-arg-type-hash* (make-hash-table)
41 "A hash table of symbols. each symbol is an interactive argument
42 type whose value is a function that is called to gather input from the
43 user (or somewhere else) and return the result. For instance,
44 :BUFFER's value is read-buffer which prompts the user for a buffer and
45 returns it.
47 This variable is here to allow modules to add new argument types easily.")
49 (defvar mark-even-if-inactive nil
50 "*Non-nil means you can use the mark even when inactive.
51 This option makes a difference in Transient Mark mode.
52 When the option is non-nil, deactivation of the mark
53 turns off region highlighting, but commands that use the mark
54 behave as if the mark were still active.")