From 4b737d59dc85e04c0d26ec755c0556768eb126c2 Mon Sep 17 00:00:00 2001 From: Peter Tillemans Date: Mon, 9 Dec 2024 18:21:17 +0100 Subject: [PATCH] add org-generate and yasnippets for boilerplate support --- init.org | 18 ++++ org-generate.org | 110 +++++++++++++++++++++ snippets/org-mode/elisp source block | 7 ++ snippets/org-mode/org title | 7 ++ snippets/org-mode/source block | 7 ++ snippets/org-mode/use-package source block | 11 +++ 6 files changed, 160 insertions(+) create mode 100644 org-generate.org create mode 100644 snippets/org-mode/elisp source block create mode 100644 snippets/org-mode/org title create mode 100644 snippets/org-mode/source block create mode 100644 snippets/org-mode/use-package source block diff --git a/init.org b/init.org index fc863e4..58ec25f 100644 --- a/init.org +++ b/init.org @@ -2695,6 +2695,24 @@ the moment. #+RESULTS: : [nil 26292 38256 549743 nil elpaca-process-queues nil nil 11000 nil] +** BoilerPlate Generator + +The way I do advent of code requires me to create a main file and a +test file every day with some boilerplate content. + +The *org-generate* package uses an org file to structure boilerplate +templates to be generated. By default it uses + +#+BEGIN_SRC emacs-lisp + (use-package org-generate + :ensure t + ) +#+END_SRC + +#+RESULTS: +: [nil 26455 5250 886750 nil elpaca-process-queues nil nil 641000 nil] + + * Communication and Interwebs #+BEGIN_SRC emacs-lisp diff --git a/org-generate.org b/org-generate.org new file mode 100644 index 0000000..532457e --- /dev/null +++ b/org-generate.org @@ -0,0 +1,110 @@ +#+TITLE: Org Generate Boilerplate Templates + +* Introduction + +This document contains boilerplate templates for generating stuff. + +To use use ~M-x org-generate~ and select the template you want to +generate. + +Templates start at level 2. Specify the root folder for the generated +files. + +Headings with a "/" at the end signify folders to be created to add +additional files into. + +You can define variables and use them in the templates using the +typical mustache syntax {{variable}}. Variables are defined in the +~org-generate-variable~ property in the properties drawer of the the +template subtree. + +*IMPORTANT* The code relies on ~#+begin_src~ and ~#+end_src~ blocks to be +written in lower case. The code looks for these case sensitively. + +* aoc + +** common-lisp +:PROPERTIES: +:org-generate-root: ~/quicklisp/local-projects/aoc +:org-generate-variable: year day +:END +*** src/ +**** {{year}}/ +***** day{{day}}.lisp +#+begin_src common-lisp + + (defpackage :aoc/2024/{{day}} + (:use :cl :aoc :alexandria :trivia :lla) + (:export + #:sample-data + #:sample-data2 + #:part1 + #:part2 + )) + + (in-package :aoc/2024/{{day}}) + + + (defun parse-line (line) + line) + + + (defun parse-input (lines) + (blocks-to-fs (mapcar #'parse-line lines))) + + (defparameter input-text (first (test-input 2024 {{day}}))) + (defparameter input-data (parse-input input-text)) + + (defparameter sample-text "") + (defparameter sample-data + (parse-input sample-text)) + + (defun part1 (data) + nil) + + (defun part2 (data) + nil) + + (defun solve-day () + (format t "part1: ~A~%" (part1 input-data)) + (format t "part2: ~A~%" (part2 input-data))) + + (defun submit () + (let ((p1 (part1 input-data)) + (p2 (part2 input-data))) + (if p1 (submit-part1 {{year}} {{day}} p1)) + (if p2 (submit-part2 {{year}} {{day}} p2)))) +#+end_src +*** tests/ +**** {{year}}/ +***** day{{day}}-test.lisp +#+begin_src common-lisp + (defpackage :aoc/2024/{{day}}/tests + (:use :cl :aoc :aoc/tests :aoc/2024/tests :parachute :aoc/2024/{{day}})) + + (in-package :aoc/2024/{{day}}/tests) + + (define-test suite-2024-{{day}} + ;:parent suite-2024 + ) + + (define-test test-foo + :parent suite-2024-{{day}} + $0) + + + (define-test test-bar + :parent suite-2024-{{day}} + ) + + + + (define-test+run test-part1 + :parent suite-2024-{{day}} + (is equal nil (part1 sample-data))) + + (define-test+run test-part2 + :parent suite-2024-{{day}} + (is equal nil (part2 sample-data))) +#+end_src + diff --git a/snippets/org-mode/elisp source block b/snippets/org-mode/elisp source block new file mode 100644 index 0000000..99a976d --- /dev/null +++ b/snippets/org-mode/elisp source block @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# name: source block +# key: