balaramadurai / .emacs.d

Spacemacs-Lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spacemacs-Lite

This is a modest version of the super amazing package called Spacemacs!

This config is for people who are either:

  1. Starting out with emacs
  2. Or tried out Spacemacs and were overwhelmed by the list of customization possible.

Index

Screenshots

My screenshots of the Spacemacs-Lite version Spacemacs-Lite-home.png

Spacemacs-Lite-Help.png

Spacemacs-Lite-Org.png

Here is my .emacs.d config. I’ve learnt from the internet, I thought I should return the favour :)

Quick Start

You’ll need emacs before we start off with this - http://wikemacs.org/index.php/Installing_Emacs

Once you have installed Emacs, you can start with this. Copy the following commands line by line and press ENTER

 # if you have a pre-existing config, also backup your .emacs from your home directory
mv .emacs.d .emacs.d.bak
git clone http://github.com/balaramadurai/.emacs.d
# Launch emacs and enjoy!

Motivation

I started using Spacemacs and I fell in love with the ease of use and the thought that has gone in to developing every brick of the emacs customization. But, somehow, there were some keybindings that I wanted it my way and it was increasingly getting difficult to have it my way. Creating a layer and maintaining it also seemed to be an uphill task. Although, I did manage it at the end. Somehow, I needed something that was, let’s say, light. At around the same time, I came across this talk by Suyash Bire, who talked about a Spacemacs-Lite. This concept appealed to me and I copied most of the code that I wanted from watching him. Eventually (in about a week’s time), he did share his settings on github.

That inspired me to do 2 things -

  1. Share my config so that someone else like me might benefit, and
  2. To have my config under a VC rather than Dropbox it.

That was my motivation, the list of whom I was inspired by are given below - Inspiration .

Get Started

Step 0: Install Emacs

http://wikemacs.org/index.php/Installing_Emacs

Step 1: Git clone or download the config

One way to use this config.org to make it your own is:

 # if you have a pre-existing config, also backup your .emacs from your home directory
mv .emacs.d .emacs.d.bak
git clone http://github.com/balaramadurai/.emacs.d

Step 2: Configure your secret.el

Edit the template provided secret.template.el to contain your secret passwords and keys.

Move the secret.el to a directory under your .emacs.d called private

mv secret.template.el private/secret.el

Step 3: Launch Emacs

emacs

Your emacs will open up in default doom-monokai-classic theme. You can customize this using SPC t t

Step 4: Customize the packages

How to add a new package to your config:

Type the words <muse and TAB

<muse <TAB>

You’ll get this

Type the name of the emacs package from http://melpa.org or use SPC p l for listing packages.

Go to the last parenthesis and type C-x C-e and the package will be installed for you.

OR restart emacs using SPC q r.

Step 5: Delete packages

If you want to remove a package, delete the package with its emacs-lisp code block in this file and also SPC p d.

By defining shortcut keys/keybindings for each package, you can make sure that when you decide to uninstall a package, the shortcut keys also go away

Step 6: Check the list of shortcuts/keybindings (Spacemacs Mnemonics)

