Skip to content

Instantly share code, notes, and snippets.

@bowbow99
bowbow99 / gist:1126263
Created August 4, 2011 20:59
#xyzzy の regexp で \d と \s
(defun string-index-of (whole part &key ignore-case)
"Return position where PART starts in WHOLE."
(let ((i 0)
(part-len (length part))
(start-with (if ignore-case #'string-equal #'string=)))
(loop
(cond ((funcall start-with whole part :end1 part-len)
(return-from string-index-of i))
((<= (length whole) part-len)
@bowbow99
bowbow99 / flet*
Created July 26, 2011 14:50
flet* を名前から想像で実装してみた
(defmacro flet* (defs &body body)
(if defs
`(flet (,(car defs))
(flet* (,@(cdr defs)) ,@body))
`(progn ,@body)))
=> flet*
(flet* ((foo (x) (1+ x))
(foo (x) (foo (* x x))))
(foo 3))
@bowbow99
bowbow99 / gist:927206
Created April 19, 2011 11:58
#xyzzy (declare (type ...)) で指定した型じゃなかったら vuvuzela
;; (defun* NAME (ARGS...) (declare (type TYPE VAR*)) ...)
;; VAR の型チェックしてダメだったらブブブーブブブブーーブブー
;; ※音が鳴るだけでエラーで止めたりはしてくれない
(require "vuvuzela") ; vuvuzela が別ライブラリ sound に依存してるのでそれも必要
(defun parse-body (body)
(let (doc intr decls)
(labels ((parse-1 (body)
(let ((form (car body)))
@bowbow99
bowbow99 / gist:896142
Created March 31, 2011 10:15
素の #xyzzy の *scratch* で lisp-unit.l を
;;; *scratch* で http://www.cs.northwestern.edu/academics/courses/325/readings/lisp-unit.html
;;; にある example をやってみたの図
(load "~/work/xyzzy.lisp-unit/site-lisp/lisp-unit.l")
t
(use-package :lisp-unit)
t
(setf (get 'define-test 'ed:lisp-indent-hook) 1)
1
@bowbow99
bowbow99 / gist:845189
Created February 26, 2011 13:22
*kill-ring* をバックアップ #xyzzy
;; - http://d.hatena.ne.jp/rubikitch/20110226/savekill
(defvar *kill-ring-file* "~/var/xyzzy-kill-ring.dat"
"*kill-ring* の内容を保存するファイル名")
;; *kill-ring* をファイルに保存/ファイルから読み込み
(defun dump-kill-ring ()
(with-open-file (out *kill-ring-file* :direction :output
:if-exists :overwrite
:if-does-not-exist :create)
@bowbow99
bowbow99 / gist:802650
Created January 30, 2011 07:28
`e' だけ(`C-x' なし)で kbd-macro を繰り返す #xyzzy
;;; repeat kbd-macro with just #\e (without #\C-x)
(let ((repeating nil))
(labels ((check-repeating-kbd-macro ()
(unless (member *this-command*
'(execute-last-kbd-macro
repeat-kbd-macro-or-self-insert
universal-argument
digit-argument
negative-argument))
(setf repeating nil)
@bowbow99
bowbow99 / gist:756971
Created December 28, 2010 06:47
#xyzzy のコマンドループっぽいもの(作りかけ
(defun command-loop (keymap)
(let (*this-command*
*last-command*
*last-command-char*
(keymap* keymap)
prefixes)
(loop
(refresh-screen)
(setf *last-command-char* (read-char *keyboard*)
*this-command* (lookup-keymap keymap* *last-command-char*))
@bowbow99
bowbow99 / fred.lisp
Created December 21, 2010 13:30
undefined-function が投げられたらファイルを load してやり直す
;; load するファイル
(format t "loading: fred.lisp~%")
(defun fred () :fred)
@bowbow99
bowbow99 / gist:740588
Created December 14, 2010 15:39
xyzzy では structure の accessor で全く関係ない structure の slot に触れてしまうことに気づいた。
;; xyzzy では structure の accessor で全く関係ない structure の slot に触れてしまう事に気づいた。
(defstruct foo
bar baz)
=> #<structure-definition: foo>
(defstruct hoge
fuga piyo)
=> #<structure-definition: hoge>
(hoge-fuga (make-foo :bar 3 :baz 4))
;;; generator っぽいものだとスッキリしそうなケースを思いついたので書いて
;;; みたけど、あまりスッキリしなかった
(define-condition stop-iteration (condition)
()
(:report (lambda (c s) (format s "Stop Iteration"))))
=> t
(defun plist-iterator (plist)
"generato iterator from plist."