@@ -24,6 +24,7 @@ allowing you to read news, send emails, play media, and much more!
2424> This [ file] [ my-emacs-tut ] is licensed under a free/libre copyleft license (GPL or CC BY-SA).
2525>
2626> ** Changelog**
27+ > - 2024-10-07: added the * Org Mode* section.
2728> - 2024-10-07: explained the * Compile* workflow.
2829> - 2024-10-05: added the * Development* section.
2930
@@ -1135,7 +1136,294 @@ Emacs contains hundreds of microscopic quality of life features:
11351136
11361137### ispell
11371138
1138- ### org mode
1139+ ### Org Mode
1140+
1141+ [ org-mode] [ org-mode ] is arguably the most advanced system for taking notes and organizing information.
1142+ It is a free software that comes with Emacs.
1143+
1144+ [ org-mode ] : https://orgmode.org/features.html
1145+
1146+ In this section we will set up a simple, yet opinionated, Getting Things Done (GTD) workflow,
1147+ as presented by Nicolas P. Rougier in his [ Emacs GTD] [ emacs-gtd ] .
1148+ This configuration has been proven to work, and I recommend using it as a starting point.
1149+ Add the following to your ` ~/.emacs ` :
1150+
1151+ ``` scheme
1152+ ;; Adjust org-mode for GTD
1153+ (use-package org
1154+ :config
1155+ ;; Define task sequence, `|` separates the completed statuses.
1156+ (setq org-todo-keywords
1157+ '((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)" "CANCELLED(c@/!)")))
1158+
1159+ ;; Record the task completion date.
1160+ (setq org-log-done 'time))
1161+ ```
1162+
1163+ #### Modern Style
1164+
1165+ Install a sleek-looking style with org-modern.
1166+ The following configuration defines a custom color for the ` NEXT `
1167+ keyword that is used by GTD:
1168+
1169+ ``` scheme
1170+ ;; Modern Org Style
1171+ (use-package org-modern
1172+ :ensure t
1173+ :config
1174+ ;; Add styles for NEXT status
1175+ (setq org-modern-todo-faces
1176+ '(("NEXT" :foreground "purple" :weight bold :background "orange")))
1177+ ;; Activate org-modern
1178+ (global-org-modern-mode))
1179+ ```
1180+
1181+ #### Your First File
1182+
1183+ In this section, we will setup your first org file.
1184+ Create a file named ` ~/org/projects.org ` with the following content:
1185+
1186+ ``` bash
1187+ * Project name
1188+ ** A task
1189+ ** Another task
1190+
1191+ * Another project
1192+ ** Yet another task
1193+ ```
1194+
1195+ Here are the commands you can apply to the headings:
1196+
1197+ | * Command* | * Description* |
1198+ | ----------------------| ------------------------------------|
1199+ | org-set-property | Assign a property like * CATEGORY* . |
1200+ | org-set-tags-command | Set the tags. |
1201+ | org-todo | Change the TODO state of an item. |
1202+
1203+
1204+ Perform the following actions:
1205+
1206+ - Set the ** CATEGORY** property for the top headings with the project codename.
1207+ - Optionally add tags, such as related technology names.
1208+ - Set some task statuses with ` C-c C-t ` or ` M-x org-todo ` .
1209+
1210+ Your buffer should look like this:
1211+
1212+ ![ emacs-tut-org-file] ( media/emacs-tut-org-file.png )
1213+
1214+ > [ !note]
1215+ > When a heading has no content, the ▶ indicator might get stuck in the open state: ▼.
1216+ > If that bothers you, add an empty paragraph with a dash ` - ` ; then pressing ` TAB ` will work as expected.
1217+
1218+
1219+ #### Refile and Capture
1220+
1221+ To move tasks, use the ` org-refile ` command (` C-x C-w ` ).
1222+ Add the following settings to make your ` projects.org ` the default target.
1223+
1224+ ``` scheme
1225+ ;; Allow moving task from anywhere into your projects:
1226+ (setq org-refile-targets '(("~/org/projects.org" :maxlevel . 1)))
1227+
1228+ ;; Automatically save org files after refile
1229+ (advice-add 'org-refile :after (lambda (&rest _) (org-save-all-org-buffers)))
1230+ ```
1231+
1232+ To add tasks, use the ` org-capture ` command.
1233+ Add the following settings:
1234+
1235+ ``` scheme
1236+ ;; Setup capture template to write new tasks to ~/org/inbox.org
1237+ (setq org-capture-templates
1238+ '(("t" "todo" entry (file "~/org/inbox.org")
1239+ "* TODO %?\n/Entered on/ %U\n")))
1240+
1241+ ;; Press F6 to capture a task
1242+ (global-set-key (kbd "<f6>") 'org-capture)
1243+ ```
1244+
1245+ > [ !tip]
1246+ > Capture tasks at any time by pressing <kbd >F6</kbd > <kbd >t</kbd >.
1247+ > Avoid using refile right away, use org-capture to quikcly move tasks off your mind.
1248+
1249+
1250+ #### Editing Org File
1251+
1252+ Org leverages a few keys to help with editing an Org file:
1253+
1254+ | * Key* | * Description* |
1255+ | ---------------------------------| -----------------------------------|
1256+ | <kbd >TAB</kbd > | Cycle folding on current heading. |
1257+ | <kbd >shift</kbd >+<kbd >TAB</kbd > | Cycle folding on the whole file. |
1258+ | <kbd >alt</kbd >+<kbd >→</kbd > | Demote heading. |
1259+ | <kbd >alt</kbd >+<kbd >←</kbd > | Promote heading. |
1260+ | <kbd >alt</kbd >+<kbd >↓</kbd > | Move subtree down. |
1261+ | <kbd >alt</kbd >+<kbd >↑</kbd > | Move subtree up. |
1262+ | ` M-g i ` | Jump to a place in the buffer. |
1263+ | ` M-RET ` | Insert a new heading. |
1264+
1265+ Here are a couple of useful commands you might need:
1266+
1267+ | * Command* | * Description* |
1268+ | -----------------------------| -----------------------------------------------------|
1269+ | org-toggle-link-display | Show the literal links. |
1270+ | org-tree-to-indirect-buffer | Focus on the current subtree in a dedicated buffer. |
1271+ | | |
1272+
1273+
1274+ #### Agenda
1275+
1276+ In this section, we will set up the agenda view, which is the main user interface you
1277+ will use to get things done.
1278+ Add the following to your Emacs config:
1279+
1280+ ``` scheme
1281+ (use-package org-agenda
1282+ :config
1283+ ;; The agenda pulls data from the following files:
1284+ (setq org-agenda-files '("~/org/projects.org" "~/org/inbox.org"))
1285+
1286+ ;; The GTD view
1287+ (setq-default org-agenda-custom-commands
1288+ '(("g" "Get Things Done (GTD)"
1289+ ((agenda ""
1290+ ((org-agenda-skip-function '(org-agenda-skip-entry-if 'deadline))
1291+ (org-deadline-warning-days 0)))
1292+ (todo "NEXT"
1293+ ((org-agenda-skip-function '(org-agenda-skip-entry-if 'deadline))
1294+ (org-agenda-prefix-format " %i %-12:c [%e] ")
1295+ (org-agenda-overriding-header "\nTasks\n")))
1296+ (tags-todo "inbox"
1297+ ((org-agenda-prefix-format " %?-12t% s")
1298+ (org-agenda-overriding-header "\nInbox\n")))
1299+ (tags "CLOSED>=\"<today>\""
1300+ ((org-agenda-overriding-header "\nCompleted today\n")))))))
1301+
1302+ ;; Press F4 to get things done!
1303+ (global-set-key (kbd "<f4>") (lambda () (interactive) (org-agenda nil "g"))))
1304+ ```
1305+
1306+ > [ !note]
1307+ > We don't need to use ` use-package ` because org-agenda is built into Emacs, but
1308+ > that helps keep your config nice and tidy.
1309+
1310+ This setup is well documented in Nicolas's [ Emacs GTD] [ emacs-gtd ] paper,
1311+ so I won't explain the settings in detail. What you need to know is that,
1312+ pressing <kbd >F4</kbd > will display a dashboard with four sections:
1313+
1314+ - The current week; see the next section for scheduling events.
1315+ - The list of tasks marked as ` NEXT ` .
1316+ - The list of tasks captured in the * inbox* that need to be refiled.
1317+ - The list of tasks completed today.
1318+
1319+ From that view, you can use the usual commands such as ` org-todo ` and ` org-refile ` .
1320+ Press ` RET ` to visit the file.
1321+ The view looks like this:
1322+
1323+ ![ emacs-tut-org-agenda] ( media/emacs-tut-org-agenda.png )
1324+
1325+ > [ !note]
1326+ > Add the following header at the top of your ` ~/org/inbox.org ` to see the untriaged tasks:
1327+ > ``` bash
1328+ > # +FILETAGS: inbox
1329+ > ` ` `
1330+
1331+ [emacs-gtd]: https://www.labri.fr/perso/nrougier/GTD/index.html
1332+
1333+ # ### Scheduling
1334+
1335+ Schedule a task with ` org-schedule` (` C-x C-s` ); this command pops up the Emacs calendar to
1336+ select a date. You can pick the date in the calendar, or type a date selection like:
1337+
1338+ - ` +3h` : three hours from now.
1339+ - ` +1d` : tomorrow.
1340+ - ` +1w` : next week.
1341+ - ` +1m` : next month.
1342+ - ` Mon` : next Monday.
1343+ - ` 20` : next 20th day of the month.
1344+ - ` 12-25` : next Dec 25th.
1345+ - ` YY-MM-DD` : a fixed date.
1346+
1347+ When a task has a scheduled property, it will appear in the calendar.
1348+ If an open task is scheduled in the past, it appears as ` Sched` in the calendar,
1349+ reminding you that you forgot to complete a scheduled task.
1350+
1351+ You can make an event repeat with the following time syntax:
1352+
1353+ - ` < 2024-11-01 Fri +1m -3d> ` for paying the rent; the task is required every month.
1354+ - ` < 2024-11-16 Sat .+2m> ` for changing toothbrush; marking this DONE shifts the date to two month after today.
1355+ - ` < 2008-02-10 Sun ++1w> ` for calling your mom; marking this DONE shifts the date by at least one week
1356+
1357+ For example, add the following heading to get started. Note that the first item is not a task, it' s just a reminder for tri-weekly event:
1358+
1359+ ```bash
1360+ * Work
1361+ ** Sprint review
1362+ SCHEDULED: <2024-10-09 Wed 09:00 ++3w>
1363+
1364+ * Home
1365+ ** TODO Pay rent
1366+ SCHEDULED: <2024-11-01 Fri +1m -3d>
1367+
1368+ ** TODO Change toothbrush
1369+ SCHEDULED: <2024-11-16 Sat .+2m>
1370+
1371+ ** TODO Call mum
1372+ SCHEDULED: <2008-02-10 Sun ++1w>
1373+ ```
1374+
1375+ Finally, add the following to record anniversary events:
1376+
1377+ ```bash
1378+ * Anniversaries
1379+ %%(diary-anniversary 5 29 2012) Zuul was created %d years ago
1380+ ```
1381+
1382+ > [!tip]
1383+ > Schedule tasks to put them at the top of your dashboard.
1384+
1385+
1386+ #### Journaling
1387+
1388+ You can write a journal with org-capture, add the following template:
1389+
1390+ ```scheme
1391+ ;; Add a new org-capture ' j' for journaling
1392+ (add-to-list ' org-capture-templates
1393+ ' ("j" "Journal" entry (file+olp+datetree "~/org/journal.org")
1394+ "* %?\n")
1395+ t)
1396+ ```
1397+
1398+ Press <kbd>F6</kbd> <kbd>j</kbd> to record an event. It will be written to
1399+ your `~/org/journal.org` using date tree headings.
1400+
1401+ > [!tip]
1402+ > Use journal capture to keep track of what you are doing.
1403+
1404+ #### Archive
1405+
1406+ When a task or project is no longer relevant, use the `org-archive-subtree`
1407+ to clean up your org file. This command moves the content to an archive file.
1408+
1409+ Here is a useful command to archive all completed tasks:
1410+
1411+ ```scheme
1412+ ;; From: https://stackoverflow.com/a/70131908
1413+ ;; With auto save disabled
1414+ (defun org-archive-done-tasks ()
1415+ "Archive all tasks marked DONE in the file."
1416+ (interactive)
1417+ ;; Disable auto save
1418+ (setq org-archive-subtree-save-file-p nil)
1419+ (unwind-protect
1420+ (mapc (lambda(entry)
1421+ (goto-char entry)
1422+ (org-archive-subtree))
1423+ ;; process the entry in reverse to avoid changes in positioning
1424+ (reverse (org-map-entries (lambda () (point)) "TODO=\"DONE\"" ' file)))
1425+ (setq org-archive-subtree-save-file-p t)))
1426+ ` ` `
11391427
11401428# ## notmuch
11411429
@@ -1151,6 +1439,8 @@ Emacs contains hundreds of microscopic quality of life features:
11511439
11521440# ## vterm
11531441
1442+ # ## org-ql
1443+
11541444# ## Tramp
11551445
11561446` ` ` scheme
0 commit comments