<concept name="properties">
<description>Key-value metadata attached to headings</description>
<example>
* Task
:PROPERTIES:
:CATEGORY: work
:EFFORT: 2h
:END:
</example>
</concept>
<concept name="drawers">
<description>Hidden content blocks</description>
<example>
:LOGBOOK:
CLOCK: [2024-01-15 Mon 10:00]--[2024-01-15 Mon 12:00] => 2:00
:END:
</example>
</concept>
<concept name="timestamps">
<description>Date and time specifications</description>
<example>
<2024-01-15 Mon> ; active timestamp
[2024-01-15 Mon] ; inactive timestamp
<2024-01-15 Mon 10:00> ; with time
<2024-01-15 Mon +1w> ; repeating weekly
<2024-01-15 Mon .+1d> ; restart from completion
</example>
</concept>
<decision_tree name="timestamp_type_selection">
<question>What is the purpose of this timestamp?</question>
<branch condition="Schedule task, show in agenda"><active timestamp></branch>
<branch condition="Record date without agenda visibility">[inactive timestamp]</branch>
<branch condition="Task repeats on fixed schedule">+1d/+1w/+1m repeater</branch>
<branch condition="Task repeats from today when done">.+1d reset repeater</branch>
<branch condition="Shift to future, catching up missed">++1d cumulative repeater</branch>
</decision_tree>
1. First ordered item
2. Second ordered item
- [ ] Checkbox item
- [x] Completed checkbox
</example>
</pattern>
<pattern name="tables">
<description>Spreadsheet-like tables with formulas</description>
<example>
| Name | Quantity | Price | Total |
|-------+----------+-------+--------|
| Item1 | 2 | 10.0 | 20.0 |
| Item2 | 3 | 15.0 | 45.0 |
|-------+----------+-------+--------|
| Total | | | 65.0 |
#+TBLFM: $4=$2*$3::@>$4=vsum(@2..@-1)
</example>
<note>C-c C-c to recalculate, C-c | to create table from region</note>
</pattern>
<pattern name="links">
<description>Internal and external hyperlinks</description>
<example>
[[https://orgmode.org][Org website]]
[[file:./other.org][Local file]]
[[file:./image.png]]
[[*Heading][Internal link]]
[[id:unique-id][ID link]]
<<target>> and [[target]]
</example>
</pattern>
<decision_tree name="link_type_selection">
<question>What are you linking to?</question>
<branch condition="External URL">[[https://...][description]]</branch>
<branch condition="Local file in project">[[file:./path][description]]</branch>
<branch condition="Heading in same file">[[*Heading Name][description]]</branch>
<branch condition="Stable cross-file reference">[[id:uuid][description]] with org-id</branch>
<branch condition="Named target in document"><<target>> and [[target]]</branch>
</decision_tree>
<pattern name="blocks">
<description>Special content blocks</description>
<example>
#+BEGIN_QUOTE
Quoted text here.
#+END_QUOTE
#+BEGIN_EXAMPLE
Verbatim text, no markup processing.
#+END_EXAMPLE
#+BEGIN_CENTER
Centered text.
#+END_CENTER
#+BEGIN_VERSE
Poetry or
formatted text.
#+END_VERSE
</example>
</pattern>
<pattern name="markup">
<description>Text formatting markup</description>
<example>
*bold*
/italic/
_underline_
=verbatim=
~code~
+strikethrough+
</example>
</pattern>
<pattern name="footnotes">
<description>Reference notes</description>
<example>
Text with footnote[fn:1].
[fn:1] Footnote definition.
Or inline[fn:: inline footnote definition].
</example>
</pattern>
- TODO Buy groceries
- NEXT Write report
- WAITING Review from team :@john:
- DONE Complete project
- CANCELLED Obsolete task
</example>
<note>@ prompts for note, ! records timestamp, | separates active from done states</note>
<decision_tree name="capture_template_type">
<question>What type of content are you capturing?</question>
<branch condition="Action item or task">entry with TODO state to inbox</branch>
<branch condition="Reference note or information">entry to notes file</branch>
<branch condition="Daily journal or log">entry with file+datetree</branch>
<branch condition="Meeting notes">entry with timestamp to meetings section</branch>
<branch condition="Add item to existing list">item or checkitem type</branch>
</decision_tree>
<pattern name="agenda">
<description>Agenda views and custom commands</description>
<example>
(setq org-agenda-files '("~/org/"))
(setq org-agenda-custom-commands
'(("d" "Dashboard"
((agenda "" ((org-agenda-span 7)))
(todo "NEXT"
((org-agenda-overriding-header "Next Actions")))
(todo "WAITING"
((org-agenda-overriding-header "Waiting For")))))
("w" "Weekly Review"
((agenda "" ((org-agenda-span 7)
(org-agenda-start-on-weekday 1)))
(stuck "")
(todo "TODO")))))
</example>
</pattern>
<pattern name="refile">
<description>Task refiling configuration</description>
<example>
(setq org-refile-targets
'((nil :maxlevel . 3)
(org-agenda-files :maxlevel . 2)))
(setq org-refile-use-outline-path 'file)
(setq org-outline-path-complete-in-steps nil)
(setq org-refile-allow-creating-parent-nodes 'confirm)
</example>
<note>C-c C-w to refile entry, C-u C-c C-w to jump to target</note>
</pattern>
<pattern name="clocking">
<description>Time tracking with clock</description>
<example>
* Task with time tracking
:LOGBOOK:
CLOCK: [2024-01-15 Mon 10:00]--[2024-01-15 Mon 12:30] => 2:30
CLOCK: [2024-01-14 Sun 14:00]--[2024-01-14 Sun 15:00] => 1:00
:END:
(setq org-clock-persist t)
(setq org-clock-in-resume t)
(setq org-clock-out-remove-zero-time-clocks t)
(setq org-clock-report-include-clocking-task t)
</example>
<note>C-c C-x C-i clock in, C-c C-x C-o clock out, C-c C-x C-r insert clock report</note>
</pattern>
<pattern name="tags">
<description>Tag-based organization</description>
<example>
#+TAGS: @home(h) @work(w) @phone(p) @computer(c)
#+TAGS: urgent(u) important(i)
- TODO Call dentist :@phone:urgent:
(setq org-tag-alist
'((:startgroup)
("@home" . ?h)
("@work" . ?w)
(:endgroup)
("urgent" . ?u)
("important" . ?i)))
</example>
</pattern>
<pattern name="archiving">
<description>Archive completed tasks</description>
<example>
(setq org-archive-location "~/org/archive.org::datetree/")
(setq org-archive-subtree-save-file-p t)
</example>
<note>C-c C-x C-a archive subtree, C-c C-x C-s archive sibling</note>
</pattern>
#+RESULTS: example-block
: Hello from Python
: Item 0
: Item 1
: Item 2
</example>
#+BEGIN_SRC shell :dir /tmp :results silent
ls -la
#+END_SRC
#+BEGIN_SRC python :session py :results output
# Persistent session across blocks
import sys
print(sys.version)
#+END_SRC
</example>
<note>
Header arguments:
- :results (value, output, silent, replace, append)
- :exports (code, results, both, none)
- :var (variable binding)
- :dir (working directory)
- :session (persistent session)
- :tangle (file to tangle to)
- :noweb (noweb reference expansion)
</note>
</pattern>
<pattern name="tangle">
<description>Extract source code to files</description>
<example>
#+PROPERTY: header-args :tangle yes
#+BEGIN_SRC python :tangle ./script.py :shebang "#!/usr/bin/env python3"
def main():
print("Generated from org file")
if **name** == "**main**":
main()
#+END_SRC
#+BEGIN_SRC nix :tangle ./default.nix :mkdirp yes
{ pkgs ? import <nixpkgs> {} }:
pkgs.hello
#+END_SRC
</example>
<note>C-c C-v t to tangle current file, :mkdirp yes to create directories</note>
</pattern>
<pattern name="noweb">
<description>Literate programming with named blocks</description>
<example>
#+NAME: imports
#+BEGIN_SRC python :noweb-ref imports
import os
import sys
#+END_SRC
#+NAME: main-function
#+BEGIN_SRC python :noweb-ref main
def main():
print("Running main")
#+END_SRC
#+BEGIN_SRC python :tangle ./program.py :noweb yes
<<imports>>
<<main>>
if **name** == "**main**":
main()
#+END_SRC
</example>
</pattern>
<pattern name="results">
<description>Result handling options</description>
<example>
#+BEGIN_SRC elisp :results value
(+ 1 2 3)
#+END_SRC
#+RESULTS:
: 6
#+BEGIN_SRC python :results output
print("line 1")
print("line 2")
#+END_SRC
#+RESULTS:
: line 1
: line 2
#+BEGIN_SRC elisp :results table
'(("Name" "Age") ("Alice" 30) ("Bob" 25))
#+END_SRC
#+RESULTS:
| Name | Age |
| Alice | 30 |
| Bob | 25 |
</example>
</pattern>
<pattern name="language_specific">
<description>Language-specific configurations</description>
<example>
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(python . t)
(shell . t)
(js . t)
(sql . t)
(plantuml . t)))
(setq org-confirm-babel-evaluate nil)
(setq org-src-preserve-indentation t)
(setq org-src-tab-acts-natively t)
(setq org-edit-src-content-indentation 0)
</example>
</pattern>
<pattern name="inline_code">
<description>Inline source code evaluation</description>
<example>
The result is src_python{return 2 + 2} {{{results(=4=)}}}.
Today is src_elisp{(format-time-string "%Y-%m-%d")}.
</example>
</pattern>
#+SETUPFILE: ./theme.setup
</example>
(setq org-html-validation-link nil)
(setq org-html-head-include-scripts nil)
(setq org-html-head-include-default-style nil)
(setq org-html-doctype "html5")
(setq org-html-html5-fancy t)
</example>
<note>C-c C-e h h to export to HTML file</note>
</pattern>
<pattern name="latex_export">
<description>LaTeX/PDF export configuration</description>
<example>
#+LATEX_CLASS: article
#+LATEX_CLASS_OPTIONS: [a4paper,11pt]
#+LATEX_HEADER: \usepackage{geometry}
#+LATEX_HEADER: \geometry{margin=1in}
(setq org-latex-pdf-process
'("latexmk -pdf -shell-escape %f"))
(add-to-list 'org-latex-classes
'("report"
"\\documentclass{report}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")))
</example>
<note>C-c C-e l p to export to PDF via LaTeX</note>
</pattern>
<pattern name="beamer">
<description>Presentation slides with Beamer</description>
<example>
#+TITLE: Presentation Title
#+AUTHOR: Presenter
#+OPTIONS: H:2 toc:nil
#+BEAMER_THEME: Madrid
#+BEAMER_COLOR_THEME: default
- Introduction
\*\* First Slide
* Point one
* Point two
\*\* Second Slide
#+ATTR_BEAMER: :overlay <+->
- Appears first
- Appears second
- Appears third
* Conclusion
\*\* Summary
Key takeaways here.
</example>
<note>H:2 means level-2 headings become frames</note>
</pattern>
<pattern name="markdown_export">
<description>Markdown export for GitHub/GitLab</description>
<example>
#+OPTIONS: toc:nil
(require 'ox-md)
(require 'ox-gfm) ; GitHub Flavored Markdown
</example>
<note>C-c C-e m m to export to Markdown</note>
</pattern>
<pattern name="publishing">
<description>Multi-file publishing projects</description>
<example>
(setq org-publish-project-alist
'(("org-notes"
:base-directory "~/org/notes/"
:base-extension "org"
:publishing-directory "~/public_html/"
:recursive t
:publishing-function org-html-publish-to-html
:headline-levels 4
:auto-preamble t)
("org-static"
:base-directory "~/org/notes/"
:base-extension "css\\|js\\|png\\|jpg\\|gif"
:publishing-directory "~/public_html/"
:recursive t
:publishing-function org-publish-attachment)
("org" :components ("org-notes" "org-static"))))
</example>
<note>C-c C-e P p to publish project</note>
</pattern>
<pattern name="selective_export">
<description>Control what gets exported</description>
<example>
* Exported heading
- Not exported :noexport:
#+BEGIN_COMMENT
This entire block is not exported.
#+END_COMMENT
Text for export only. @@html:<br>@@ continues.
#+BEGIN_EXPORT html
<div class="custom">Raw HTML here</div>
#+END_EXPORT
</example>
</pattern>
1---2name: org-ecosystem3description: This skill should be used when the user asks to "write org", "org-mode", "org file", ".org file", "org syntax", "org document", "org babel", "org export", "org agenda", "org capture", "GTD", "literate programming", "org publishing", or "org-mode workflow". Provides comprehensive Org-mode patterns and best practices.4---5
6<purpose>
7 Provide comprehensive patterns for Org-mode document creation, GTD workflow, literate programming with Babel, and export/publishing.
8</purpose>
9
10<org_syntax>
11 <fundamentals>
12 <concept name="headings">
13 <description>Hierarchical outline structure with stars</description>
14 <example>
15 - Top-level heading
16 ** Second-level heading \*** Third-level heading
17 </example>
18 </concept>
19
20 <concept name="properties">
21 <description>Key-value metadata attached to headings</description>
22 <example>
23 * Task
24 :PROPERTIES:
25 :CATEGORY: work
26 :EFFORT: 2h
27 :END:
28 </example>
29 </concept>
30
31 <concept name="drawers">
32 <description>Hidden content blocks</description>
33 <example>
34 :LOGBOOK:
35 CLOCK: [2024-01-15 Mon 10:00]--[2024-01-15 Mon 12:00] => 2:00
36 :END:
37 </example>
38 </concept>
39
40 <concept name="timestamps">
41 <description>Date and time specifications</description>
42 <example>
43 <2024-01-15 Mon> ; active timestamp
44 [2024-01-15 Mon] ; inactive timestamp
45 <2024-01-15 Mon 10:00> ; with time
46 <2024-01-15 Mon +1w> ; repeating weekly
47 <2024-01-15 Mon .+1d> ; restart from completion
48 </example>
49 </concept>
50
51 <decision_tree name="timestamp_type_selection">
52 <question>What is the purpose of this timestamp?</question>
53 <branch condition="Schedule task, show in agenda"><active timestamp></branch>
54 <branch condition="Record date without agenda visibility">[inactive timestamp]</branch>
55 <branch condition="Task repeats on fixed schedule">+1d/+1w/+1m repeater</branch>
56 <branch condition="Task repeats from today when done">.+1d reset repeater</branch>
57 <branch condition="Shift to future, catching up missed">++1d cumulative repeater</branch>
58 </decision_tree>
59 </fundamentals>
60
61 <patterns>
62 <pattern name="lists">
63 <description>Ordered and unordered lists</description>
64 <example>
65 - Unordered item
66 - Another item
67 - Nested item
68
69 1. First ordered item
70 2. Second ordered item
71
72 - [ ] Checkbox item
73 - [x] Completed checkbox
74 </example>
75 </pattern>
76
77 <pattern name="tables">
78 <description>Spreadsheet-like tables with formulas</description>
79 <example>
80 | Name | Quantity | Price | Total |
81 |-------+----------+-------+--------|
82 | Item1 | 2 | 10.0 | 20.0 |
83 | Item2 | 3 | 15.0 | 45.0 |
84 |-------+----------+-------+--------|
85 | Total | | | 65.0 |
86 #+TBLFM: $4=$2*$3::@>$4=vsum(@2..@-1)
87 </example>
88 <note>C-c C-c to recalculate, C-c | to create table from region</note>
89 </pattern>
90
91 <pattern name="links">
92 <description>Internal and external hyperlinks</description>
93 <example>
94 [[https://orgmode.org][Org website]]
95 [[file:./other.org][Local file]]
96 [[file:./image.png]]
97 [[*Heading][Internal link]]
98 [[id:unique-id][ID link]]
99 <<target>> and [[target]]
100 </example>
101 </pattern>
102
103 <decision_tree name="link_type_selection">
104 <question>What are you linking to?</question>
105 <branch condition="External URL">[[https://...][description]]</branch>
106 <branch condition="Local file in project">[[file:./path][description]]</branch>
107 <branch condition="Heading in same file">[[*Heading Name][description]]</branch>
108 <branch condition="Stable cross-file reference">[[id:uuid][description]] with org-id</branch>
109 <branch condition="Named target in document"><<target>> and [[target]]</branch>
110 </decision_tree>
111
112 <pattern name="blocks">
113 <description>Special content blocks</description>
114 <example>
115 #+BEGIN_QUOTE
116 Quoted text here.
117 #+END_QUOTE
118
119 #+BEGIN_EXAMPLE
120 Verbatim text, no markup processing.
121 #+END_EXAMPLE
122
123 #+BEGIN_CENTER
124 Centered text.
125 #+END_CENTER
126
127 #+BEGIN_VERSE
128 Poetry or
129 formatted text.
130 #+END_VERSE
131 </example>
132 </pattern>
133
134 <pattern name="markup">
135 <description>Text formatting markup</description>
136 <example>
137 *bold*
138 /italic/
139 _underline_
140 =verbatim=
141 ~code~
142 +strikethrough+
143 </example>
144 </pattern>
145
146 <pattern name="footnotes">
147 <description>Reference notes</description>
148 <example>
149 Text with footnote[fn:1].
150
151 [fn:1] Footnote definition.
152
153 Or inline[fn:: inline footnote definition].
154 </example>
155 </pattern>
156 </patterns>
157</org_syntax>
158
159<gtd_workflow>
160 <concept name="todo_states">
161 <description>Task state workflow configuration</description>
162 <example>
163 #+TODO: TODO(t) NEXT(n) WAITING(w@/!) | DONE(d!) CANCELLED(c@)
164
165 - TODO Buy groceries
166 - NEXT Write report
167 - WAITING Review from team :@john:
168 - DONE Complete project
169 - CANCELLED Obsolete task
170 </example>
171 <note>@ prompts for note, ! records timestamp, | separates active from done states</note>
172 </concept>
173
174 <patterns>
175 <pattern name="capture">
176 <description>Quick capture templates</description>
177 <example>
178 (setq org-capture-templates
179 '(("t" "Todo" entry (file+headline "~/org/inbox.org" "Tasks")
180 "* TODO %?\n %i\n %a")
181 ("n" "Note" entry (file "~/org/notes.org")
182 "* %? :note:\n %U\n %i")
183 ("j" "Journal" entry (file+datetree "~/org/journal.org")
184 "* %?\n %U")
185 ("m" "Meeting" entry (file+headline "~/org/work.org" "Meetings")
186 "* MEETING %? :meeting:\n %T")))
187 </example>
188 <note>%? cursor position, %i active region, %a annotation, %U inactive timestamp, %T active timestamp</note>
189 </pattern>
190
191 <decision_tree name="capture_template_type">
192 <question>What type of content are you capturing?</question>
193 <branch condition="Action item or task">entry with TODO state to inbox</branch>
194 <branch condition="Reference note or information">entry to notes file</branch>
195 <branch condition="Daily journal or log">entry with file+datetree</branch>
196 <branch condition="Meeting notes">entry with timestamp to meetings section</branch>
197 <branch condition="Add item to existing list">item or checkitem type</branch>
198 </decision_tree>
199
200 <pattern name="agenda">
201 <description>Agenda views and custom commands</description>
202 <example>
203 (setq org-agenda-files '("~/org/"))
204
205 (setq org-agenda-custom-commands
206 '(("d" "Dashboard"
207 ((agenda "" ((org-agenda-span 7)))
208 (todo "NEXT"
209 ((org-agenda-overriding-header "Next Actions")))
210 (todo "WAITING"
211 ((org-agenda-overriding-header "Waiting For")))))
212 ("w" "Weekly Review"
213 ((agenda "" ((org-agenda-span 7)
214 (org-agenda-start-on-weekday 1)))
215 (stuck "")
216 (todo "TODO")))))
217 </example>
218 </pattern>
219
220 <pattern name="refile">
221 <description>Task refiling configuration</description>
222 <example>
223 (setq org-refile-targets
224 '((nil :maxlevel . 3)
225 (org-agenda-files :maxlevel . 2)))
226
227 (setq org-refile-use-outline-path 'file)
228 (setq org-outline-path-complete-in-steps nil)
229 (setq org-refile-allow-creating-parent-nodes 'confirm)
230 </example>
231 <note>C-c C-w to refile entry, C-u C-c C-w to jump to target</note>
232 </pattern>
233
234 <pattern name="clocking">
235 <description>Time tracking with clock</description>
236 <example>
237 * Task with time tracking
238 :LOGBOOK:
239 CLOCK: [2024-01-15 Mon 10:00]--[2024-01-15 Mon 12:30] => 2:30
240 CLOCK: [2024-01-14 Sun 14:00]--[2024-01-14 Sun 15:00] => 1:00
241 :END:
242
243 (setq org-clock-persist t)
244 (setq org-clock-in-resume t)
245 (setq org-clock-out-remove-zero-time-clocks t)
246 (setq org-clock-report-include-clocking-task t)
247 </example>
248 <note>C-c C-x C-i clock in, C-c C-x C-o clock out, C-c C-x C-r insert clock report</note>
249 </pattern>
250
251 <pattern name="tags">
252 <description>Tag-based organization</description>
253 <example>
254 #+TAGS: @home(h) @work(w) @phone(p) @computer(c)
255 #+TAGS: urgent(u) important(i)
256
257 - TODO Call dentist :@phone:urgent:
258
259 (setq org-tag-alist
260 '((:startgroup)
261 ("@home" . ?h)
262 ("@work" . ?w)
263 (:endgroup)
264 ("urgent" . ?u)
265 ("important" . ?i)))
266 </example>
267 </pattern>
268
269 <pattern name="archiving">
270 <description>Archive completed tasks</description>
271 <example>
272 (setq org-archive-location "~/org/archive.org::datetree/")
273
274 (setq org-archive-subtree-save-file-p t)
275 </example>
276 <note>C-c C-x C-a archive subtree, C-c C-x C-s archive sibling</note>
277 </pattern>
278 </patterns>
279
280 <decision_tree name="task_state_selection">
281 <question>What is the current status of the task?</question>
282 <branch condition="Not yet started, actionable">TODO</branch>
283 <branch condition="Next physical action to take">NEXT</branch>
284 <branch condition="Blocked, waiting for someone/something">WAITING</branch>
285 <branch condition="Successfully completed">DONE</branch>
286 <branch condition="Will not be done">CANCELLED</branch>
287 </decision_tree>
288</gtd_workflow>
289
290<babel>
291 <concept name="code_blocks">
292 <description>Executable source code blocks</description>
293 <example>
294 #+NAME: example-block
295 #+BEGIN_SRC python :results output :exports both
296 print("Hello from Python")
297 for i in range(3):
298 print(f" Item {i}")
299 #+END_SRC
300
301 #+RESULTS: example-block
302 : Hello from Python
303 : Item 0
304 : Item 1
305 : Item 2
306 </example>
307 </concept>
308
309 <patterns>
310 <pattern name="header_args">
311 <description>Common header arguments for code blocks</description>
312 <example>
313 #+BEGIN_SRC elisp :var x=5 :results value
314 (* x x)
315 #+END_SRC
316
317 #+BEGIN_SRC shell :dir /tmp :results silent
318 ls -la
319 #+END_SRC
320
321 #+BEGIN_SRC python :session py :results output
322
323 # Persistent session across blocks
324
325 import sys
326 print(sys.version)
327 #+END_SRC
328 </example>
329 <note>
330 Header arguments:
331
332 - :results (value, output, silent, replace, append)
333 - :exports (code, results, both, none)
334 - :var (variable binding)
335 - :dir (working directory)
336 - :session (persistent session)
337 - :tangle (file to tangle to)
338 - :noweb (noweb reference expansion)
339 </note>
340 </pattern>
341
342 <pattern name="tangle">
343 <description>Extract source code to files</description>
344 <example>
345 #+PROPERTY: header-args :tangle yes
346
347 #+BEGIN_SRC python :tangle ./script.py :shebang "#!/usr/bin/env python3"
348 def main():
349 print("Generated from org file")
350
351 if **name** == "**main**":
352 main()
353 #+END_SRC
354
355 #+BEGIN_SRC nix :tangle ./default.nix :mkdirp yes
356 { pkgs ? import <nixpkgs> {} }:
357 pkgs.hello
358 #+END_SRC
359 </example>
360 <note>C-c C-v t to tangle current file, :mkdirp yes to create directories</note>
361 </pattern>
362
363 <pattern name="noweb">
364 <description>Literate programming with named blocks</description>
365 <example>
366 #+NAME: imports
367 #+BEGIN_SRC python :noweb-ref imports
368 import os
369 import sys
370 #+END_SRC
371
372 #+NAME: main-function
373 #+BEGIN_SRC python :noweb-ref main
374 def main():
375 print("Running main")
376 #+END_SRC
377
378 #+BEGIN_SRC python :tangle ./program.py :noweb yes
379 <<imports>>
380
381 <<main>>
382
383 if **name** == "**main**":
384 main()
385 #+END_SRC
386 </example>
387 </pattern>
388
389 <pattern name="results">
390 <description>Result handling options</description>
391 <example>
392 #+BEGIN_SRC elisp :results value
393 (+ 1 2 3)
394 #+END_SRC
395
396 #+RESULTS:
397 : 6
398
399 #+BEGIN_SRC python :results output
400 print("line 1")
401 print("line 2")
402 #+END_SRC
403
404 #+RESULTS:
405 : line 1
406 : line 2
407
408 #+BEGIN_SRC elisp :results table
409 '(("Name" "Age") ("Alice" 30) ("Bob" 25))
410 #+END_SRC
411
412 #+RESULTS:
413 | Name | Age |
414 | Alice | 30 |
415 | Bob | 25 |
416 </example>
417 </pattern>
418
419 <pattern name="language_specific">
420 <description>Language-specific configurations</description>
421 <example>
422 (org-babel-do-load-languages
423 'org-babel-load-languages
424 '((emacs-lisp . t)
425 (python . t)
426 (shell . t)
427 (js . t)
428 (sql . t)
429 (plantuml . t)))
430
431 (setq org-confirm-babel-evaluate nil)
432 (setq org-src-preserve-indentation t)
433 (setq org-src-tab-acts-natively t)
434 (setq org-edit-src-content-indentation 0)
435 </example>
436 </pattern>
437
438 <pattern name="inline_code">
439 <description>Inline source code evaluation</description>
440 <example>
441 The result is src_python{return 2 + 2} {{{results(=4=)}}}.
442
443 Today is src_elisp{(format-time-string "%Y-%m-%d")}.
444 </example>
445 </pattern>
446 </patterns>
447
448 <decision_tree name="results_type">
449 <question>What kind of output do you need?</question>
450 <branch condition="Return value of expression">:results value</branch>
451 <branch condition="Stdout/printed output">:results output</branch>
452 <branch condition="Tabular data">:results table</branch>
453 <branch condition="Raw org markup">:results raw</branch>
454 <branch condition="No output needed">:results silent</branch>
455 </decision_tree>
456</babel>
457
458<export>
459 <concept name="export_basics">
460 <description>Document export fundamentals</description>
461 <example>
462 #+TITLE: Document Title
463 #+AUTHOR: Author Name
464 #+DATE: 2024-01-15
465 #+OPTIONS: toc:2 num:t author:t
466
467 #+SETUPFILE: ./theme.setup
468 </example>
469 </concept>
470
471 <patterns>
472 <pattern name="html_export">
473 <description>HTML export configuration</description>
474 <example>
475 #+OPTIONS: html-postamble:nil html-preamble:nil
476 #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="style.css"/>
477 #+HTML_HEAD_EXTRA: <script src="script.js"></script>
478
479 (setq org-html-validation-link nil)
480 (setq org-html-head-include-scripts nil)
481 (setq org-html-head-include-default-style nil)
482 (setq org-html-doctype "html5")
483 (setq org-html-html5-fancy t)
484 </example>
485 <note>C-c C-e h h to export to HTML file</note>
486 </pattern>
487
488 <pattern name="latex_export">
489 <description>LaTeX/PDF export configuration</description>
490 <example>
491 #+LATEX_CLASS: article
492 #+LATEX_CLASS_OPTIONS: [a4paper,11pt]
493 #+LATEX_HEADER: \usepackage{geometry}
494 #+LATEX_HEADER: \geometry{margin=1in}
495
496 (setq org-latex-pdf-process
497 '("latexmk -pdf -shell-escape %f"))
498
499 (add-to-list 'org-latex-classes
500 '("report"
501 "\\documentclass{report}"
502 ("\\chapter{%s}" . "\\chapter*{%s}")
503 ("\\section{%s}" . "\\section*{%s}")))
504 </example>
505 <note>C-c C-e l p to export to PDF via LaTeX</note>
506 </pattern>
507
508 <pattern name="beamer">
509 <description>Presentation slides with Beamer</description>
510 <example>
511 #+TITLE: Presentation Title
512 #+AUTHOR: Presenter
513 #+OPTIONS: H:2 toc:nil
514 #+BEAMER_THEME: Madrid
515 #+BEAMER_COLOR_THEME: default
516
517 - Introduction
518 \*\* First Slide
519
520 * Point one
521 * Point two
522
523 \*\* Second Slide
524 #+ATTR_BEAMER: :overlay <+->
525
526 - Appears first
527 - Appears second
528 - Appears third
529
530 * Conclusion
531 \*\* Summary
532 Key takeaways here.
533 </example>
534 <note>H:2 means level-2 headings become frames</note>
535 </pattern>
536
537 <pattern name="markdown_export">
538 <description>Markdown export for GitHub/GitLab</description>
539 <example>
540 #+OPTIONS: toc:nil
541
542 (require 'ox-md)
543 (require 'ox-gfm) ; GitHub Flavored Markdown
544 </example>
545 <note>C-c C-e m m to export to Markdown</note>
546 </pattern>
547
548 <pattern name="publishing">
549 <description>Multi-file publishing projects</description>
550 <example>
551 (setq org-publish-project-alist
552 '(("org-notes"
553 :base-directory "~/org/notes/"
554 :base-extension "org"
555 :publishing-directory "~/public_html/"
556 :recursive t
557 :publishing-function org-html-publish-to-html
558 :headline-levels 4
559 :auto-preamble t)
560 ("org-static"
561 :base-directory "~/org/notes/"
562 :base-extension "css\\|js\\|png\\|jpg\\|gif"
563 :publishing-directory "~/public_html/"
564 :recursive t
565 :publishing-function org-publish-attachment)
566 ("org" :components ("org-notes" "org-static"))))
567 </example>
568 <note>C-c C-e P p to publish project</note>
569 </pattern>
570
571 <pattern name="selective_export">
572 <description>Control what gets exported</description>
573 <example>
574 * Exported heading
575
576 - Not exported :noexport:
577
578 #+BEGIN_COMMENT
579 This entire block is not exported.
580 #+END_COMMENT
581
582 Text for export only. @@html:<br>@@ continues.
583
584 #+BEGIN_EXPORT html
585 <div class="custom">Raw HTML here</div>
586 #+END_EXPORT
587 </example>
588 </pattern>
589 </patterns>
590
591 <decision_tree name="export_backend">
592 <question>What is the target format?</question>
593 <branch condition="Web page">HTML (ox-html)</branch>
594 <branch condition="Print document">PDF via LaTeX (ox-latex)</branch>
595 <branch condition="Presentation slides">Beamer (ox-beamer)</branch>
596 <branch condition="README/docs">Markdown (ox-md, ox-gfm)</branch>
597 <branch condition="Word document">ODT (ox-odt)</branch>
598 </decision_tree>
599</export>
600
601<tools>
602 <tool name="org-capture">
603 <description>Quick capture notes and tasks</description>
604 <use_case>Capturing ideas without interrupting current work</use_case>
605 </tool>
606
607 <tool name="org-agenda">
608 <description>Unified view of scheduled items and TODOs</description>
609 <use_case>Daily/weekly planning and review</use_case>
610 </tool>
611
612 <tool name="org-refile">
613 <description>Move entries to different locations</description>
614 <use_case>Organizing captured items into proper locations</use_case>
615 </tool>
616
617 <tool name="org-babel">
618 <description>Execute code blocks in documents</description>
619 <use_case>Literate programming, reproducible research</use_case>
620 </tool>
621
622 <tool name="org-export">
623 <description>Export to various formats</description>
624 <use_case>Publishing documents, creating presentations</use_case>
625 </tool>
626
627 <tool name="org-clock">
628 <description>Time tracking within org files</description>
629 <use_case>Project time tracking, productivity analysis</use_case>
630 </tool>
631</tools>
632
633<best_practices>
634 <practice priority="critical">Use one file per major project or area of responsibility</practice>
635 <practice priority="critical">Keep inbox.org for quick captures, refile regularly</practice>
636 <practice priority="high">Use consistent TODO state workflow across all files</practice>
637 <practice priority="high">Add SCHEDULED or DEADLINE to time-sensitive tasks</practice>
638 <practice priority="high">Use tags for context (@home, @work, @phone) not categories</practice>
639 <practice priority="high">Archive completed subtrees periodically</practice>
640 <practice priority="medium">Use org-id for stable cross-file links</practice>
641 <practice priority="medium">Set :EFFORT: property for time estimation</practice>
642 <practice priority="medium">Use column view for project overviews</practice>
643 <practice priority="medium">Configure org-agenda-custom-commands for common views</practice>
644</best_practices>
645
646<anti_patterns>
647 <avoid name="single_giant_file">
648 <description>Putting everything in one org file</description>
649 <instead>Split by project, area, or topic; use org-agenda-files</instead>
650 </avoid>
651
652 <avoid name="deep_nesting">
653 <description>Excessive heading depth (beyond 4-5 levels)</description>
654 <instead>Refactor into separate files or flatten structure</instead>
655 </avoid>
656
657 <avoid name="no_refile">
658 <description>Never refiling captured items</description>
659 <instead>Regular inbox processing (daily or at least weekly)</instead>
660 </avoid>
661
662 <avoid name="overcomplex_templates">
663 <description>Capture templates with too many fields</description>
664 <instead>Capture quickly with minimal fields, refine later</instead>
665 </avoid>
666
667 <avoid name="babel_side_effects">
668 <description>Code blocks that modify external state unexpectedly</description>
669 <instead>Use :results silent for side-effect blocks, document clearly</instead>
670 </avoid>
671
672 <avoid name="hardcoded_paths">
673 <description>Absolute paths in org files</description>
674 <instead>Use relative paths or org-directory variable</instead>
675 </avoid>
676</anti_patterns>
677
678<workflow>
679 <phase name="analyze">
680 <objective>Understand org document requirements</objective>
681 <step>1. Identify document type: notes, project, literate program, publication</step>
682 <step>2. Determine required features: GTD, babel, export</step>
683 <step>3. Check existing org patterns in project</step>
684 </phase>
685 <phase name="implement">
686 <objective>Create or modify org document</objective>
687 <step>1. Set up document header with appropriate options</step>
688 <step>2. Structure content with appropriate heading levels</step>
689 <step>3. Add metadata (properties, tags, timestamps) as needed</step>
690 <step>4. Configure babel blocks for executable content</step>
691 </phase>
692 <phase name="validate">
693 <objective>Verify org document correctness</objective>
694 <step>1. Check syntax with org-lint</step>
695 <step>2. Test babel blocks execute correctly</step>
696 <step>3. Verify export produces expected output</step>
697 </phase>
698</workflow>
699
700<rules priority="critical">
701 <rule>Use appropriate heading levels (do not skip levels)</rule>
702 <rule>Close all drawers and blocks properly</rule>
703 <rule>Use consistent timestamp format throughout document</rule>
704</rules>
705
706<rules priority="standard">
707 <rule>Add :PROPERTIES: drawer after heading, not before</rule>
708 <rule>Use #+NAME: before code blocks that are referenced</rule>
709 <rule>Set document-wide header-args with #+PROPERTY:</rule>
710 <rule>Use :noexport: tag for internal notes</rule>
711</rules>
712
713<error_escalation>
714 <level severity="low">
715 <example>Minor formatting inconsistency</example>
716 <action>Fix and continue</action>
717 </level>
718 <level severity="medium">
719 <example>Babel block execution error</example>
720 <action>Debug block, check language support</action>
721 </level>
722 <level severity="high">
723 <example>Export failure or corrupted output</example>
724 <action>Check document structure, present options to user</action>
725 </level>
726 <level severity="critical">
727 <example>Data loss from failed tangle or corrupted file</example>
728 <action>Block operation, require explicit user acknowledgment</action>
729 </level>
730</error_escalation>
731
732<related_agents>
733 <agent name="execute">Implementation of org document structures and babel configurations</agent>
734 <agent name="docs">Documentation generation from org files</agent>
735 <agent name="design">Architecture for complex org-based systems</agent>
736</related_agents>
737
738<related_skills>
739 <skill name="emacs-ecosystem">Emacs Lisp configuration for org-mode customization</skill>
740 <skill name="serena-usage">Symbol operations for navigating org structures</skill>
741 <skill name="context7-usage">Fetch latest org-mode documentation</skill>
742 <skill name="technical-documentation">Documentation patterns applicable to org export</skill>
743</related_skills>
744
745<constraints>
746 <must>Use consistent heading structure (do not skip levels)</must>
747 <must>Close all blocks and drawers properly</must>
748 <must>Use relative paths for portability</must>
749 <avoid>Excessive nesting beyond 4-5 levels</avoid>
750 <avoid>Side effects in babel blocks without clear documentation</avoid>
751 <avoid>Hardcoded absolute paths in documents</avoid>
752</constraints>