Org-mode settings

1 Appearance

Indent headings and text

(require 'org-indent)
(setq org-startup-indented t)

Do not truncate lines and enable word wrap

(set-default 'truncate-lines nil)
(set-default 'word-wrap t)
(setq helm-buffers-truncate-lines nil)
(setq org-startup-truncated nil)

Do not align Tags automatically

(setq org-auto-align-tags nil)

Set the symbols for different heading levels

(setq org-bullets-bullet-list (quote ("◉" "◆" "✚" "☀" "○")))

Load org-pretty-tags. See https://gitlab.com/marcowahl/org-pretty-tags

(load "~/emacs-spacemacs-config/org-pretty-tags/org-pretty-tags.el")

On startup, content should be in folded state

(setq org-startup-folded t)

Count all checkboxes, not just the ones directly below

(setq org-checkbox-hierarchical-statistics nil)

Custom org-display-inline-images function that displays the images according to the logic:

  1. Always conserve the aspect ratio
  2. Image shouldn't exceed the current window's width (minus 50 pixels)
  3. Image shouldn't exceed half of the current window's height
  4. Resize only if the actual dimensions do not conform to the above two points
(setq org-image-actual-width 1800)
(load "~/emacs-spacemacs-config/org-display-inline-images-custom.el")

2 To-Do states and related

Keywords

(setq org-todo-keywords
      (quote
       ((sequence "TODO" "PROG" "PAUS" "|" "DONE" "CANC"))))

Colors for todo states

(setq org-todo-keyword-faces
      '(("PROG" . "orange") ("PAUS" . "magenta") ("CANC" . "red") ("DONE" . "green")))

Priority settings : default is H, highest is A, and lowest is Z

(setq org-default-priority 72)
(setq org-highest-priority 65)
(setq org-lowest-priority 90)

3 Capture

Hotkey

(global-set-key (kbd "<f6>") 'org-capture)

Templates

(setq org-capture-templates
      (quote (
              ("w"         ; hotkey
               "Work Todo" ; name
               entry       ; type
               (file+headline "~/Dropbox/org/work.org" "Tasks") ;target
               "* TODO [#A] %^{Task}" ; template
               )
              ("t"
               "Task Diary"
               entry
               (file+datetree "~/Dropbox/org/tasks.org")
               "* TODO [#A] %^{Task}")
              ("j"
               "Journal"
               item
               (file+datetree "~/Dropbox/org/journal.org")
               "- %U - %^{Activity}")
              ("b"
               "Add a book to read"
               entry
               (file+headline "~/Dropbox/org/notes.org" "Books to read")
               "* TODO %^{Book name}\n%^{Why to read this book?}"
               )
              ("s"
               "Schedule an event or a task"
               entry
               (file+datetree "~/Dropbox/org/tasks.org")
               "* %^{Event or Task}\nSCHEDULED: %^t"
               )
              )))

4 Agenda

Enable the compact layout in agenda

(setq org-agenda-compact-blocks t)

Restore layout after exit from agenda view

(setq org-agenda-restore-windows-after-quit t)

Default appointment duration

(setq org-agenda-default-appointment-duration 30)

Pressing Tab while the cursor is on a task will expand that task in a separate buffer

(add-hook 'org-agenda-mode-hook
          (lambda () (local-set-key [tab] 'org-agenda-tree-to-indirect-buffer)))

Include these files and directories when creating the agenda

(setq org-agenda-files '("~/Dropbox/org"))

Don't show tasks in agenda if they are done

(setq org-agenda-skip-deadline-if-done t)
(setq org-agenda-skip-scheduled-if-done t)

Max number of days to show in agenda

(setq org-agenda-span 45)

Warn about a deadline

(setq org-deadline-warning-days 90)

Agenda starts on the current day

(setq org-agenda-start-on-weekday nil)

Sorting strategy

(setq org-agenda-sorting-strategy
      (quote
       ((agenda priority-down alpha-up)
        (todo priority-down alpha-up)
        (tags priority-down alpha-up))))

Display format

(setq org-agenda-prefix-format
      (quote
       ((agenda . "%s %?-12t %e ")
        (timeline . "  %s")
        (todo . " %i %e ")
        (tags . " %i %e ")
        (search . " %i %e "))))

Default format for columns view

(setq org-columns-default-format
      "%75ITEM %TODO %PRIORITY %SCHEDULED %DEADLINE %CLOSED %ALLTAGS")

Place tags close to the right-hand side of the window. From http://lists.gnu.org/archive/html/emacs-orgmode//2010-12/msg00410.html

(add-hook 'org-finalize-agenda-hook 'place-agenda-tags)
(defun place-agenda-tags ()
  "Put the agenda tags by the right border of the agenda window."
  (setq org-agenda-tags-column (- 4 (window-width)))
  (org-agenda-align-tags))

By default, agenda will reorganize frames/splits

(setq org-agenda-window-setup 'reorganize-frame)

By default, Org maintains only a single agenda buffer and rebuilds it each time you change the view, to make sure everything is always up to date. If you often switch between agenda views and the build time bothers you, you can turn on sticky agenda buffers or make this the default by customizing the variable org-agenda-sticky. With sticky agendas, the agenda dispatcher will not recreate agenda views from scratch, it will only switch to the selected one, and you need to update the agenda by hand with r or g when needed. You can toggle sticky agenda view any time with org-toggle-sticky-agenda.

(setq org-agenda-sticky nil)

When you run an agenda command, Org visits agenda files that are not yet visited. When finding a file for the first time, Org checks the startup options and apply them to the buffer: those options are either globally set through the org-startup-* variables or on a per-file basis through the #+STARTUP keyword. Especially, Org will honor the startup visibility status, as set by org-startup-folded or #+STARTUP: folded. This may slow down the operation of visiting a file very much, and the process of selecting agenda entries consequently. To prevent agenda commands to honor startup options when visiting an agenda file for the first time, do this

(setq org-agenda-inhibit-startup t)

5 Custom agenda views

5.1 Helper functions

Extract the date of completion, and use it for comparison. From http://emacs.stackexchange.com/questions/26351/custom-sorting-for-agenda

(defun cmp-date-property (prop)
  "Compare two `org-mode' agenda entries, `A' and `B', by some date property. If a is before b, return -1. If a is after b, return 1. If they are equal return t."
  (lexical-let ((prop prop))
    #'(lambda (a b)

        (let* ((a-pos (get-text-property 0 'org-marker a))
               (b-pos (get-text-property 0 'org-marker b))
               (a-date (or (org-entry-get a-pos prop)
                           (format "<%s>" (org-read-date t nil "now"))))
               (b-date (or (org-entry-get b-pos prop)
                           (format "<%s>" (org-read-date t nil "now"))))
               (cmp (compare-strings a-date nil nil b-date nil nil))
               )
          (if (eq cmp t) nil (signum cmp))
          ))))

Display the total number of tasks in Agenda. From http://emacs.stackexchange.com/questions/18710/display-count-of-tasks-in-agenda-instead-of-tasks-based-on-tag

(load "~/emacs-spacemacs-config/org-agenda-count.el")

Sort agenda items by link's text and not link's URL

(defun remove-priority (str)
  (replace-regexp-in-string "\\[#[^\\[]*\\] " "" str))

(defun extract-link-text (str)
  (replace-regexp-in-string "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]" "\\3" str))

(defun org-cmp-alpha-2 (a b)
  "Compare the headlines, alphabetically. (after extract link texts if any links present)"
  (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
         (plb (text-property-any 0 (length b) 'org-heading t b))
         (ta (and pla (substring a pla)))
         (tb (and plb (substring b plb)))
         (case-fold-search nil))
    (when pla
      (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
                                  "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
        (setq ta (substring ta (match-end 0))))
      (setq ta (downcase ta)))
    (when plb
      (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
                                  "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
        (setq tb (substring tb (match-end 0))))
      (setq tb (downcase tb)))
    (setq ta (extract-link-text ta))
    (setq tb (extract-link-text tb))
    (cond ((not (or ta tb)) nil)
          ((not ta) +1)
          ((not tb) -1)
          ((string-lessp ta tb) -1)
          ((string-lessp tb ta) +1))))

5.2 Views

(setq org-agenda-custom-commands
      (quote
       (
        ("Q" "Closed Tasks"
         ((tags "CLOSED>=\"<-4w>\"" (
                                     (org-agenda-cmp-user-defined (cmp-date-property "CLOSED"))
                                     (org-agenda-sorting-strategy '(user-defined-down))
                                     (org-agenda-overriding-header (format "Tasks done in the last week (%s)" (org-agenda-count "CLOSED")))
                                     )))
         nil)
        ("H" "Z Tasks"
         ((tags-todo "+PRIORITY=\"Z\""
                     ((org-agenda-overriding-header (format "Z Tasks (%s)" (org-agenda-count ""))))))
         nil)
        ("W" "Work ToDos"
         ((tags-todo "+work"
                     ((org-agenda-overriding-header (format "Work Tasks (%s)" (org-agenda-count "")))
                      (org-agenda-hide-tags-regexp "work")
                      )))
         nil)
        ("E" "Non-Work ToDos"
         ((tags-todo "-work" (
                              (org-agenda-overriding-header (format "Non-Work Tasks (%s)" (org-agenda-count "")))
                              (org-agenda-cmp-user-defined 'org-cmp-alpha-2)
                              (org-agenda-sorting-strategy '(user-defined-up))
                              )))
         nil)
        )))

6 Export

Stylize exported html according to specified CSS

(setq org-html-htmlize-output-type 'css)
(setq org-html-html5-fancy t
      org-html-doctype "html5")

Backends to enable

(setq org-export-backends (quote (html icalendar md)))

7 Refile

(setq org-refile-allow-creating-parent-nodes (quote confirm))
(setq org-refile-targets '((nil :maxlevel . 9)
                           (org-agenda-files :maxlevel . 9)))
(setq org-outline-path-complete-in-steps nil)         ; Refile in a single go
(setq org-refile-use-outline-path (quote file))       ; Show full paths for refiling

8 Clocking

Log the clocks into this drawer

(setq org-log-into-drawer "LOGBOOK")

Remember to clock out the clock on exit

(setq org-remember-clock-out-on-exit t)

Display clock time both in mode line and frame title

(setq org-clock-clocked-in-display (quote both))

9 Miscellaneous

Modules to load

(setq org-modules (quote (org-crypt org-habit org-mouse)))

Collapse everything except current tab. From https://stackoverflow.com/questions/25161792/emacs-org-mode-how-can-i-fold-everything-but-the-current-headline

(defun org-show-current-heading-tidily ()
  (interactive)
  "Show next entry, keeping other entries closed."
  (if (save-excursion (end-of-line) (outline-invisible-p))
      (progn (org-show-entry) (show-children))
    (outline-back-to-heading)
    (unless (and (bolp) (org-on-heading-p))
      (org-up-heading-safe)
      (hide-subtree)
      (error "Boundary reached"))
    (org-overview)
    (org-reveal t)
    (org-show-entry)
    (show-children)))

helm-org-rifle settings

(require 'helm-org-rifle)
(setq helm-org-rifle-show-path t)

org-download settings

(require 'org-download)
(setq-default org-download-image-dir "~/Dropbox/org/pics")

Load a requirement for org-cliplink

(load "~/emacs-spacemacs-config/emacs-request/request.el")

Load org-notify

(require 'org-notify)

10 Dashboard

Create a dashboard with multiple Agenda views

(defun org-dashboard ()
  "Dashboard-like setting in org"
  (interactive)
  (setq org-agenda-sticky t)
  (setq org-agenda-window-setup 'current-window)
  (setq-default mode-line-format nil)
  (split-window-right)
  ;; (split-window-below)
  ;; (org-agenda nil "W")
  ;; (other-window 1)
  (org-agenda nil "E")
  (other-window 1)
  (split-window-below)
  (org-agenda nil "a")
  (other-window 1)
  (org-agenda nil "Q")
  ;; (other-window 1)
  ;; (shrink-window-if-larger-than-buffer)
  ;; (other-window 2)
  ;; (shrink-window-horizontally 10)
  ;; (other-window 1)
  ;; (shrink-window 15)
  ;; (other-window 1)
  (run-with-timer 0 (* 5 60) 'refresh-dashboard)
  )
(global-set-key (kbd "<f7>") 'org-dashboard)

(defun refresh-dashboard ()
  "Run some commands in sequence."
  (interactive)
  ;; (message "%s" "i started")
  ;; (message nil)
  (cl-loop repeat 3 do (execute-kbd-macro (kbd "r")) (other-window 1))
  ;; (message "%s" "i ran")
  ;; (message nil)
  )

(require 'cl)
(defun bk-kill-buffers (regexp)
  "Kill buffers matching REGEXP without asking for confirmation."
  (interactive "sKill buffers matching this regular expression: ")
  (flet ((kill-buffer-ask (buffer) (kill-buffer buffer)))
    (kill-matching-buffers regexp)))
(defun close-dashboard ()
  "Dashboard-like setting in org"
  (interactive)
  (cancel-function-timers 'refresh-dashboard)
  (bk-kill-buffers ".*Org.*Agenda.*")
  (delete-other-windows)
  )

11 Disabled

;; any items below the headings with these tags dont inherit that tag
;; (setq org-tags-exclude-from-inheritance (quote ("PROJECT" "crypt")))

;; crypt
;; (require 'org-crypt)
;; (org-crypt-use-before-save-magic)
;; (setq org-tags-exclude-from-inheritance (quote ("crypt")))

;; GPG key to use for encryption
;; Either the Key ID or set to nil to use symmetric encryption.
;; (setq org-crypt-key nil)

;; org-publish
;; (require 'ox-publish)
;; (setq org-publish-project-alist
;;       '(
;;         ("org"
;;          :base-directory "~/Dropbox/org/"
;;          :publishing-directory "~/Dropbox/org/"
;;          :base-extension "---"
;;          :recursive nil
;;          :publishing-function org-html-publish-to-html
;;          :include ("bayesian.org" "classification.org" "clustering.org" "data_science_misc.org" "data_structs_algos.org" "deep_learning.org" "ds_tools.org" "machine_learning_misc.org" "nlp.org" "recommendations.org" "regression.org" "reinforcement-learning.org" "statistics.org" "supervised_learning.org" "time_series.org")
;;          )))

;; change ... to
;; (setq org-ellipsis "⤵")

;; calendar export settings
;; (setq org-icalendar-exclude-tags (quote ("noexport")))
;; (setq org-icalendar-include-todo t)
;; (setq org-icalendar-use-deadline (quote (event-if-not-todo event-if-todo)))
;; (setq org-icalendar-use-scheduled (quote (event-if-not-todo event-if-todo)))

;; lists are also collapsed by default, not just headings
;; (setq org-cycle-include-plain-lists 'integrate)

;; Don't show tasks with "home" tag during day time
;; (defun my/org-agenda-skip-home ()
;;   (let ((current-hour (string-to-number (format-time-string "%H"))))
;;     (when (and (< 10 current-hour 18)
;;                (member "home" (org-get-tags-at)))
;;       (or (outline-next-heading)
;;           (goto-char (point-max))))))
;; (setq org-agenda-skip-function #'my/org-agenda-skip-home)

12 Final

Let the Spacemacs use this configuration.

(provide 'org-config)

Author: Sainath Adapa

Created: 2019-09-12 do 10:42

Validate