Skip to content

Instantly share code, notes, and snippets.

@bowbow99
bowbow99 / gist:9114585
Created February 20, 2014 14:18
#xyzzy cons の CAR-TYPE/CDR-TYPE を再帰的に指定する typespec で plist
(deftype plist (&optional key-type value-type)
(let* ((tail (list value-type nil))
(spec `(or null
(cons ,key-type
(cons ,@tail)))))
(setf (cadr tail) spec)
spec))
(si:canonicalize-type '(plist keyword number))
=> #1=(or null (cons keyword (cons number #1#)))
@bowbow99
bowbow99 / gist:4611628
Created January 23, 2013 19:01
Common Lisp の type system で fizzbuzz
(defun fizzp (n) (zerop (mod n 3)))
(defun buzzp (n) (zerop (mod n 5)))
(deftype fizz () `(and integer (satisfies fizzp)))
(deftype buzz () `(and integer (satisfies buzzp)))
(deftype fizzbuzz () `(and fizz buzz))
(defun fizzbuzz-1 (n)
(etypecase n
@bowbow99
bowbow99 / gist:4012153
Created November 4, 2012 14:37
#xyzzy バッファ名を "<GIT: リポジトリ名>/そこ/からの/パス/なまえ.拡張子" みたいに
;;;;; relative pathname as buffer-name etc. in repository
(defvar *repository-type/landmark-alist*
'(("GIT" . ".git")
("HG" . ".hg")))
(defun repository-type (dir-pathname)
(dolist (x *repository-type/landmark-alist* nil)
(when (file-exist-p (merge-pathnames (cdr x) dir-pathname))
(return (car x)))))
@bowbow99
bowbow99 / gist:3987914
Created October 31, 2012 16:04
#xyzzy lisp なバッファの *buffer-package* を保存時に設定とか
;;;;; set *buffer-package*
(defparameter *lisp-mode-family* '(lisp-mode lisp-interaction-mode)
"lisp-mode な感じのメジャーモードたち(あちこちで定義してる気がする...)")
(defun find-buffer-package-from-magic-comment ()
"-*- ... package: PACKAGE -*- を拾ってくる"
(cdr (assoc "package" (ed::find-file-scan-params) :test #'string-equal)))
(defun set-buffer-package (&optional (package (find-buffer-package-from-magic-comment)))
@bowbow99
bowbow99 / keyword-mode.l
Created October 12, 2012 10:48
#xyzzy のキーワード編集用モード
;;; -*- mode: lisp; package: keyword-mode -*-
;;;
;;; keyword-mode.l --- Major mode for editing keyword file for xyzzy.
;;; Code:
(defpackage :keyword-mode
(:use :lisp :editor))
(in-package :keyword-mode)
;;; example output of DESCRIBE on Armed Bear Common Lisp (1.0.1)
;; (describe FOO)
FOO is an internal symbol in the COMMON-LISP-USER package.
;; (describe DESCRIBE)
DESCRIBE is an external symbol in the COMMON-LISP package.
Its function binding is #<DESCRIBE {E312}>.
The function's lambda list is:
(OBJECT &OPTIONAL STREAM)
@bowbow99
bowbow99 / gist:2622281
Created May 6, 2012 13:10
#xyzzy unittest で今いるdeftestを実行
;(require "simple-test") ;無駄だった
(defun read-deftest-at-point ()
"カーソル位置の deftest 式を読み込む。"
(save-excursion
(while (up-list -1 t))
(let ((*readtable* *test-file-readtable*)
(*package* (find-package :user)))
(with-input-from-selected-buffer (read)))))
@bowbow99
bowbow99 / gist:2430946
Created April 20, 2012 18:41
#xyzzy M-x start-repl するのに疲れた
(defun switch-to-repl ()
"repl を開く。
既に見えてたらそのウィンドウへ。既に開いてたらそのバッファへ。まだ開いて
なかったら開く。"
(interactive)
(let* ((repl-buffer (find-buffer "*repl*"))
(repl-window (when repl-buffer (get-buffer-window repl-buffer))))
(cond (repl-window (set-window repl-window))
(repl-buffer (switch-to-buffer repl-buffer))
@bowbow99
bowbow99 / gist:2021165
Created March 12, 2012 11:01
なんか疲れたので #xyzzy で三三七拍子してみた
(defun 337-ding (&optional (rhythm '(nil nil t nil nil t nil nil nil nil nil nil)))
(labels ((backding ()
(ding)
(when rhythm
(start-timer (if (car rhythm) 0.6 0.3)
#'backding t)
(setf rhythm (cdr rhythm)))))
(start-timer 1 #'backding t)))
=> 337-ding
@bowbow99
bowbow99 / gist:1975221
Created March 4, 2012 22:50
#xyzzy interactive で循環参照してるリストを要素として持つリストを使うと M-x で死ぬ
(defun interactive-test (x)
(interactive (list '#1=(a . #1#)))
(let ((*print-circle* t))
(msgbox "~S" x)))
=> interactive-test
(interactive-test '#1=(a . #1#))
;; msgbox で
;; #1=(a . #1#)
;; と表示される