Skip to content

Instantly share code, notes, and snippets.

@dysinger
Last active August 9, 2019 22:05
Show Gist options
  • Save dysinger/5749feb4004e3fbc7047b6f3cfe95fdc to your computer and use it in GitHub Desktop.
Save dysinger/5749feb4004e3fbc7047b6f3cfe95fdc to your computer and use it in GitHub Desktop.
Emacs Org-Mode Init File

Emacs Configuration

My User Variables

(setq user-full-name "Tim Dysinger"
      user-login-name "tim"
      user-mail-address "[email protected]")

My Constants

(defconst my/pgp-public-key "0x3F1AB897B5072741")
(defconst my/org-directory (expand-file-name "~/org"))
(defconst my/org-agenda-file
  (expand-file-name "agenda.org" my/org-directory))
(defconst my/org-projectile-file
  (expand-file-name "projects.org" my/org-directory))

My Functions

Sort Words

(defun my/sort-words (reverse beg end)
  "Sort words from BEG to END alphabetically, in REVERSE if negative.
Prefixed with negative \\[universal-argument], sorts in reverse.
The variable `sort-fold-case' determines whether alphabetic case
affects the sort order.  See `sort-regexp-fields'."
  (interactive "*P\nr")
  (sort-regexp-fields reverse "\\w+" "\\&" beg end))

General

UTF-8

