aboutsummaryrefslogtreecommitdiff
path: root/moo.org
diff options
context:
space:
mode:
authorshoshin <shoshin@cicadas.surf>2022-05-21 13:19:47 -0500
committershoshin <shoshin@cicadas.surf>2022-05-21 13:19:47 -0500
commitbb67745117cd1cf3b1ec0944fc367f47167cd071 (patch)
tree0a55e8175c8779af864f8f81e87d1ae9a148729f /moo.org
Add: first pass of literate config
Diffstat (limited to 'moo.org')
-rw-r--r--moo.org98
1 files changed, 98 insertions, 0 deletions
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 =<<moo>>=
+
+#+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 =<<moo>>= 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))
+ <<moo>>)
+#+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))
+ <<moo>>)
+#+end_src
+
+#+RESULTS:
+: let: Symbol’s value as variable is void: <<moo>>
+
+** 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