Skip to content

Instantly share code, notes, and snippets.

View jaawerth's full-sized avatar

Jesse Wertheim jaawerth

View GitHub Profile
; lie and say it's clojure for highlighting
; vim: ft=clojure
; this is a hack that won't be necessary if/when we add `get-option` to the macro environment
(local meta-enabled (-> _SCOPE.specials.doc
(pcall (list (sym :doc) (sym :doc)) _SCOPE _CHUNK)))
(fn meta/when-enabled [...]
"Execute body in an implicit `do` when metadata is enabled. Otherwise,
contents are excluded from compiled output."
@jaawerth
jaawerth / client.fnl
Last active January 6, 2020 17:16
first pass on wrapping nvim-client in Fennel to generate api functions w/ docstrings
; lie to gist's syntax highlight and say it's clojure
; vim: ft=clojure
(require-macros :fnl.fennel-nvim.macros.metadata)
(local (mpack Session Tcp) (values (require :mpack)
(require :nvim.session)
(require :nvim.tcp_stream)))
(local fmt string.format)
(fn get-api-doc []
(let [fh (io.open "./fnl/fennel-nvim/api.mpack")
; trick gist syntax highlighting
; vim: ft=clojure
(local (fmt searchpath) (values string.format package.searchpath))
(var *ns-module-root* nil)
(λ *ns-module-root! [?val]
"Sets or gets the name of the root module name; used for namespacing
require-import. Can only be set once, before `require-include` is ever used."
(if (not ?val) *ns-module-root*
(do (assert (not *ns-module-root*)
"module-root-name! can only be called once")
@jaawerth
jaawerth / vim-shim.lua
Last active December 23, 2019 20:24
shim nvim 0.4.x with items from norcalli/nvim.luaa
-- shim lua API on nvim < 0.5.x
-- requires nvim.lua from https://github.com/norcalli/nvim.lua
local vim = vim
vim.startswith = vim.startswith or function(s, n) return s:sub(1, #n) == n end
vim.endswith = vim.endswith or function(s, n) return s:sub(-#n) == n end
vim.cmd = vim.cmd or vim.api.nvim_command
local helpers = {'fn', 'g', 'v', 'o', 'env', 'wo', 'bo'}
for _, method in ipairs(helpers) do
vim[method] = vim[method] or require('nvim')[method]
@jaawerth
jaawerth / take-values-macro-example.fnl
Created December 20, 2019 23:40
fennel macro to limit varargs from the front
; fake clojure for highlighting
; vim: ft=clojure
(macro take-values [n ...]
(assert (and (= :number (type n)) (= n (math.floor n)) (> n 0))
"take-values requires first arg to be n > 0")
(local bindings (list))
(for [i 1 n] (tset bindings i (gensym)))
`(let [,bindings ,...] (values ,(unpack bindings))))
(foo (take-values 2 (bar)))
@jaawerth
jaawerth / fnl
Created December 10, 2019 23:14
#!/usr/bin/sh
FNL_LUA="${FNL_LUA:-$(command -v lua)}"
FNL_LUAJIT="${FNL_LUAJIT:-$(command -v luajit)}"
FNL="${FNL:-$(command -v fennel)}"
FNL_EXE='';
function error() { >&2 printf "\u001b[31m%s\n\u001b[0m" "$@"; exit 1; }
use_jit=1;
args="";
@jaawerth
jaawerth / emoji
Last active June 8, 2021 16:00
emoji finder script using fzf, awk, etc
#!/usr/bin/env bash
##
# For this to work, put emojidata.tsv in $HOME/.local/share/myemoji
# or set the EMOJI_FILE env var to its local before running.
##
data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/myemoji"
EMOJI_FILE="${EMOJI_FILE:-$data_dir/emojidata.tsv}"
tabular() { cat - | column -t -s $'\t'; }
firstcol() { awk '{ print $1 }' -; }
@jaawerth
jaawerth / test.fnl.fnl
Last active October 18, 2019 22:14 — forked from turbo/test.fnl.clj
; vi: ft=clojure
(macro make [receiver classtable ...]
`(local ,receiver (doto (class ,(tostring receiver) ,classtable)
,...)))
; Handler that takes a single argument 'username'
(make UserHandler turbo.web.RequestHandler
(tset :get (fn [self name]
(self:write (.. "Username is " name)))))
#!/bin/bash
# Based on: https://gist.github.com/XVilka/8346728
awk -v term_cols="${width:-$(tput cols || echo 80)}" 'BEGIN{
s="/\\";
for (colnum = 0; colnum<term_cols; colnum++) {
r = 255-(colnum*255/term_cols);
g = (colnum*510/term_cols);
b = (colnum*255/term_cols);
if (g>255) g = 510-g;
@jaawerth
jaawerth / .fnl_inputrc
Last active October 21, 2019 17:04
tiny fennel cli wrapper
# vi:ft=readline
set show-all-if-ambiguous On
set enable-bracketed-paste On
set blink-matching-paren On