Skip to content

Instantly share code, notes, and snippets.

@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: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: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 / 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: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 / autoload-misc.l
Created August 23, 2011 10:44
autoload 指定されたシンボルを調べる #xyzzy
(defun autoload-symbol-p (symbol)
(and (symbolp symbol)
(fboundp symbol)
(autoload-function-p symbol)))
(defun autoload-module (symbol)
(unless (autoload-symbol-p symbol)
(error "autoload 指定されたシンボルじゃないです: ~S" symbol))
(let* ((def (or (macro-function symbol)
(si:closure-body (symbol-function symbol))))
@bowbow99
bowbow99 / gist:1182248
Created August 30, 2011 22:15
#xyzzy require で読み込まれたのに provide してない奴を探す
;;; require で読み込まれたのに provide してない奴を探す
;;; .xyzzy の先頭に書いといて起動すると、provide しなかった奴が記録されるので
;;; *scratch* で (print-required-but-not-provided) するとてきとーに表示
(defconstant +original-require+ #'require)
(defparameter *required-but-not-provided* nil)
(defun require (&rest args)
(let ((modules-prev (copy-list *modules*))
(module-name (car args)))
@bowbow99
bowbow99 / gist:1190576
Created September 3, 2011 04:43
#xyzzy labels をコンパイルすると泣ける
;; labels の lambda-list 内の init-form で同じ labels 式で定義したローカル
;; 関数を呼び出してると、コンパイルで挙動が変わる
(defun x () :global)
=> x
(defun test ()
(labels ((x () :local)
(test-1 (&optional (val (x))) val))
(test-1)))
@bowbow99
bowbow99 / gist:1190635
Created September 3, 2011 05:35
#xyzzy バッファの lisp ソースから式の書いてあった位置を覚えつつ読み込む
;;; 式の位置を記録しながら読み込む
(require "cmu_loop")
(defun read-forms-with-code-position (buffer &optional print-debug-info)
(with-input-from-buffer (buffer (point-min))
(let ((*readtable* (copy-readtable *readtable*))
(positions (make-hash-table))
(*read-depth* 0))
(declare (special *read-depth*))
@bowbow99
bowbow99 / gist:1312709
Created October 25, 2011 13:24
#xyzzy のバッククォートをいぢめてみた
;; Clozure CL
CL-USER> (let ((x #\a)) `#(,x))
#(#\a)
;; xyzzy
(let ((x #\a)) `#(,x))
=> #((#:|| x))