Skip to content

Instantly share code, notes, and snippets.

@anekos
Last active August 29, 2015 14:00
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 anekos/2f8caefee2ab99482a03 to your computer and use it in GitHub Desktop.
Save anekos/2f8caefee2ab99482a03 to your computer and use it in GitHub Desktop.
iron-maiden 取扱説明書
インストール
1. sbcl をインストール
2. quicklisp をインストール http://www.quicklisp.org/beta/
3. sbcl で以下の実行
> (ql:quickload :clx)
> (ql:quickload :cl-ppcre)
4. git checkout -t origin/feature/key-map-with-class
5. iron-maiden のディレクトリで make
実行
$ sudo ./iron-maiden <設定ファイル>
; vim: set lispwords+=tap,for-device,for-window-class,def-event-co-routine,when-let :
(in-package :im-user)
; utils {{{
(defun command-path (name)
(dolist (dir *path*)
(let ((path (merge-pathnames name dir)))
(when (probe-file path)
(return (namestring path))))))
(defun run (cmd &rest args)
(if-let (cmd-path (command-path cmd))
(sb-ext:run-program "/bin/sudo" `("-u" ,*user* ,cmd-path ,@(alexandria:flatten args)) :wait nil :output t)
(format t "command not found: ~A~%" cmd)))
(defun slock ()
(run "slock"))
(defun zip-with (func &rest lists)
(apply #'mapcar (cons func lists)))
(defmacro key-map-to-action (lhs &rest action)
(with-gensyms (history lhs-c wait-for last-key)
(eval `(defvar ,lhs-c (im-key:key-pair-list-from-text ,lhs :symbol-modifiers t)))
(eval `(defvar ,history (im-ring-buffer:make-ring-buffer (length ,lhs-c))))
(eval `(defvar ,wait-for nil))
(eval `(defvar ,last-key (caar (last ,lhs-c))))
`(if ,wait-for
(when-key-press
(when (= code ,last-key)
(equal-case value
(value-repeat
,@action)
(value-up
(setf ,wait-for nil)))
(next-event)))
(let ((modifiers ($ im keyboard-state im-state:current-modifires)))
(when-key-down
(im-ring-buffer:put-to-buffer ,history (cons code modifiers))
(when (equalp (coerce ,lhs-c 'vector) (im-ring-buffer:get-straight ,history))
,@action
(im-ring-buffer:clear-all-buffer ,history)
(setf ,wait-for t)
(next-event)))))))
(defmacro key-map-to-key (lhs rhs)
`(key-map-to-action ,lhs (press-key im ,rhs)))
(defmacro key-map (lhs rhs &rest rhs-rest)
(if (stringp rhs)
`(key-map-to-key ,lhs ,rhs)
`(key-map-to-action ,lhs ,rhs ,@rhs-rest)))
(defmacro x-and-y (original-key change-key modifier-key)
(with-gensyms (pressing any-key-pressed)
(eval `(defvar ,pressing nil))
(eval `(defvar ,any-key-pressed nil))
`(when-key-press
(if (= code ,original-key)
(equal-case
value
(imv:value-down
(setf ,pressing t)
(next-event))
(imv:value-repeat
(next-event))
(imv:value-up
(if ,any-key-pressed
(progn
(send-event im imv:ev-key ,modifier-key imv:value-up)
(setf ,any-key-pressed nil))
(progn
(let ((send-key (or ,change-key ,original-key)))
(send-event im imv:ev-key send-key imv:value-down)
(send-event im imv:ev-key send-key imv:value-up))))
(setf ,pressing nil)
(next-event)))
(when (and (= value imv:value-down) ,pressing (not ,any-key-pressed))
(send-event im imv:ev-key ,modifier-key imv:value-down)
(setf ,any-key-pressed t))))))
(defun toggle-output-mode ()
(format t "toggle output-mode~%")
(setf *output-mode* (not *output-mode*)))
; }}}
; co-routines {{{
(def-pedal-routine pedal-shell key-a "shell")
(def-pedal-routine pedal-ranger key-b "ranger")
(def-pedal-routine pedal-calc key-c "calc")
; }}}
; main {{{
(defvar *output-mode* nil)
(defvar *user* "anekos")
(defvar *home-directory* (merge-pathnames #P"/home/" *user*))
(defvar *path* (list #P"/home/anekos/.xmonad/bin/"
#P"/home/anekos/local/bin/"
#P"/home/anekos/bin/"
#P"/usr/bin/"))
(iron-maiden
(define-keyboard "HHKB"
:path #P"/dev/input/by-id/usb-Topre_Corporation_HHKB_Professional-event-kbd")
(define-keyboard "Pedal3"
:path #P"/dev/input/by-id/usb-RDing_FootSwitch3F1.-event-mouse")
; safety
(let ((ring (imrb:make-ring-buffer 10)))
(define-processor
(for-keyboard
(when-key-down
(when (= code key-esc)
(imrb:put-to-buffer ring msec)
(when-let (next (imrb:next-buffer ring))
(when (< (- msec next) 2000)
(imrb:clear-all-buffer ring)
(sb-ext:exit))))))))
; pp - alt 三回おすとデバッグ出力
(define-processor
(when *output-mode*
(pp t ev))
(for-keyboard
(key-map-to-action
"<leftalt><leftalt><leftalt>"
(toggle-output-mode))))
; ignore
(define-processor
(for-device "PowerMate"
(next-event)))
; キー入れ替え
(define-processor
(for-device "Kinesis"
(change key-capslock key-leftctrl))))
@kozo2
Copy link

kozo2 commented May 4, 2014

こんなん出ました

~/src/iron-maiden-cl$ make
sbcl --load make.cl
This is SBCL 1.1.14.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at http://www.sbcl.org/.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
To load "cl-annot":
Install 2 Quicklisp releases:
alexandria cl-annot
; Fetching #<URL "http://beta.quicklisp.org/archive/alexandria/2014-04-25/alexandria-20140425-git.tgz">

; 48.35KB

49,512 bytes in 0.14 seconds (358.16KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-annot/2014-01-13/cl-annot-20140113-git.tgz">

; 9.75KB

9,985 bytes in 0.00 seconds (9750.98KB/sec)
; Loading "cl-annot"
[package alexandria.0.dev]........................
[package cl-annot.util]...........................
[package cl-annot.core]...........................
[package cl-annot.expand].........................
[package cl-annot.syntax].........................
[package cl-annot.helper].........................
[package cl-annot]................................
[package cl-annot.std]............................
[package cl-annot.eval-when]......................
[package cl-annot.doc]............................
[package cl-annot.class]..........................
[package cl-annot.slot]
To load "alexandria":
Load 1 ASDF system:
alexandria
; Loading "alexandria"

To load "cl-cont":
Load 1 ASDF system:
alexandria
Install 2 Quicklisp releases:
cl-cont closer-mop
; Fetching #<URL "http://beta.quicklisp.org/archive/closer-mop/2014-04-25/closer-mop-20140425-git.tgz">

; 19.26KB

19,726 bytes in 0.00 seconds (19263.67KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-cont/2011-02-19/cl-cont-20110219-darcs.tgz">

; 11.44KB

11,715 bytes in 0.00 seconds (11440.43KB/sec)
; Loading "cl-cont"
[package closer-mop]..............................
[package closer-common-lisp]......................
[package closer-common-lisp-user].................
[package cl-cont]...
To load "cl-fad":
Load 1 ASDF system:
alexandria
Install 2 Quicklisp releases:
bordeaux-threads cl-fad
; Fetching #<URL "http://beta.quicklisp.org/archive/bordeaux-threads/2013-06-15/bordeaux-threads-0.8.3.tgz">

; 18.31KB

18,754 bytes in 0.00 seconds (4578.61KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-fad/2013-07-20/cl-fad-0.7.2.tgz">

; 23.84KB

24,411 bytes in 0.00 seconds (4767.77KB/sec)
; Loading "cl-fad"
[package bordeaux-threads]........................
[package cl-fad]..................................
[package path]........
To load "cl-op":
Install 1 Quicklisp release:
cl-op
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-op/2012-04-07/cl-op-20120407-svn.tgz">

; 3.00KB

3,067 bytes in 0.00 seconds (748.78KB/sec)
; Loading "cl-op"
[package cl-op]...................................
[package cl-op.hof]..
To load "clx":
Load 1 ASDF system:
clx
; Loading "clx"

To load "cl-ppcre":
Load 1 ASDF system:
cl-ppcre
; Loading "cl-ppcre"
..

debugger invoked on a SIMPLE-ERROR in thread

<THREAD "main thread" RUNNING {1002A8B263}>:

Error opening shared object "/home/anekos/project/iron-maiden-cl/iron-maiden.so":
/home/anekos/project/iron-maiden-cl/iron-maiden.so: cannot open shared object file: No such file or directory.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [RETRY ] Retry EVAL of current toplevel form.
1: [CONTINUE] Ignore error and continue loading file "/home/knishida/src/iron-maiden-cl/iron-maiden.cl".
2: [ABORT ] Abort loading file "/home/knishida/src/iron-maiden-cl/iron-maiden.cl".
3: Retry EVAL of current toplevel form.
4: Ignore error and continue loading file "/home/knishida/src/iron-maiden-cl/make.cl".
5: Abort loading file "/home/knishida/src/iron-maiden-cl/make.cl".
6: Ignore runtime option --load "make.cl".
7: Skip rest of --eval and --load options.
8: Skip to toplevel READ/EVAL/PRINT loop.
9: [EXIT ] Exit SBCL (calling #'EXIT, killing the process).

(SB-SYS:DLOPEN-OR-LOSE #S(SB-ALIEN::SHARED-OBJECT :PATHNAME #P"/home/anekos/project/iron-maiden-cl/iron-maiden.so" :NAMESTRING "/home/anekos/project/iron-maiden-cl/iron-maiden.so" :HANDLE NIL :DONT-SAVE NIL))
0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment