add org-generate and yasnippets for boilerplate support
This commit is contained in:
parent
35fd6ce31a
commit
4b737d59dc
6 changed files with 160 additions and 0 deletions
18
init.org
18
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
|
||||
|
|
110
org-generate.org
Normal file
110
org-generate.org
Normal file
|
@ -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
|
||||
|
7
snippets/org-mode/elisp source block
Normal file
7
snippets/org-mode/elisp source block
Normal file
|
@ -0,0 +1,7 @@
|
|||
# -*- mode: snippet -*-
|
||||
# name: source block
|
||||
# key: <se
|
||||
# --
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
$0
|
||||
#+END_SRC
|
7
snippets/org-mode/org title
Normal file
7
snippets/org-mode/org title
Normal file
|
@ -0,0 +1,7 @@
|
|||
# -*- mode: snippet -*-
|
||||
# name Org Mode Title
|
||||
# key: ttl
|
||||
# --
|
||||
#+TITLE: $1
|
||||
|
||||
* $0
|
7
snippets/org-mode/source block
Normal file
7
snippets/org-mode/source block
Normal file
|
@ -0,0 +1,7 @@
|
|||
# -*- mode: snippet -*-
|
||||
# name: source block
|
||||
# key: <s
|
||||
# --
|
||||
#+BEGIN_SRC $1
|
||||
$0
|
||||
#+END_SRC
|
11
snippets/org-mode/use-package source block
Normal file
11
snippets/org-mode/use-package source block
Normal file
|
@ -0,0 +1,11 @@
|
|||
# -*- mode: snippet -*-
|
||||
# name: source block
|
||||
# key: <sup
|
||||
# --
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package $1
|
||||
:ensure t
|
||||
:config
|
||||
(progn
|
||||
$0))
|
||||
#+END_SRC
|
Loading…
Reference in a new issue