#+TITLE: Martin Foot's Emacs Configuration #+AUTHOR: Martin Foot #+EMAIL: martin@mfoot.com #+STARTUP: indent #+OPTIONS: ^:nil # Disable underscore causing subscript #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: This file stores my emacs configuration. The latest version can be found [[https://github.com/mfoo/dotfiles/blob/master/.emacs.d/config.org][on GitHub]]. It is written using [[http://orgmode.org/][org-mode]] which is an excellent way to organise notes and, as it turns out, an excellent way to organise my configuration file. It is intended to be used with ~org-babel-load-file~ which parses this file, generates a =config.el= file, then executes that during emacs startup. In this way my Emacs configuration serves as both the configuration settings /and/ a high level documentation of those settings. It provides an incredibly convenient way to organise configuration the full benefit of org mode's functionality available within the configuration file itself. More information can be found in the [[Installation instructions][Installation instructions]] section. I am not a long term emacs user yet, having started in October 2015 after using vim for around 7 years. As such I use [[https://bitbucket.org/lyro/evil/wiki/Home][evil-mode]] all the time. This file is a work in progress that I try to keep organised. Like many people experiencing a new editor rather than spending an extended period of time reading emacs' extensive documentation, the configuration here has been a mix of searching and reading other people's =.emacs= files. I would recommend taking small parts of it and asking the inbuilt help system what each command does. I've tried to keep each section documented. You can do this with =C-h a=. Organising my configuration in this way came about after a general interest in literate programming and after seeing these: - a [[http://mescal.imag.fr/membres/arnaud.legrand/misc/init.php][blog post by Arnaud Legrand]] - a [[https://www.youtube.com/watch?v=VIuOwIBL-ZU][YouTube video by Daniel Mai]] I already make notes on all my work and a lot of personal tasks throughout the day. This way I know I can confirm exactly what queries I executed or steps I took on a support request, or the methods I took at resolving a certain issue. Since I've been using org to do this, having org's power inside my editor configuration was a huge plus. This file makes a lot of use of the ~use-package~ function. This is a really nice way to keep the installation of a package, it's keybindings, configuration, packaged together in the config file. There's a good description on how it works [[http://www.lunaryorn.com/2015/01/06/my-emacs-configuration-with-use-package.html][here]] and you can see the project page [[https://github.com/jwiegley/use-package][here]]. *Note*: Parts of this file are marked =TODO=. These are sections that require more work. They may not be properly documented, may be badly organised (maybe they should be part of other sections), or could be part of my old emacs configuration from before I used =org-mode= that I still haven't converted. * Installation instructions #+BEGIN_COMMENT I couldn't get org mode's publishing to handle this link nicely, so unfortunately it's in raw HTML. #+END_COMMENT #+BEGIN_HTML Copy the raw version of this file to ~/.emacs.d/config.org. #+END_HTML Then add ~(org-babel-load-file (concat user-emacs-directory "config.org"))~ to =~/.emacs=. Here is the contents of my =~/.emacs= file: #+BEGIN_SRC lisp :results none :exports code ;; Martin's .emacs file ;; ;; Author: Martin Foot <<<<<<< HEAD ;; Load the config (require 'org) (org-babel-load-file (concat user-emacs-directory "config.org")) ======= ; Limit garbage collection to speed up startup (TODO revert this after the config is loaded) (setq gc-cons-threshold 100000000) ;; Load the config (org-babel-load-file (concat user-emacs-directory "config.org")) (setq gc-cons-threshold 800000) >>>>>>> org-jekyll #+END_SRC That's it. The reason that this works is that some parts of this file are carefully organised. =org-babel-load-file= pulls out and executes =emacs-lisp= code blocks in the order they're in the file. This means that it's very important that my [[Package repositories][Package repositories]] section comes before any of the other non-standard config. <<<<<<< HEAD * Package repositories I use Melpa and Marmalade for repositories. #+BEGIN_SRC emacs-lisp :results none (require 'package) (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/") t) ======= Small note for readers of the source file: The example above uses the org babel source language of ~lisp~ rather than ~emacs-lisp~, meaning that it won't be executed by ~org-babel-load-file~ on startup. Initially I had a ~tangle~ block here so =~/.emacs.d/.emacs= would be written conveniently by org, but it adds to the startup time of every emacs load. Removing the ~tangle~ block meant a recursive load, so my workaround is to change the source language. ~org-babel-load-file~ will only evaluate ~emacs-lisp~ blocks. * Package repositories I use Melpa and Marmalade for repositories as well as Org's official repository. #+BEGIN_SRC emacs-lisp :results none (require 'package) (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t) (add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/") t) >>>>>>> org-jekyll (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t) (package-initialize) #+END_SRC Then, since I use ~use-package~ for every package from the repositories, initialise this first. <<<<<<< HEAD #+BEGIN_SRC emacs-lisp :results none (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (eval-when-compile (setq use-package-always-ensure t) (require 'use-package) ) ======= Note this is currently commented, it exists in =.emacs=. #+BEGIN_SRC emacs-lisp :results none ;(unless (package-installed-p 'use-package) ; (package-refresh-contents) ; (package-install 'use-package)) ; ;(eval-when-compile ; (setq use-package-always-ensure t) ; (setq use-package-verbose t) ; Put slow loading packages / config warnings in the *Messages* buffer ; (require 'use-package) ;) >>>>>>> org-jekyll #+END_SRC =use-package= has support for removing minor modes from the bottom. This requires the =diminish= package. #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package diminish) ======= (use-package diminish :defer t ) >>>>>>> org-jekyll #+END_SRC * Startup time benchmarking It's possible to benchmark startup time in emacs. This is useful if evaluating this gets too slow. I keep these lines commented as it's not something I do generally. It also isn't safe to run on every machine since the =benchmark-init-el= package needs to be downloaded manually. #+BEGIN_SRC emacs-lisp :results none ;(add-to-list 'load-path "/home/martinfoot/repositories/benchmark-init-el/") ;(require 'benchmark-init-loaddefs) ;(benchmark-init/activate) #+END_SRC * Load path TODO: Fix this! #+BEGIN_SRC emacs-lisp <<<<<<< HEAD (add-to-list 'load-path "~/org-mode/lisp/") ======= ;;(add-to-list 'load-path "~/org-mode/lisp/") >>>>>>> org-jekyll #+END_SRC * User information #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD ;(setq user-full-name "Martin Foot" ; user-mail-address "martin@mfoot.com") (setq user-full-name "" user-mail-address "") ======= (setq user-full-name "Martin Foot" user-mail-address "martin@mfoot.com") >>>>>>> org-jekyll #+END_SRC * Parentheses Use =electric-pair-mode= to automatically close inserted parentheses and braces. I don't have this enabled in text modes because when using =org-mode= it makes inserting links annoying. #+BEGIN_SRC emacs-lisp :results none (add-hook 'prog-mode-hook (lambda () (electric-pair-mode))) #+END_SRC =show-paren-mode= makes emacs highlight closing parentheses, braces, and curly braces. #+BEGIN_SRC emacs-lisp :results none (show-paren-mode) ; Automatically highlight parenthesis pairs (setq show-paren-delay 0) ; show the paren match immediately #+END_SRC Then I use =[[https://github.com/Fanael/rainbow-delimiters][rainbow-delimiters]]= to highlight nested parentheses in different colours. #+BEGIN_SRC emacs-lisp :results none (use-package rainbow-delimiters <<<<<<< HEAD ======= :diminish :defer t >>>>>>> org-jekyll :config (add-hook 'prog-mode-hook 'rainbow-delimiters-mode) ) #+END_SRC * Fill columns and line highlighting I find a 120 character line length is best for modern screens. Individual languages/major modes can override this. In text-based modes (non-programming modes) I enable automatic line wrapping also. #+BEGIN_SRC emacs-lisp :results none (setq-default fill-column 120) (add-hook 'text-mode-hook 'auto-fill-mode) #+END_SRC I also like a highlight on the screen to show the current cursor line. #+BEGIN_SRC emacs-lisp :results none (global-hl-line-mode) #+END_SRC I also like to highlight git changes in buffers in a git repository: #+BEGIN_SRC emacs-lisp :results none (use-package git-gutter+ <<<<<<< HEAD ======= :diminish :defer t >>>>>>> org-jekyll :config (global-git-gutter+-mode) ) #+END_SRC * Indentation guides When working with structured code it's nice to have an indentation guide. #+BEGIN_SRC emacs-lisp :results none (use-package indent-guide <<<<<<< HEAD ======= :defer t :diminish >>>>>>> org-jekyll :config (add-hook 'prog-mode-hook (lambda () (indent-guide-mode))) ) #+END_SRC * Shortcut help It's very difficult to remember all the shortcuts available in emacs. The =guide-key= plugin pops up a list of available suggestions after a little while. =:diminish guide-key-mode= configures the mode to not show up in the list of minor modes. I've configured it to wait 0.5 seconds before popping up the suggestions list. - =C-c= :: Active mode specific commands - =C-x= :: Emacs commands #+BEGIN_SRC emacs-lisp :results none (use-package which-key :diminish which-key-mode <<<<<<< HEAD ======= :defer t >>>>>>> org-jekyll :init (setq which-key-idle-delay 0.5) (which-key-mode) ) #+END_SRC * Line numbering and cursor position I've had a slight change of heart. Typically I would show line numbers everywhere, but now, instead, I leave them turned off to save space. If I need to jump to a specific line, I'm using Avy mode to enable =g l= for go to line. This is just as fast. See my [[file:config.org::*Window navigation and scrolling][Window navigation and scrolling section]]. I also show the current cursor position column number in the bottom left of the screen: #+BEGIN_SRC emacs-lisp :results none (column-number-mode) #+END_SRC * Yes or no prompts Use 'y' or 'n' instead of 'yes' and 'no' in interactive prompts. This saves typing. #+BEGIN_SRC emacs-lisp :results none (defalias 'yes-or-no-p 'y-or-n-p) #+END_SRC I also configure emacs to ask me if I really want to quit when hitting =C-x C-c= because I find this way too easy to do. #+BEGIN_SRC emacs-lisp :results none (setq confirm-kill-emacs 'y-or-n-p) #+END_SRC <<<<<<< HEAD ======= * Multiple cursors [[https://github.com/magnars/multiple-cursors.el][Multiple cursors]] is cool. #+BEGIN_SRC emacs-lisp :results none (use-package multiple-cursors :diminish multiple-cursors-mode :defer t :init (global-set-key (kbd "C->") 'mc/mark-next-like-this) (global-set-key (kbd "C-<") 'mc/mark-previous-like-this) (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this) ) #+END_SRC >>>>>>> org-jekyll * Symbolic links By default emacs doesn't follow symlinks #+BEGIN_SRC emacs-lisp :results none (setq vc-follow-symlinks t) #+END_SRC * OS Clipboard integration Add proper support for the OS clipboard integrations. Only tested under X. First we enable the emacs copy buffer to be linked to the OS clipboard. Lines copied from the OS can be pasted into emacs and lines copied from emacs can be pasted into other OS windows. #+BEGIN_SRC emacs-lisp :results none (setq x-select-enable-clipboard t) #+END_SRC Now we enable 'primary selection'. The clipboard config above is for the operating system copy buffer with =C-c= and =C-v=. Primary selection is the mouse select buffer that usually works as pasted with a middle click. Enabling this allows selected text in emacs to be copied there so I can select in the program and paste into somewhere else using X. #+BEGIN_SRC emacs-lisp :results none (setq x-select-enable-primary t) (setq mouse-drag-copy-region t) #+END_SRC * Temporary backup files Auto backup can be disabled in emacs with ~(setq make-backup-files nil)~ but rather than disabling them we can simply move the directory that they get placed in. This keeps them out of the way in case we need them. I've used =~/.emacs-backups= because my ~/.emacs.d is in git, I don't need to keep backups. #+BEGIN_SRC emacs-lisp :results none ; From http://www.emacswiki.org/emacs/BackupDirectory ; and http://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files (setq backup-by-copying t ; Ensure backups are copied, not renamed. Important for symlinks backup-directory-alist '(("" . "~/.emacs-backups")) ; Keep backups in ~/.emacs-backups, not the same directory tree delete-old-versions t ; Delete old versions without prompting kept-new-versions 10 ; Keep multiple versioned backup files kept-old-versions 0 ; Don't keep any beyond that version-control t) ; Use versioned backups (setq vc-make-backup-files t) ; Backup even when it's a version controlled project #+END_SRC * Font size Add some keybindings to increase and decrease the font size #+BEGIN_SRC emacs-lisp :results none (global-set-key (kbd "C-+") 'text-scale-increase) (global-set-key (kbd "C--") 'text-scale-decrease) ;; C-x C-0 restores the default font size #+END_SRC * Startup message Don't show the default emacs startup message when it's opened #+BEGIN_SRC emacs-lisp :results none (setq inhibit-startup-message t) #+END_SRC Let's also show a fortune message in the scratch buffer when we start emacs: [[https://github.com/andschwa/fortune-cookie][Source here]] #+BEGIN_SRC emacs-lisp :results none (use-package fortune-cookie <<<<<<< HEAD ======= :defer t :diminish >>>>>>> org-jekyll :config (setq fortune-cookie-cowsay-enable nil) ; Disable cowsay (fortune-cookie-mode) ; Enable fortune cookie mode ) #+END_SRC * Terminal bells Disable the terminal bell. Use a visible bell instead. A non-nil value causes emacs to try and flash the frame to represent a bell. #+BEGIN_SRC emacs-lisp :results none (setq visible-bell 1) #+END_SRC * Menu bar Don't show emacs' menu bar - I remember enough shortcuts and understand how to use the inbuilt help system if I don't remember the shortcut for something. When we're using graphical emacs, also disable the tooltips for the mouse an the scroll bar. #+BEGIN_SRC emacs-lisp :results none (when window-system (tooltip-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1)) (menu-bar-mode -1) #+END_SRC * Whitespace Whitespace mode is enabled for all programming and text buffers. #+BEGIN_SRC emacs-lisp :results none (add-hook 'prog-mode-hook (lambda () (whitespace-mode))) (add-hook 'text-mode-hook (lambda () (whitespace-mode))) #+END_SRC ** Trailing whitespace Delete trailing whitespace automatically on save. I used to configure editors to highlight trailing whitespace, but it's pointless if it can be auto-deleted on save. #+BEGIN_SRC emacs-lisp :results none (add-hook 'before-save-hook 'delete-trailing-whitespace) #+END_SRC I also don't like seeing tabs mixed with spaces. This section needs some work however so is currently commented out. I need to customise the faces that =whitespace-mode= uses. #+BEGIN_SRC emacs-lisp :results none (setq whitespace-line-column 118) ; Highlight lines over 118 characters in whitespace-mode #+END_SRC ** Default emacs backspace behaviour I despise emacs' default behaviour when hitting backspaces on tabs - it converts the tab into the tab-width number of spaces and inserts tab-width -1 spaces. This seems like an insane default. #+BEGIN_SRC emacs-lisp :results none (setq backward-delete-char-untabify-method nil) #+END_SRC ** Tabs Display tabs as four spaces: #+BEGIN_SRC emacs-lisp :results none (setq-default tab-width 4) ;(setq-default tab-always-indent 'complete) #+END_SRC Set up the tab stop list. This is what emacs uses when it can't find an appropriate tab stop - i.e how much to try indenting when tab is hit. #+BEGIN_SRC emacs-lisp :results none (setq-default tab-stop-list (number-sequence 4 200 4)) #+END_SRC Insert tabs by default when auto-formatting. #+BEGIN_SRC emacs-lisp :results none (setq-default indent-tabs-mode t) #+END_SRC =electric-indent-mode= is used to automatically indent a new line when RET is typed. #+BEGIN_SRC emacs-lisp :results none (electric-indent-mode) #+END_SRC ** TODO Highlighting font faces Highlighting colours for whitespace indicators: #+BEGIN_SRC emacs-lisp :results none (custom-set-faces '(whitespace-hspace ((t (:foreground "black")))) '(whitespace-space ((t (:foreground "dark slate gray" :slant italic)))) '(whitespace-tab ((t (:foreground "black"))))) #+END_SRC ** Highlighting long lines I have whitespace mode configured to show lines longer than 120 characters. #+BEGIN_SRC emacs-lisp :results none (setq whitespace-line-column 120) #+END_SRC ** Showing mixed tabs-spaces I highlight mixed spaces and tabs, and have whitespace mode clean out blank lines at the beginning and end of files. #+BEGIN_SRC emacs-lisp :results none (setq whitespace-style (quote (face space-before-tab empty space-after-tab))) #+END_SRC ** Highlighting colours * Region selection =expand-region= makes it really easy to quickly select regions of text getting larger. #+BEGIN_SRC emacs-lisp :results none (use-package expand-region <<<<<<< HEAD ======= :diminish >>>>>>> org-jekyll :defer t :bind ("C-=" . er/expand-region) ) #+END_SRC * Org Mode When I originally wrote this file I had a few simple customisations here. As I discovered new features and customised more things it became larger and larger and I had to split it into subcategories. <<<<<<< HEAD #+BEGIN_SRC emacs-lisp :results none (require 'org) #+END_SRC ======= >>>>>>> org-jekyll ** Key bindings :LOGBOOK: - State "IN_PROGRESS" from "TODO" [2015-12-03 Thu 10:17] - State "TODO" from "" [2015-12-03 Thu 09:51] :END: This table lists (and defines) the key bindings that I often use. Most are set to the defaults but it provides both an easy way to set variables and a handy reference. Check the source for how the table is used. *Note* to future me: If the key is already bound and you're setting a default here, you can find out the name of the function with =C-h k =. TODO: These are the header rows but they cause problems with org-babel evaluation. I would also like to use org's =monospace markup= but this is causing problems. I need to strip the "=" character out of the value in the table cells. | Key binding | Description | Function | |-------------+-------------+------------| #+tblname: org-key-bindings | C-c a | View agenda | org-agenda | | C-c b | Switch buffer between different org mode files | org-switchb | | C-c C-t | Assign or modify a TODO state for the current node | org-todo | | C-c C-a | View current task attachments / attach a file to current task | org-attach | | C-c C-b | Move to previous heading at the same level | org-backwards-heading-same-level | | C-c C-d | Set the deadline for a task | org-deadline | | C-c C-e | Launch the org export dialog | org-export-dispatch | | C-c C-w | Refile (move subtree elsewhere in document) | org-refile | | C-c C-s | Schedule current note/task | org-schedule | | C-c C-t | Toggle todo state to any allowed | org-todo | | C-c C-o | Open link at point | org-open-at-point | | C-c $ | Archive the subtree to the archive file (useful as large org files are slow) | org-archive-subtree | | C-c ' | Edit the current code block in buffer in the correct major mode | org-edit-special | | C-c * | Recalculate formulas on an org mode table | org-ctrl-c-star | | C-c { | Enable the debugger for table formulas | org-table-toggle-formula-debugger | #+BEGIN_SRC emacs-lisp :results none :var org-key-bindings=org-key-bindings (defun mfoot-define-key-bindings (input) (global-set-key (kbd (car input)) (last input))) ; Handle using org's monospace markup (=example=) ;(global-set-key (kbd (remove "=" (car input))) (remove "=" (last input)))) (mapcar #'mfoot-define-key-bindings org-key-bindings) #+END_SRC ** Task tracking *** Task transition timing I like to see timestamps for task transitions but I don't want them filling up screen real estate. Logging these into drawers makes them easily expandable and collapsible. #+BEGIN_SRC emacs-lisp :results none (setq org-log-into-drawer t) #+END_SRC *** TODO State transitions <<<<<<< HEAD Here states transitions are configured. This is largely based on [[http://doc.norang.ca/org-mode.html#TasksAndStates][this document]] but I use =IN_PROGRESS= instead of =NEXT=. ======= State transitions are largely based on [[http://doc.norang.ca/org-mode.html#TasksAndStates][this document]] but I use =IN_PROGRESS= instead of =NEXT=. >>>>>>> org-jekyll #+BEGIN_SRC emacs-lisp :results none (setq org-todo-keywords (quote ((sequence "TODO(t!)" "IN_PROGRESS(i!)" "|" "DONE(d!)") (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)"))) ) #+END_SRC I have defined colours for each task state. TODO is red (bad), blocked is orange and magnta (somewhat bad), in progress is gold (OK) and complete is green. #+BEGIN_SRC emacs-lisp :results none (setq org-todo-keyword-faces (quote (("TODO" :foreground "red" :weight bold) ("IN_PROGRESS" :foreground "gold" :weight bold) ("DONE" :foreground "forest green" :weight bold) ("WAITING" :foreground "orange" :weight bold) ("HOLD" :foreground "magenta" :weight bold) ("CANCELLED" :foreground "forest green" :weight bold) ) )) #+END_SRC Since I have more than two states, moving between them with the default =S-= and =S-= is slow. This enables =C-c c t= as a shortcut for quickly choosing the state. some of the states below have an "@" symbol next to them. This lets me write a reason why a task is cancelled or blocked, or what it's waiting on. The buffer will appear when selecting such a state that lets me enter the reason. #+BEGIN_SRC emacs-lisp :results none (setq org-use-fast-todo-selection t) #+END_SRC ** Agenda Tell org mode where my notes are usually kept. This allows the agenda view to index all my org notes for TODO items and scheduled items. Some of these directories won't exist on some machines so we filter the list at startup based on whether or not the file exists. #+BEGIN_SRC emacs-lisp :results none (require 'cl) ; remove-if-not is inside the common-lisp package <<<<<<< HEAD (setq org-agenda-files (remove-if-not 'file-exists-p '("~/Repositories/notes" "~/repositories/notes" "~/Dropbox/life" "~/repositories/life"))) ======= (setq org-agenda-files (remove-if-not 'file-exists-p '( "~/Repositories/notes" "~/repositories/notes" "~/repositories/life" "~/repositories/life/projects" "~/repositories/life/tasks"))) ;(setq org-agenda-files (remove-if-not 'file-exists-p '("~/Repositories/notes" "~/repositories/notes"))) >>>>>>> org-jekyll #+END_SRC Set up a key binding for the org agenda #+BEGIN_SRC emacs-lisp :results none (global-set-key (kbd "C-c a") 'org-agenda) #+END_SRC <<<<<<< HEAD ======= ** Switching buffers >>>>>>> org-jekyll =org-iswitchb= is a quick way to switch org mode buffers. #+BEGIN_SRC emacs-lisp :results none (global-set-key (kbd "C-c b") 'org-iswitchb) #+END_SRC <<<<<<< HEAD ======= ** LaTeX entities >>>>>>> org-jekyll Enable pretty entities - shows e.g. \alpha \beta \gamma as UTF-8 characters. #+BEGIN_SRC emacs-lisp :results none (setq org-pretty-entities t) #+END_SRC <<<<<<< HEAD ======= ** Emphasis and italics >>>>>>> org-jekyll In =org-mode= we can use [[http://orgmode.org/manual/Emphasis-and-monospace.html][several different emphasis types]] using different emphasis markup. When a block of text has some emphasis on it, get emacs to hide the markup characters: #+BEGIN_SRC emacs-lisp :results none (setq org-hide-emphasis-markers t) #+END_SRC <<<<<<< HEAD ======= ** Syntax highlighting for code blocks >>>>>>> org-jekyll Ensure native syntax highlighting is used for inline source blocks in org files #+BEGIN_SRC emacs-lisp :results none (setq org-src-fontify-natively t) #+END_SRC When emacs source-formats a code block, don't add spaces before it (it messes with syntax highlighting in major modes). #+BEGIN_SRC emacs-lisp :results none (setq org-edit-src-content-indentation 0) #+END_SRC Configure the languages that Babel will automatically syntax highlight #+BEGIN_SRC emacs-lisp :results none ;; active Babel languages (org-babel-do-load-languages 'org-babel-load-languages '((sql . t) <<<<<<< HEAD (sh . t) ======= (shell . t) >>>>>>> org-jekyll (ditaa . t) (dot . t) (calc . t) (java . t) (emacs-lisp . t) (ruby . t) (python . t) <<<<<<< HEAD ) ) #+END_SRC ======= (gnuplot . t) (latex . t) ) ) #+END_SRC ** Displaying images referenced in org files >>>>>>> org-jekyll When we're using a GUI emacs we can display embedded images on startup #+BEGIN_SRC emacs-lisp :results none (add-hook 'org-babel-after-execute-hook 'org-display-inline-images) (add-hook 'org-mode-hook 'org-display-inline-images) (add-hook 'org-mode-hook 'org-babel-result-hide-all) #+END_SRC <<<<<<< HEAD ======= I use graphical emacs so that I can display inline images. Set them to have a maximum size so large images don't fill the screen. #+BEGIN_SRC emacs-lisp :results none (setq org-image-actual-width 800) #+END_SRC ** Export org's checkboxes as HTML checkboxes on HTML export >>>>>>> org-jekyll When exporting to HTML change check boxes into actual HTML check boxes. #+BEGIN_SRC emacs-lisp :results none (setq org-html-checkbox-type 'html) #+END_SRC <<<<<<< HEAD ======= ** Ditaa (generating images from textual block diagrams) >>>>>>> org-jekyll I use =ditaa= for block diagrams. This executes a java program and needs to know where to find the jar. #+BEGIN_SRC emacs-lisp :results none (setq org-ditaa-jar-path "/home/martin/bin/ditaa0_9.jar") #+END_SRC <<<<<<< HEAD I use graphical emacs so that I can display inline images. Set them to have a maximum size so large images don't fill the screen. #+BEGIN_SRC emacs-lisp :results none (setq org-image-actual-width 800) #+END_SRC ======= ** To Do list and agenda >>>>>>> org-jekyll I've been using a single TODO list file and using org-capture to capture todo items to my org agenda from anywhere. This tends to happen at home rather than at work as my work org files contain appropriate TODOs arranged by date headers. At home and in my blog I can capture TODO items and put them in this directory. #+BEGIN_SRC emacs-lisp :results none (if (file-exists-p "~/Dropbox/life/life.org") (setq org-default-notes-file "~/Dropbox/life/life.org") (setq org-default-notes-file "~/repositories/notes/notes.org") ) (define-key global-map "\C-cc" 'org-capture) #+END_SRC Customise the colours of TODO task priority indicators: #+BEGIN_SRC emacs-lisp :results none (setq org-priority-faces '((?A :foreground "dark orange") (?B :foreground "tomato") (?C :foreground "firebrick"))) #+END_SRC I would like a custom agenda view that shows me unscheduled TODO tasks: #+BEGIN_SRC emacs-lisp :results none (setq org-agenda-custom-commands '(("c" . "My Custom Agendas") ("cu" "Unscheduled TODO" ((todo "" ((org-agenda-overriding-header "\nUnscheduled TODO") (org-agenda-skip-function '(org-agenda-skip-entry-if 'scheduled))))) nil nil))) #+END_SRC We'll also make the agenda view appear in the current window, not in a right split. It messes up existing splits. #+BEGIN_SRC emacs-lisp :results none (setq org-agenda-window-setup 'current-window) #+END_SRC TODO: Investigate org-capture, org-agenda etc. See http://pages.sachachua.com/.emacs.d/Sacha.html#orgheadline45. There is a HUGE wealth of information here. ** Emoji I rarely use smiley faces in notes, but sometimes the occasion calls for it. Emojify displays these emojis in interactive buffers. Example: :) #+BEGIN_SRC emacs-lisp :results none (use-package emojify <<<<<<< HEAD :init (add-hook 'org-mode-hook 'emojify-mode)) ======= :diminish :defer t ) >>>>>>> org-jekyll #+END_SRC ** Improved bullet point styles *** Section headers The =org-bullets= package allows pretty unicode bullet points. These are taken from https://thraxys.wordpress.com/2016/01/14/pimp-up-your-org-agenda/. #+BEGIN_SRC emacs-lisp :results none (use-package org-bullets <<<<<<< HEAD ======= :defer t :diminish >>>>>>> org-jekyll :init (setq org-bullets-bullet-list '("◉" "◎" "⚫" "○" "►" "◇")) (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))) ) #+END_SRC *** Bullet point lists For bullet lists, I use a slightly modified (removed =*= chars) versino of Howard Abrams' [[http://www.howardism.org/Technical/Emacs/orgmode-wordprocessor.html][Better bullets]] changes. #+BEGIN_SRC emacs-lisp (font-lock-add-keywords 'org-mode '(("^ *\\(-\\) " (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))) #+END_SRC ** Screenshot attachment I use a package called [[https://github.com/dfeich/org-screenshot][org-attach-screenshot]] which is awesome. Calling the function hides emacs and allows you to grab a section of the screen to insert, where it uses =org-attach= to save it, embeds it at the cursor position, and calls =org-redisplay-inline-images=. This is great for capturing issues at work. #+BEGIN_SRC emacs-lisp :results none (use-package org-attach-screenshot <<<<<<< HEAD ======= :diminish >>>>>>> org-jekyll :bind (("C-c S" . org-attach-screenshot)) ) #+END_SRC ** Presentations I use =org-reveal= for HTML/JS presentations. TODO: Get org-reveal installed. #+BEGIN_SRC emacs-lisp <<<<<<< HEAD (add-to-list 'load-path "~/.emacs.d/org-reveal/") (setq org-reveal-root (expand-file-name (concat user-emacs-directory "reveal.js"))) (add-hook 'org-mode-hook (lambda () (load-library "ox-reveal"))) #+END_SRC ** Additional URL schemes *** TODO Man pages The following code adds a new link type from org that can link to man pages. It's taken from [[http://orgmode.org/manual/Adding-hyperlink-types.html][the org mode manual]]. I need to improve this to see if I can link directly to a heading inside the man page. #+BEGIN_SRC emacs-lisp (require 'org) (org-add-link-type "man" 'org-man-open) (add-hook 'org-store-link-functions 'org-man-store-link) (defcustom org-man-command 'man "The Emacs command to be used to display a man page." :group 'org-link :type '(choice (const man) (const woman))) (defun org-man-open (path) "Visit the manpage on PATH. PATH should be a topic that can be thrown at the man command." (funcall org-man-command path)) (defun org-man-store-link () "Store a link to a manpage." (when (memq major-mode '(Man-mode woman-mode)) ;; This is a man page, we do make this link (let* ((page (org-man-get-page-name)) (link (concat "man:" page)) (description (format "Manpage for %s" page))) (org-store-link-props :type "man" :link link :description description)))) (defun org-man-get-page-name () "Extract the page name from the buffer name." ;; This works for both `Man-mode' and `woman-mode'. (if (string-match " \\(\\S-+\\)\\*" (buffer-name)) (match-string 1 (buffer-name)) (error "Cannot create link to this man page"))) #+END_SRC ======= ;(add-to-list 'load-path "~/.emacs.d/org-reveal/") ;(setq org-reveal-root (expand-file-name (concat user-emacs-directory "reveal.js"))) ;(add-hook 'org-mode-hook (lambda () (load-library "ox-reveal"))) ; #+END_SRC >>>>>>> org-jekyll * Blog [[http://www.mfoot.com][My blog]] uses a static site generator called [[https://jekyllrb.com/][Jekyll]]. This parses YAML files and produces static HTML content which I then host on [[https://aws.amazon.com/s3/][Amazon S3]]. I really like the power of =org-mode= in Emacs, so this configuration block enables me to write blog posts using =org-mode= and then use =org-mode='s publishing system to publish these files in a format that Jekyll understands. I can then run Jekyll normally and it will take these org-published files and convert them into the static website. The configuration here is based on [[http://orgmode.org/worg/org-tutorials/org-jekyll.html][Using org to Blog with Jekyll]], so reading through that is a good idea before trying to understand this. I've adapted it slightly to work with the latest =org-mode= (the publishing functions changed name). I've also added an third part of the project that handles exporting this org mode config file into a =/static/emacs-config= directory. Whenever I run ~org-publish-all~ the latest version of the config file gets pulled in and so the config file hosted on my blog is always as up-to-date as the latest blog post. Here we define a list of projects for org mode. When using the export processor (=C-c C-e=) a projects option now appears at the bottom from any file. Two projects are defined; one for the blog posts that get processed with the HTML publishing function, and one for static content that gets copied verbatim. I can select a project and select either one of the two projects or the component project that wraps both of them. Org will maintain timestamps and caches of these files so that it doesn't regenerate what it doesn't have to. TODO: Describe folder structure. Link to GitHub? Additionally I embed my Google Analytics tracking code in my org mode config for purely informational purposes. Everybody likes cool statistics. To do this I define a custom HTML export that derives from the default org HTML export. It includes a translation function that calls the default HTML template renderer then uses string manipulation to insert the Google Analytics code at the end of the == tag. #+BEGIN_SRC emacs-lisp :results none (defun mfoot-append-google-analytics-tag (template info) "Appends my Google Analytics script segment to the body" (let ((html-template (org-html-template template info))) (let ((pos (string-match (regexp-quote "") html-template))) (concat (substring html-template 0 pos) "" (substring html-template pos))))) (eval-after-load "org" '(progn (require 'ox-html) (org-export-define-derived-backend 'mfoot-html-with-google-analytics 'html :translate-alist '( (template . mfoot-append-google-analytics-tag) ) ) ) ) (defun mfoot-export-emacs-config-to-file (plist filename pub-dir) "Export current buffer to an blog HTML file" (let* ((extension (concat "." org-html-extension)) (org-export-coding-system org-html-coding-system)) (org-publish-org-to 'mfoot-html-with-google-analytics filename extension plist pub-dir))) (setq org-publish-project-alist '( ("org-mfoot" ; Export my blog to the Jekyll format for ~jekyll build~ <<<<<<< HEAD :base-directory "~/repositories/mfoot.com/jekyll/_posts" :base-extension "org" ;; Path to your Jekyll project. :publishing-directory "~/repositories/mfoot.com/jekyll/_posts" ======= :base-directory "~/repositories/mfoot.com/org/" :base-extension "org" ;; Path to your Jekyll project. :publishing-directory "~/repositories/mfoot.com/jekyll/" >>>>>>> org-jekyll :recursive t :publishing-function org-html-publish-to-html :html-extension "html" :body-only t ;; Only export section between :section-numbers nil :with-toc nil :auto-index nil :auto-preamble nil :body-only t :auto-postamble nil ) <<<<<<< HEAD ;("org-static-mfoot" ; :base-directory "~/repositories/mfoot.com/org/" ; :base-extension "css\\|js\\|png\\|jpg\\|gif" ; :publishing-directory "~/repositories/mfoot.com/jekyll" ; :recursive t ; :publishing-function org-publish-attachment ;) ======= ("org-static-mfoot" :base-directory "~/repositories/mfoot.com/org/" :base-extension "css\\|js\\|png\\|jpg\\|gif" :publishing-directory "~/repositories/mfoot.com/jekyll" :recursive t :publishing-function org-publish-attachment ) >>>>>>> org-jekyll ("emacs-dotfiles-mfoot.com" ; Publish an HTML version of this file to the static folder. :base-directory "~/repositories/dotfiles/.emacs.d/" :base-extension "org" :publishing-directory "~/repositories/mfoot.com/jekyll/static/emacs-config" :exclude ".*" :include ("config.org") :publishing-function mfoot-export-emacs-config-to-file :html-extension "html" ) ("emacs-config.org-mfoot.com" ; Publish the raw version of this file alongside the HTML :base-directory "~/repositories/dotfiles/.emacs.d/" :base-extension "org" :publishing-directory "~/repositories/mfoot.com/jekyll/static/emacs-config" :exclude ".*" :include ("config.org") :publishing-function org-publish-attachment ) ("mfoot.com" :components ( "org-mfoot" <<<<<<< HEAD ;"org-static-mfoot" ======= "org-static-mfoot" >>>>>>> org-jekyll "emacs-dotfiles-mfoot.com" "emacs-config.org-mfoot.com" ) ) )) #+END_SRC In addition, I need to install the =htmlize= package to provide syntax highlighting when exporting HTML. See [[http://stackoverflow.com/questions/24082430/org-mode-no-syntax-highlighting-in-exported-html-page][here]] for more information. #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package htmlize) ======= (use-package htmlize :defer t ) >>>>>>> org-jekyll #+END_SRC In order to get images to work both inside emacs and inside the generated output I need to register a custom image format. Emacs currently will only generate ~~ tags for images it can actually resolve on the filesystem. Since my images on my blog are hosted under =/images=, emacs will generate =file:///images= URLs which is not useful. The following allows me to use =img:../images/2015/11/photo.png= as an image reference and have both emacs and the html generator generate the correct paths. This is modified from [[http://stackoverflow.com/a/14841597][this StackOverflow answer]]. #+BEGIN_SRC emacs-lisp :results none (defun org-custom-link-img-follow (path) (org-open-file-with-emacs (format "../images/%s" path))) (defun org-custom-link-img-export (path desc format) (cond ((eq format 'html) (format "\"%s\"/" path desc)))) (org-add-link-type "img" 'org-custom-link-img-follow 'org-custom-link-img-export) #+END_SRC TODO: Write some notes on how I publish this to S3 with s3-website. I always forget this and have to check my bash history. * Window navigation and scrolling Scroll smoothly rather than by paging #+BEGIN_SRC emacs-lisp :results none (setq scroll-step 1) #+END_SRC When the cursor moves past the top or bottom of the window, scroll one line at a time rather than jumping. I don't like having to find my place in the file again. #+BEGIN_SRC emacs-lisp :results none (setq scroll-conservatively 10000) #+END_SRC Add vim-like navigation between panes in a window using windmove. #+BEGIN_SRC emacs-lisp :results none (windmove-default-keybindings) (global-set-key (kbd "C-c ") 'windmove-left) (global-set-key (kbd "C-c ") 'windmove-right) (global-set-key (kbd "C-c ") 'windmove-up) (global-set-key (kbd "C-c ") 'windmove-down) #+END_SRC I use [[https://github.com/abo-abo/avy][avy-mode]] for fast buffer navigation. As I use =evil-mode= I've bound =gc= to goto-char and =gl= to goto-line. This makes for some really fast navigation of the visible buffer. #+BEGIN_SRC emacs-lisp :results none (use-package avy <<<<<<< HEAD :init (progn (use-package evil) ======= :defer t :diminish :init (progn (use-package evil :diminish :defer t ) >>>>>>> org-jekyll ) :config (define-key evil-normal-state-map (kbd "gc") 'avy-goto-char) (define-key evil-normal-state-map (kbd "gl") 'avy-goto-line) ) #+END_SRC * Reloading files I swap branches a lot. =auto-reload-mode= will automatically reload opened buffers (prompting to save or not) #+BEGIN_SRC emacs-lisp :results none (global-auto-revert-mode t) #+END_SRC * Programming language support I use flycheck mode for syntax highlighting and linting when programming. See https://github.com/flycheck/flycheck #+BEGIN_SRC emacs-lisp :results none (use-package flycheck <<<<<<< HEAD :init ======= :defer t :diminish :config >>>>>>> org-jekyll (add-hook 'prog-mode-hook (lambda () (flycheck-mode))) ) #+END_SRC ** YAML Add a major mode for yaml highlighting #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package yaml-mode) ======= (use-package yaml-mode :defer t :diminish ) >>>>>>> org-jekyll #+END_SRC ** C At work we use BSD-style C/C++. We also set the default indentation to four spaces. #+BEGIN_SRC emacs-lisp :results none (setq-default c-basic-offset 4) (setq-default c-default-style "bsd") #+END_SRC ** Go I've just started learning about Go so this is very basic. Enough to run through the tutorials. #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package go-mode) (setenv "GOPATH" "~/go") (add-hook 'go-mode-hook (lambda () ( (add-hook 'before-save-hook 'gofmt-before-save) ))) ======= (use-package go-mode :mode "\\.go" :init (setenv "GOPATH" "~/go") :config (add-hook 'go-mode-hook (lambda () ( (add-hook 'before-save-hook 'gofmt-before-save) ))) ) >>>>>>> org-jekyll #+END_SRC ** SCSS When doing web development, SCSS is really useful. We use [[https://github.com/antonj/scss-mode][scss-mode]] for this. By default hitting tab will insert four spaces. We'll modify this to use two in the same format that Twitter's Bootstrap library uses. #+BEGIN_SRC emacs-lisp :results none (use-package scss-mode <<<<<<< HEAD ======= :defer t >>>>>>> org-jekyll :config (add-hook 'scss-mode-hook (lambda () ( (setq css-indent-offset 2) (setq tab-always-indent nil) ; electric-indent-mode will insert tabs otherwise to minimise whitespace characters (setq indent-tabs-mode nil) ; Always use spaces for scss ))) ) #+END_SRC <<<<<<< HEAD * Linting prose I came across a [[http://unconj.ca/blog/linting-prose-in-emacs.html][cool blog post]] on linting prose in emacs with the [[http://proselint.com][proselint package]] for python wrapped as a flycheck checker. #+BEGIN_SRC emacs-lisp :results none (flycheck-define-checker proselint "A linter for prose." :command ("proselint" source-inplace) :error-patterns ((warning line-start (file-name) ":" line ":" column ": " (id (one-or-more (not (any " ")))) (message) line-end)) :modes (text-mode markdown-mode org-mode)) (add-to-list 'flycheck-checkers 'proselint) #+END_SRC ======= >>>>>>> org-jekyll * Autocompletion I use [[http://company-mode.github.io/][company-mode]] for autocompletion. It's bound to =C-= in a similar way to eclipse. Since I use =evil-mode= I don't use emacs' default mark combo. #+BEGIN_SRC emacs-lisp :results none (use-package company <<<<<<< HEAD :init (use-package helm-company :config (define-key company-mode-map (kbd "C-SPC") 'helm-company) (define-key company-active-map (kbd "C-SPC") 'helm-company) ) :config (add-hook 'prog-mode-hook 'company-mode) (progn ;; Company mode interferes with yasnippets, so this fixes it and integrates them: ;; http://emacs.stackexchange.com/questions/10431/get-company-to-show-suggestions-for-yasnippet-names ;; Add yasnippet support for all company backends ;; https://github.com/syl20bnr/spacemacs/pull/179 (defvar company-mode/enable-yas t "Enable yasnippet for all backends.") (defun company-mode/backend-with-yas (backend) (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend))) backend (append (if (consp backend) backend (list backend)) '(:with company-yasnippet)))) (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends)) ======= :defer t :diminish :config (progn ;; Company mode interferes with yasnippets, so this fixes it and integrates them: ;; http://emacs.stackexchange.com/questions/10431/get-company-to-show-suggestions-for-yasnippet-names ;; Add yasnippet support for all company backends ;; https://github.com/syl20bnr/spacemacs/pull/179 (defvar company-mode/enable-yas t "Enable yasnippet for all backends.") (defun company-mode/backend-with-yas (backend) (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend))) backend (append (if (consp backend) backend (list backend)) '(:with company-yasnippet)))) (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends)) (global-company-mode) >>>>>>> org-jekyll ) ) #+END_SRC * Code folding I've discovered =yafolding-mode= for all my code folding needs. #+BEGIN_SRC emacs-lisp :results none (use-package yafolding <<<<<<< HEAD ======= :defer t :diminish >>>>>>> org-jekyll :config (add-hook 'prog-mode-hook (lambda() (yafolding-mode))) ) #+END_SRC * Git [[https://github.com/magit/magit][Magit]] is awesome. It's git integration with emacs and it's incredibly well made. Taking the time to learn it is highly advised. #+BEGIN_SRC emacs-lisp :results none (use-package magit <<<<<<< HEAD :config (global-set-key (kbd "C-x g") 'magit-status) ======= :diminish :bind (("C-x g" . magit-status)) :config (setq magit-completing-read-function 'ivy-completing-read) >>>>>>> org-jekyll ) #+END_SRC * TODO Base editor configuration I came from Vim and some of the default emacs functionality felt weird to me. #+BEGIN_SRC emacs-lisp :results none (set-face-attribute 'default nil :height 90) (tool-bar-mode -1) ;; TODO: Try and get projectile-ag to work. Is git grep better? ;; Human readable sizes in dired (setq dired-listing-switches "-alh") <<<<<<< HEAD ======= >>>>>>> org-jekyll #+END_SRC ** Mouse support for terminals Enable the mouse when running in a terminal. #+BEGIN_SRC emacs-lisp :results none (when (not (window-system)) (xterm-mouse-mode +1)) #+END_SRC * TODO Package installation All of the packages that I use get automatically installed. First we define ~required-packages~ and then a function that iterates over all of them, installing each one. My =~/.emacs= configures [[https://melpa.org/][Melpa]] and [[https://marmalade-repo.org/][Marmalade]] before this gets executed. #+BEGIN_SRC emacs-lisp :results none (defvar required-packages '( ;; https://github.com/benprew/flymake-puppet ;; ;; Puppet flymake support with puppet-lint flymake-puppet ;; https://github.com/purcell/whitespace-cleanup-mode ;; ;; whitespace-cleanup is a handy function, but putting it in ;; before-save-hook for every buffer is overkill, and causes messy ;; diffs when editing third-party code that did not initially have ;; clean whitespace. Additionally, whitespace preferences are ;; often project-specific, and it's inconvenient to set up ;; before-save-hook in a .dir-locals.el file. ;; whitespace-cleanup-mode is a minor mode which calls ;; whitespace-cleanup before saving the current buffer, but only ;; if the whitespace in the buffer was initially clean. It ;; determines this by quickly checking to see if ;; whitespace-cleanup would have any effect on the buffer whitespace-cleanup-mode ;; Provides git modification markers in the left hand side gutter~ ;; window that shows which lines have been locally modified ;; compared to the git index ;; ;; This is currently commented out because it does not work well ;; with linum-mode. ; git-gutter markdown-mode dockerfile-mode yaml-mode ;; https://github.com/genehack/smart-tab ;; ;; An intelligent tab completion function for Emacs ;; http://www.emacswiki.org/emacs/TabCompletion smart-tab indent-guide ;; https://github.com/lunaryorn/puppet-mode ;; ;; Puppet Mode lets you edit Puppet 3 manifests with GNU Emacs 24. puppet-mode ) "a list of packages to ensure are installed at launch.") <<<<<<< HEAD ;; method to check if all packages are installed ;(defun packages-installed-p () ; (loop for p in required-packages ; when (not (package-installed-p p)) do (return nil) ; finally (return t))) ; ;; if not all packages are installed, check one by one and install the missing ones. ;(unless (packages-installed-p) ; ; check for new packages (package versions) ; (message "%s" "Emacs is now refreshing its package database...") ; (package-refresh-contents) ; (message "%s" " done.") ; ; install the missing packages ; (dolist (p required-packages) ; (when (not (package-installed-p p)) ; (package-install p)))) ======= >>>>>>> org-jekyll #+END_SRC * Remote shells I use =tramp= to edit files on remote machines. Locally I use =zsh= but this might not be installed on the target machine. Use =bash= when connecting to a remote host. TODO: This sets my local shell also. I don't really use =M-x shell= yet, but if I move further into the "everything inside emacs" way, something like [[https://github.com/bbatsov/projectile/issues/921][this]] (with hostname-specificity removed) might be useful. #+BEGIN_SRC emacs-lisp :results none (setq shell-file-name "/bin/bash") #+END_SRC * Themes and visual config ** Custom-safe-themes Emacs requires used themes to be whitelisted. This section contains all of the hash identifiers of themes I'm OK with loading. #+BEGIN_SRC emacs-lisp :results none (custom-set-variables '(custom-safe-themes (quote ("a8245b7cc985a0610d71f9852e9f2767ad1b852c2bdea6f4aadc12cce9c4d6d0" "1297a022df4228b81bc0436230f211bad168a117282c20ddcba2db8c6a200743" "3c83b3676d796422704082049fc38b6966bcad960f896669dfc21a7a37a748fa" "d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879" "8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" default))) ) #+END_SRC ** Smart mode line [[https://github.com/Malabarba/smart-mode-line][Smart Mode Line]] is a mode-line for emacs. #+BEGIN_QUOTE Smart Mode Line is a sexy mode-line for Emacs. It aims to be easy to read from small to large monitors by using colors, a prefix feature, and smart truncation. #+END_QUOTE This is customised to use the =solarized= theme. #+BEGIN_SRC emacs-lisp :results none (use-package solarized-theme <<<<<<< HEAD :init (load-theme 'solarized-dark) (use-package smart-mode-line ======= :defer t :init (load-theme 'solarized-dark) :config (use-package smart-mode-line :defer t :diminish >>>>>>> org-jekyll :config (progn (setq sml/no-confirm-load-theme t) (sml/setup) ) ) ) #+END_SRC ** Displaying the time Displaying the time in the bottom right of the mode line is useful. This displays the time, system load over the last minute, and if I have new emails. #+BEGIN_SRC emacs-lisp :results none (display-time-mode 1) #+END_SRC * Editor augmentation ** Vim customisations [[http://www.emacswiki.org/emacs/Evil][Evil mode]] provides vim-style keybindings for emacs. It makes it much more usable for a long-time vim user. [[https://github.com/timcharper/evil-surround][Evil-surround]] is an emacs wrapper of Tim Pope's [[https://github.com/tpope/vim-surround][vim-surround]] plugin. [[https://github.com/krisajenkins/evil-tabs][Evil-tabs]] is an emacs mode that allows tabs with vim's tab keybindings. #+BEGIN_SRC emacs-lisp :results none (use-package evil <<<<<<< HEAD ======= :diminish >>>>>>> org-jekyll :config (evil-mode) ; Enable evil mode globally ) (use-package evil-surround <<<<<<< HEAD ======= :defer t :diminish >>>>>>> org-jekyll :config (global-evil-surround-mode t) ) (use-package evil-tabs <<<<<<< HEAD ======= :defer t :diminish >>>>>>> org-jekyll :config (global-evil-tabs-mode t) ) #+END_SRC By default emacs doesn't tab indent to the current level when you hit return. Move to vim style. Note: actually electric-indent-mode is used for this. #+BEGIN_SRC emacs-lisp :results none (global-set-key (kbd "RET") 'newline-and-indent) #+END_SRC ** Projectile [[https://github.com/bbatsov/projectile][Projectile]] is a project interaction library for Emacs. Its goal is to provide a nice set of features operating on a project level without introducing external dependencies(when feasible). For instance - finding project files has a portable implementation written in pure Emacs Lisp without the use of GNU find (but for performance sake an indexing mechanism backed by external commands exists as well). #+BEGIN_SRC emacs-lisp :results none (use-package projectile <<<<<<< HEAD ======= :diminish >>>>>>> org-jekyll :config (projectile-global-mode) ) #+END_SRC I use =helm-projectile-ag= quite a lot which requires the =ag= package. #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package ag) ======= (use-package ag :defer t :diminish ) >>>>>>> org-jekyll #+END_SRC ** Recentf mode As well as using Projectile for browsing projects, [[https://www.emacswiki.org/emacs/RecentFiles][recentf]] shows recently opened files in the buffer list for fast switching to them. #+BEGIN_SRC emacs-lisp :results none (use-package recentf :diminish :config (recentf-mode) :bind ("C-x C-r" . recentf-open-files) ) #+END_SRC ** Neotree Sometimes I need to see the directory structure for the current file. The [[http://www.emacswiki.org/emacs/NeoTree][NeoTree]] plugin helps here with a togglable pane that will pop up and disappear with the =F8= key. #+BEGIN_SRC emacs-lisp :results none (use-package neotree :bind ([f8] . neotree-toggle) ) #+END_SRC <<<<<<< HEAD ** TODO Helm mode :LOGBOOK: - State "TODO" from "" [2015-11-21 Sat 10:01] :END: [[https://github.com/emacs-helm/helm][Helm]] is incremental completion and selection narrowing framework for Emacs. It will help steer you in the right direction when you're looking for stuff in Emacs (like buffers, files, etc). It's awesome when combined with [[http://tuhdo.github.io/helm-projectile.html][helm-projectile]] for jumping around projects and finding files within them. #+BEGIN_SRC emacs-lisp :results none (use-package helm :init (progn (require 'helm-config) (use-package helm-projectile :commands helm-projectile ) (use-package helm-ag) (helm-mode 1) ) :bind ("M-x" . helm-M-x) ("C-x b" . helm-mini) :config (setq projectile-completion-system 'helm) ) #+END_SRC Use [[https://github.com/yasuyk/helm-git-grep][helm-git-grep]] for fast searches within the current git directory. #+BEGIN_SRC emacs-lisp :results none (use-package helm-git-grep :config (global-set-key (kbd "C-c g") 'helm-git-grep) ) #+END_SRC The TODO here is that helm is /awesome/. There are so many functions to learn. I need to find some easy-to-remember shortcuts for things like =helm-occur=. Spend some time reading http://pages.sachachua.com/.emacs.d/Sacha.html#orgheadline12. ======= ** Swiper I've switched to Swiper from Helm. #+BEGIN_SRC emacs-lisp :results none (use-package counsel :ensure t ) (use-package swiper :ensure t :config (ivy-mode 1) (setq ivy-use-virtual-buffers t) (global-set-key "\C-s" 'swiper) (global-set-key (kbd "C-c C-r") 'ivy-resume) (global-set-key (kbd "") 'ivy-resume) (global-set-key (kbd "M-x") 'counsel-M-x) (global-set-key (kbd "C-x C-f") 'counsel-find-file) (global-set-key (kbd " u") 'counsel-unicode-char) (global-set-key (kbd "C-c j") 'counsel-git-grep) (global-set-key (kbd "C-c k") 'counsel-ag) (global-set-key (kbd "C-x l") 'counsel-locate) (define-key read-expression-map (kbd "C-r") 'counsel-expression-history) (setq projectile-completion-system 'ivy) ) #+END_SRC >>>>>>> org-jekyll ** Anzu [[https://github.com/syohex/emacs-anzu][Anzu]] shows how many strings match the regex you're replacing and show the effect of replacement as the substitution is typed. This is awesome. Using =%s/using/foo/= you'll see the change to =foo= in the buffer. http://pragmaticemacs.com/emacs/prettier-text-replacement-with-anzu/ #+BEGIN_SRC emacs-lisp :results none (use-package anzu <<<<<<< HEAD :init (global-anzu-mode) ======= :diminish :defer t :config (global-anzu-mode) >>>>>>> org-jekyll :bind ( ("M-%" . anzu-query-replace) ("C-M-%" . anzu-query-replace-regexp) ) ) #+END_SRC ** Rainbow mode Highlights CSS colours in their actual colour. For instance (probably won't be visible in the export): #+BEGIN_SRC css div.example { background-color: #cc3; } #+END_SRC This is enabled globally: #+BEGIN_SRC emacs-lisp :results none (use-package rainbow-mode :config (rainbow-mode) <<<<<<< HEAD (add-hook 'scss-mode-hook (lambda () (rainbow-mode))) ======= :diminish :defer t >>>>>>> org-jekyll ) #+END_SRC ** Coffee mode Major mode for editing CoffeeScript files. #+BEGIN_SRC emacs-lisp :results none (use-package coffee-mode <<<<<<< HEAD ======= :mode "\\.coffee$" >>>>>>> org-jekyll :config (setq coffee-tab-width 2) ) (use-package flymake-coffee <<<<<<< HEAD ======= :defer t :diminish >>>>>>> org-jekyll :init (add-hook 'coffee-mode-hook 'flymake-coffee-load) ) #+END_SRC ** Docker #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package docker) (use-package dockerfile-mode) ======= (use-package docker :defer t :diminish ) (use-package dockerfile-mode :defer t ) >>>>>>> org-jekyll #+END_SRC ** Ruby configuration Provide a =ruby-mode= for editing ruby files. #+BEGIN_SRC emacs-lisp :results none (use-package enh-ruby-mode <<<<<<< HEAD :mode "\\.rb\\'" ======= :mode "\\.rb$" >>>>>>> org-jekyll :config (setq enh-ruby-deep-indent-paren nil) ; Don't indent ruby function parameters at column index of function parentheses ) #+END_SRC I use rspec a lot, and [[https://github.com/pezra/rspec-mode][rspec-mode]] is very useful. #+BEGIN_SRC emacs-lisp :results none (use-package rspec-mode <<<<<<< HEAD ======= :mode "_spec.rb$" >>>>>>> org-jekyll :config (setq rspec-use-rake-when-possible nil) (setq rspec-use-bundler-when-possible t) (setq rspec-use-rvm-when-possible t) (setenv "PATH" (concat (getenv "PATH") ":" "/usr/local/bin")) (eval-after-load "rspec-mode" '(progn (setenv "PAGER" (executable-find "cat")) (inf-ruby-switch-setup) (define-key global-map (kbd "M-T") 'rspec-toggle-spec-and-target) ) ) ) #+END_SRC [[https://github.com/rejeep/ruby-end.el][ruby-end]] inserts =end= blocks whenever I type =do= automatically. #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package ruby-end) ======= (use-package ruby-end :defer t :diminish :init (add-hook 'ruby-mode-hook #'ruby-end-mode) ) >>>>>>> org-jekyll #+END_SRC The following allows using =binding.pry= in =rspec-mode=. #+BEGIN_SRC emacs-lisp :results none (use-package inf-ruby :init (add-hook 'after-init-hook 'inf-ruby-switch-setup) :bind ("C-c r r" . inf-ruby) ) (use-package robe <<<<<<< HEAD :init (add-hook 'enh-ruby-mode-hook 'robe-mode) :config (push 'company-robe company-backends) ) #+END_SRC ** CMake #+BEGIN_SRC emacs-lisp :results none (use-package cmake-mode) #+END_SRC ======= :defer t :init (add-hook 'enh-ruby-mode-hook 'robe-mode) (with-eval-after-load 'company (add-to-list 'company-backends 'company-robe)) ) (defun mfoot/rdb () "Run rake db:rdb." (interactive) (let ((default-directory "~/repositories/cube/src/webapp")) (async-shell-command "bundle exec rake db:rdb" "*Bundle exec*"))) (defun mfoot/trdb () "Run rake db:trdb." (interactive) (let ((default-directory "~/repositories/cube/src/webapp")) (async-shell-command "bundle exec rake db:trdb" "*Bundle exec*"))) (add-hook 'enh-ruby-mode-hook (lambda () (local-set-key (kbd "C-x r t") 'mfoot/trdb)) (lambda () (local-set-key (kbd "C-x r d") 'mfoot/rdb))) #+END_SRC [[https://github.com/asok/projectile-rails][projectile-rails]] provides quick jump-to-model and jump-to-helper support for rails projects. #+BEGIN_SRC emacs-lisp :results none (use-package projectile-rails :defer t :diminish :init (add-hook 'projectile-mode-hook 'projectile-rails-on) ) #+END_SRC ** CMake #+BEGIN_SRC emacs-lisp :results none (use-package cmake-mode :diminish :mode ("CMakeLists.txt" . cmake-mode) ) #+END_SRC >>>>>>> org-jekyll ** MySQL Emacs has a built-in MySQL client. When using it, I want to disable line wrapping. I can use standard text navigation features to see what I need ([[https://zeekat.nl/articles/making-emacs-work-for-me.html][source]]). #+BEGIN_SRC emacs-lisp :results none (add-hook 'sql-interactive-mode-hook (lambda () (toggle-truncate-lines t))) #+END_SRC * Syntax highlighting and static analysis I use [[https://github.com/flycheck/flycheck][flycheck]] as a framework for syntax checking and static analysis. E.g. it will provide language-specific syntax checking for known languages. Some languages also provide linting as well via flycheck. <<<<<<< HEAD ======= TODO: This section should be merged with my =use-package= declaration for flycheck. >>>>>>> org-jekyll #+BEGIN_SRC emacs-lisp :results none (add-hook 'prog-mode-hook (lambda () (flycheck-mode))) #+END_SRC * Spell checking I have several modes that execute =flyspell-mode=. There's a problem with this with xemacs by default: middle clicking to save a correction also inadvertently pastes whatever was in the selection buffer. This can be fixed by swapping around the bindings ([[http://emacs.stackexchange.com/questions/580/inadvertent-paste-when-correcting-spelling-mistakes-using-flyspell][source]]). I don't flyspell =org-mode= buffers inside the =PROPERTIES=, =LOGBOOK=, or =BEGIN_SRC..END_SRC= blocks. #+BEGIN_SRC emacs-lisp :results none (add-hook 'prog-mode-hook (lambda () (flyspell-prog-mode))) (add-hook 'text-mode-hook (lambda () (flyspell-mode))) (eval-after-load "flyspell" '(progn ; (define-key flyspell-mouse-map [down-mouse-2] nil) ; (define-key flyspell-mouse-map [mouse-2] #'flyspell-correct-word)) (add-to-list 'ispell-skip-region-alist '(":\\(PROPERTIES\\|LOGBOOK\\):" . ":END:")) (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC")) ) ) #+END_SRC * Presenting I've been using [[https://github.com/yjwen/org-reveal][org-reveal]] for presentations. <<<<<<< HEAD ##+BEGIN_SRC emacs-lisp :results none #(use-package ox-reveal # :ensure t # :defer t # :config # (setq org-reveal-root (concat user-emacs-directory "reveal-js/reveal.js")) # (add-hook 'org-mode-hook (lambda () (load-library 'ox-reveal))) #) ##+END_SRC ======= #+BEGIN_SRC emacs-lisp :results none ;; (use-package ox-reveal ;; :ensure t ;; :defer t ;; :config ;; (setq org-reveal-root (concat user-emacs-directory "reveal-js/reveal.js")) ;; (add-hook 'org-mode-hook (lambda () (load-library 'ox-reveal))) ;; ) #+END_SRC >>>>>>> org-jekyll * TODO Code snippet handling I use [[https://github.com/capitaomorte/yasnippet][yasnippet]] for code snippet handling. This is enabled globally. #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD (use-package yasnippet :config (yas-global-mode 1) ======= (use-package yasnippet :config (yas-global-mode 1) :diminish :defer t >>>>>>> org-jekyll ) #+END_SRC * TODO Other configuration This section holds configuration from before I moved to using =org-babel= (i.e. it lived directly inside =~/.emacs=). It is here just because I haven't had the time or the impetus to categorise and document it. #+BEGIN_SRC emacs-lisp :results none <<<<<<< HEAD ;(add-hook 'projectile-mode-hook 'projectile-custom-hook) ;(add-hook 'helm-projectile-mode-hook 'projectile-custom-hook) ;(global-unset-key (kbd "C-c p g")) ;(global-set-key (kbd "C-c p g") 'helm-projectile-grep) ;(define-key projectile-command-map (kbd "C-c p g") 'helm-projectile-grep) ======= >>>>>>> org-jekyll ;; If we're at the end of a word and hit TAB, run the expand command ;; for tab completion. If we're not at the end of a word, run the ;; normal tab command ;; http://emacsblog.org/2007/03/12/tab-completion-everywhere/ (defun indent-or-expand (arg) "Either indent according to mode, or expand the word preceding point." (interactive "*P") (if (and (or (bobp) (= ?w (char-syntax (char-before)))) (or (eobp) (not (= ?w (char-syntax (char-after)))))) (dabbrev-expand arg) (indent-according-to-mode))) (local-set-key (kbd "") 'indent-or-expand) (add-to-list 'auto-mode-alist '("\\.hamlc$" . haml-mode)) ;;; Things that are not in melpa ; NOTE: flymake-easy now is in melpa. What am I using that requires it? Is it one of the linters? Does it come in as a dependency? Check if this works without it. ;(add-to-list 'load-path "~/Dropbox/lisp/") ;(require 'flymake-easy) (set-default 'tramp-default-proxies-alist (quote ((".*" "\\`root\\'" "/ssh:%h:")))) #+END_SRC # LocalWords: whitespace