My Emacs config
This is a literate configuration for Emacs. So even though this looks like a document explaining why I configured things a certain way, believe it or not, it actually is my config.
Feel free to take whatever you like! There are some neat little tricks and workarounds in here that might be useful to you person-who-is-reading this..!
This file changes over time, and new tricks are added occasionally. And if this file is able to help more than just myself, that’s kinda awesome.
Header
In the header of the config… We want the file to include lexical binding:
;; -*- lexical-binding: t -*-This is used later for let closures.
Also, I include this library to give me some of the functions I like from Common Lisp:
;; For other Common Lisp-ish stuff in here
(require 'cl-lib)Setting up the package manager
The package manager in Emacs is pretty sweet, but the default repos are quite limited in their selection of packages… So instead, I add a couple more repos. (I am sure almost everyone has this in their configuration somewhere)
;; Package Manager URLs
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")
("org" . "http://orgmode.org/elpa/")))Then, we want to require TLS… This is for erc-tls, yes, but I
believe it will also be used for all other pieces of Emacs that use
SSL. (Like the package manager eventually, hence its location in the
config file.)
;; SSL Support (For ERC primarily)
(require 'tls)And then we initialize the package manager and use-package:
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))Package checker and installer
I wrote a little package installer before I decided to convert
everything to use-package. I still need this for the time being, but
hopefully that will change soon:
;; My little package checker and installer
(defun check-packages (&rest packages)
"Checks if the passed in packages are installed, and installs
the ones that are not."
(cl-loop for package in packages
with refreshed = nil
unless (package-installed-p package)
unless refreshed
do (package-refresh-contents)
and do (setq refreshed t)
end
and do (package-install package)))And here is the list of packages I configure that I don’t yet handler
with use-package:
;; Ensuring packages are installed
(check-packages 'pp-c-l 'multiple-cursors 'web-mode 'rsense 'robe
'projectile 'plsql 'php-mode 'paredit 'yasnippet
'markdown-mode+ 'magit 'lua-mode 'langtool 'js2-refactor 'jedi
'htmlize 'helm-projectile 'helm-emmet 'grizzl 'graphviz-dot-mode
'flymake-ruby 'flymake-easy 'feature-mode 'expand-region 'evil
'erefactor 'enh-ruby-mode 'emmet-mode 'ecukes 'nginx-mode
'cucumber-goto-step 'firebelly-theme 'apache-mode 'avy 'ac-sly
'ac-js2 'ac-emmet 'ac-cider 'sauron
'tern-auto-complete 'org-plus-contrib 'racer 'flycheck-rust)Convenience functions
Sometimes, its nice to have a few functions to make my configuration easier and more modular… That is the purpose of this section.
Path file checker
This is a function I wrote to check to see if there is any file in the
current path that matches the passed in filename… The purpose behind
this was to be able to check if there are binaries that Emacs can use
for particular functionality… (Like Tern for example; I would only
want to enable its functionality if a ”tern” binary existed
somewhere on the system):
(defun exec-exists-p (filename)
"Checks to see if Emacs can see a file in the execution path.
Returns \"t\" if the passed in filename exists in any of the
executable search directories (\"exec-path\"). Returns \"nil\"
otherwise."
(cl-reduce (lambda (exists dir)
(or exists (file-exists-p (concat dir "/" filename))))
exec-path :initial-value nil))Style options
I don’t care too much for the default appearance of Emacs… I generally like to remove the toolbar at the top of the screen:
;; Remove unsightly toolbar...
(tool-bar-mode 0)As for in-depth styling, I have my own set of basic default faces:
(setq archenoth-faces
(if (boundp 'archenoth-theme)
archenoth-theme
'((fringe ((t (:background "#111" :width expanded))))
(linum ((t (:inherit (shadow default) :background "#111" :foreground "#e0e0e0"))) t)
(pe/directory-face ((t (:inherit dired-directory :weight normal :height 0.9))) t)
(pe/file-face ((t (:inherit default :background "#111" :weight normal :height 0.9))) t))))This essentially is just a minimal set of sane defaults, though if the
variable archenoth-theme is set, those faces will be used instead
of the default.
The defaults do work reasonably well I think, though the way I have this final font setup in my .emacs
(add-to-list 'default-frame-alist
'(font . "-unknown-M+ 1m-light-normal-normal-*-*-98-*-*-d-0-iso10646-1"))This is not a part of the tangled code because it requires this awesome font. (Though I like to have it here for reference)
The following is the definition for the function that will handle the logic for switching from windowed to fullscreen (Mostly just small interface tweaks):
(defun set-fullscreen-settings ()
"Sets the default theme I use for maximixed Emacs"
(interactive)
(set-face-attribute 'default (selected-frame) :height 113)
(fringe-mode '(20 . 0))
(scroll-bar-mode -1)
(menu-bar-mode -1))Now for windowed!
Since switching to windowed mode has some strange results with frame sizing, here is a function that can restore the size back to the normal windowed state:
(defun set-default-window-size ()
"Sets the default window size..."
(interactive)
(modify-frame-parameters
(selected-frame)
'((width . 80) (height . 34))))And now, here is the function that gets called to handle switching from fullscreen to windowed:
(defun set-window-settings ()
"Sets the default theme I use for Windowed Emacs"
(interactive)
(set-face-attribute 'default (selected-frame) :height 98)
(fringe-mode '(8 . 0))
(scroll-bar-mode 1)
(menu-bar-mode 1)
(set-default-window-size))Spifftastic! Now time to put it all together…
The actual style logic
What we want here is something that allows me to toggle between two style configurations, one for fullscreen mode, the other for windowed with the [F11] key.
For the toggling logic, we create this function:
(defun toggle-fullscreen ()
"Toggles fullscreen emacs"
(interactive)
(if is-fullscreen
(progn
(set-frame-parameter nil 'fullscreen nil)
(setq is-fullscreen nil)
(set-window-settings))
(progn
(set-frame-parameter nil 'fullscreen 'fullboth)
(setq is-fullscreen t)
(set-fullscreen-settings))))I also want a piece of advice for display-buffer to prefer to not
create new windows when in fullscreen mode.
It will, when the is-fullscreen variable is set, make sure the
action parameter is not set to ”t” when calling display-buffer,
because that will pop up a new window:
(defun my-display-buffer (args)
(cl-destructuring-bind (buffer-or-name &optional action frame) args
(let ((action (unless (and is-fullscreen (null frame)
(or (eq action t) (eq action 'other-window)))
action)))
(list buffer-or-name action frame))))
(advice-add 'display-buffer :filter-args #'my-display-buffer)I also check for other-window explicitly, because some commands like
compile-goto-error open new windows regardless of other settings by
passing this value directly into display-buffer. This is really
annoying when, for example, you are trying to grep a project, you
click on a result, and it pops up as new window in your
otherwise-fullscreen environment.
This, of course, doesn’t stop explicit actions from creating new windows, but it deters a lot of the defaults that drive me up the wall.
Now, of course, here is the use-package declarations for the
Firecode theme which glues all of this together if there is a window
system to work with.
(use-package firecode-theme
:if window-system
:ensure t
:init
(load-theme 'firecode t)
(apply #'custom-set-faces archenoth-faces)
(set-window-settings)
(let ((is-fullscreen nil))
<<toggle-fullscreen>>
<<display-buffer-advice>>)
:bind ("<f11>" . toggle-fullscreen))And of course, Powerline is nice!
(use-package powerline
:if window-system
:ensure t
:config (powerline-center-theme))Languages
The following are package-loaded language support configurations:
Language agonistic
This section is all about the setup that is about programming, but not for a particular language.
Flymake
Of course, there are a few modes that I like to have Flymake. enabled on by default…
;; FlymakeOf those, we have perl-mode:
(add-hook 'perl-mode-hook (lambda () (flymake-mode t)))And php-mode:
(add-hook 'php-mode-hook (lambda () (flymake-mode t)))Autocomplete
Autocomplete is magnificent. I will have it enabled for almost every programming mode in existence.
(ac-config-default)Compile
I generally like having a compile command as [F5]:
(define-key global-map (kbd "<f5>") 'compile)No, compiling is not always relevant to all languages, but it doubles as a quick command-line, which is almost always useful.
Bash
A neat little trick when editing shell scripts is to add the function
executable-make-buffer-file-executable-if-script-p to the
after-save-hook.
;; Shell scripting
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)What this does it is means when creating or editing scripts, you don’t
need to chmod +x it. Emacs will detect it as a script automagically,
and do that for you.
C and C++
Emacs’ Semantic mode is really good at C… I have not tested it extensively with C++ though.
But with it, we get definition jumping and some quite intelligent
autocomplete… So I simply define the jumping keybinding, the
autocomplete sources, and add it to both C and C++ modes as hooks:
;; C and C++
(defun c-modes-hook ()
(semantic-mode)
(local-set-key (kbd "s-<f3>") #'semantic-ia-fast-jump)
(semantic-idle-summary-mode 1)
(setq ac-sources '(ac-source-semantic-raw
ac-source-yasnippet)))
(add-hook 'c-mode-hook 'c-modes-hook)
(add-hook 'c++-mode-hook 'c-modes-hook)Clojure
For Clojure, I turn on eldoc-mode and setup Autocomplete with
ac-cider:
;; CIDER, Clojure
(add-hook 'cider-mode-hook
(lambda ()
;; For handy modeline function descriptions
(eldoc-mode 1)
;; So autocomplete can pull Clojure documentation
(ac-cider-setup)))For the REPL, I don’t really need autocomplete because of the tab
completion, so I only enable eldoc-mode.
(add-hook 'cider-repl-mode-hook (lambda () (eldoc-mode 1)))For the s-<f3> find-definition binding:
(defun cider-bindings ()
(local-set-key (kbd "s-<f3>") 'cider-find-var))
(add-hook 'cider-repl-mode-hook 'cider-bindings)
(add-hook 'cider-mode-hook 'cider-bindings)Common Lisp
The Common Lisp setup is largely just setting up Sly and Sly’s
autocomplete source.
;; Common Lisp
(add-hook 'sly-mode-hook 'set-up-sly-ac)
(add-hook 'sly-mrepl-mode-hook 'set-up-sly-ac)
(add-to-list 'ac-modes 'sly-mrepl-mode)Nothing really special here.
ELISP
;; ELISPMy ELISP configuration is largely just setting up erefactor and then
adding it to the three ELISP modes.
So first I require the package:
(require 'erefactor)Then I define a hook that turns on erefactor’s scope highlighting,
eldoc-mode, and defines a key for to start refactoring:
;; Hook for all ELISP modes
(defun el-hook ()
(define-key emacs-lisp-mode-map "\C-c\C-v" erefactor-map)
(erefactor-lazy-highlight-turn-on)
(define-key emacs-lisp-mode-map (kbd "s-<f3>") 'find-function-at-point)
(eldoc-mode t))Then I simply assign the function as a hook for all of the ELISP modes:
;; And assigning to said modes
(add-hook 'emacs-lisp-mode-hook 'el-hook)
(add-hook 'lisp-interaction-mode-hook 'el-hook)
(add-hook 'ielm-mode-hook 'el-hook)Feature
;; Feature modeSince I work with Cucumber feature files reasonably often, I find it useful to be able to jump right to the definition of some Cucumber step I am looking at. I also like Slime’s evaluation bindings, so I emulate those here:
(add-hook 'feature-mode-hook
(lambda ()
(local-set-key (kbd "C-c C-c") 'feature-verify-scenario-at-pos)
(local-set-key (kbd "C-c C-k") 'feature-verify-all-scenarios-in-buffer)
(local-set-key (kbd "<f5>") 'feature-verify-all-scenarios-in-project)
(local-set-key (kbd "s-<f3>") 'jump-to-cucumber-step)))HTML, JSP, PHP, and so on…
For most markup-centric web development, I start up web-mode:
;; Web Mode for HTML, JSPs, etc...
(add-to-list 'auto-mode-alist '("\\.[sj]?html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.jsp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.phtml$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.php[34]?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.ejs$" . web-mode))
(setq web-mode-engines-alist '(("jsp" . "\\.tag\\'")))I also start up Emmet for web-mode, any sgml-mode derivative, and
for css-mode…
I also have a few other web-mode tweaks in the web-mode-hook I
define.
(defun web-mode-hook ()
"Hooks for Web mode."
(setq web-mode-html-offset 2)
(setq web-mode-css-offset 2)
(setq web-mode-script-offset 2)
(emmet-mode 1)
(setq emmet-indentation 2)
(toggle-truncate-lines t)
(yas-minor-mode 1))
(add-hook 'web-mode-hook 'web-mode-hook)
(add-hook 'sgml-mode-hook 'ac-emmet-html-setup)
(add-hook 'css-mode-hook 'ac-emmet-css-setup)Java
I don’t do much Java in Emacs, that generally is the job of Eclipse because of its super-intelligent support, integration with everything, and ridiculous debugger capabilities… But when I do… I only have two real tweaks to make:
;; Java
(add-hook 'java-mode-hook
(lambda ()
;; Because Semantic jumping in Java is gnarly
(local-set-key (kbd "s-<f3>") #'semantic-ia-fast-jump)
;; Because these tend to be a lot longer than 80 width
;; and wrapping is ugly.
(toggle-truncate-lines t)
;; Because we like information about local variables.
(semantic-idle-summary-mode 1)
;; Semantic does a good job of parsing Java now, so we
;; don't need to rely on words found in the buffers for
;; completion anymore.
(setq ac-sources '(ac-source-semantic-raw
ac-source-yasnippet))))JavaScript
;; JavaScriptThe support for JavaScript in Emacs is ridiculous. We have an entire
parser in the js2-mode package, which is very well-written.
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))We also possibly have Tern, which gives us even more advanced JavaScript IDE functionality like cross-file references, type inference, and lots of other neat things… But it requires an external executable. That means we need to check to see if it is set up on this system. Either way, we will want to act accordingly:
(defvar *tern-exists* (exec-exists-p "tern")
"Whether or not we can use Tern on this system. Set to \"t\"
when we can, or \"nil\" when we can't.")We will use the above for a number of checks to determine our strategy for setting up our JavaScript functionality.
Of course, if Tern does not exist, we can install it with the following (Assuming we have npm):
npm install -g ternNow, if Tern does not exist, we can also use js2’s parser, for things
like js2-refactor, which allows for advanced automatic refactoring
such as renaming variables and extracting code blocks with intelligent
attention to scope (But it’s only local to the current file as of the
time of writing):
(unless *tern-exists*
(require 'js2-refactor)
(local-set-key (kbd "s-r") 'js2r-rename-var))There is also great autocomplete support with ac-js2… And that
allows for scope-intelligent jumping to definitions… I still want
js2’s autocomplete for local variables because IMO it is superior
to Tern, but having two jumping bindings is redundant, so I disable
this one if we have Tern:
(add-hook 'js2-mode-hook
(lambda ()
(ac-js2-mode)
(unless *tern-exists*
(local-set-key (kbd "s-<f3>") #'ac-js2-jump-to-definition))))Now, finally, the Tern configuration if we have it on this system… It uses an Node.js process to give us essentially a JavaScript IDE:
(when *tern-exists*
(add-hook 'js2-mode-hook
(lambda ()
(setq-local ac-sources nil)
(tern-mode)
(tern-ac-setup)
(local-set-key (kbd "s-r") 'tern-rename-variable)
(local-set-key (kbd "s-<f3>") 'tern-find-definition))))Markdown mode
;; MarkdownAs of the time of writing, I don’t think markdown mode has it set
automagically start for files with the .md file extension, so:
(add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))Python
I don’t really write Python, but for the times I do, Jedi is neat:
;; Jedi, for Python sweetness
(add-hook 'python-mode-hook
(lambda ()
(jedi:ac-setup)
(setq jedi:complete-on-dot t)))Ruby
;; Ruby supportThe default Ruby mode in Emacs is pretty good, partially because it was written by Matz himself. But there is still room for improvement:
First off, when ruby-mode is loaded, we also want to load
robe-mode, which allows for using an interactive Ruby instance for
completion…
(add-hook 'ruby-mode-hook 'robe-mode)And for error checking, we use flymake-ruby:
(add-hook 'ruby-mode-hook 'flymake-ruby-load)There is an Enhanced Ruby Mode enh-ruby, though it is a bit finicky
currently, so I don’t load it by default… But for the times I do
use it, I have defined this hook to configure it to use robe-mode
like normal Ruby mode and set up a bunch of autocomplete sources
for code assist:
(add-hook 'enh-ruby-mode-hook
(lambda ()
(robe-mode)
(add-to-list 'ac-sources 'ac-source-robe)
(add-to-list 'ac-sources 'ac-source-rsense-method)
(add-to-list 'ac-sources 'ac-source-rsense-constant)))Rust
;; Rust supportRust is a pretty neat language. Racer is a pretty neat mode. Lets combine these a bit and get some autocomplete support while we’re at it
(add-hook 'rust-mode-hook #'flycheck-mode)
(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'ac-racer-setup)
(add-hook 'racer-mode-hook #'flycheck-rust-setup)And to make auto-complete a little less annoying:
(add-hook 'racer-mode-hook
(lambda ()
(setq ac-sources '(ac-source-racer))
(setq ac-auto-start nil)
(setq ac-trigger-key "TAB")))SQL
Emacs seems to fail at escaping backslashes in SQL files… So I have slightly modified the syntax entry for the backslash character in SQL files so it acts like a proper escape:
;; SQL, fix buffer escaping
(add-hook 'sql-mode-hook
(lambda ()
(modify-syntax-entry ?\\ "\\" sql-mode-syntax-table)))Utility
The following are things that are nice to have set up during normal Emacs usage, but aren’t for any type of task in particular.
XWidget browser
Emacs now has a WebKit-based browser embedded in it with XWidget. This is cool and all, but its defaults are pretty much unusable, so here is my configuration to make it act like a slightly-reasonable browser:First I define two functions, since [Home] and [End] functionality
is sorely lacking. It just scrolls the browser itself out of view and
doesn’t scroll. The alternative is to scroll a few pixels at a time
until you are at the bottom. Annoying.
So:
(defun xwidget-webkit-scroll-top ()
"Scroll webkit to the top of the page."
(interactive)
(xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical nil 0))(defun xwidget-webkit-scroll-bottom ()
"Scroll webkit to the bottom of the page."
(interactive)
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
"window.scrollTo(0, document.body.scrollHeight);"))This part is to define a bunch of keys to make the browser actually-usable. The following was largely stolen from this Reddit post, with a few modifications to add my own functions above:
;; Add usable keybindings whenever we try to use the XWidget browser
(add-hook
'xwidget-webkit-mode-hook
(lambda ()
(define-key xwidget-webkit-mode-map [mouse-4] 'xwidget-webkit-scroll-down)
(define-key xwidget-webkit-mode-map [mouse-5] 'xwidget-webkit-scroll-up)
(define-key xwidget-webkit-mode-map (kbd "<up>") 'xwidget-webkit-scroll-down)
(define-key xwidget-webkit-mode-map (kbd "<down>") 'xwidget-webkit-scroll-up)
(define-key xwidget-webkit-mode-map (kbd "M-w") 'xwidget-webkit-copy-selection-as-kill)
(define-key xwidget-webkit-mode-map (kbd "C-c") 'xwidget-webkit-copy-selection-as-kill)
(define-key xwidget-webkit-mode-map (kbd "<home>") 'xwidget-webkit-scroll-top)
(define-key xwidget-webkit-mode-map (kbd "<end>") 'xwidget-webkit-scroll-bottom)))
;; Whenever the window changes size and we are in the XWidget browser,
;; we will want to resize it.
(add-hook
'window-configuration-change-hook
(lambda ()
(when (equal major-mode 'xwidget-webkit-mode)
(xwidget-webkit-adjust-size-dispatch))))Evil
I find that one of the first things I do when I start Emacs recently is start Evil… I may as well just put it in my config.
(evil-mode 1)Sauron
;; Supremely useful monitor -- SauronThe all-seeing eye, Sauron is quite useful, though I want to add some
functionality to the modeline with it, so I make higher-priority
messages set a variable: sauron-alert:
(add-hook 'sauron-event-added-functions
(lambda (what priority message &optional event)
(when (<= 4 priority)
(setq sauron-alert t))))The above means you can do something like the following:
(when (boundp 'sauron-alert)
"Code goes here for when Suaron sees something, yo.")And of course, to set it back to nothingness:
(makunbound 'sauron-alert)I actually use this in the modeline and have the modeline use the following function to generate a spooky eye that notifies me if Sauron has seen something of interest with clickable text to bring me to the Sauron buffer:
(defun make-sauron-text ()
"Creates a clickable Sauron text that switches to the Sauron
buffer."
(let ((map (make-keymap)))
(define-key map [follow-link]
(lambda (pos)
(makunbound 'sauron-alert)
(switch-to-buffer "*Sauron*" nil t)))
(propertize " 0"
'keymap map
'face 'compilation-error
'help-echo "Sauron has seen something"
'pointer 'hand)))And because I get notified of high-priority events normally with the above, I have no need for Sauron to be its own frame:
(setq sauron-separate-frame nil)Expand Region
Expand Region is a very handy package for selecting arbitrary blocks of text, be it code or whatever.
;; Expand region
(require 'expand-region)
(global-set-key (kbd "s-SPC") 'er/expand-region)
(global-set-key (kbd "s-S-SPC") 'er/contract-region)Multiple Cursors
From the famous Emacs Rocks video where it was introduced to the masses, my configuration for this super-handy mode is as follows (Just keybindings):
;; Multiple-cursors
(require 'multiple-cursors)
(global-set-key (kbd "s-s") 'mc/mark-next-like-this)
(global-set-key (kbd "C-s-s") 'mc/mark-all-like-this)
(global-set-key (kbd "M-s-s") 'mc/mark-next-symbol-like-this)
(global-set-key (kbd "s-S") 'mc/mark-sgml-tag-pair)Projectile
Another really handy usability mode: Projectile!
I use Projectile with Helm to browse to files in the current (Or any) project really fast:
;; Projectile
(require 'grizzl)
(setq projectile-enable-caching t)
(setq projectile-completion-system 'grizzl)
(global-set-key (kbd "s-f") 'helm-projectile)
(global-set-key (kbd "C-s-f") 'helm-projectile-all)And since I want to enable Projectile everywhere, because jumping between files fast is very handy:
;; Enable projectile
(projectile-global-mode)Avy
Avy is a re-imagining of ace-jump-mode, which allows for very fast
jumping around a buffer.
It is very handy for navigation regardless of mode, so:
(define-key global-map (kbd "s-/") 'avy-goto-subword-1)
(define-key global-map (kbd "s-?") 'avy-goto-char)And since effective motions are essential to Evil:
(define-key evil-motion-state-map (kbd "p") #'avy-goto-subword-1)
(define-key evil-motion-state-map (kbd "P") #'avy-goto-char)Show parenthesis mode
To my knowledge, there is not a single mode where this minor mode isn’t helpful or mildly amusing.
(show-paren-mode)Pretty-print ^L characters
By default, Emacs uses the control character ^L pretty often and prints it as a control character in buffers.
I find this to be ugly, so instead, I install pretty-control-l-mode
so I can make it look nice.
(require 'pp-c-l)
(pretty-control-l-mode 1)Org Mode
Org mode deserves a section for itself because it is just that important.
My Org mode setup includes support for spell checking, grammar
checking, tangling source files from Org mode, auto-fill, and syntax
coloring:
;; Org mode
(require 'org-install)
(require 'ob-tangle)
(add-hook
'org-mode-hook
(lambda ()
(progn
(flyspell-mode t)
(auto-fill-mode t)
(setq-default indent-tabs-mode nil)
(setq org-src-fontify-natively t)
(setq org-export-latex-listings 'minted)
;; LanguageTool setup
(require 'langtool))))Nothing too crazy, because most of Org’s default configuration is pretty sweet.
As for evaluation, especially evaluation with images, It kinda annoys
me that I have to re-run org-redisplay-inline-images whenever I eval
a code block that spits out an image, so I stole this snippet to fix
it:
(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images);; Global org-mode bindings
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c n") 'org-capture)I did, however, bind a few global Org-mode commands, things that can be useful anywhere…
Variables
;;;; VariablesThere are some variables that I want to setq because I don’t want
to have to customize them from their defaults.
Lock Files
I really don’t like Emacs lockfiles… They are annoying and mess up an otherwise clean folder:
(setq create-lockfiles nil) ;; Nasty at timesTabs vs Spaces: The endless war
I am on the spaces side, because tab width screws up formatting hardcore on things like Github if you want to do granular spacing and their tabs are different from yours:
(setq-default indent-tabs-mode nil) ;; Screws up in other editors and GithubCome at me bro.
Auto-backup config
Stolen from here… Very useful to have backup files not mess up the current folder, and yet still exist:
;; Auto-backups
(setq backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/.saves")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t) ; use versioned backups
(setq backup-directory-alist `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))Aliases
Aliases to replace one piece of functionality with another is super-handy.
Yes and No questions
Having to type “yes” is annoying when I just want to do something
simple… So, I alias yes-or-no-p to the single-keystroke
equivalent:
;; Make boolean questions less annoying
(defalias 'yes-or-no-p 'y-or-n-p)Hooks
Hooks! A few small tweaks to suit my work style.
;;;; HooksWhitespace begone!
First of all, I dislike having messy whitespace in the files I am working with, so I am sure to delete trailing whitespace whenever I save a file… (This might become a problem sometime down the line, but so far everything is good.)
(add-hook 'before-save-hook 'delete-trailing-whitespace)Bindings
;;;; Non-specific bindingsThis is a section for key and event bindings that don’t fit anywhere else.
USR1 signal
When I am running Emacs, I don’t always think about starting a server of it, because I simply don’t need it… But what happens if something terrible happens to my desktop manager and Emacs is still intact? I can’t do a lot with it…
That is why I am going to make kill -USR1 $(pidof emacs) start an
Emacs server.
(define-key special-event-map (kbd "<sigusr1>") 'server-start)