To make shortcut keys, use the :general and type in =(spacemacs-leader-key <shortcut key in quotes> ‘<macro>’=.

I have evil (Vim emulation) enabled by default, hence I’d strongly recommend learning practicing “evil-mode” using evil-tutor using (SPC h T)

Shortcuts

[2018-12-10 Mon 16:53] The long list of shortcut keys are given below, as defined my this config file: All these work in all evil modes except insert Screenshots of the Spacemacs “menu” and the Org helper “menu”

Spacemacs-Lite-Help.png

Spacemacs-Lite-Org.png

The following table can be obtained from M-x general-describe-keybindings

KeybindingMacro name
SPCSpacemacs-Lite Leader
SPC SPCM-x (helm)
SPC ?show keybindings (helm)
SPC !shell pop (requires shell-pop)
SPC :shell command
SPC aapps
SPC addired/ranger
SPC accalendar
SPC aeeasy-hugo
SPC ammu4e
SPC aoorg
SPC bbuffer
SPC bblist of buffers (helm)
SPC b] (also M-])next buffer
SPC b[ (also M-[)previous buffer
SPC bacopy whole buffer to clipboard
SPC bccopy file
SPC bdkill the current buffer
SPC bRrename file and buffer
SPC brrevert buffer (when changed on disk)
SPC bmshow Messages buffer
SPC bhshow Dashboard buffer
SPC TABshow the last buffer used
SPC ccomments
SPC clcomment or uncomment line
SPC crcomment region
SPC ffiles
SPC ffopen files (helm)
SPC fropen recent files
SPC feemacs files
SPC fedopen init.el
SPC fecopen config.org (this file)
SPC feRload init.el
SPC fssave the current file
SPC iinsert
SPC ikshow kill ring (clipboard)
SPC ppackages
SPC piinstall a new package
SPC pllist all packages
SPC puupgrade all packages
SPC pdremove a package
SPC prauto remove unnecessary packages
SPC qquit
SPC qqquit emacs
SPC qrquit and restart emacs
SPC qdquit and restart emacs with debug-init
SPC aoorg
SPC aocorg capture
SPC aolorg store link
SPC aoo (also F2)org agenda
SPC rorg reviews
SPC rwweekly review
SPC rqquarterly review
SPC ryyearly review
SPC ssearch
SPC sssearch within a buffer (helm)
SPC swweb
SPC swdDuckduckgo search using w3m
SPC tthemes
SPC ttload themes
SPC tdload dichromacy theme
SPC tlload leuven theme
SPC tsdload spacemacs dark theme
SPC tslload spacemacs light theme
SPC tpload poet theme
SPC wwindows
SPC wmmaximize window
SPC wddelete window
SPC w/split window vertically
SPC w-split window horizontally
SPC 1select window 1
SPC 2select window 2

Org Mode

[2018-12-12 Wed 17:15]

Org Mode shortcuts (or major mode shortcuts can be accessed through). I’ll add the keybindings soon.

keybindingDescription
.Org Mode helper

Inspiration

This is inspired (read “copied/borrowed/reused”) from the following sources (and not limited to):

Elisp Files

Base

(package-initialize)
(add-to-list 'package-archives
	     '("melpa" . "https://melpa.org/packages/")
             '("elpy" . "http://jorgenschaefer.github.io/packages/"))

(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)

(when (not package-archive-contents)
 (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
(defconst private-dir  (expand-file-name "private" user-emacs-directory))
(defconst temp-dir (format "%s/cache" private-dir)
  "Hostname-based elisp temp directories")
(load "~/.emacs.d/private/secret.el" t)

;; Core settings
;; UTF-8 please
(set-charset-priority 'unicode)
(setq locale-coding-system   'utf-8)   ; pretty
(set-terminal-coding-system  'utf-8)   ; pretty
(set-keyboard-coding-system  'utf-8)   ; pretty
(set-selection-coding-system 'utf-8)   ; please
(prefer-coding-system        'utf-8)   ; with sugar on top
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))

;; Emacs customizations
(setq exec-path                          (append exec-path '("/usr/local/bin/"))
      fringes-outside-margins            t
      x-select-enable-clipboard          t)

(provide 'base)
;;; base ends here

Who am I & My Org Files

My personal details

;; *****************
;; Personal Information
   (setq user-full-name "Bala Ramadurai"
      user-mail-address "bala@balaramadurai.net")
   (setq org-agenda-files '("~/org/index.org" "~/org/writing.org" "~/org/teaching.org" "~/org/learning.org" "~/org/marketing.org" "~/org/inbox.org"))
(defun my/phone-p ()
  (and (equal (system-name) "localhost") (not (equal user-login-name "bala"))))

Base Emacs

Initialization of the startup file. I made a design choice of moving to an org file and tangle all these blocks, since I like the modular approach that org mode allows.

(eval-and-compile
  (setq gc-cons-threshold 402653184
      gc-cons-percentage 0.6))

;; Init time start
(defvar my-init-el-start-time (current-time) "Time when init.el was started")

(setq inhibit-startup-screen t )	; inhibit useless and old-school startup screen
(setq ring-bell-function 'ignore )	; silent bell when you make a mistake
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

(setq sentence-end-double-space nil)	; sentence SHOULD end with only a point.
(setq default-fill-column 99999)		; toggle wrapping to a really long line
(defalias 'yes-or-no-p 'y-or-n-p) ; Simplify life
(setq ad-redefinition-action 'accept)         ; to get rid of the annoying "ad-handle-definition" warning
(add-hook 'text-mode-hook
	  (lambda ()
	    (variable-pitch-mode 1)))
(set-face-attribute 'default nil :family "Iosevka" :height 95)
(set-face-attribute 'fixed-pitch nil :family "Iosevka" :height 95)
(set-face-attribute 'variable-pitch nil :family "Baskerville" :height 110)

					;  (flyspell-mode 1)        ;; Catch Spelling mistakes
(blink-cursor-mode 0)    ;; Reduce visual noise

;; These instructions are coming from this website - https://sam217pa.github.io/2016/09/02/how-to-build-your-own-spacemacs/
;;
;; Packages

(use-package auto-compile
  :config (auto-compile-on-load-mode))
(setq load-prefer-newer t)
(server-start)

Base Theme

Doom modeline

(use-package doom-modeline
  :config (doom-modeline-mode 1))

Graphical Features

Prettify Symbols

(global-prettify-symbols-mode +1)
(setq org-ellipsis "")

(add-hook 'org-mode-hook
              (lambda ()
                ;; (push '("TODO"  . ?⏹) prettify-symbols-alist)
                (push '("NEXT"  . ?☞) prettify-symbols-alist)
                (push '("MEETING"  . ?會) prettify-symbols-alist)
                ;; (push '("DONE"  . ?✓) prettify-symbols-alist)
                (push '("CANCELLED"  . ?✘) prettify-symbols-alist)
))
(add-hook 'org-mode-hook (lambda ()
			   "Beautify Org Checkbox Symbol"
			   (push '("[ ]" . "") prettify-symbols-alist)
			   (push '("[X]" . "" ) prettify-symbols-alist)
			   (push '("[-]" . "" ) prettify-symbols-alist)
			   ))
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)

Emacs stuff

;  (menu-bar-mode -1)
  (when (not (my/phone-p))
     (scroll-bar-mode -1))
  (tool-bar-mode -1)
  (winner-mode 1)
  (setq initial-frame-alist (quote ((fullscreen . maximized))))

Emacs Functionality

Emacs Basics

[2018-01-05 Fri 12:44]

(global-auto-revert-mode 1)
(setq frame-title-format "%b")

Browser

[2018-01-05 Fri 12:37]

(setq browse-url-browser-function (quote browse-url-default-browser))

Backups

This is one of the things people usually want to change right away. By default, Emacs saves backup files in the current directory. These are the files ending in ~ that are cluttering up your directory lists. The following code stashes them all in ~/.emacs.d/backups, where I can find them with C-x C-f (find-file) if I really need to.

(unless (file-directory-p (concat private-dir "/backups"))
		       (make-directory (concat private-dir "/backups") :parents))
(setq backup-directory-alist '(("." . "~/.emacs.d/private/backups")))

Disk space is cheap. Save lots.

(setq delete-old-versions -1)
(setq version-control t)
(setq vc-make-backup-files t)
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/private/auto-save-list/" t)))
(unless (file-exists-p (concat private-dir "/cache/recentf"))
		       (make-directory (concat private-dir "/cache/") :parents))
(setq recentf-save-file "~/.emacs.d/private/cache/recentf")

History

From http://www.wisdomandwonder.com/wordpress/wp-content/uploads/2014/03/C3F.html

(setq savehist-file "~/.emacs.d/private/cache/savehist")
(savehist-mode 1)
(setq history-length t)
(setq history-delete-duplicates t)
(setq savehist-save-minibuffer-history 1)
(setq savehist-additional-variables
      '(kill-ring
        search-ring
        regexp-search-ring))

Save my place or I’ll rearrange your face

(setq-default save-place t)

Detect Internet Connection

(defun internet-up-p (&optional host)
  (= 0 (call-process "ping" nil nil nil "-c" "1" "-W" "1"
                     (if host host "www.google.com"))))

Base Extensions

Diminish

[2018-12-04 Tue 14:14]

(use-package diminish

  :config
  (diminish 'eldoc-mode "")
  (diminish 'buffer-face-mode "")
  (diminish 'undo-tree-mode "")
)

General

;; General package
(use-package general

;  :after which-key
  :config
  (general-override-mode 1)

   (general-create-definer spacemacs-lite/set-leader-keys
    :states '(normal visual motion emacs)
    :prefix "SPC")

    (general-create-definer spacemacs-lite/set-leader-keys-for-major-mode
    :states '(normal emacs)
    :prefix ".")

    (general-define-key
    :keymaps 'key-translation-map
    "ESC" (kbd "C-g"))

    (general-def
    "<f2>"             'org-agenda
    "M-]"              'next-buffer
    "M-["              'previous-buffer
    "C-+"              'text-scale-increase
    "C--"              'text-scale-decrease
    )

    (spacemacs-lite/set-leader-keys-for-major-mode
    ""      '(nil :which-key "Org helper"))

    (spacemacs-lite/set-leader-keys
    ""     '(nil :which-key "Spacemacs-Lite")
    "a"    '(:ignore t :which-key "apps")
    "b"    '(:ignore t :which-key "buffer")
    "c"    '(:ignore t :which-key "comments")
    "f"    '(:ignore t :which-key "files")
    "g"    '(:ignore t :which-key "git")
    "h"    (general-simulate-key "C-h" :which-key "help")
    "i"    '(:ignore t :which-key "insert")
    "m"    '(:ignore t :which-key "modes")
    "P"    '(:ignore t :which-key "Packages")
    "q"    '(:ignore t :which-key "quit")
    "s"    '(:ignore t :which-key "search")
    "u"    (general-simulate-key "C-u" :which-key "universal")
    "w"    '(:ignore t :which-key "window")
    "x"    '(:ignore t :which-key "text")
    "xg"   '(:ignore t :which-key "google-translate")
    "xw"   '(:ignore t :which-key "words")

    ;; Applications
    "ad"   'dired
;    "ac"   'calendar
    "as"   'ansi-term

    ":"    'shell-command

    ;; buffer management
    ;; "bb"   'switch-to-buffer
    "b]"   'next-buffer
    "b["   'previous-buffer
    "ba"   'copy-whole-buffer-to-clipboard
    "bc"   'write-file
    "bd"   'kill-this-buffer
    "bD"   'spacemacs-lite/kill-other-buffers
    "bR"   'rename-file-and-buffer
    "br"   'revert-buffer
    "bm"   'show-messages-buffer
    "bh"   'show-home-buffer
    "bs"   'show-scratch-buffer
    "bY"   'copy-whole-buffer-to-clipboard
    "TAB"  '(mode-line-other-buffer :wk "last buffer")

    ;; Comments
    "cl"   'comment-or-uncomment-line
    "cr"   'comment-region

    ;; file operations
    ;; "ff"   'find-file
    "fc"   '(spacemacs-lite/copy-file :wk "copy-file")
    "fD"   '(spacemacs-lite/delete-current-buffer-file :wk "delete-file")
    "fe"   '(:ignore t :which-key "emacs")
    "fE"   '(spacemacs-lite/sudo-edit :wk "sudo-edit")
    "fed"  'find-user-init-file
    "feR"  'load-user-init-file
    "fec"  'find-user-config-org-file
    "fo"   '(spacemacs-lite/open-file-or-directory-in-external-app :wk "open-in-ext")
    "fR"   '(spacemacs-lite/rename-current-buffer-file :wk "rename-file")
    "fs"   'save-buffer

    ;; help

    ;; package manager
    "Pr"   'package-autoremove
    "Pd"   'package-delete
    "Pl"   'list-packages
    "Pi"   'package-install
    "Pu"   'package-upgrade-all

    ;; quit emacs
    "qq"   'kill-emacs

    ;; window management
    "wm"   'delete-other-windows
    "w/"   'split-window-horizontally
    "w-"   'split-window-vertically
    "wd"   'delete-window

    )

    (general-def 'normal doc-view-mode-map
      "/"   'isearch-forward)

    (general-def 'normal package-menu-mode-map
      "i"   'package-menu-mark-install
      "U"   'package-menu-mark-upgrades
      "d"   'package-menu-mark-delete
      "u"   'package-menu-mark-unmark
      "x"   'package-menu-execute
      "q"   'quit-window)

    (general-def 'normal term-mode-map
      "i"   'package-menu-mark-install
      "U"   'package-menu-mark-upgrades
      "d"   'package-menu-mark-delete
      "u"   'package-menu-mark-unmark
      "x"   'package-menu-execute
      "q"   'quit-window)

  )

Which Key

;; Which-Key
(use-package which-key

  :diminish (which-key-mode . "")
  :config
  (which-key-mode)
  (setq which-key-popup-type 'minibuffer)
  (setq which-key-sort-order 'which-key-key-order-alpha)
  (setq which-key-idle-delay 0.25)
  (setq which-key-echo-keystrokes 0.18)
  )

Helm

~/.emacs.d/elisp/base-extensions.el
;; Helm
(use-package helm

  :diminish (helm-mode . "")
  :general
  (spacemacs-lite/set-leader-keys
    "SPC"  'helm-M-x
    "bb"   'helm-mini
    "ff"   'helm-find-files
    "fr"   'helm-recentf
    "ik"   'helm-show-kill-ring
    )
  (general-def 'emacs org-agenda-mode-map
    "<SPC><SPC>"  '(helm-M-x :wk "M-x")
    "<SPC>bb"   'helm-mini
    "<SPC>ff"   'helm-find-files
    )

  :config
  (helm-mode 1)
  ;; https://github.com/emacs-helm/helm/issues/2175 - for arrows to go back or forward in find files
  (customize-set-variable 'helm-ff-lynx-style-map t)

  ;; https://emacs.stackexchange.com/questions/33727/how-does-spacemacs-allow-tab-completion-in-helm
  (define-key helm-map (kbd "TAB") #'helm-execute-persistent-action)
  (define-key helm-map (kbd "<tab>") #'helm-execute-persistent-action)
  (define-key helm-map (kbd "C-z") #'helm-select-action)
  )

(use-package helm-swoop

:general
(spacemacs-lite/set-leader-keys "ss" 'helm-swoop)
(general-def '(normal visual emacs motion) "/" 'helm-swoop-without-pre-input)
)

(use-package helm-projectile
  :general
  (spacemacs-lite/set-leader-keys
    "p"    '(:ignore t :wk "projects")
    "pr"   '(helm-projectile-recentf :wk "recent projects")
    "pf"   '(helm-projectile-find-file :wk "files")
    "pd"   '(projectile-dired :wk "directory")
    )

)

(use-package helm-descbinds

; :diminish
 :general
 (spacemacs-lite/set-leader-keys "?" '(helm-descbinds :wk "show keybindings"))
 :config
 (setq helm-descbinds-window-style 'split)
 :hook helm-mode-hook
)

Ivy

(use-package ivy
  :diminish (ivy-mode . "")
  :general
  (spacemacs-lite/set-leader-keys
   "fr" 'counsel-recentf
   "rl" 'ivy-resume
   "bb" 'ivy-switch-buffer)
  :config
  (ivy-mode 1)
  (setq-default ivy-initial-inputs-alist nil)
  (setq ivy-count-format ""
       ivy-display-style nil
       ivy-fixed-height-minibuffer t
       ivy-height 20
       ivy-re-builders-alist '((t . ivy--regex-plus))
       ivy-format-functions-alist '((t . ivy-format-function-line)))
  )


(setq ivy-use-virtual-buffers t)

;; Example setting for ivy-views
(setq ivy-views
      `(("config {}"
         (vert
          (file "~/.emacs.d/README.org")
          (file "~/.emacs.d/init.el")
          ))
        ("kdt {}"
         (horz
          (file "~/Google Drive/1 Projects/2020 Karmic Design Thinking/manuscript/KDT-orange.org")))))
          
(use-package counsel
  :diminish (counsel-mode . "")
  :general
  (spacemacs-lite/set-leader-keys
    "SPC"  'counsel-M-x
    "ff"   'counsel-find-file
    "fr"   'counsel-recentf
    "fL"  'counsel-locate
    ;; help
    "?"   'counsel-descbinds
    ;; insert
    "iu"  'counsel-unicode-char
    ;; jump
    ;; register/ring
    "ry"  'counsel-yank-pop
    ;; jumping
    "sj"  'counsel-imenu
    )
  (general-def 'emacs org-agenda-mode-map
    "<SPC><SPC>"  '(counsel-M-x :wk "M-x")
    "<SPC>bb"   'counsel-switch-buffer
    "<SPC>ff"   'counsel-find-files
    )
  :config
  (counsel-mode 1)
  )

(use-package swiper
  :general
  (spacemacs-lite/set-leader-keys "ss" 'me/swiper)
					;  (general-def '(normal visual emacs motion) "/" 'swiper)
  :config
  (defun me/swiper ()
    "`swiper' with string returned by `ivy-thing-at-point' as initial input."
    (interactive)
    (swiper (ivy-thing-at-point)))
  (setq swiper-goto-start-of-match t))

Alda

(use-package alda-mode
:after evil
)

Backup

;; backup settings
(setq delete-old-versions t)
(setq kept-new-versions 6)
(setq kept-old-versions 2)
(setq version-control t)

Beancount

(use-package beancount
    :load-path "~/.emacs.d/plugin"
)

Calfw

 ~/.emacs.d/elisp/base-extensions.el
(use-package calfw
  :general
  (spacemacs-lite/set-leader-keys "ac" 'my-open-calendar)
  :init
  (progn
    (use-package calfw-cal)
    (use-package calfw-org)
    (use-package calfw-ical))
  :config
  (defun my-open-calendar ()
    (interactive)
    (cfw:open-calendar-buffer
     :contents-sources
     (list
      (cfw:org-create-source "DarkGreen")  ; orgmode source
      (cfw:ical-create-source family-cal-name family-gcal-ics "orange red")
      (cfw:ical-create-source company-cal-name company-gcal-ics  "dark blue")
      (cfw:ical-create-source personal-cal-name personal-gcal-ics "DarkMagenta") ; google calendar ICS
      )
     :view 'two-weeks
     ))
  )

Company

(use-package company

  :diminish (company-mode . "")
  :config
  (global-company-mode t))

Easy Hugo

[2018-01-26 Fri 11:53]

~/.emacs.d/elisp/base-extensions.el
 (use-package easy-hugo

 :general
 (spacemacs-lite/set-leader-keys "ae" 'easy-hugo)
 (general-def 'normal easy-hugo-mode-map
     "n" 'easy-hugo-newpost
     "M" 'easy-hugo-magit
     "D" 'easy-hugo-article
     "p" 'easy-hugo-preview
     "P" 'easy-hugo-publish
     "o" 'easy-hugo-open
     "d" 'easy-hugo-delete
     "e" 'easy-hugo-open
     ">" 'easy-hugo-next-blog
     "<" 'easy-hugo-previous-blog
     "c" 'easy-hugo-open-config
     "f" 'easy-hugo-open
     "N" 'easy-hugo-no-help
     "v" 'easy-hugo-view
     "r" 'easy-hugo-refresh
     "g" 'easy-hugo-refresh
     "s" 'easy-hugo-sort-time
     "S" 'easy-hugo-sort-char
     "u" 'easy-hugo-sort-publishday
     "G" 'easy-hugo-github-deploy
     "A" 'easy-hugo-amazon-s3-deploy
     "C" 'easy-hugo-google-cloud-storage-deploy
     "q" 'evil-delete-buffer
     (kbd "RET") 'easy-hugo-open)

     :config
     (setq easy-hugo-basedir "~/Nextcloud/2 Areas/Websites/balaramadurai.net/")
     (setq easy-hugo-postdir "content/blog")
     (setq easy-hugo-url "http://balaramadurai.net")
     (setq easy-hugo-sshdomain "gitlab.com")
     (setq easy-hugo-root "~/")
     (setq easy-hugo-image-directory "img")
     ;;(setq easy-hugo-previewtime "300")
     (setq easy-hugo-default-ext ".org")


     )

Emoji

~/.emacs.d/elisp/base-extensions.el
(use-package emojify


 :diminish
; :general
; :config
)

ESS

[2018-12-05 Wed 11:33]

 ~/.emacs.d/elisp/base-extensions.el
(use-package ess
)

Evil

(use-package evil

  :diminish (evil-mode . "")
  :hook (after-init . evil-mode)
  :config
  (evil-mode 1)
  (evil-set-initial-state 'shell-mode 'normal)
  (evil-set-initial-state 'package-menu-mode 'normal)
  (evil-set-initial-state 'doc-view-mode 'normal)
  (evil-set-initial-state 'magit-mode 'normal)
  (cua-mode 1)
  (setq doc-view-continuous t)
  :general
  (spacemacs-lite/set-leader-keys
    "bN"   'evil-buffer-new
    "fd"   'evil-save-and-close
    )
  )

Unimpaired

[2018-12-07 Fri 06:22]

(use-package evil-unimpaired

  :requires evil
;  https://www.github.com/syl20bnr/spacemacs/layers/+spacemacs/spacemacs-evil/local/evil-unimpaired/evil-unimpaired.el
  :load-path "~/.emacs.d/plugin"
					; :diminish
					; :general
					; :config
  )

Evil Goggles

(use-package evil-goggles
					; :diminish
					; :general
  :config
  (setq evil-goggles-pulse t) ;; default is to pulse when running in a graphic display
  (evil-goggles-use-diff-faces)
  (evil-goggles-mode)
  )

Evil Tutor

[2018-12-08 Sat 06:56]

(use-package evil-tutor

; :diminish
 :general
 (general-define-key
 :keymaps 'help-mode-map
 :which-key "evil-tutor"
 "T" 'evil-tutor)
 :config
 (setq evil-tutor-working-directory "/tmp")
)

Evil Magit

[2018-12-08 Sat 22:59]

(use-package evil-magit

; :diminish
; :general
; :config
)

Fountain

[2018-06-23 Sat 17:55]

(use-package fountain-mode

  :config
  (setq fountain-pages-show-in-mode-line (quote timer))
  (setq fountain-trans-suffix-list (quote ("TO:" "WITH:" "FADE OUT" "TO BLACK" "CUT TO:"))))

Google Translate

[2018-12-03 Mon 11:33]

 ~/.emacs.d/elisp/base-extensions.el
(use-package define-word

  :defer t
  :general
  (spacemacs-lite/set-leader-keys
    "xwd" 'define-word-at-point))
;;; The following functions are from https://github.com/syl20bnr/spacemacs/

(use-package google-translate

  :config
  (defun spacemacs-lite/set-google-translate-languages (source target)
    "Set source language for google translate.
For instance pass En as source for English."
    (interactive
     "sEnter source language (ie. en): \nsEnter target language (ie. en): "
     source target)
    (message
     (format "Set google translate source language to %s and target to %s"
             source target)))
  (setq google-translate-default-source-language (downcase source))
  (setq google-translate-default-target-language (downcase target))
  (setq google-translate-enable-ido-completion t)
  (setq google-translate-show-phonetic t)
  (setq google-translate-default-source-language "en")
  (setq google-translate-default-target-language "fr")
  :general
  (spacemacs-lite/set-leader-keys
    "xgl" 'spacemacs-lite/set-google-translate-languages
    "xgQ" 'google-translate-query-translate-reverse
    "xgq" 'google-translate-query-translate
    "xgT" 'google-translate-at-point-reverse
    "xgt" 'google-translate-at-point))

Magit

(use-package magit

  :general
  (spacemacs-lite/set-leader-keys
    "gs"   'magit-status
    "gc"   'magit-commit-create
    "gp"   'magit-push-other
    "gS"   'magit-stage-file
    "gl"   'magit-log-all
    )
  )

Olivetti & typo

[2018-11-22 Thu 14:36]

~/.emacs.d/elisp/base-extensions.el
(use-package olivetti
  :config
  (setq olivetti-body-width 80)
  )

(use-package typo)

Openwith

(use-package openwith
  :config
  (openwith-mode t)
  (setq openwith-associations '(("\\.pdf\\'" "xreader" (file)))))

Restart Emacs

(use-package restart-emacs

 :config
  (defun spacemacs-lite/restart-emacs-debug-init (&optional args)
    "Restart emacs and enable debug-init."
    (interactive)
    (restart-emacs (cons "--debug-init" args)))
   :general
   (spacemacs-lite/set-leader-keys
     "qr"   'restart-emacs
     "qd"   '(spacemacs-lite/restart-emacs-debug-init :which-key "quit with debug-init")
     )
   )

Smartparens

[2018-12-04 Tue 15:33]

 ~/.emacs.d/elisp/base-extensions.el
(use-package smartparens

:diminish (smartparens-mode . "")
:config
   (smartparens-mode))

Shell ANSI-term

[2018-12-06 Thu 09:11]

(defadvice term-sentinel (around my-advice-term-sentinel (proc msg))
  (if (memq (process-status proc) '(signal exit))
      (let ((buffer (process-buffer proc)))
        ad-do-it
        (kill-buffer buffer))
    ad-do-it))
(ad-activate 'term-sentinel)

TOC org

[2018-12-05 Wed 08:39]

 ~/.emacs.d/elisp/base-extensions.el
(use-package toc-org

:init (toc-org-mode 1))

Treemacs

(defvar +treemacs-git-mode 'simple
  "Type of git integration for `treemacs-git-mode'.
There are 3 possible values:
  1) `simple', which highlights only files based on their git status, and is
     slightly faster,
  2) `extended', which highlights both files and directories, but requires
     python,
  3) `deferred', same as extended, but highlights asynchronously.
This must be set before `treemacs' has loaded.")

(use-package treemacs
  :init
  (setq treemacs-follow-after-init t
        treemacs-is-never-other-window t
        treemacs-sorting 'alphabetic-case-insensitive-asc
        )
  
  :general
  (spacemacs-lite/set-leader-keys "at" 'treemacs
    "0"  'treemacs-select-window)
  :config
  (treemacs-follow-mode -1)
  (treemacs-filewatch-mode t)
  (treemacs-fringe-indicator-mode t)
  (setq treemacs-wrap-around t)
  (when +treemacs-git-mode
    ;; If they aren't supported, fall back to simpler methods
    (when (and (memq +treemacs-git-mode '(deferred extended))
               (not (executable-find "python3")))
      (setq +treemacs-git-mode 'simple))
    (treemacs-git-mode +treemacs-git-mode)
    (setq treemacs-collapse-dirs
          (if (memq treemacs-git-mode '(extended deferred))
              3
            0)))
        )

(use-package treemacs-icons-dired
  :after treemacs dired
  :config (treemacs-icons-dired-mode))

(use-package treemacs-evil
  :after treemacs evil)

(use-package treemacs-magit
  :after treemacs magit)

Tufte Style

~/.emacs.d/elisp/base-extensions.el
(use-package ox-tufte


; :diminish
; :general
:config
(setq safe-local-variable-values
   (quote
    ((eval add-hook
	   (quote after-save-hook)
	   (quote org-latex-export-to-pdf)
	   nil t)
     (org-inline-image-overlays)
     (org-latex-caption-above)
     (org-hide-macro-markers . t)
     (org-fontify-quote-and-verse-blocks . t)
     (eval org-sbe "latex-link")
     (eval org-sbe "latex-opt-link")
     (eval org-sbe "jk-keywords")
     (eval org-sbe "pdf-process-bibtex")
     (eval org-sbe "ngz-nbsp")
     (eval org-sbe "latex-filter-footcites")
     (eval org-sbe "biblatex-cite-link")
     (eval org-sbe "biblatex-textcite-link")
     (eval org-sbe "biblatex-parencite-link")
     (eval org-sbe "biblatex-sidecite-link")
     (eval org-sbe "biblatex-multicite-link")
     (eval org-sbe "biblatex-footcite-link")
     (eval org-sbe "tufte-ebib-setup")
     (eval org-sbe "tufte-handout")
     (eval org-sbe "tufte-book")
     (eval org-sbe "user-entities")
     (eval require
	   (quote ox-tufte-latex)))))
)

(use-package ox-tufte-latex
  :load-path "~/.emacs.d/plugin/tufte-org-mode"
)

Undo Tree

[2019-01-05 Sat 09:22]

 ~/.emacs.d/elisp/base-extensions.el
(use-package undo-tree

  :diminish
  (undo-tree-mode . "")
  :general
  (spacemacs-lite/set-leader-keys "au" 'undo-tree-visualize)
  :config
  (progn
    (global-undo-tree-mode)
    (setq undo-tree-visualizer-timestamps t)
    (setq undo-tree-visualizer-diff t))
  )

Window Numbering

(use-package winum

:general
(spacemacs-lite/set-leader-keys "1" 'winum-select-window-1
  "2" 'winum-select-window-2
  "3" 'winum-select-window-3)
:config
  (setq winum-auto-setup-mode-line nil)
  (winum-mode 1)
)

Writeroom

 ~/.emacs.d/elisp/base-extensions.el
(use-package writeroom-mode
:defer t

:init
;;; writemode hooks
   (defun my-writemode-mode-hooks ()
     (wc-mode 1)
     (writegood-mode 1)
     )


:hook (writeroom-mode-hook . my-writeroom-mode-hooks)

:general
  (spacemacs-lite/set-leader-keys "wc" '(writeroom-mode :wk "distraction-free"))
)

Writegood & Word Count Mode

 ~/.emacs.d/elisp/base-extensions.el
(use-package writegood-mode

:config
(setq writegood-weasel-words
   (quote
    ("many" "various" "very" "fairly" "several" "extremely" "exceedingly" "quite" "remarkably" "surprisingly" "mostly" "largely" "huge" "tiny" "are a number" "is a number" "excellent" "interestingly" "significantly" "substantially" "clearly" "vast" "relatively" "completely" "literally" "not rocket science" "outside the box" "about" "just" "really" "started" "began" "all" "again" "very" "that" "any" "so" "then" "rather" "some" "only" "almost" "like" "close" "even" "somehow" "sort" "pretty" "well" "back" "up" "down ,anyway" "many" "real" "already" "own" "over" "ever" "be able to" "still" "bit" "far" "often" "also" "enough" "quite" "maybe" "one of" "thing" "mostly" "most" "in order to" "off" "out" "as" "while" "since" "when" "before" "after")))
)

(use-package wc-mode

)

Writing Mode

(use-package writing-mode
  :load-path "~/.emacs.d/plugin/writing-mode"
  :general
  (spacemacs-lite/set-leader-keys
    "m w"  'writing-mode
    )
  )

(defun br/org-export-as-pdf ()
  (interactive)
  (save-buffer)
  (org-latex-export-to-pdf))

Zoom

[2019-01-09 Wed 09:42]

(use-package zoom
  :config
  ;; Golden Ratio
  (setq zoom-size '(0.618 . 0.618))
  (zoom-mode t))

Base Org Mode

Org mode package definition with keybindings

[2018-12-03 Mon 10:41]

(use-package org
   :ensure org-plus-contrib
   :pin org
   :init
   (defun my-org-mode-hooks ()
     (visual-line-mode)
     (diminish 'visual-line-mode "")
;     (flyspell-mode)
;     (diminish 'flyspell-mode " Ⓕ")
;     (smartparens-mode)
     )
   (add-hook 'org-mode-hook 'my-org-mode-hooks)

   :general
   (spacemacs-lite/set-leader-keys
     "ao"   '(:ignore t :which-key "org")
     "aoc"   'org-capture
     "aol"   'org-store-link
     "aoo"   'org-agenda
     "r"     '(:ignore t :wk "Org Reviews")
     "rd"    'daily-review
     "rw"    'weekly-review
     "rq"    'quarterly-review
     "ry"    'yearly-review
     )
   (spacemacs-lite/set-leader-keys-for-major-mode
     ","    'org-time-stamp
     "!"    'org-time-stamp-inactive
     "."    'org-ctrl-c-ctrl-c
     "'"    'org-edit-special
     ":"    'org-set-tags-command
     "*"    'org-ctrl-c-star
     "a"    'org-agenda
     "A"    'org-attach
     "c"    'org-capture
     "C"    '(:ignore t :which-key "Clocks")
     "Ci"   'org-clock-in
     "Co"   'org-clock-out
     "Cq"   'org-clock-cancel
     "Cl"    'org-clock-in-last
     "e"     '(:ignore t :wk "export")
     "ee"   'org-export-dispatch
     "l"    'org-store-link
     "i"    '(:ignore t :which-key "insert")
     "id"   '(:ignore t :which-key "dates")
     "idi"     'org-time-stamp-inactive
     "ida"     'org-time-stamp
     "il"      'org-insert-link
     "d"       '(:ignore t :wk "dates")
     "ds"      'org-schedule
     "dd"      'org-deadline
     "o"       'org-open-at-point
     "r"       'org-refile
     "P"       'org-set-property
     "R"       '(:ignore t :which-key "Reviews")
     "Rd"      'daily-review
     "Rw"      'weekly-review
     "Rq"      'quarterly-review
     "Ry"      'yearly-review
     "s"       '(:ignore t :which-key "subtrees")
     "sc"      'org-copy-subtree
     "sa"      'org-archive-subtree
     "t"       'org-babel-tangle
     "<right>" 'org-agenda-do-date-later
     "<left>"  'org-agenda-do-date-earlier
     "x"       'my/org-agenda-done
     )

   (general-def org-mode-map
     "<f8>"      'org-narrow-to-subtree
     "M-<f8>"    'widen
     "<f6>"          'my/org-done
     )

   (general-define-key
    :definer 'minor-mode
    :states 'normal
    :keymaps 'org-capture-mode
    ".c"           'org-capture-finalize
    ".k"           'org-capture-kill
    ".r"           'org-capture-refile)

  (general-define-key
    :definer 'minor-mode
    :states 'normal
    :keymaps 'org-src-mode
    ".c"           'org-edit-src-exit
    ".k"           'org-edit-src-abort)

  (general-define-key
    :keymaps 'org-agenda-mode-map
    ","                              'org-agenda-goto-today
    "n"                              'org-agenda-later
    "p"                              'org-agenda-earlier
    [remap org-clock-in]             'org-agenda-clock-in
    [remap org-clock-out]            'org-agenda-clock-out
    [remap org-clock-cancel]         'org-agenda-clock-cancel
    [remap org-schedule]             'org-agenda-schedule
    [remap org-deadline]             'org-agenda-deadline)

   :config

   (defun my/org-done (&optional arg)
     "Mark current TODO as done.
   This changes the line at point, all other lines in the agenda referring to
   the same tree node, and the headline of the tree node in the Org-mode file."
     (interactive "P")
     (org-todo "DONE"))

   (defun my/org-agenda-done (&optional arg)
     "Mark current TODO as done.
   This changes the line at point, all other lines in the agenda referring to
   the same tree node, and the headline of the tree node in the Org-mode file."
     (interactive "P")
     (org-agenda-todo "DONE"))
   (defun daily-review()
     (interactive)
     (org-capture nil "rd")
     (org-capture-finallize t)
     (org-speed-move-safe 'outline-up-heading)
     (org-narrow-to-subtree)
     (fetch-calendar)
     )
   (defun weekly-review ()
     (interactive)
     (progn
       (org-capture nil "rw")
       (org-capture-finalize t)
       (org-speed-move-safe 'outline-up-heading)
       (org-narrow-to-subtree)
       (fetch-calendar)))

   (defun quarterly-review ()
     (interactive)
     (progn
       (org-capture nil "rq")
       (org-capture-finalize t)
       (org-speed-move-safe 'outline-up-heading)
       (org-narrow-to-subtree)
       (fetch-calendar)))

   (defun yearly-review ()
     (interactive)
     (progn
       (org-capture nil "ry")
       (org-capture-finalize t)
       (org-speed-move-safe 'outline-up-heading)
       (org-narrow-to-subtree)
       (fetch-calendar)))

Org mode Setup

Capture templates

;; (setq org-protocol-default-template-key "l")
;; Capture templates for: TODO tasks, Notes, appointments, phone calls, meetings, and org-protocol
(setq org-capture-templates
      (quote (("t" "todo" entry (file "~/org/inbox.org")
               "* TODO %?\nSCHEDULED: %^{Time of task?}T\n%U\n%a\n")
              ("m" "Meeting" entry (file "~/org/inbox.org")
	       (file "~/org/templates/meeting.org") :clock-in t)
              ("i" "Invoice" entry (file "~/org/inbox.org")
	       (file "~/org/templates/invoice-template.org"))
	      ("f" "New FD" entry (file+headline "~/org/Fava/ALK-finance-open-close.org" "FD")
	       (file "~/org/templates/ALK-FD.org"))
              ("p" "Project" entry (file "~/org/inbox.org")
	       (file "~/org/templates/project-template.org"))
              ("s" "Someday / Maybe Idea" entry (file+headline "~/org/somedaymaybe.org" "Someday / Maybe")
               "* SOMEDAY %?\n")
              )))

iCalendar setup

(setq org-agenda-default-appointment-duration 30)
(setq org-icalendar-store-UID t)
(setq org-icalendar-use-scheduled (quote (event-if-todo todo-start)))

Refile Setup

; Targets include this file and any file contributing to the agenda - up to 9 levels deep
(setq org-refile-targets (quote ((nil :maxlevel . 9)
                                 (org-agenda-files :maxlevel . 9)
                                 ("~/org/somedaymaybe.org" :maxlevel . 2)
)))

; Use full outline paths for refile targets - we file directly with IDO
(setq org-refile-use-outline-path t)

; Targets complete directly with IDO
(setq org-outline-path-complete-in-steps nil)

; Allow refile to create parent tasks with confirmation
(setq org-refile-allow-creating-parent-nodes (quote confirm))

; Use the current window for indirect buffer display
(setq org-indirect-buffer-display 'current-window)

;;;; Refile settings
; Exclude DONE state tasks from refile targets
(defun bh/verify-refile-target ()
  "Exclude todo keywords with a done state from refile targets"
  (not (member (nth 2 (org-heading-components)) org-done-keywords)))

(setq org-refile-target-verify-function 'bh/verify-refile-target)

Agenda properties

[2018-01-05 Fri 12:14]

(setq org-agenda-hide-tags-regexp nil)
(setq org-agenda-ignore-properties (quote (effort appt stats)))
(setq org-agenda-include-diary t)
(setq org-agenda-remove-tags nil)
(setq org-agenda-span 1)
(setq org-agenda-start-on-weekday 0)
(setq org-agenda-start-with-log-mode (quote (closed clock state)))
(setq org-agenda-use-tag-inheritance (quote (nil)))
(require 'notifications)
 ; Erase all reminders and rebuilt reminders for today from the agenda
(defun bh/org-agenda-to-appt ()
  (interactive)
  (setq appt-time-msg-list nil)
  (org-agenda-to-appt))

; Rebuild the reminders everytime the agenda is displayed
(add-hook 'org-agenda-finalize-hook 'bh/org-agenda-to-appt 'append)

; This is at the end of my .emacs - so appointments are set up when Emacs starts
(bh/org-agenda-to-appt)

; Activate appointments so we get notifications
(appt-activate t)
(display-time)                   ;; activate time display

(defcustom appt-notification-bus :session
   "D-Bus bus to use for notification."
   :version "25.1"
   :group 'appt-notification
   :type '(choice (const :tag "Session bus" :session) string))

(defun psachin/appt-display (min-to-app new-time msg)
   "Send notification."
   (notifications-notify :bus appt-notification-bus
                         :title (format "Appointment in %s minutes." min-to-app)
                         :body (format "%s" msg)
                         :replaces-id nil
                         :app-icon nil
                         :timeout 5000
                         :desktop-entry "emacs"))

(setq appt-disp-window-function (function psachin/appt-display))

(setq-default diary-file "~/.emacs.d/diary"
		   appt-display-format 'window
		   appt-display-duration 60
		   appt-audible t
		   appt-display-interval 3
		   appt-message-warning-time 10
		   display-time-24hr-format t
		   display-time-day-and-date t)

(run-at-time "24:01" 3600 'bh/org-agenda-to-appt)           ;; update appt list hourly
(add-hook 'org-finalize-agenda-hook 'bh/org-agenda-to-appt) ;; update appt list on agenda view
;; (setq diary-file "~/org/mycal.org")

Custom Agenda Views

(setq org-agenda-custom-commands
      (quote
       (("rw" "Weekly Review"
         ((agenda ""
                  ((org-agenda-overriding-header "This Week & The Next")
                   (org-agenda-show-all-dates t)
                   (org-agenda-archives-mode t)
                   (org-agenda-span
                    (quote fortnight))
                   ))
          (tags-todo "-CANCELLED-HOLD+Proj/!"
                     ((org-agenda-overriding-header "Stuck Projects")
                      (org-agenda-skip-function
                       (quote bh/skip-non-stuck-projects))
                      (org-agenda-sorting-strategy
                       (quote
                        (category-keep))))
                      )
          (tags-todo "-HOLD-CANCELLED+Proj/!"
                     ((org-agenda-overriding-header "Projects")
                      (org-agenda-skip-function
                       (quote bh/skip-non-projects))
                      (org-tags-match-list-sublevels
                       (quote indented))
                      (org-agenda-sorting-strategy
                       (quote
                        (category-keep)))))
          (tags "SOMEDAY"
                (
                 (org-agenda-files '("~/org/somedaymaybe.org"))
                 (org-agenda-overriding-header "Someday to Inbox")))
          (tags-todo "-CANCELLED+WAITING|HOLD/!"
                     ((org-agenda-overriding-header
                       (concat "Waiting and Postponed Tasks"
                               (if bh/hide-scheduled-and-waiting-next-tasks "" " (including WAITING and SCHEDULED tasks)")))
                      (org-agenda-skip-function
                       (quote bh/skip-non-tasks))
                      (org-tags-match-list-sublevels nil)
                      (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
                      (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)))
          (tags "-REFILE/"
                ((org-agenda-overriding-header "Tasks to Archive")
                 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
                 (org-tags-match-list-sublevels nil))))
         )
        ("rq" "Quarterly Review"
         ((tags-todo "-HOLD-CANCELLED+Proj/!"
                     ((org-agenda-overriding-header "Projects")
                      (org-agenda-skip-function
                       (quote bh/skip-non-projects))
                      (org-tags-match-list-sublevels
                       (quote indented))
                      (org-agenda-sorting-strategy
                       (quote
                        (category-keep)))))
          (tags "SOMEDAY"
                (
                 (org-agenda-files '("~/org/somedaymaybe.org"))
                 (org-agenda-overriding-header "Someday to Projects")))
          (tags "-REFILE/"
                ((org-agenda-overriding-header "Tasks to Archive")
                 (org-agenda-skip-function
                  (quote bh/skip-non-archivable-tasks))
                 (org-tags-match-list-sublevels nil)))
          )
         )
        ("ry" "Yearly Review"
         ((tags "CYear"
                ((org-agenda-overriding-header "Completed Projects")
                 (org-tags-match-list-sublevels nil)))
          (tags-todo "-HOLD-CANCELLED+Proj/!"
                     ((org-agenda-overriding-header "Projects")
                      (org-agenda-skip-function
                       (quote bh/skip-non-projects))
                      (org-tags-match-list-sublevels
                       (quote indented))
                      (org-agenda-sorting-strategy
                       (quote
                        (category-keep)))))
          (tags-todo "-CANCELLED+Proj/!"
                     ((org-agenda-overriding-header "Stuck Projects")
                      (org-agenda-skip-function
                       (quote bh/skip-non-stuck-projects))
                      (org-agenda-sorting-strategy
                       (quote
                        (category-keep)))))
          (tags "SOMEDAY"
                ((org-agenda-overriding-header "Someday to Projects"))))
         )
        ("r" . "Reviews")

  (" " agenda "Whole Agenda"
   ((org-agenda-include-diary t)
    ))
  )))

Org Config

Add my emacs directories

These are my standard add-on library paths

(add-hook 'org-mode-hook #'org-indent-mode)
;(add-hook 'text-mode-hook 'variable-pitch-mode)

Agenda tweaks

;; Keep tasks with dates on the global todo lists
(setq org-agenda-todo-ignore-with-date nil)

;; Keep tasks with deadlines on the global todo lists
(setq org-agenda-todo-ignore-deadlines nil)

;; Keep tasks with scheduled dates on the global todo lists
(setq org-agenda-todo-ignore-scheduled nil)

;; Keep tasks with timestamps on the global todo lists
(setq org-agenda-todo-ignore-timestamp nil)

;; Remove completed deadline tasks from the agenda view
(setq org-agenda-skip-deadline-if-done t)

;; Remove completed scheduled tasks from the agenda view
(setq org-agenda-skip-scheduled-if-done t)

;; Remove completed items from search results
(setq org-agenda-skip-timestamp-if-done t)


;; Show all future entries for repeating tasks
(setq org-agenda-repeating-timestamp-show-all t)

;; Show all agenda dates - even if they are empty
(setq org-agenda-show-all-dates t)

Handling blocked tasks

(setq org-enforce-todo-dependencies t)

Attachments

(setq org-id-method (quote uuidgen))

Logging Stuff

(setq org-log-done (quote time))
(setq org-log-into-drawer t)
(setq org-log-state-notes-insert-after-drawers nil)
(setq org-log-note-headings '((done        . "CLOSING NOTE %t")
                              (state       . "State %-12s from %-12S %t")
                              (note        . "Note taken on %t")
                              (reschedule  . "Schedule changed on %t: %S -> %s")
                              (delschedule . "Not scheduled, was %S on %t")
                              (redeadline  . "Deadline changed on %t: %S -> %s")
                              (deldeadline . "Removed deadline, was %S on %t")
                              (refile      . "Refiled on %t")
                              (clock-out   . "")))

Remove multiple state change log details from the agenda

[2011-04-30 Sat 11:14]

I skip multiple timestamps for the same entry in the agenda view with the following setting.

(setq org-agenda-skip-additional-timestamps-same-entry t)

This removes the clutter of extra state change log details when multiple timestamps exist in a single entry.

Drop old style references in tables

[2011-04-30 Sat 11:19]

I drop the old A3/B4 style references from tables when editing with the following setting.

(setq org-table-use-standard-references (quote from))

Use the current window for the agenda

[2011-05-28 Sat 21:20]

; Overwrite the current window with the agenda
(setq org-agenda-window-setup 'current-window)

Delete IDs when cloning

[2011-05-28 Sat 21:27]

(setq org-clone-delete-id t)

Cycling plain lists

Org mode can fold (cycle) plain lists.

(setq org-cycle-include-plain-lists t)

I find this setting useful when I have repeating tasks with lots of sublists with checkboxes. I can fold the completed list entries and focus on what is remaining easily.

Showing source block syntax highlighting

It is possible to display org-mode source blocks fontified in their native mode. This allows colourization of keywords for C and shell script source etc. If I edit the source I use =C-c ‘= (control-c single quote) to bring up the source window which is then rendered with syntax highlighting in the native mode. This setting also shows the syntax highlighting when viewing in the org-mode buffer.

(setq org-src-fontify-natively t)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
(set-face-attribute 'org-block nil :inherit 'fixed-pitch)
(set-face-attribute 'org-tag nil :inherit '(fixed-pitch shadow))

Inserting Structure Template Blocks

[2012-03-04 Sun 11:42]

There is a shortcut key sequence in org-mode to insert structure templates quickly into your org files.

I use example and source blocks often in my org files.

Key SequenceExpands to
< s TAB#+BEGIN_SRC … #+END_SRC
< e TAB#+begin_example … #+end_example

Next is for tasks

[2012-03-04 Sun 12:41]

NEXT keywords are for tasks and not projects. I’ve added a function to the todo state change hook and clock in hook so that any parent tasks marked NEXT automagically change from NEXT to TODO since they are now projects and not tasks.

(defun bh/mark-next-parent-tasks-todo ()
  "Visit each parent task and change NEXT states to TODO"
  (let ((mystate (or (and (fboundp 'org-state)
                          state)
                     (nth 2 (org-heading-components)))))
    (when mystate
      (save-excursion
        (while (org-up-heading-safe)
          (when (member (nth 2 (org-heading-components)) (list "NEXT"))
            (org-todo "TODO")))))))

(add-hook 'org-after-todo-state-change-hook 'bh/mark-next-parent-tasks-todo 'append)
(add-hook 'org-clock-in-hook 'bh/mark-next-parent-tasks-todo 'append)

Startup in folded view

[2012-04-08 Sun 07:26]

Startup in folded view.

(setq org-startup-folded t)

I used to use content view by default so I could review org subtrees before archiving but my archiving workflow has changed so I no longer need this manual step.

Allow alphabetical list entries

(setq org-alphabetical-lists t)

In order for filling to work correctly this needs to be set before the exporters are loaded.

Preserving source block indentation

I do not preserve indentation for source blocks mainly because this doesn’t look nice with indented org-files. The only reason I’ve found to preserve indentation is when TABs in files need to be preserved (e.g. Makefiles). I don’t normally edit these files in org-mode so I leave this setting turned off.

I’ve changed the default block indentation so that it is not indented from the text in the org file. This allows editing source blocks in place without requiring use of =C-c ‘= so that code lines up correctly.

(setq org-src-preserve-indentation nil)
(setq org-edit-src-content-indentation 0)

Prevent editing invisible text

[2012-07-20 Fri 22:26]

The following setting prevents accidentally editing hidden text when the point is inside a folded region. This can happen if you are in the body of a heading and globally fold the org-file with S-TAB

I find invisible edits (and undo’s) hard to deal with so now I can’t edit invisible text. C-c C-r (org-reveal) will display where the point is if it is buried in invisible text to allow editing again.

(setq org-catch-invisible-edits 'smart)

In collapsed view, hide empty lines between subtrees

[2019-06-04 Tue 08:33]

Set org-cycle-separator-lines to 0. Gives a more compact and consistent view, especially in a large Org file with many headings.

(setq org-cycle-separator-lines 0)

Use utf-8 as default coding system

[2013-01-01 Tue 13:49]

I use utf-8 as the default coding system for all of my org files.

(setq org-export-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(set-charset-priority 'unicode)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))

Keep clock durations in hours

[2013-02-17 Sun 12:37]

The default for clock durations has changed to include days which is 24 hours. At work I like to think of a day as 6 hours of work (the rest of the time is lost in meetings and other overhead on average) so displaying clock durations in days doesn’t make sense to me.

The following setting displays clock durations (from C-c C-x C-d in hours and minutes.

(setq org-time-clocksum-format
      '(:hours "%d" :require-hours t :minutes ":%02d" :require-minutes t))

Create unique IDs for tasks when linking

[2013-06-23 Sun 10:38]

The following setting creates a unique task ID for the heading in the PROPERTY drawer when I use C-c l. This allows me to move the task around arbitrarily in my org files and the link to it still works.

(setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
(setq org-emphasis-alist (quote (("*" bold "<b>" "</b>")
                                 ("/" italic "<i>" "</i>")
                                 ("_" underline "<span style=\"text-decoration:underline;\">" "</span>")
                                 ("=" org-code "<code>" "</code>" verbatim)
                                 ("~" org-verbatim "<code>" "</code>" verbatim)
				 ("+" '(:strike-through t :foreground "gray"))
				 ("+" org-emphasis-alist :key 'car :test 'equal))))

(setq org-use-sub-superscripts nil)

(setq org-odd-levels-only nil)

(run-at-time "00:59" 3600 'org-save-all-org-buffers)
(defun org-set-line-checkbox (arg)
  (interactive "P")
  (let ((n (or arg 1)))
    (when (region-active-p)
      (setq n (count-lines (region-beginning)
                           (region-end)))
      (goto-char (region-beginning)))
    (dotimes (i n)
      (beginning-of-line)
      (insert "- [ ] ")
      (forward-line))
    (beginning-of-line)))

Place tags on Org Agenda

[2018-11-13 Tue 11:56]

;; Place tags close to the right-hand side of the window
(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))
(defun clocktable-by-tag/shift-cell (n)
  (let ((str ""))
    (dotimes (i n)
      (setq str (concat str "| ")))
    str))

(defun clocktable-by-tag/insert-tag (params)
  (let ((tag (plist-get params :tags)))
    (insert "|--\n")
    (insert (format "| %s | *Tag time* |\n" tag))
    (let ((total 0))
  (mapcar
       (lambda (file)
     (let ((clock-data (with-current-buffer (find-file-noselect file)
                 (org-clock-get-table-data (buffer-name) params))))
       (when (> (nth 1 clock-data) 0)
         (setq total (+ total (nth 1 clock-data)))
         (insert (format "| | File *%s* | %.2f |\n"
                 (file-name-nondirectory file)
                 (/ (nth 1 clock-data) 60.0)))
         (dolist (entry (nth 2 clock-data))
           (insert (format "| | . %s%s | %s %.2f |\n"
                   (org-clocktable-indent-string (nth 0 entry))
                   (nth 1 entry)
                   (clocktable-by-tag/shift-cell (nth 0 entry))
                   (/ (nth 3 entry) 60.0)))))))
       (org-agenda-files))
      (save-excursion
    (re-search-backward "*Tag time*")
    (org-table-next-field)
    (org-table-blank-field)
    (insert (format "*%.2f*" (/ total 60.0)))))
    (org-table-align)))

(defun org-dblock-write:clocktable-by-tag (params)
  (insert "| Tag | Headline | Time (h) |\n")
  (insert "|     |          | <r>  |\n")
  (let ((tags (plist-get params :tags)))
    (mapcar (lambda (tag)
          (setq params (plist-put params :tags tag))
          (clocktable-by-tag/insert-tag params))
        tags)))
(defun my-tbl-export (name)
  "Search for table named `NAME` and export."
  (interactive "s")
  (show-all)
  (let ((case-fold-search t))
    (if (search-forward-regexp (concat "#\\+NAME: +" name) nil t)
    (progn
      (next-line)
      (next-line)
      (next-line)
      (org-table-export (format "%s.csv" name+org-time-stamp) "orgtbl-to-csv")))))

Clocking setup

(defun bh/find-project-task ()
  "Move point to the parent (project) task if any"
  (save-restriction
    (widen)
    (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
      (while (org-up-heading-safe)
	(when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
	  (setq parent-task (point))))
      (goto-char parent-task)
      parent-task)))
(setq org-clock-clocked-in-display (quote mode-line))
(setq org-clock-idle-time nil)
(setq org-clock-out-remove-zero-time-clocks nil)
(setq org-clocktable-defaults
   (quote
    (:maxlevel 2 :lang "en" :scope file :block nil :wstart 1 :mstart 1 :tstart nil :tend nil :step nil :stepskip0 nil :fileskip0 nil :link nil :narrow 40! :indent t :timestamp nil :level nil :tcolumns nil :formatter nil :inherit-props t :emphasize t)))
(setq org-columns-default-format "%80ITEM(Task) %10Effort(Effort){:} %10CLOCKSUM")

;; Clock out when moving task to a done state
(setq org-clock-out-when-done t)
(setq org-stuck-projects (quote ("" nil nil "")))
(defun bh/is-project-p ()
  "Any task with a todo keyword subtask"
  (save-restriction
    (widen)
    (let ((has-subtask)
          (subtree-end (save-excursion (org-end-of-subtree t)))
          (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
      (save-excursion
        (forward-line 1)
        (while (and (not has-subtask)
                    (< (point) subtree-end)
                    (re-search-forward "^\*+ " subtree-end t))
          (when (member (org-get-todo-state) org-todo-keywords-1)
            (setq has-subtask t))))
      (and is-a-task has-subtask))))

(defun bh/is-project-subtree-p ()
  "Any task with a todo keyword that is in a project subtree.
Callers of this function already widen the buffer view."
  (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
                              (point))))
    (save-excursion
      (bh/find-project-task)
      (if (equal (point) task)
          nil
        t))))

(defun bh/is-task-p ()
  "Any task with a todo keyword and no subtask"
  (save-restriction
    (widen)
    (let ((has-subtask)
          (subtree-end (save-excursion (org-end-of-subtree t)))
          (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
      (save-excursion
        (forward-line 1)
        (while (and (not has-subtask)
                    (< (point) subtree-end)
                    (re-search-forward "^\*+ " subtree-end t))
          (when (member (org-get-todo-state) org-todo-keywords-1)
            (setq has-subtask t))))
      (and is-a-task (not has-subtask)))))

(defun bh/is-subproject-p ()
  "Any task which is a subtask of another project"
  (let ((is-subproject)
        (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
    (save-excursion
      (while (and (not is-subproject) (org-up-heading-safe))
        (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
          (setq is-subproject t))))
    (and is-a-task is-subproject)))

(defun bh/list-sublevels-for-projects-indented ()
  "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
  This is normally used by skipping functions where this variable is already local to the agenda."
  (if (marker-buffer org-agenda-restrict-begin)
      (setq org-tags-match-list-sublevels 'indented)
    (setq org-tags-match-list-sublevels nil))
  nil)

(defun bh/list-sublevels-for-projects ()
  "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
  This is normally used by skipping functions where this variable is already local to the agenda."
  (if (marker-buffer org-agenda-restrict-begin)
      (setq org-tags-match-list-sublevels t)
    (setq org-tags-match-list-sublevels nil))
  nil)

(defvar bh/hide-scheduled-and-waiting-next-tasks t)

(defun bh/toggle-next-task-display ()
  (interactive)
  (setq bh/hide-scheduled-and-waiting-next-tasks (not bh/hide-scheduled-and-waiting-next-tasks))
  (when  (equal major-mode 'org-agenda-mode)
    (org-agenda-redo))
  (message "%s WAITING and SCHEDULED NEXT Tasks" (if bh/hide-scheduled-and-waiting-next-tasks "Hide" "Show")))

(defun bh/skip-stuck-projects ()
  "Skip trees that are not stuck projects"
  (save-restriction
    (widen)
    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
      (if (bh/is-project-p)
          (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
                 (has-next ))
            (save-excursion
              (forward-line 1)
              (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
                (unless (member "WAITING" (org-get-tags))
                  (setq has-next t))))
            (if has-next
                nil
              next-headline)) ; a stuck project, has subtasks but no next task
        nil))))

(defun bh/skip-non-stuck-projects ()
  "Skip trees that are not stuck projects"
  ;; (bh/list-sublevels-for-projects-indented)
  (save-restriction
    (widen)
    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
      (if (bh/is-project-p)
          (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
                 (has-next ))
            (save-excursion
              (forward-line 1)
              (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
                (unless (member "WAITING" (org-get-tags))
                  (setq has-next t))))
            (if has-next
                next-headline
              nil)) ; a stuck project, has subtasks but no next task
        next-headline))))

(defun bh/skip-non-projects ()
  "Skip trees that are not projects"
  ;; (bh/list-sublevels-for-projects-indented)
  (if (save-excursion (bh/skip-non-stuck-projects))
      (save-restriction
        (widen)
        (let ((subtree-end (save-excursion (org-end-of-subtree t))))
          (cond
           ((bh/is-project-p)
            nil)
           ((and (bh/is-project-subtree-p) (not (bh/is-task-p)))
            nil)
           (t
            subtree-end))))
    (save-excursion (org-end-of-subtree t))))

(defun bh/skip-project-trees-and-habits ()
  "Skip trees that are projects"
  (save-restriction
    (widen)
    (let ((subtree-end (save-excursion (org-end-of-subtree t))))
      (cond
       ((bh/is-project-p)
        subtree-end)
       ((org-is-habit-p)
        subtree-end)
       (t
        nil)))))

(defun bh/skip-projects-and-habits-and-single-tasks ()
  "Skip trees that are projects, tasks that are habits, single non-project tasks"
  (save-restriction
    (widen)
    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
      (cond
       ((org-is-habit-p)
        next-headline)
       ((and bh/hide-scheduled-and-waiting-next-tasks
             (member "WAITING" (org-get-tags)))
        next-headline)
       ((bh/is-project-p)
        next-headline)
       ((and (bh/is-task-p) (not (bh/is-project-subtree-p)))
        next-headline)
       (t
        nil)))))

(defun bh/skip-project-tasks-maybe ()
  "Show tasks related to the current restriction.
When restricted to a project, skip project and sub project tasks, habits, NEXT tasks, and loose tasks.
When not restricted, skip project and sub-project tasks, habits, and project related tasks."
  (save-restriction
    (widen)
    (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
           (next-headline (save-excursion (or (outline-next-heading) (point-max))))
           (limit-to-project (marker-buffer org-agenda-restrict-begin)))
      (cond
       ((bh/is-project-p)
        next-headline)
       ((org-is-habit-p)
        subtree-end)
       ((and (not limit-to-project)
             (bh/is-project-subtree-p))
        subtree-end)
       ((and limit-to-project
             (bh/is-project-subtree-p)
             (member (org-get-todo-state) (list "NEXT")))
        subtree-end)
       (t
        nil)))))

(defun bh/skip-project-tasks ()
  "Show non-project tasks.
Skip project and sub-project tasks, habits, and project related tasks."
  (save-restriction
    (widen)
    (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
      (cond
       ((bh/is-project-p)
        subtree-end)
       ((org-is-habit-p)
        subtree-end)
       ((bh/is-project-subtree-p)
        subtree-end)
       (t
        nil)))))

(defun bh/skip-non-project-tasks ()
  "Show project tasks.
Skip project and sub-project tasks, habits, and loose non-project tasks."
  (save-restriction
    (widen)
    (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
           (next-headline (save-excursion (or (outline-next-heading) (point-max)))))
      (cond
       ((bh/is-project-p)
        next-headline)
       ((org-is-habit-p)
        subtree-end)
       ((and (bh/is-project-subtree-p)
             (member (org-get-todo-state) (list "NEXT")))
        subtree-end)
       ((not (bh/is-project-subtree-p))
        subtree-end)
       (t
        nil)))))

(defun bh/skip-projects-and-habits ()
  "Skip trees that are projects and tasks that are habits"
  (save-restriction
    (widen)
    (let ((subtree-end (save-excursion (org-end-of-subtree t))))
      (cond
       ((bh/is-project-p)
        subtree-end)
       ((org-is-habit-p)
        subtree-end)
       (t
        nil)))))

(defun bh/skip-non-subprojects ()
  "Skip trees that are not projects"
  (let ((next-headline (save-excursion (outline-next-heading))))
    (if (bh/is-subproject-p)
        nil
      next-headline)))

(setq org-archive-mark-done nil)
(setq org-archive-location "%s_archive::")

(defadvice org-archive-subtree (around fix-hierarchy activate)
  (let* ((fix-archive-p (and (not current-prefix-arg)
                             (not (use-region-p))))
         (afile (org-extract-archive-file (org-get-local-archive-location)))
         (buffer (or (find-buffer-visiting afile) (find-file-noselect afile))))
    ad-do-it
    (when fix-archive-p
      (with-current-buffer buffer
        (goto-char (point-max))
        (while (org-up-heading-safe))
        (let* ((olpath (org-entry-get (point) "ARCHIVE_OLPATH"))
               (path (and olpath (split-string olpath "/")))
               (level 1)
               tree-text)
          (when olpath
            (org-mark-subtree)
            (setq tree-text (buffer-substring (region-beginning) (region-end)))
            (let (this-command) (org-cut-subtree))
            (goto-char (point-min))
            (save-restriction
              (widen)
              (-each path
                (lambda (heading)
                  (if (re-search-forward
                       (rx-to-string
                        `(: bol (repeat ,level "*") (1+ " ") ,heading)) nil t)
                      (org-narrow-to-subtree)
                    (goto-char (point-max))
                    (unless (looking-at "^")
                      (insert "\n"))
                    (insert (make-string level ?*)
                            " "
                            heading
                            "\n"))
                  (cl-incf level)))
              (widen)
              (org-end-of-subtree t t)
              (org-paste-subtree level tree-text))))))))

(defun bh/skip-non-archivable-tasks ()
  "Skip trees that are not available for archiving"
  (save-restriction
    (widen)
    ;; Consider only tasks with done todo headings as archivable candidates
    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max))))
          (subtree-end (save-excursion (org-end-of-subtree t))))
      (if (member (org-get-todo-state) org-todo-keywords-1)
          (if (member (org-get-todo-state) org-done-keywords)
              (let* ((daynr (string-to-number (format-time-string "%d" (current-time))))
                     (a-month-ago (* 60 60 24 (+ daynr 1)))
                     (last-month (format-time-string "%Y-%m-" (time-subtract (current-time) (seconds-to-time a-month-ago))))
                     (this-month (format-time-string "%Y-%m-" (current-time)))
                     (subtree-is-current (save-excursion
                                           (forward-line 1)
                                           (and (< (point) subtree-end)
                                                (re-search-forward (concat last-month "\\|" this-month) subtree-end t)))))
                (if subtree-is-current
                    subtree-end ; Has a date in this month or last month, skip it
                  nil))  ; available to archive
            (or subtree-end (point-max)))
        next-headline))))

Backup setup

(setq backup-directory-alist `(("." . "~/.saves")))

[2018-08-01 Wed 12:03]

Exporter Setup

(setq org-alphabetical-lists t)
(setq org-ditaa-jar-path "~/org/Misc/ditaa.jar")
(setq org-plantuml-jar-path "~/org/Misc/plantuml.jar")

Org-babel setup

(org-babel-do-load-languages
 (quote org-babel-load-languages)
 (quote ((emacs-lisp  . t)
         (dot . t)
         (ditaa . t)
	 (R . t)
         (python . t)
         (ruby . t)
         (gnuplot . t)
	 ;;        (clojure . t)
	 (shell . t)
	 ;;        (ledger . t)
         (org . t)
         (plantuml . t)
         (latex . t))))

(setq org-confirm-babel-evaluate nil)

(add-to-list 'org-src-lang-modes (quote ("plantuml" . fundamental)))

(setq org-babel-python-command "python3")
(setq org-html-inline-images t)
(setq org-export-with-sub-superscripts nil)
(setq org-html-head-include-default-style nil)
; Do not generate internal css formatting for HTML exports
(setq org-export-htmlize-output-type (quote css))
; Export with LaTeX fragments
(setq org-export-with-LaTeX-fragments t)
; Increase default number of headings to export
(setq org-export-headline-levels 6)

(setq org-export-allow-BIND t)
(setq org-export-allow-bind-keywords t)

Tasks

Org-Todo keywords and colors
(setq org-todo-keywords
      (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
              (sequence "WAITING(w@/!)" "HOLD(h@/!)" "SOMEDAY(s)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
	      (sequence "DRAFT(k)" "|" "SENT(b@/!)" "PAID(p)")
	      (sequence "TODO(t)" "DRAFT(f@/!)" "FUTURE" "|""POSTED(o)")
        )))

(setq org-todo-state-tags-triggers
      (quote (("CANCELLED" ("CANCELLED" . t))
              ("WAITING" ("WAITING" . t))
              ("HOLD" ("WAITING") ("HOLD" . t))
              (done ("WAITING") ("HOLD"))
              ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
              ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
              ("DONE" ("WAITING") ("CANCELLED") ("HOLD"))
	      ("SOMEDAY" ("SOMEDAY" . t)))))
Fast Todo Selection

Fast todo selection allows changing from any task todo state to any other state directly by selecting the appropriate key from the fast todo selection key menu. This is a great feature!

(setq org-use-fast-todo-selection t)

Changing a task state is done with C-c C-t KEY

where KEY is the appropriate fast todo state selection key as defined in org-todo-keywords.

The setting

(setq org-treat-S-cursor-todo-selection-as-state-change nil)

allows changing todo states with S-left and S-right skipping all of the normal processing when entering or leaving a todo state. This cycles through the todo states but skips setting timestamps and entering notes which is very convenient when all you want to do is fix up the status of an entry.

Remove empty property drawers

(defun br/org-remove-empty-propert-drawers ()
  "*Remove all empty property drawers in current file."
  (interactive)
  (unless (eq major-mode 'org-mode)
    (error "You need to turn on Org mode for this function."))
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward ":ID:" nil t)
      (save-excursion
        (org-remove-empty-drawer-at "ID" (match-beginning 0))))))

Misc Org settings

[2018-01-05 Fri 12:40]

Others

[2018-08-03 Fri 04:46]

(setq org-deadline-warning-days 0)
(setq org-fontify-done-headline t)
(setq org-footnote-auto-adjust t)
(setq org-footnote-auto-label (quote plain))
(setq org-hide-leading-stars t)
(setq org-icalendar-timezone "Asia/Calcutta")
(setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
	"bibtex %b"
	"pdflatex -interaction nonstopmode -output-directory %o %f"
	"pdflatex -interaction nonstopmode -output-directory %o %f"))
(setq org-log-reschedule (quote time))
(setq org-pandoc-epub-rights
   "Copyright © 2016 Dr. Bala Ramadurai <bala@balaramadurai.net>")
(setq org-show-mode t)
(setq org-startup-truncated nil)
(setq org-support-shift-select t)
(setq org-tags-column -117)

Latex settings

~/.emacs.d/elisp/base-org.el

(add-to-list 'org-latex-classes
	     '("beamer"
               "\\documentclass\[presentation\]\{beamer\}"
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))

(add-to-list 'org-latex-classes
         '("memoir"
           "\\documentclass[11pt]{memoir}"
	     ("\\part{%s}" . "\\part*{%s}")
           ("\\chapter{%s}" . "\\chapter*{%s}")
           ("\\section{%s}" . "\\section*{%s}")
           ("\\subsection{%s}" . "\\subsection*{%s}")
           ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
           ("\\paragraph{%s}" . "\\paragraph*{%s}")
           ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
         )
(add-to-list 'org-latex-classes
         '("book"
           "\\documentclass[11pt]{book}"
	     ("\\part{%s}" . "\\part*{%s}")
           ("\\chapter{%s}" . "\\chapter*{%s}")
           ("\\section{%s}" . "\\section*{%s}")
           ("\\subsection{%s}" . "\\subsection*{%s}")
           ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
           ("\\paragraph{%s}" . "\\paragraph*{%s}")
           ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
         )

 ;; tufte-book class for writing classy books
(add-to-list 'org-latex-classes
	     '("tufte-book"
	       "\\documentclass{tufte-book}")
)

(setq org-latex-default-packages-alist
   (quote
    (("utf8" "inputenc" t
      ("pdflatex"))
     ("T1, T2A" "fontenc" t
      ("pdflatex"))
     ("" "graphicx" t)
     ("" "grffile" t)
     ("" "longtable" nil)
     ("" "wrapfig" nil)
     ("" "rotating" nil)
     ("normalem" "ulem" t)
     ("" "amsmath" t)
     ("" "textcomp" t)
     ("" "amssymb" t)
     ("" "capt-of" nil))))

Org Templates

(add-to-list 'load-path (expand-file-name "~/.emacs.d/lib/org/contrib/lisp"))
(with-eval-after-load 'org
  (require 'ox-extra)
  (require 'ox-bibtex)
  (ox-extras-activate '(ignore-headlines))
  (ox-extras-activate '(latex-header-blocks ignore-headlines))
  )

(with-eval-after-load 'org
  (require 'org-tempo)
  (require 'org-habit)
  (require 'org-checklist)
  (require 'org-protocol)
  (add-to-list 'org-capture-templates
               '("l" "Protocol" entry (file "~/org/inbox.org")
                 "* %^{Title}\nSource: [[%:link][%:description]]\n%u, %c\n #+BEGIN_QUOTE\n%:initial\n#+END_QUOTE\n\n\n%?"))
  (add-to-list 'org-capture-templates
               '("L" "Protocol Link" entry (file "~/org/inbox.org")
                 "* TODO %? \n SCHEDULED: %^{Time of Response?}T\n\n [[%:link][%:description]]\nCaptured On: %U"))
  )
(setq org-structure-template-alist
      (quote(("q" . "QUOTE")
	     ("v" . "VERSE")
	     ("muse" . "SRC emacs-lisp :tangle ~/.emacs.d/elisp/base-extensions.el \n(use-package ?\n\n\n :diminish\n; :general\n; :config\n)\n")
	     ("m" . "SRC emacs-lisp")
	     ("r" . "SRC R :results output :session *R* :exports both")
	     ("R" . "SRC R :results output graphics :file (org-babel-temp-file \"figure\" \".png\") :exports both :width 600 :height 400 :session *R*")
	     ("RR" . "SRC R :results output graphics :file  (org-babel-temp-file (concat (file-name-directory (or load-file-name buffer-file-name)) \"figure-\") \".png\") :exports both :width 600 :height 400 :session *R*")
	     ("p" . "SRC python :results output :exports both")
	     ("P" . "SRC python :results output :session :exports both")
	     ("PP" . "SRC python :results file :session :var matplot_lib_filename=(org-babel-temp-file \"figure\" \".png\") :exports both\nimport matplotlib.pyplot as plt\n\nimport numpy\nx=numpy.linspace(-15,15)\nplt.figure(figsize=(10,5))\nplt.plot(x,numpy.cos(x)/x)\nplt.tight_layout()\n\nplt.savefig(matplot_lib_filename)\nmatplot_lib_filename")
	     )))

)

Org Reveal

(use-package org-re-reveal
   :after org
   :config
   (setq org-reveal-external-plugins
   (quote
    ((menu . "{src: '%splugin/menu/menu.js'}")
     (toolbar . "{src: '%splugin/toolbar/toolbar.js'}")
     (jump . "{ src: '%splugin/jump/jump.js', async: true }")
     (zoom-js . "{ src: '%splugin/zoom-js/zoom.js', async: true }"))))
 )

Org clock convenience

(use-package org-clock-convenience

  :general
  (general-def org-agenda-mode-map
    "<S-up>"   'org-clock-convenience-timestamp-up
    "<S-down>" 'org-clock-convenience-timestamp-down))

Org Download

[2018-12-08 Sat 18:16]

(use-package org-download

					; :diminish
  :general
  (spacemacs-lite/set-leader-keys-for-major-mode
    "is" 'org-download-screenshot
    "iy" 'org-download-yank
    )

; :config
)

Org Pomodoro

[2018-11-29 Thu 08:54]

(use-package org-pomodoro
  :general
  (spacemacs-lite/set-leader-keys-for-major-mode    "p"    'org-pomodoro)
 :config
 (setq org-pomodoro-length 45)
 (setq org-pomodoro-long-break-frequency 3)
 (setq org-pomodoro-long-break-length 30)
 (setq org-pomodoro-short-break-length 5)
 (setq org-pomodoro-ticking-sound-p t)
 (setq org-pomodoro-ticking-sound-states (quote (:short-break :long-break))))

Org Fancy Priority

(use-package org-fancy-priorities
  :hook
  (org-mode . org-fancy-priorities-mode)
  :config
  (setq org-fancy-priorities-list '("(#I)" "(#II)" "(#III)" "(#IV)")))

Org Ref

(use-package org-ref
  :defer t
  :commands (org-ref-bibtex-next-entry
             org-ref-bibtex-previous-entry
             org-ref-open-in-browser
             org-ref-open-bibtex-notes
             org-ref-open-bibtex-pdf
             org-ref-bibtex-hydra/body
             org-ref-bibtex-hydra/org-ref-bibtex-new-entry/body-and-exit
             org-ref-sort-bibtex-entry
             arxiv-add-bibtex-entry
             arxiv-get-pdf-add-bibtex-entry
             doi-utils-add-bibtex-entry-from-doi
             isbn-to-bibtex
             pubmed-insert-bibtex-from-pmid)
  :config
  (add-to-list 'load-path ".")
  (require 'org-ref-citeproc)

  (let ((org-export-before-parsing-hook '(orcp-citeproc)))
    (browse-url (org-html-export-to-html)))

  :general
  (spacemacs-lite/set-leader-keys-for-major-mode 'normal bibtex-mode-map
    (kbd "C-j") 'org-ref-bibtex-next-entry
    (kbd "C-k") 'org-ref-bibtex-previous-entry
    "gj" 'org-ref-bibtex-next-entry
    "gk" 'org-ref-bibtex-previous-entry)

  (spacemacs-lite/set-leader-keys-for-major-mode 'bibtex-mode
    ;; Navigation
    "j" 'org-ref-bibtex-next-entry
    "k" 'org-ref-bibtex-previous-entry

    ;; Open
    "b" 'org-ref-open-in-browser
    "n" 'org-ref-open-bibtex-notes
    "p" 'org-ref-open-bibtex-pdf

    ;; Misc
    "h" 'org-ref-bibtex-hydra/body
    "i" 'org-ref-bibtex-hydra/org-ref-bibtex-new-entry/body-and-exit
    "s" 'org-ref-sort-bibtex-entry

    ;; Lookup utilities
    "la" 'arxiv-add-bibtex-entry
    "lA" 'arxiv-get-pdf-add-bibtex-entry
    "ld" 'doi-utils-add-bibtex-entry-from-doi
    "li" 'isbn-to-bibtex
    "lp" 'pubmed-insert-bibtex-from-pmid

    "ic" 'org-ref-helm-insert-cite-link)

  :hook (org-mode-hook . org-ref))

Ox Hugo

(use-package ox-hugo
  :config
  (setq org-export-with-author nil)
  ;; Populates only the EXPORT_FILE_NAME property in the inserted headline.
  (with-eval-after-load 'org-capture
    (defun org-hugo-new-subtree-post-capture-template ()
      "Returns `org-capture' template string for new Hugo post.
See `org-capture-templates' for more information."
      (let* ((title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title
	     (fname (org-hugo-slug title)))
	(mapconcat #'identity
		   `(
		     ,(concat "* TODO " title)
		     ":PROPERTIES:"
		     ,(concat ":EXPORT_FILE_NAME: " fname)
		     ":END:"
		     "%?\n")          ;Place the cursor here finally
		   "\n")))

    (add-to-list 'org-capture-templates
		 '("h"                ;`org-capture' binding + h
		   "Hugo post"
		   entry
		   ;; It is assumed that below file is present in `org-directory'
		   ;; and that it has a "Blog Post Ideas" heading. It can even be a
		   ;; symlink pointing to the actual location of all-posts.org!
		   (file+olp "balaramadurai.net.org" "Blog Post Ideas")
		   (function org-hugo-new-subtree-post-capture-template))))
  )

Org Tracktable

(use-package org-tracktable

; :diminish
; :general
; :config
)

Gnuplot

[2018-12-05 Wed 09:33]

(use-package gnuplot
    :defer t
    :general
    (spacemacs-lite/set-leader-keys         "ap" '(org-plot/gnuplot :which-key "gnuplot")))

Org Superstar

(use-package org-superstar
					; :general
  :config
  (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1)))
  (setq org-superstar-special-todo-items t)
  )

Org Bullets

[2018-12-03 Mon 10:42]

~/.emacs.d/elisp/base-org.el
(use-package org-bullets
  :load-path "~/.emacs.d/plugin/org-bullets.el"
  :custom
  (org-bullets-bullet-list '("" "" "" "" "" "" "" "" "" "" "" "" ""))
  (org-ellipsis "")
  :hook (org-mode . org-bullets-mode))
(font-lock-add-keywords 'org-mode
			'(("^ *\\([-]\\) "
			   (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) ""))))))
(font-lock-add-keywords 'org-mode
			'(("^ *\\([+]\\) "
			   (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) ""))))))

Base Functions

[2018-12-07 Fri 21:06]

(defun spacemacs/system-is-mac ()
  (eq system-type 'darwin))
(defun spacemacs/system-is-linux ()
  (eq system-type 'gnu/linux))
(defun spacemacs/system-is-mswindows ()
(eq system-type 'windows-nt))

;; found at http://emacswiki.org/emacs/KillingBuffers
(defun spacemacs-lite/kill-other-buffers (&optional arg)
  "Kill all other buffers.
If the universal prefix argument is used then will the windows too."
  (interactive "P")
  (when (yes-or-no-p (format "Killing all buffers except \"%s\"? "
                             (buffer-name)))
    (mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
    (when (equal '(4) arg) (delete-other-windows))
    (message "Buffers deleted!")))

;; from magnars
(defun spacemacs-lite/delete-current-buffer-file ()
  "Removes file connected to current buffer and kills buffer."
  (interactive)
  (let ((filename (buffer-file-name))
        (buffer (current-buffer))
        (name (buffer-name)))
    (if (not (and filename (file-exists-p filename)))
        (ido-kill-buffer)
      (when (yes-or-no-p "Are you sure you want to delete this file? ")
        (delete-file filename t)
        (kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))

(defun spacemacs-lite/copy-file ()
  "Write the file under new name."
  (interactive)
(call-interactively 'write-file))

;; from magnars
  ;; http://stackoverflow.com/a/10216338/4869
(defun spacemacs-lite/sudo-edit (&optional arg)
  (interactive "P")
  (let ((fname (if (or arg (not buffer-file-name))
                   (read-file-name "File: ")
                 buffer-file-name)))
    (find-file
     (cond ((string-match-p "^/ssh:" fname)
            (with-temp-buffer
	      (insert fname)
	      (search-backward ":")
	      (let ((last-match-end nil)
                    (last-ssh-hostname nil))
                (while (string-match "@\\\([^:|]+\\\)" fname last-match-end)
                  (setq last-ssh-hostname (or (match-string 1 fname)
					      last-ssh-hostname))
                  (setq last-match-end (match-end 0)))
                (insert (format "|sudo:%s" (or last-ssh-hostname "localhost"))))
	      (buffer-string)))
           (t (concat "/sudo:root@localhost:" fname))))))

;; from magnars
(defun spacemacs-lite/rename-current-buffer-file ()
  "Renames current buffer and file it is visiting."
  (interactive)
  (let* ((name (buffer-name))
        (filename (buffer-file-name)))
    (if (not (and filename (file-exists-p filename)))
        (error "Buffer '%s' is not visiting a file!" name)
      (let* ((dir (file-name-directory filename))
             (new-name (read-file-name "New name: " dir)))
        (cond ((get-buffer new-name)
               (error "A buffer named '%s' already exists!" new-name))
              (t
               (let ((dir (file-name-directory new-name)))
                 (when (and (not (file-exists-p dir)) (yes-or-no-p (format "Create directory '%s'?" dir)))
                   (make-directory dir t)))
               (rename-file filename new-name 1)
               (rename-buffer new-name)
               (set-visited-file-name new-name)
               (set-buffer-modified-p nil)
               (when (fboundp 'recentf-add-file)
                   (recentf-add-file new-name)
                   (recentf-remove-if-non-kept filename))
(message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))

(defun spacemacs//open-in-external-app (file-path)
  "Open `file-path' in external application."
  (cond
   ((spacemacs/system-is-mac) (shell-command (format "open \"%s\"" file-path)))
   ((spacemacs/system-is-linux) (let ((process-connection-type nil))
(start-process "" nil "xdg-open" file-path)))))

(defun spacemacs-lite/open-file-or-directory-in-external-app (arg)
  "Open current file in external application.
If the universal prefix argument is used then open the folder
containing the current file by the default explorer."
  (interactive "P")
  (if arg
      (spacemacs//open-in-external-app (expand-file-name default-directory))
    (let ((file-path (if (derived-mode-p 'dired-mode)
                         (dired-get-file-for-visit)
                       buffer-file-name)))
      (if file-path
          (spacemacs//open-in-external-app file-path)
(message "No file associated to this buffer.")))))

(defun copy-whole-buffer-to-clipboard ()
  "Copy entire buffer to clipboard"
  (interactive)
  (clipboard-kill-ring-save (point-min) (point-max)))

;; https://emacs.stackexchange.com/questions/16398/noninteractively-upgrade-all-packages
(defun package-upgrade-all ()
  "Upgrade all packages automatically without showing *Packages* buffer."
  (interactive)
  (package-refresh-contents)
  (let (upgrades)
    (cl-flet ((get-version (name where)
			   (let ((pkg (cadr (assq name where))))
			     (when pkg
			       (package-desc-version pkg)))))
      (dolist (package (mapcar #'car package-alist))
        (let ((in-archive (get-version package package-archive-contents)))
          (when (and in-archive
                     (version-list-< (get-version package package-alist)
                                     in-archive))
            (push (cadr (assq package package-archive-contents))
                  upgrades)))))
    (if upgrades
        (when (yes-or-no-p
               (message "Upgrade %d package%s (%s)? "
                        (length upgrades)
                        (if (= (length upgrades) 1) "" "s")
                        (mapconcat #'package-desc-full-name upgrades ", ")))
          (save-window-excursion
            (dolist (package-desc upgrades)
              (let ((old-package (cadr (assq (package-desc-name package-desc)
                                             package-alist))))
                (package-install package-desc)
                (package-delete  old-package)))))
      (message "All packages are up to date"))))

(defconst user-config-org-file "~/.emacs.d/README.org")

(defun find-user-init-file ()
  "Finds the user init file"
  (interactive)
  (find-file user-init-file))

(defun find-user-config-org-file ()
  "Finds the user config file"
  (interactive)
  (find-file user-config-org-file))

(defun load-user-init-file ()
    "loads the user init file"
    (interactive)
    (load-file user-init-file))

(defun show-scratch-buffer ()
  (interactive)
  (switch-to-buffer "*scratch*"))

(defun show-home-buffer ()
  (interactive)
  (switch-to-buffer "*dashboard*"))

(defun show-messages-buffer ()
  (interactive)
  (switch-to-buffer "*Messages*"))

(defun org-babel-tangle-append ()
  "Append source code block at point to its tangle file.
The command works like `org-babel-tangle' with prefix arg
but `delete-file' is ignored."
  (interactive)
  (cl-letf (((symbol-function 'delete-file) #'ignore))
    (org-babel-tangle '(4))))

(defun org-babel-tangle-append-setup ()
  "Add key-binding C-c C-v C-t for `org-babel-tangle-append'."
  (org-defkey org-mode-map (kbd "C-c C-v +") 'org-babel-tangle-append))

(add-hook 'org-mode-hook #'org-babel-tangle-append-setup)

;; from https://pages.sachachua.com/.emacs.d/Sacha.html#weekly-review

(defvar my/weekly-done-line-regexp
  "^  \\([^:]+\\): +.*?\\(?:Clocked\\|Closed\\):.*?\\(TODO\\|DONE\\) \\(.*?\\)\\(?:[       ]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[        ]*$"
  "Regular expression matching lines to include as completed tasks.")
(defun br/extract-tasks-from-agenda (string matchers prefix line-re)
  (with-temp-buffer
    (insert string)
    (goto-char (point-min))
    (while (re-search-forward line-re nil t)
      (let ((temp-list matchers))
        (while temp-list
          (if (save-match-data
                (string-match (car (car temp-list)) (match-string 1)))
              (progn
                (add-to-list (cdr (car temp-list)) (concat prefix (match-string 3)) t)
                (setq temp-list nil)))
          (setq temp-list (cdr temp-list)))))))
(defun br/get-previous-tasks ()
  (let (string)
    (save-window-excursion
      (org-agenda nil "W")
      (org-agenda-later -1)
      (org-agenda-log-mode 16)
      (setq string (buffer-string))
      ;; Get any completed tasks from the current week as well
      (org-agenda-later 1)
      (org-agenda-log-mode 16)
      (setq string (concat string "\n" (buffer-string)))
      (br/extract-tasks-from-agenda string
                                         '(("routines" . ignore)
                                           ("business" . business)
                                           ("people" . relationships)
                                           ("tasks" . emacs)
                                           ("." . life))
                                         "  - [X] "
                                        my/weekly-done-line-regexp)
      )))

(defun split-and-indirect-orgtree ()
"Splits window to the right and opens an org tree section in it"
(interactive)
(split-window-right)
(org-tree-to-indirect-buffer)
(windmove-left))


(defun kill-and-unsplit-orgtree ()
"Kills the cloned buffer and deletes the window."
(interactive)
(kill-this-buffer)
(delete-window))

(general-def
"<f3>"        'split-and-indirect-orgtree
"M-<f3>"      'kill-and-unsplit-orgtree)

Startup Buffer

Emacs Dashboard

[2018-12-04 Tue 08:36] Make the similarity to spacemacs complete 😃

(use-package dashboard
  :config
  (dashboard-setup-startup-hook)
  :custom
  (dashboard-items '((recents  . 5)
			  ))
  )

Lastly

Alternate melpa, org and gnu package repos

~/.emacs.d/user-init.el
(setq package-archives
      '(("melpa" . "https://raw.githubusercontent.com/d12frosted/elpa-mirror/master/melpa/")
        ("org"   . "https://raw.githubusercontent.com/d12frosted/elpa-mirror/master/org/")
        ("gnu"   . "https://raw.githubusercontent.com/d12frosted/elpa-mirror/master/gnu/")))

The end of base-extensions, base-theme, base-emacs, base-functions and base-org

(provide 'base-extensions)
;;; base-extensions ends here
(provide 'base-theme)
;;; base-theme ends here
(provide 'base-org)
;;; base-org ends here
(provide 'base-functions)
;;; base-org ends here
(provide 'base-emacs)
;;; base-org ends here

About

Spacemacs-Lite


Languages

Language:Emacs Lisp 99.6%Language:TeX 0.4%