Skip to content

Instantly share code, notes, and snippets.

@zahardzhan
Created January 22, 2010 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zahardzhan/283759 to your computer and use it in GitHub Desktop.
Save zahardzhan/283759 to your computer and use it in GitHub Desktop.
(defun str (&rest args)
"Returns the concatenation of string values of the args.
With no or nil args, returns the empty string."
(with-output-to-string (s)
(dolist (arg args) (princ (or arg "") s))))
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
(defmacro set-keys ((key1 &optional key2 key3) command)
(cond ((not key2)
`(progn (define-key *top-map* (kbd ,key1) ,command)
*top-map*))
((not key3)
(let ((binding1 (lookup-key *top-map* (kbd key1))))
(cond ((and binding1 (symbolp binding1))
(let ((binding1 (lookup-key *top-map* (kbd key1))))
`(progn (define-key ,binding1 (kbd ,key2) ,command)
,binding1)))
(t
(let ((binding1 (make-symbol (str key1 "-map"))))
`(progn (defparameter ,binding1 (make-sparse-keymap)) ;;;;; Вот тут надо объявить глобальную переменную
(define-key ,binding1 (kbd ,key2) ,command)
(define-key *top-map* (kbd ,key1) ,binding1)
,binding1))))))))
(set-keys ("s-a") "exec urxvt")
(set-keys ("s-d" "w") "delete")
STUMPWM> (eval `(defparameter ,(gensym) 'value))
#:G914
STUMPWM> #:G914
The variable #:G914 is unbound.
Теперь - работает:
(defmacro set-keys ((key1 &optional key2 key3) command)
(cond ((not key2)
`(progn (define-key *top-map* (kbd ,key1) ,command)
*top-map*))
((not key3)
(let ((binding1 (lookup-key *top-map* (kbd key1))))
(cond ((and binding1 (symbolp binding1))
`(progn (define-key ,binding1 (kbd ,key2) ,command)
,binding1))
(t
(multiple-value-bind (binding1) (intern (str key1 "-MAP")
(find-package '#:STUMPWM))
`(progn (defparameter ,binding1 (make-sparse-keymap))
(define-key ,binding1 (kbd ,key2) ,command)
(define-key *top-map* (kbd ,key1) (quote ,binding1))
,binding1))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment