From bb67745117cd1cf3b1ec0944fc367f47167cd071 Mon Sep 17 00:00:00 2001 From: shoshin Date: Sat, 21 May 2022 13:19:47 -0500 Subject: Add: first pass of literate config --- moo.org | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 moo.org (limited to 'moo.org') diff --git a/moo.org b/moo.org new file mode 100644 index 0000000..6d08b8d --- /dev/null +++ b/moo.org @@ -0,0 +1,98 @@ +#+PROPERTY: header-args:emacs-lisp :lexical t + +Setting the property for the whole buffer to have lexical binding in emacs-lisp +source blocks. Lexical binding will hold when evaluating any source block where +no other ~:lexical~ header arg is present. + +* Moo +:PROPERTIES: +:header-args:emacs-lisp+: :noweb-ref moo +:END: + +noweb-ref will make all blocks under this heading expand with =<>= + +#+begin_src emacs-lisp + (+ x 3) +#+end_src + +* Goo +:PROPERTIES: +:header-args:emacs-lisp+: :noweb yes +:header-args:emacs-lisp+: :var foo="bar" +:END: + +turn noweb on so we interpret the =<>= syntax as code to expand +setting a var ~foo~ to the string "bar" to be used later. + +** Poop + +properties go down into the subtrees + +#+begin_src emacs-lisp + (let ((x 1)) + <>) +#+end_src + +#+RESULTS: +: 4 + +*** Floppy +:PROPERTIES: +:header-args:emacs-lisp+: :noweb no +:END: + +apparently continuing with the "+" pattern takes the no over the yes above +this will fail to expand moo. + +#+begin_src emacs-lisp + (let ((x 1)) + <>) +#+end_src + +#+RESULTS: +: let: Symbol’s value as variable is void: <> + +** Gah + +Define a function with a free variable x. + +#+begin_src emacs-lisp :results none + (defun getx () + x) +#+end_src + +Because ~x~ is lexically bound in this block, ~getx~ will error +since ~x~ is not a dynamic variable and isn't bound with indefinite scope. + +#+begin_src emacs-lisp + (let ((x 1)) ; ‘x’ is lexically bound. + (getx)) +#+end_src + +#+RESULTS: +: Symbol’s value as variable is void: x + +we can flip lexical binding off for the evaluation of this block and +the free variable ~x~ is bound when ~getx~ is evaluated. + +#+begin_src emacs-lisp :lexical no + (let ((x 2)) ; ‘x’ is dynamically bound + (getx)) +#+end_src + +#+RESULTS: +: 2 + +** Bah +:PROPERTIES: +:header-args:emacs-lisp+: :var foo="baz" +:END: + +overriding the variable in this subtree + +#+begin_src emacs-lisp + foo +#+end_src + +#+RESULTS: +: baz -- cgit v1.2.3