Skip to content

Instantly share code, notes, and snippets.

@garlic0x1
garlic0x1 / os.lisp
Created June 29, 2024 06:10
Lem OS utilities
(defpackage #:config/os
(:use :cl :lem :alexandria-2))
(in-package :config/os)
(defun complete-cmd (s)
"Completion function for shell commands (incomplete)."
(line-up-first
(format nil "compgen -c ~a" s)
(uiop:run-program :output :string)
(str:lines)))
@garlic0x1
garlic0x1 / fonts.lisp
Created June 29, 2024 06:08
Lem font selector
(defpackage :config/fonts
(:use :cl :lem :alexandria-2))
(in-package :config/fonts)
(defparameter *font-directory* #p"/usr/share/fonts/TTF/")
(defun font-files (font)
(values (merge-pathnames (uiop:strcat font "-Regular.ttf") *font-directory*)
(merge-pathnames (uiop:strcat font "-Bold.ttf") *font-directory*)))
@garlic0x1
garlic0x1 / configuration.nix
Created June 22, 2024 03:15
nixos xmodmap
services.xserver.displayManager.sessionCommands = ''
${pkgs.xorg.xmodmap}/bin/xmodmap -e "remove Lock = Caps_Lock"
${pkgs.xorg.xmodmap}/bin/xmodmap -e "keysym Caps_Lock = Control_L"
${pkgs.xorg.xmodmap}/bin/xmodmap -e "add Control = Control_L"
${pkgs.xorg.xmodmap}/bin/xmodmap -e "remove Shift = Shift_R"
${pkgs.xorg.xmodmap}/bin/xmodmap -e "keysym Shift_R = Caps_Lock"
${pkgs.xorg.xmodmap}/bin/xmodmap -e "add Lock = Caps_Lock"
'';
@garlic0x1
garlic0x1 / init.el
Created June 17, 2024 11:13
Emacs config
;;--------------;;
;; Setup elpaca ;;
;;--------------;;
(defvar elpaca-installer-version 0.7)
(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory))
(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git"
:ref nil :depth 1
@garlic0x1
garlic0x1 / ts_query.c
Created May 28, 2024 20:24
Performing a query in tree-sitter
#include <stdint.h>
#include <stdio.h>
#include <tree_sitter/api.h>
#include <tree_sitter/tree-sitter-c.h>
int main() {
// Create a Tree-sitter parser
const TSLanguage *language = tree_sitter_c();
TSParser *parser = ts_parser_new();
ts_parser_set_language(parser, language);
@garlic0x1
garlic0x1 / cffi.md
Last active May 23, 2024 19:28
CFFI passing structs by value

I am trying to return a struct by value from a C function, and then pass it by value to another C function using cffi-libffi.

Here are the relevant functions and structure with links to the definitions in the header file:

(use-foreign-library "libtree-sitter.so")

;; https://github.com/tree-sitter/tree-sitter/blob/master/lib/include/tree_sitter/api.h#L99
(defcstruct ts-node
  (context :uint32 :count 4)
  (id :pointer)
@garlic0x1
garlic0x1 / hooks.lisp
Created February 25, 2024 05:17
Lisp hook API
(defpackage :hooks
(:use :cl)
(:import-from :alexandria :if-let)
(:export :register-hook :run-hook))
(in-package :hooks)
(defvar *hooks* (make-hash-table)
"Global hook table.
Use `register-hook` and `clear-hook` to modify this.")
@garlic0x1
garlic0x1 / readtable-case.lisp
Created February 18, 2024 19:53
Common Lisp case-sensitive keywords
(set-macro-character
#\$
(lambda (stream char)
(declare (ignore char))
(let ((*readtable* (copy-readtable nil)))
(setf (readtable-case *readtable*) :preserve)
(read stream))))
$:CaseSensitiveKeyword
;; => :|CaseSensitiveKeyword|
@garlic0x1
garlic0x1 / setup.sh
Last active February 7, 2024 08:01
Setup Lisp Machine (Fedora)
#!/bin/bash
set -x
### Packages
dnf update -y
dnf install -y sbcl git make gcc ncurses-devel redhat-rpm-config curl rlwrap
### Config
curl https://raw.githubusercontent.com/garlic0x1/dotfiles/master/.bashrc > ~/.bashrc
@garlic0x1
garlic0x1 / glob.lisp
Created January 29, 2024 07:45
Glob match with CFFI
(cffi:defcfun ("fnmatch" fnmatch) :int
(pattern :string)
(string :string)
(flags :int))
(defun glob-match (pattern string &optional (flags 4))
(= 0 (fnmatch pattern string flags)))