Skip to content

Instantly share code, notes, and snippets.

;; -*- Mode: Lisp; Syntax: Common-Lisp -*-
;;; Package Management
(in-package :cl-user)
(defpackage :hige
(:use :cl
:drakma
:cl-ppcre)
#+ABCL (:shadow :y-or-n-p)
;;;; Emacs Lisp
(require 'cl)
(setf *opening-stream-buffers*
(make-hash-table))
(defmacro with-default-values (binds &rest body)
`(progn
,@(mapcar
(defun read-line (buf)
(let ((start (point)))
(end-of-line)
(prog1
(buffer-substring start (point))
(forward-char))))
(defun make-nesting-print-fn (up-pre down-pre &optional (*standard-output* *standard-output*))
(let ((counter 0))
(list
;;count-up
(lambda (obj)
(incf counter)
(dotimes (i counter)
(format t "~A" up-pre))
(defun dotted-list-p (lst)
(when (consp lst)
(loop :for rest = (cdr lst) then (cdr rest)
:while (consp rest)
:finally (return (not (null rest))))))
(defun walk-inner (sexp pre mid post)
(cond
((atom sexp)
(funcall mid sexp))
;;; loop
(defun split-str-1 (str sep)
(labels ((sep? (ch)
(typecase sep
(function
(funcall sep ch))
(list (find ch sep))
(sequence (find ch sep))
(atom (eq sep ch))
(T nil))))
(defun kill-to-regexp-forward (regexp)
(interactive "sRegexp:")
(let ((start-point (point)))
(when (re-search-forward regexp nil t)
(re-search-backward regexp nil t)
(kill-region start-point (point)))))
(defun kill-to-regexp-backward (regexp)
(interactive "sRegexp:")
;;; examples
(def-binary-raw u1
;; reader
([type in]
(bit-and 255 (.read in)))
;; writer
([type value out]
(.write out)))
(def-binary-raw u2
(defmacro with-assoc-values (binds alist &body body)
(let ((al (gensym "alist")))
(flet ((expand-bind (bind)
`(,(first bind)
(cdr (assoc ,(second bind) ,al)))))
`(let ((,al ,alist))
(let ,(mapcar #'expand-bind binds)
,@body)))))
;; (with-assoc-values ((a :hoge) (b :fuga)) `((:hoge . (3 4)) (:fuga . 4))
(defmacro switch (val &body clauses)
(let ((syms (loop :repeat (length clauses)
:collect (gensym))))
`(tagbody
(case ,val
,@(mapcar
#'(lambda (clause sym)
`(,(car clause) (go ,sym)))
clauses
syms))