Hippocamplus My Second Memory

Org mode

I’m giving Org mode a try. This page will contain my configuration and the small subset of commands that I want to learn.

Org file

  • Start with MY PROJECTS -*- mode: org; -*-


In .emacs file:

(require 'org)
;; Change M-TAB completion to C-TAB
(define-key org-mode-map (kbd "C-<tab>") 'pcomplete)
(setq org-todo-keywords
      '((sequence "TODO" "ONGOING" "CLOCKING" "|" "DONE")))
(global-set-key (kbd "C-c a") 'org-agenda)
(setq org-startup-truncated nil) ;; wrap lines
(setq org-startup-indented 1) ;; heading indentation
(setq org-return-follows-link 1) ;; RET to follow links
(setq org-agenda-start-on-weekday nil) ;; start agenda on current day
(setq calendar-week-start-day 1) ;; but calendar starts on Monday (not Sunday!)
(setq org-catch-invisible-edits nil) ;; block (confusing) invisible edits ("...")
(setq org-enforce-todo-dependencies t) ;; Switch TODO dependencies on
(setq org-agenda-dim-blocked-tasks 'invisible) ;; Hide tasked blocked by dependencies
;; path to org files
(setq org-directory "~/Documents/orgmode")
(setq org-agenda-files (list org-directory))
;; capture
(setq org-default-notes-file (concat org-directory "/notes.org"))
(global-set-key (kbd "C-c c") 'org-capture)


  • *bold*, /italic/, _underlined_, +strike-through+.
  • =verbatim=, ~code~.


From anywhere

  • Capture a note: bound to C-c c
  • Open agenda views: bound to C-c a.

Edit mode

  • Completion: changed to C-tab.
  • Move to next/previous heading: C-c C-n/C-c C-p.
  • Move to next/previous same-level heading: C-c C-f/C-c C-b.
  • Move up to higher heading: C-c C-u.
  • Insert a new heading at the end of the current subtree: C-RET.
  • Promote/demote heading: M-LEFT/M-RIGHT.
  • Promote/demote subtree: M-S-LEFT/M-S-RIGHT.
  • Move subtree up/down: M-UP/M-DOWN.
  • Cycle through TODO states: S-RIGHT/S-LEFT.
  • Toggle the sparse tree view: C-c /.
  • Open link: C-c C-o.
  • New/edit link: C-c C-l.
  • Add property field: C-c C-x p.
  • Narrow/widen to subtree: C-x n s/C-x n w.


  • Insert/edit date: C-c .
  • Insert/edit schedule: C-c C-s.
  • Insert/edit deadline: C-c C-d.
  • Navigate with S-ARROW.
  • Toggle the calendar at a specific date: C-c >.
  • Insert selected date in the calendar at cursor position: C-c <.

Agenda views

  • Add/remove document to agenda files: C-c [/C-c ].
  • Highlight in file: SPC.
  • Jump to file: TAB.
  • Jump to file and close agenda: RET.
  • Change TODO states with t.
  • Jump to a specific date: j.
  • Previous/next day/week/month: b/f


  • Finish capture and go back to current buffer: C-c C-c.

TODO entry

*** TODO Do this before the deadline
    SCHEDULED: <2004-02-22 Sun>
    DEADLINE: <2004-02-29 Sun>


  • C-c C-c format the table. If on a TBLFM: line, recompute the formula.
  • "| " TAB make a new row.
  • "|-" TAB make a line separation.
  • M-RIGHT/M-LEFT move column.
  • M-UP/M-DOWN move row.
  • S-M-RIGHT/S-M-DOWN add new column/row.
  • S-M-LEFT/S-M-UP remove current column/row.
  • C-c } show rows/columns labels.

An example with a right-aligned column, a field formula (:=) and a column formula (=)

|  <r> |      |      |
| ColA | ColB | ColC |
|  tes |   13 |   12 |
|  asd |    3 |    2 |
|    a |   16 |   15 |
| mean | 10.7 |  9.7 |
#+TBLFM: $3=$2-1::@6$2:=vmean(@3..@5);p3

Property drawer

No empty lines between header/scheduled/deadline and property chunk.

* John Doe
:EMAIL:    [[mailto:john.doe@gmail.com][john.doe@gmail.com]]
:BIRTHDAY: 1982-01-14
  • To define which columns to show in the columns view, add at the beginning of the file: #+COLUMNS: %25ITEM %BIRTHDAY.
  • Toggle columns view on current item or whole file: C-c C-x C-c.
    • c to toggle compact table.
    • g to refresh.

Habits entry

** TODO Go for a run
SCHEDULED: <2019-07-16 Tue .+2d/7d>
:STYLE:    habit
:LAST_REPEAT: [2019-07-14 Sun 14:13]
- State "DONE"       from "WAITING"    [2019-07-14 Sun 14:13] 

For a view of the habit and how well they are followed, I added to my .emacs:

(add-to-list 'org-modules 'org-habit)
(require 'org-habit)
;; (setq org-habit-show-all-today t
;;       org-habit-show-habits-only-for-today t
;;       org-habit-show-done-always-green t
;;       org-habit-graph-column 40
;;       org-habit-preceding-days 28
;;       org-habit-following-days 7)

Code block

A simple code block:

#+NAME: <name>
#+BEGIN_SRC <language>

See the list of available languages. To switch on syntax highlighting, add to .emacs:

(setq org-src-fontify-natively t)


  • Set/edit tag: C-c C-q

Clocking time

  • C-c C-x ; starts a timer/pomodoro.
  • C-c C-x C-i starts clocking, or I in agenda view.
  • C-c C-x C-o stops clocking (also stops when the task is DONE).
  • C-c C-x C-d shows a summary of the file.
  • C-c C-x C-r inserts a report table.

To force saving the clock items in a LOGBOOK drawer I added in my ~/.emacs:

(setq org-clock-into-drawer t)
(setq org-pretty-entities t)
(setq org-clock-in-switch-to-state "CLOCKING")

Custom agenda views

I either want to know the tasks and events for the day, or just the events for the upcoming week/year.

    1. Today’s agenda and un-scheduled tasks.
    1. Events for the upcoming week.
    1. Events for the upcoming year (recurrent events and birthdays excluded).
(setq org-agenda-custom-commands
      '(("c" "Today's agenda"
         ((agenda "" ((org-agenda-ndays 1)
                       '(org-agenda-skip-subtree-if 'regexp ":habit:")
          (alltodo ""
                     (lambda nil
                       (org-agenda-skip-entry-if (quote scheduled)
                                                 (quote deadline))))
                    (org-agenda-overriding-header "Un-scheduled tasks:")
          (agenda ""
                  ((org-agenda-ndays 1)
                   (org-agenda-use-time-grid nil)
                    '(org-agenda-skip-subtree-if 'notregexp ":habit:")
                   (org-agenda-overriding-header "Habits:")
         ((org-agenda-compact-blocks t))
        ("w" "Week's events"
         ((agenda "" ((org-agenda-span 7)
                       '(or (org-agenda-skip-entry-if 'todo '("TODO" "ONGOING" "DONE"))
                      (org-agenda-show-all-dates nil)
                      (org-agenda-overriding-header "Week's events:")
          ((org-agenda-compact-blocks t))
        ("y" "Year's events (no recurrents)"
         ((agenda "" ((org-agenda-span 365)
                       '(or (org-agenda-skip-entry-if 'todo '("TODO" "ONGOING" "DONE"))
                            (org-agenda-skip-subtree-if 'regexp ":recurrent:")
                            (org-agenda-skip-subtree-if 'regexp ":birthday:")
                      (org-agenda-show-all-dates nil)
                      (org-agenda-overriding-header "Year's events (no recurrents):")
          ((org-agenda-compact-blocks t))

I also changed the way tasks are displayed in the agenda view. Instead of showing the filename where the task resides, I show the first characters of the parent heading. That way I can use short and generic task names and still understand it in the agenda. No need to repeat the context in the task name anymore. I added in my .emacs:

;; Prefix tasks with parent heading
(defun getlasthead ()
  (let ((x (nth 0 (last (org-get-outline-path)))))
    (if x
    (if (> (string-width x) 12)
        (concat "[" (org-format-outline-path (list (substring x 0 12))) "]")
      (concat "[" (org-format-outline-path (list x)) "]"))
(setq org-agenda-prefix-format " %i %-15(getlasthead)%?-12t% s ")