Skip to content

Instantly share code, notes, and snippets.


Chris Barrett chrisbarrett

View GitHub Profile
View sexp.go
// Compiler from Go types to an S-Expression representation.
// The output a drop-in replacement for the Elisp JSON parser output, and can be
// consumed directly with `read`.
package main
import (
chrisbarrett / Learn Emacs in 7 days.el
Last active Feb 9, 2020
Paste into the scratch buffer and `M-x eval-buffer` to begin the journey.
View Learn Emacs in 7 days.el
(url-copy-file ""
(defun you-lack-discipline ()
(insert-image (create-image "~/discipline.jpg")))
(dolist (k '([up] [left] [down] [right]))
(global-set-key k 'you-lack-discipline))
chrisbarrett / cal-usage.el
Created Jul 25, 2013
Usage example of `cal`
View cal-usage.el
; Infix algebra in Lisp because yolo
sin(2) * ([1,2,3] + [4,5,6])
; => [0.174497483513, 0.244296476918, 0.314095470323]
chrisbarrett / cal.el
Last active Dec 20, 2015
Macro for writing math expressions with infix syntax. Requires calc, smartparens, dash and s.
View cal.el
(defmacro cal (&rest expression)
"Evaluate algebraic EXPRESSION using calc."
((expr (with-temp-buffer
(insert (->> expression
(-map 'pp-to-string)
(apply 'concat)
(s-replace (rx space) "")))
;; Unpack unquote forms applied by the lisp reader.
chrisbarrett / c_obj_usage.c
Last active Mar 24, 2017
C Array object usage example
View c_obj_usage.c
#include <stdio.h>
#include "array_obj.h"
int main()
// Allocate an array of 5 ints.
Array_new(xs, int, 5);
// Initialize elements using their indices.
xs.each_i(^(int x, int i) { xs.set(i, i); });
// Print elements.
chrisbarrett / array_obj.h
Last active Mar 24, 2017
C object using blocks language extension
View array_obj.h
#include <assert.h>
#include <stdlib.h>
#define Array_new(name, type, len) \
typedef void(^name##_each)(type); \
typedef void(^name##_each_i)(type, int); \
struct { \
type *data; \
size_t length; \
chrisbarrett / ruby-hideshow.el
Last active Oct 16, 2019
Ruby code folding using hideshow
View ruby-hideshow.el
(eval-after-load "hideshow"
'(add-to-list 'hs-special-modes-alist
,(rx (or "def" "class" "module" "{" "[")) ; Block start
,(rx (or "}" "]" "end")) ; Block end
,(rx (or "#" "=begin")) ; Comment start
ruby-forward-sexp nil)))
chrisbarrett / emr-binding.el
Created Apr 16, 2013
An example of an EMR binding
View emr-binding.el
;;; Let-bind variable
(emr-declare-action emr-extract-to-let emacs-lisp-mode "let-bind"
:predicate (not (or (emr--looking-at-definition?)
:description "let")
View init.el
;; Initialize packages.
(require 'package)
(dolist (source '(("melpa" . "")
("marmalade" . "")))
(add-to-list 'package-archives source))
(unless package-archive-contents