Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
485 lines (435 sloc) 12.9 KB

Emacs configuration file

Packages

Package Repositories

(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(eval-when-compile
  (require 'use-package))
;;(use-package benchmark-init
;;  :ensure t
;;  :config
;;  ;; To disable collection of benchmark data after init is done.
;;  (add-hook 'after-init-hook 'benchmark-init/deactivate))

Mac OS

(when (memq window-system '(mac ns))
  (setq ns-pop-up-frames nil
        x-select-enable-clIpboard t)
(use-package exec-path-from-shell
  :if (memq window-system '(mac ns))
  :ensure t
  :config (exec-path-from-shell-initialize))
  (when (fboundp 'mac-auto-operator-composition-mode)
    (mac-auto-operator-composition-mode 1)))'

Security

Inspired by ogbe.net and Your Text Editor Is Malware.

Check TLS

(setq tls-checktrust t)
(setq gnutls-verify-error t)

Automatic package installation

Install use-package

And its dependencies if needed.

(mapc
 (lambda (package)
   (if (not (package-installed-p package))
       (progn
         (package-refresh-contents)
         (package-install package))))
 '(use-package diminish bind-key))

Trigger use-package

And force the install of missing packages.

(eval-when-compile
  (require 'use-package))
(require 'diminish)
(require 'bind-key)
(setq use-package-always-ensure t)

My information

All the relevant and personal information that Emacs needs. If you are going to use it, needless to say to use your own information.

(setq user-full-name "Neil Grogan"
      user-mail-address "neil@grogan.org"
      calendar-latitude 53.42
      calendar-longitude -7.94
      calendar-location-name "Athlone, Ireland")

Theme

(use-package solarized-theme :config (load-theme 'solarized-dark t))

Quickly edit this config file

(defun edit-config-file ()
  (interactive)
  (find-file (concat config-load-path "emacs-init.org")))

Defaults

Backup and autosave

By default, emacs writes a backup file next to the file being editing with a trailing ~ turd.

;; store all autosave files in the tmp dir
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))

;; backups in backup dir
(setq backup-by-copying t
      backup-directory-alist '(("." . "~/.emacs.d/backup"))
      delete-old-versions t
      kept-new-versions 24
      kept-old-versions 12
      version-control t)

(setq create-lockfiles nil)

Require

Some features are not loaded by default to minimize initialization time, so they have to be required (or loaded, if you will). require-calls tends to lead to the largest bottleneck’s in a configuration. idle-require delays the require-calls to a time where Emacs is in idle. So this is great for stuff you eventually want to load, but is not a high priority.

(use-package recentf
    :defer 1
    :config (recentf-mode 1)
(setq recentf-max-menu-items 300)
(setq recentf-max-saved-items 300)
(setq recentf-exclude
   '("/elpa/" ;; ignore all files in elpa directory
     "recentf" ;; remove the recentf load file
     ".*?autoloads.el$"
     "treemacs-persist"
     "company-statistics-cache.el" ;; ignore company cache file
     "/intero/" ;; ignore script files generated by intero
     "/journal/" ;; ignore daily journal files
     ".gitignore" ;; ignore `.gitignore' files in projects
     "/tmp/" ;; ignore temporary files
     "NEWS" ;; don't include the NEWS file for recentf
     "bookmarks"  "bmk-bmenu" ;; ignore bookmarks file in .emacs.d
     "loaddefs.el"
     "^/\\(?:ssh\\|su\\|sudo\\)?:" ;; ignore tramp/ssh files
     ))
(setq-default recent-save-file "~/.emacs.d/recentf"))

Disable the big fat toolbars

(tool-bar-mode -1)
;;(menu-bar-mode -1)

Disable the scroll bar

(scroll-bar-mode -1)

Disable splash screen

And set it in emacs-lisp mode

(setq inhibit-startup-message t)
(setq initial-major-mode 'emacs-lisp-mode)

Empty Scratch buffer

(setq initial-scratch-message nil)

Helm

(use-package helm
  :ensure t
  :demand
  :diminish helm-mode
  :bind (("C-x C-r" . helm-recentf)
           ("M-x" . helm-M-x)
           ("C-x C-f" . helm-find-files)
           ("C-c h" . helm-command-prefix)
           ("<tab>" . helm-execute-persistent-action)
           ("C-i" . helm-execute-persistent-action)
           ("C-z" . helm-select-action))

    :config (setq projectile-project-search-path '("~/repos/" "~/.dotfiles/"))
            (setq helm-split-window-inside-p t
                  helm-M-x-fuzzy-match t
                  helm-buffers-fuzzy-matching t
                  helm-ff-file-name-history-use-recentf t
                  helm-recentf-fuzzy-match t
                  helm-move-to-line-cycle-in-source t
                  projectile-completion-system 'helm)

            (set-face-attribute 'helm-selection nil :background "cyan")
            (helm-mode 1)
            (helm-adaptive-mode 1))

(use-package helm-rg)
(use-package helm-system-packages)

Evil

(use-package evil
  :ensure t
  :config (evil-mode 1))

Company Mode

Company mode provides auto completion for editing.

(use-package company
    :diminish company-mode
    :init
  (autoload 'helm-company "helm-company") ; Not necessary if using ELPA package
  (eval-after-load 'company
    '(progn
       (define-key company-mode-map (kbd "C-<tab>") 'helm-company)
       (define-key company-active-map (kbd "C-<tab>") 'helm-company)))
    :config
   (setq company-idle-delay 0
      company-echo-delay 0
      company-dabbrev-downcase nil
      company-minimum-prefix-length 2
      company-selection-wrap-around t
      company-transformers '(company-sort-by-occurrence
                             company-sort-by-backend-importance)))
(use-package helm-company
     :ensure t
     :init (autoload 'helm-company "helm-company"))

Enable company-jedi

(use-package company-jedi
  :config (add-to-list 'company-backends 'company-jedi))

Git

Git client inside of Emacs

(use-package magit
    :defer 5
    :ensure t
    :init (progn
           (bind-key "C-x g" 'magit-status)
           ))

Git Gutter

(use-package git-gutter
    :ensure t
    :init
      (global-git-gutter-mode t)
    :diminish git-gutter-mode
    :config
    (dolist (p '((git-gutter:added    . "#0c0")
                (git-gutter:deleted  . "#c00")
                (git-gutter:modified . "#c0c")))
     (set-face-foreground (car p) (cdr p))
     (set-face-background (car p) (cdr p))))

Neotree

(use-package neotree
    :defer 5
    :bind ([f8] . neotree-toggle)
    :config (setq neo-smart-open t))

Org Mode

Default settings for orgmode, such as where files are located:

(use-package htmlize)
(use-package org
    :ensure t
    :pin org)

(setq org-completion-use-ido nil)
;; Set to the location of your Org files on your local system
(setq org-directory "~/Dropbox/org")
(setq org-agenda-files '("~/Dropbox/org/inbox.org"
                      "~/Dropbox/org/gtd.org"
                      "~/Dropbox/org/tickler.org"))

(setq org-capture-templates '(("t" "Todo [inbox]" entry
                            (file+headline "~/Dropbox/org/inbox.org" "Tasks")
                            "* TODO %i%?")
                          ("T" "Tickler" entry
                            (file+headline "~/Dropbox/org/tickler.org" "Tickler")
                            "* %i%? \n %U")))

(setq org-refile-targets '(("~/Dropbox/org/gtd.org" :maxlevel . 3)
                        ("~/Dropbox/org/someday.org" :level . 1)
                        ("~/Dropbox/org/tickler.org" :maxlevel . 2)))

(add-to-list 'org-file-apps '("\\.xls\\'" . default))
(add-to-list 'org-file-apps '("\\.xlsx\\'" . default))

(setq org-todo-keywords '((sequence "TODO(t)" "WAITING(w)" "|" "DONE(d)" "CANCELLED(c)")))

Key bindings for orgmode.

(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-cb" 'org-iswitchb)

Enable babel to use different languages in orgmode:

(setq org-confirm-babel-evaluate nil)
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
  (C . t)
  (css . t)
  (ditaa . t)
  (gnuplot . t)
  (ledger . t)
  (java . t)
  (python . t)
  (ruby . t)
  (shell . t)))

When editing org-files with source-blocks, we want the source blocks to be themed as they would in their native mode.

(setq org-src-fontify-natively t
      org-src-tab-acts-natively t
      org-confirm-babel-evaluate nil
      org-edit-src-content-indentation 0)

Add org-bullets:

(use-package org-bullets
  :config (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

Display images inline

(setq org-startup-with-inline-images t)

Add youtube link capability:

(defvar yt-iframe-format
  ;; You may want to change your width and height.
  (concat "<iframe width=\"440\""
          " height=\"335\""
          " src=\"https://www.youtube.com/embed/%s\""
          " frameborder=\"0\""
          " allowfullscreen>%s</iframe>"))

(org-add-link-type
 "yt"
 (lambda (handle)
   (browse-url
    (concat "https://www.youtube.com/embed/"
            handle)))
 (lambda (path desc backend)
   (cl-case backend
     (html (format yt-iframe-format
                   path (or desc "")))
     (latex (format "\href{%s}{%s}"
                    path (or desc "video"))))))

Prodigy

Can start servers in Emacs

(use-package prodigy
:ensure t
:config
(prodigy-define-service
  :name "blog@localhost"
  :command "python2"
  :args '("-m" "SimpleHTTPServer" "8000")
  :cwd "~/repos/org-blog"
  :tags '(file-server)
  :stop-signal 'sigkill
  :kill-process-buffer-on-stop t))

Projectile

(use-package projectile
  :ensure t
  :diminish projectile-mode
  :bind ("C-c p" . projectile-command-map)
  :config
  (projectile-mode))

With a twist of helm

(use-package helm-projectile
  :bind (("C-c v" . helm-projectile)
         ("C-c C-v" . helm-projectile-ag)
         ("C-c w" . helm-projectile-switch-project)))

Snippets

I use yasnippet a lot.

(use-package yasnippet
  :diminish yas-minor-mode
  :config (setq yas-snippet-dirs
           '("~/.dotfiles/conf/emacs.d/snippets"   ;; git synced snippets
             "~/.emacs.d/snippets"                 ;; local snippets
           ))
          (yas-global-mode 1))

Which Key

(use-package which-key
  :diminish which-key-mode
  :config (which-key-mode 1))

Programming Languages & Markup

Docker

(use-package dockerfile-mode
  :mode "Dockerfile\\'")

Logs

EditorConfig

(use-package editorconfig
    :diminish editorconfig-mode
    :config (editorconfig-mode 1))

Emacs Lisp

Enable eldoc

(use-package eldoc
  :diminish eldoc-mode
  :config (add-hook 'emacs-lisp-mode-hook 'eldoc-mode))

Erlang

(use-package erlang
    :defer t
    :mode ("\\.[eh]rl\\'" . erlang-mode))

(use-package company-erlang
  :config
(add-hook 'erlang-mode-hook #'company-erlang-init))

Markdown

For editing markdown files…

(use-package markdown-mode
  :ensure t
  :commands markdown-mode
  :init
  (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)))

Python

YAML

Yet Another Markup Language

(use-package yaml-mode
  :ensure t
  :commands yaml-mode
  :init
(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
(add-to-list 'auto-mode-alist '("\\.yaml$" . yaml-mode)))

Enable undo-tree

(use-package undo-tree
  :diminish undo-tree-mode
  :config
  (global-undo-tree-mode t)
  (setq undo-tree-visualizer-diff t))