(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

No Frills

(setq inhibit-splash-screen t)
(menu-bar-mode -1)
(when (display-graphic-p)
  (scroll-bar-mode -1)
  (tool-bar-mode -1))

No Locks

(setq create-lockfiles nil)

Tabs! OMG NO TABS FFS!

(setq-default indent-tabs-mode nil)
(setq-default tabs-always-indent 'complete)

80 Columns

(setq-default fill-column 80)

Indent After [RETURN]

(add-hook
 'prog-mode-hook
 '(lambda ()
    (bind-key "\C-m" 'newline-and-indent)))

Column/Line Numbers

(setq column-number-mode t)

Don’t Nag RE: Symlinks

(setq-default vc-follow-symlinks t)

Backup Files

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

Packages

Bootstrap

Require Libraries
(require 'package)
Remove after nixification of pkgs
(setq-default package-archives
              '(("gnu"          . "https://elpa.gnu.org/packages/")
              ;;("melpa-stable" . "https://stable.melpa.org/packages/")
                ("melpa"        . "https://melpa.org/packages/"))
              package-enable-at-startup nil
              ;; TLS BUG IN EMACS =< 26.3
              gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package)
  (package-install 'bind-key)
  (package-install 'delight))
Require Libraries
(require 'use-package)
Remove after nixification of pkgs
(require 'use-package-ensure)
(setq use-package-always-ensure t)
(setq use-package-always-pin "melpa")
Require Libraries
(require 'bind-key)
(require 'delight)

Use Package Chords

(use-package use-package-chords
  :config (key-chord-mode +1))

Auto Update

(use-package auto-package-update
  :custom
  ((auto-package-update-delete-old-versions t)
   (auto-package-update-hide-results t))
  :config
  (auto-package-update-maybe))

Quelpa

(use-package quelpa)
(use-package quelpa-use-package)

Base16

(use-package base16-theme
  :config
  (setq base16-theme-256-color-source
        (if (display-graphic-p) "colors" "base16-shell"))
  (load-theme 'base16-phd t))

Whitespace

(use-package whitespace
  :custom
  ((whitespace-line-column 80)
   (whitespace-style '(face empty indentation tabs trailing lines)))
  :config (global-whitespace-mode +1)
  :hook (before-save . whitespace-cleanup))

Direnv

(use-package direnv
  :hook (after-init . direnv-mode))

Fish Shell

(use-package fish-mode)
(use-package fish-completion)

Flycheck

(use-package flycheck
  :hook (after-init . global-flycheck-mode))
(use-package flycheck-rust
  :hook (flycheck-mode . flycheck-rust-setup))
(use-package flycheck-ocaml  :disabled t)
(use-package flycheck-ledger :disabled t)

Ido

(use-package ido
  :custom
  ((ido-enable-flex-matching t)
   (ido-use-filename-at-point 'guess))
  :hook (after-init . ido-mode))
(use-package ido-yes-or-no
  :hook (after-init . ido-yes-or-no-mode))

Auto Revert

(use-package autorevert
  :delight auto-revert-mode
  :hook (after-init . global-auto-revert-mode))

Rainbows

(use-package rainbow-identifiers
  :hook (prog-mode . rainbow-identifiers-mode))
(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode))

Projectile

(use-package projectile
  :delight '(:eval (concat " " (projectile-project-name)))
  :bind-keymap ("C-c p" . projectile-command-map)
  :config (projectile-mode))
(use-package projectile-direnv :disabled t)
(use-package projectile-git-autofetch :disabled t)

Org Mode

(use-package org
  :custom
  ((org-agenda-dim-blocked-tasks 'dim)
   (org-agenda-files (list my/org-agenda-file my/org-projectile-file))
   (org-agenda-hide-tags-regexp "^:$")
;; (org-agenda-skip-deadline-if-done t)
;; (org-agenda-skip-deadline-prewarning-if-scheduled t)
;; (org-agenda-skip-scheduled-if-deadline-is-shown t)
;; (org-agenda-skip-scheduled-if-done t)
   (org-agenda-span 'day)
   (org-agenda-tags-column -120)
;; (org-agenda-tags-todo-honor-ignore-options t)
;; (org-agenda-todo-ignore-deadlines 3)
;; (org-agenda-todo-ignore-scheduled 3)
   (org-agenda-custom-commands
    ;; https://orgmode.org/manual/Custom-Agenda-Views.html
    ;; https://github.com/alphapapa/org-super-agenda
    '(("--" "Agenda"
       ((agenda
         ""
         ((org-super-agenda-groups
           '((:name "Overdue" :and (:deadline past :not (:tag "DONE")))
             (:name "Today" :time-grid t :log t :habit t)
             (:auto-group "CATEGORY")))))
        (todo
         ""
         ((org-agenda-overriding-header "Projects")
          (org-super-agenda-groups
           '((:name none :children todo)
             (:discard (:anything t))))))))
      ("-c" "@COMPUTER"
       ((tags-todo
         "@COMPUTER"
         ((org-agenda-dim-blocked-tasks 'invisible)))))
      ("-e" "@ERRAND"
       ((tags-todo
         "@ERRAND"
         ((org-agenda-dim-blocked-tasks 'invisible)))))
      ("-h" "@HOME"
       ((tags-todo
         "@HOME"
         ((org-agenda-dim-blocked-tasks 'invisible)))))
      ("-w" "@WORK"
       ((tags-todo
         "@WORK"
         ((org-agenda-dim-blocked-tasks 'invisible)))))
      ("-s" "@SARA"
       ((tags-todo
         "@SARA"
         ((org-agenda-dim-blocked-tasks 'invisible)))))
      ("-j"
       "@JACOB"
       ((tags-todo
         "@JACOB"
         ((org-agenda-dim-blocked-tasks 'invisible)))))
      ("-a"
       "@ABI"
       ((tags-todo
         "@ABI"
         ((org-agenda-dim-blocked-tasks 'invisible)))))))
   (org-archive-location ".%s.bak::")
   (org-babel-load-languages '((ditaa . t) (dot . t) (emacs-lisp . t) (gnuplot . t) (ledger . t) (shell . t) (shen . t)))
   (org-capture-templates '(("t" "TODO" entry (file+headline my/org-agenda-file "Inbox") "* TODO %?\n")))
   (org-completion-use-ido t)
   (org-crypt-key my/pgp-public-key)
   (org-crypt-tag-matcher "SECRET")
   (org-default-notes-file my/org-agenda-file)
   (org-directory my/org-directory)
   (org-ditaa-jar-path "/run/current-system/sw/lib/ditaa.jar")
   (org-enforce-todo-checkbox-dependencies t)
   (org-enforce-todo-dependencies t)
   (org-global-properties '(("Effort_ALL". "0 0:15 0:30 1:00 2:00 3:00 4:00")))
   (org-habit-graph-column 60)
   (org-hide-block-startup t)
   (org-hide-leading-stars t)
   (org-modules '(org-habit))
   (org-startup-folded 'content)
   (org-tag-alist '(("@COMPUTER" . ?c) ("@ERRAND" . ?e) ("@HOME" . ?h) ("@WORK" . ?w) ("@TIM" . ?t) ("@SARA" . ?s) ("@JACOB" . ?j) ("@ABI" . ?a)))
   (org-odd-levels-only t)
   (org-outline-path-complete-in-steps nil)
   (org-refile-allow-creating-parent-nodes 'confirm)
   (org-refile-targets '((nil :maxlevel . 6) (org-agenda-files :maxlevel . 6)))
   (org-refile-use-outline-path 'file)
   (org-return-follows-link t)
   (org-tags-column 0)
   (org-tags-exclude-from-inheritance '("SECRET"))
;; (org-track-ordered-property-with-tag t)
;; (org-use-property-inheritance t)
   )
  :config
  (org-babel-do-load-languages 'org-babel-load-languages nil)
  (require 'org-crypt)
  :bind
  (("C-c a" . org-agenda)
   ("C-c c" . org-capture)
   ("C-c t" . (lambda () (interactive) (org-capture nil "t")))
   ("C-c s" . org-sort))
  :hook
  (kill-emacs-query-functions . 'my/org-clock-query-out))
(use-package org-ql)
(use-package org-clock-csv :disabled t)
(use-package org-caldav
  :disabled t
  :config
  (progn
    (setq org-caldav-url "https://www.google.com/calendar/dav"
          org-caldav-inbox my/org-agenda-file
          org-caldav-files (list my/org-calendar-file)
          org-icalendar-timezone "America/Los_Angeles")))
(use-package org-pomodoro)
(use-package org-super-agenda
  :hook (org-agenda-mode . org-super-agenda-mode))
(use-package ox-reveal
  :disabled t
  :commands org-reveal
  :config
  (setq org-reveal-root
        "/nix/var/nix/profiles/system/sw/lib/node_modules/reveal"))
(use-package org-projectile
  :requires (:all org projectile)
  :custom
  ((org-projectile-projects-file my/org-projectile-file))
  :config
  (push (org-projectile-project-todo-entry) org-capture-templates)
  :bind
  (("C-c n p" . org-projectile-project-todo-completing-read)))

Deft

(use-package deft
  :custom
  ((deft-directory my/org-directory)
   (deft-default-extension "org")
   (deft-use-filename-as-title t))
  :bind
  (("C-x d" . deft)
   ("C-x D" . deft-new-file)))

Yasnippet

(use-package yasnippet)

Treemacs

(use-package treemacs)
(use-package treemacs-projectile)
(use-package treemacs-magit)

Magit

(use-package magit :bind (("C-x g" . magit-status)))
(use-package magit-annex    :disabled t)
(use-package magit-gerrit   :disabled t)
(use-package magit-gh-pulls :disabled t)
(use-package magit-gitflow  :disabled t)
(use-package magit-lfs      :disabled t)
(use-package magit-pop-up   :disabled t)
(use-package magit-svn      :disabled t)
(use-package magit-topgit   :disabled t)

Origiami

(use-package origami
  :disabled t
  :delight origami-mode
;;:config
;;(add-to-list 'origami-parser-alist '(reason-mode . origami-c-style-parser))
  :hook prog-mode
  :bind
  (("<backtab>" . origami-forward-toggle-node)))

Iedit

(use-package iedit
  :disabled t
  :bind (("C-c i" . iedit-mode)))

Markdown

(use-package markdown-mode)

Nix

(use-package nix-mode
  :config (add-to-list 'auto-mode-alist '(".*\\.nix\\'" . nix-mode)))

Config/Data Files

(use-package dhall-mode)
(use-package json-mode)
(use-package toml-mode)
(use-package yaml-mode)

Web

(use-package web-mode)
(use-package js2-mode :custom ((js-indent-level 2)))
(use-package rjsx-mode
  :config (add-to-list 'auto-mode-alist '(".*\\.js\\'" . rjsx-mode)))

Helm

(use-package helm
  :bind (("M-x" . helm-M-x)
         ("C-x b" . helm-mini)
         ("C-x C-b" . helm-buffers-list)
         ("C-h f" . helm-apropos))
  :hook (after-init . (lambda () (helm-mode +1))))
(use-package helm-dash :disabled t)
(use-package helm-projectile)
(use-package helm-lsp)

Company

(use-package company :hook (after-init . global-company-mode))
(use-package company-lsp)
(use-package company-ngram)
(use-package company-racer)
(use-package company-shell)
(use-package company-statistics)
(use-package company-web)

LSP

(use-package lsp-mode)
(use-package lsp-haskell)
(use-package lsp-ocaml :disabled t)
(use-package lsp-origami)
(use-package lsp-rust :hook (rust-mode . lsp-rust-enable))
(use-package lsp-sh :disabled t)
(use-package lsp-treemacs)

OCaml / ReasonML

(use-package merlin
  :requires (tuareg company)
  :custom
  ((merlin-command "ocamlmerlin")
   (merlin-completion-with-doc t))
  :config
  (add-to-list 'company-backends 'merlin-company-backend)
  :bind
  (:map merlin-mode-map
        ("M-." . merlin-locate)
        ("M-," . merlin-pop-stack)
        ("M-m" . merlin-error-next)
        ("M-n" . merlin-error-prev)
        ("C-c C-o" . merlin-occurrences)
        ("C-c C-j" . merlin-jump)
        ("C-c i" . merlin-locate-ident)
        ("C-c C-e" . merlin-iedit-occurrences))
  :hook tuareg-mode)
(use-package tuareg)
(use-package ocp-indent :config (ocp-setup-indent))
(use-package utop
  :requires tuareg
  :hook (tuareg-mode . utop-minor-mode))
(use-package reason-mode
  :requires (utop merlin)
  :hook
  ((before-save . refmt-before-save)
   (reason-mode . merlin-mode)
   (reason-mode . utop-minor-mode))
  :custom
  ((utop-command "rtop -emacs")))
;; ADD DUNE (OCAML/REASONML) FILES TO LISP MODE
(let ((mode-alist (list '("dune-project\\'" . lisp-mode)
                        '("dune\\'" . lisp-mode)
                        '("jbuild\\'" . lisp-mode))))
  (dolist (mode mode-alist)
    (add-to-list 'auto-mode-alist mode)))

Rust

(use-package rust-mode :custom (rust-format-on-save t))
(use-package rust-playground :disabled t)
(use-package cargo
  :hook ((rust-mode . cargo-minor-mode)
         (toml-mode . cargo-minor-mode)))
(use-package racer
  :hook
  ((rust-mode . racer-mode)
   (racer-mode . eldoc-mode)))

Haskell

(use-package haskell-mode)
(use-package ghcid :load-path "lisp")
(use-package intero
  :config
  (flycheck-add-next-checker 'intero '(warning . haskell-hlint))
  :hook (haskell-mode . inter-mode))
(use-package dante
  :disabled t ; USE INTERO FOR NOW
  :hook (haskell-mode . dante-mode)
  :config
  (flycheck-add-next-checker 'haskell-dante '(warning . haskell-hlint)))
(use-package hindent :hook haskell-mode)

Idris

(use-package idris-mode)

Paredit

(use-package paredit
  :hook
  ((emacs-lisp-mode . paredit-mode)
   (lisp-mode       . paredit-mode)
   (racket-mode     . paredit-mode)
   (scheme-mode     . paredit-mode)
   (shen-mode       . paredit-mode)))

Racket

(use-package racket-mode)
(use-package flymake-racket)

Shen

(use-package shen-elisp)
(use-package shen-mode :pin gnu
  :config
  (add-to-list 'auto-mode-alist '(".*\\.shen\\'" . shen-mode)))

Docker

(use-package docker-cli)
(use-package dockerfile-mode)

Kubernetes

(use-package kubernetes      :disabled t)
(use-package kubernetes-helm :disabled t)

Ledger

(use-package ledger-mode)
(use-package ledger-import)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment