Skip to content

Latest commit

 

History

History
executable file
·
1075 lines (818 loc) · 34.3 KB

EmacsInit.org

File metadata and controls

executable file
·
1075 lines (818 loc) · 34.3 KB

Sean’s Emacs Configuration

Quick Start

Embedded within the text of this file is my actual emacs configuration. It uses org-babel mode to document everything inline ala ‘literate programming’. The inline code blocks are evaluated directly by emacs on startup.

To use this configuration, run the following:

cd $HOME
mv .emacs.d .emacs.d.saved
git clone github.com:rhythmx/emacs-config .emacs.d

Documentation

Cheatsheet

As I add and remove things from my configuration I tend to forget what functionality is available with what keybindings. Here is some at-a-glance documentation to help keep track of all of it.

Helm
Most any prompt launches a helm session.

C-j   : Enter directory
C-l   : Go up a directory
C-SPC : mark file
M-a   : mark all files
Helm-projectile (prefix: C-c p)
Commands that operate on projects

C-c p p : switch project
C-c p f : find file in project 
C-c p k : kill all buffers for project
C-c p d : find dir in project
C-c p c : compile project
Emacs-client
C-x # : close buffer opened with emacs-client
Semantic
C-c spc : complete symbol
C-c j : find symbol
semantic-ia-show-summary
Speedbar
C-c s o : open speedbar
C-c s c : close speedbar
C-c s t : toggle speedbar
WindMove
[shift] + arrow key : focus switch to window in that direction
FullScreen
F11 : toggle fullscreen mode 
Editing nested languages
C-c ' : edit code block, enter again to exit
Following links
C-c C-o : open link at point
Inline LaTeX / GraphViz / etc previews
C-c C-c : evaluate inline code block
C-c C-x C-v : toggle inline image previews
Helm-gtags (prefix: C-c g)
M-. : find a tag
M-* : pop tag stack
C-c g t : find a tag
C-c g r : find references

Prerequisites

Most pre-requisites are handled automatically and are conditionally enabled based on the presence (or lack thereof) of needed binaries on the local system. See “Emacs Package Management” below to add/remove dependancies.

Some things you might want to have installed:

  • GnuPG
  • Aspell/Ispell (don’t forget to install a dictionary too!)
  • Gnu Global (ctags but better)
  • LaTeX
  • GraphViz
  • Dev tools (gcc, clang, ruby, etc.)

Configuration

This is a handy place to enable/disable larger features

(setq sb:helm-enabled t)
(setq sb:speedbar-enabled t)
(setq sb:lean-enabled nil)

Personal/Local Information

Some emacs features need access to sensitive data like passwords, keys, etc. Since this configuration is being posted publicly, fake values are inserted later overridden by a file that will never be committed into source control.

Set up personalization vars

(setq user-full-name "Sean Bradly")
(setq user-mail-addr "sb@nsfw.jp")
(setq browse-url-generic-program "chrome")

Load up personalization from a file

If the PrivateConfig.org file exists, it will be evaluated but never commited to source control so it is suitable for storage of more sensitive info.

(if (file-readable-p "~/.emacs.d/PrivateConfig.org")
    (org-babel-load-file "~/.emacs.d/PrivateConfig.org"))

Runtime Environment

Setup / Init

Helper functions
;; Extra PATHs to check (because windows ENV mgmt sucks)
(setq sb:aux-paths '(
                    "C:/Program Files (x86)/Google/Chrome/Application"))

;; System PATH as a list
(setq sb:path
     (append (split-string (getenv "PATH") (if (eq system-type 'windows-nt) ";" ":"))
             sb:aux-paths))

;; Since Windows is still holding onto semantic filenames for dear life
(setq sb:exe-suffixes (if (eq system-type 'windows-nt) '(".exe") nil))

;; Look for a required system binary
(defun sb:exe-in-path? (exefile)
  (not (not ;; convert to pure bool
        (locate-file exefile sb:path sb:exe-suffixes 'file-executable-p))))

;; Return full path of a basename in PATH
(defun sb:find-in-path (filename)
  (locate-file filename sb:path sb:exe-suffixes))
Setup $PATH

Load an interactive shell so all paths from .bashrc are included. This helps especially for certain scripting environments that dynamically configure their environment.

(defun sb:set-path-from-shell ()
  (let ((path-from-shell (replace-regexp-in-string
                                                  "[ \t\n]*$"
                                                  ""
                                                  (shell-command-to-string "$SHELL --login -c 'echo $PATH'"))))
        (setenv "PATH" path-from-shell)
        (setq eshell-path-env path-from-shell) ; for eshell users
        (setq exec-path (split-string path-from-shell path-separator))))

;; Windows can't handle the bash
(if (not (eq system-type 'windows-nt))
        (sb:set-path-from-shell))
Package Management

Set up the package management system and add some of the more popular public package repositories. This should sync with the remote servers to ensure package lists are up-to-date.

   	(require 'package)

   	(add-to-list 'package-archives
			 '("melpa" . "http://melpa.milkbox.net/packages/"))

   	;; Some other package sources
   	;; '("elpa" . "http://tromey.com/elpa/") ;; ELPA is the official emacs repo (iirc?)
   	;; '("melpa-stable" . "http://melpa-stable.milkbox.net/packages/")
   	;; '("marmalade" . "http://marmalade-repo.org/packages/")

   	(package-initialize)

The use-package package simplifies the installation, initialization, configuration, and management of packages installed through the package manager.

It will always be installed, as any subsequent initialization will depend on it for proper operation. This also serves as a clean way to refresh the package archives on the first run only.

;; Install use-package if not installed
(when (not (package-installed-p 'use-package))
  (package-refresh-contents)
  (package-install 'use-package))

System Prerequisites

We should check for any external programs required by later configuration like programming language tools or system utilities that have special emacs modes, etc. If they aren’t present, handle this gracefully by presenting an error or warning message and quietly disabling the dependent functionality.

GNU Global (aka GTAGS)

Global is basically a replacement for CTAGS. It indexes many different types of source files and allows any editor to easily add advanced source code navigation.

This configuration combines uses gtags & helm integration if global is found on the system. If not, loading of this plugin is skipped.

Install https://aur.archlinux.org/global.git and https://aur.archlinux.org/idutils.git

(setq sb:has-gtags nil)
(if (not (sb:exe-in-path? "gtags"))
    (warn "GNU Global does not appear to be installed. Disabling helm+gtags")
  (setq sb:has-gtags t))
GPG
(setq sb:has-gpg nil)
(if (not (sb:exe-in-path? "gpg"))
    (warn "GPG does not appear to be installed. y u no SECURITY!?")
  (setq sb:has-gpg t))
LaTeX
pacman -Ss texlive-core texlive-latexextra
(setq sb:has-latex nil)
(if (not (sb:exe-in-path? "latex"))
    (warn "LaTeX is not installed. Disabling previews in org-mode")
  (setq sb:has-latex t))
Graphviz
(setq sb:has-graphviz nil)
(if (not (sb:exe-in-path? "dot"))
    (warn "graphviz is not installed. Inline dot previews will not be available")
  (setq sb:has-graphviz t))
Mail (offlineimap / mu / mu4e)
Check if this system does mu4e mail
(setq sb:has-email nil)
(if (not (file-readable-p "~/.emacs.d/EmailConfig.org"))
    (warn "No local email settings found, disabling email configuration.")
  (setq sb:has-email t))
  
ispell + dictionary
(setq sb:has-spell nil)
(if (not (sb:exe-in-path? "aspell"))
    (warn "ispell/aspell does not appear to be installed. Disabling spell checking globally")
  (setq sb:has-spell t))

(when (and sb:has-spell
         (string= (shell-command-to-string "aspell dicts") ""))
  (warn "spell checker is install but no dictionary is available. disabling spell checking globally")
  (setq sb:has-spell nil))
Default browser

We’ll take defaults from a sorted list of preferences. The first one to exist will be the default. This should be good enough for now but might possibly change depending on platform.

(setq
 sb:browser-preferences
 '(
   "chrome.exe"
   "firefox.exe"
   "chrome"
   "google-chrome-stable"
   "chromium"
   "firefox"
   "iceweasel"
   )
 )

(defun sb:set-browser (blist)
  (if blist
      (if (sb:exe-in-path? (car blist))
          (setq browse-url-browser-function 'browse-url-generic
                browse-url-generic-program (sb:find-in-path (car blist)))
        (sb:set-browser (cdr blist)))))

(sb:set-browser sb:browser-preferences)

Appearance

Select a better font.

Consolas is my favorite, but it’s only available by default in Windows. However it’s easy enough to install the Microsoft TrueType fonts in *nix.

; List of fonts in order of preference
(setq sb:preferred-fonts 
  '(
     "Consolas" 
     "Droid Sans Mono"
     "Courier New" 
     "terminus" 
     "DejaVu Sans Mono"
  )
)

(defun sb:set-font (fontlist)
  (if (find-font  (font-spec :name (car fontlist)))

      ; Font exists, so set it
      (progn (set-frame-font (car fontlist))
             (set-face-attribute 'default nil :height 110))

      ; Font not found, move on to next
      (progn (sb:set-font (cdr fontlist)))))

(when (display-graphic-p)
      (sb:set-font sb:preferred-fonts))

Remove all of the UI

I don’t like looking at a bunch of menus and scrollbars. This goes double when I’m on one of my smaller laptops where screen space is premium.

(scroll-bar-mode 0)
(menu-bar-mode 0)
(tool-bar-mode 0)

Default Theme

You can set per-mode themes later on

(when (display-graphic-p) ;; if not in a terminal mode
  
  ;;(use-package zenburn-theme   :ensure t)
  ;;(use-package cyberpunk-theme :ensure t)
  ;;(use-package solarized-theme :ensure t)
  (use-package abyss-theme     :ensure t)
  ;;(use-package base16-theme    :ensure t)

  ;; Load a preferred theme
  ;;(load-theme 'base16-default-dark)
  ;;(load-theme 'cyberpunk t)
  ;;(load-theme 'solarized-dark t)
  ;;(load-theme 'abyss t)
  ) 

Fullscreen mode [F11 key]

Here I define a function that will toggle fullscreen mode on/off.

(defun toggle-fullscreen (&optional f)
  (interactive)
  (let ((current-value (frame-parameter nil 'fullscreen)))
    (set-frame-parameter nil 'fullscreen
      (if (equal 'fullboth current-value)
        (if (boundp 'old-fullscreen) old-fullscreen nil)
        (progn (setq old-fullscreen current-value)
          'fullboth)))))
(global-set-key [f11] 'toggle-fullscreen)

; Uncomment to auto-fullscreen on startup
;(toggle-fullscreen)

Transparency (disabled)

Transparency is picky platform to platform, and most of the time it just gets in the way.

;  (set-frame-parameter (selected-frame) 'alpha '(93 50))

Show line and column numbers in status bar

(linum-mode 0)
(line-number-mode 1)
(column-number-mode 1)

Spaceline modeline

Default Emacs Behaviors

No startup screen

Get’s old after the 9000th time you see it :)

(setq inhibit-startup-screen t)

Spawn a server

This allows other programs (like external email, for example) to call emacsclient to popup a new editor window as needed.

(server-start)

Get rid of annoying backup files (Foo.bar~)

This forces all backup files into a single system-wide directory so that they don’t pollute the whole filesytem.

 (setq backup-by-copying t
	    backup-directory-alist '(("." . "~/.saves")))

Setup Modes

Helm: way better auto complete for most prompts

A good intro to helm is available at http://tuhdo.github.io/helm-intro.html

(when sb:helm-enabled
  (use-package helm :ensure t)
  (require 'helm-config)
  (helm-mode 1)
  (global-set-key (kbd "C-x C-f") 'helm-find-files))

WindMove

Use [shift]+arrow to move the cursor from window to window instead of C-x o

(when (fboundp 'windmove-default-keybindings)
  (windmove-default-keybindings))

Org System (Notes/Agendas/Journal/Wiki)

General Org Mode
Windmove overrides todo/prio keys
(defun sb:org-windmove-hook ()
  (when (fboundp 'windmove-default-keybindings)
    (add-hook 'org-shiftup-hook 'windmove-up)
    (add-hook 'org-shiftleft-hook 'windmove-left)
    (add-hook 'org-shiftdown-hook 'windmove-down)
    (add-hook 'org-shiftright-hook 'windmove-right)))

(add-hook 'org-mode-hook 'sb:org-windmove-hook)
  
Inline LaTeX

Preview with “C-c C-x C-l”

;; Make math mode previews look better
(setq preview-scale-function 1.2)
(setq preview-fast-conversion 'off)
(setq org-format-latex-options (plist-put org-format-latex-options :scale 1.6))
  
Personalized

Load org system config from file share, if present. One day I might make an example layout and commit that publicly too. Until then, just use your imaginations ;)

; Determine root dir of org system based on system type (because
; windows paths are retarded)

(cond ((eq system-type 'gnu/linux) 
       (setq sb:orgdir "/storage/organizer"))
      ((eq system-type 'windows-nt)
       (setq sb:orgdir "Z:\\organizer"))
      (t
       (setq sb:orgdir "/")))

; Define some helper functions to keep path specs small

(defun sb:orgdircat (filename)
  (concat (file-name-as-directory sb:orgdir)  filename))

; Check that guessed paths are sane, assume connectivity problem if not

(if (and (file-directory-p sb:orgdir)
         (file-exists-p (sb:orgdircat "config.org")))
        (org-babel-load-file (sb:orgdircat "config.org"))
  (warn "File server does not seem to be accessible"))

Development Environment

Global settings
Spaces, not tabs
(setq indent-tabs-mode nil)
  
Projectile (Project Management)

Projectile mode keeps a cache of recently used VCS projects and allows quick navigation to an within them. This integrates nicely with helm.

(use-package projectile :ensure t)
(projectile-global-mode)
(when sb:helm-enabled 
  (use-package helm-projectile :ensure t)
  (setq projectile-completion-system 'helm)
  (helm-projectile-on))
GTags (Source navigation)
(when (and sb:has-gtags sb:helm-enabled)
  (use-package helm-gtags :ensure t)
  (setq helm-gtags-ignore-case t
        helm-gtags-auto-update t
        helm-use-input-at-cursor t
        helm-gtags-pulse-at-cursor t
        helm-gtags-prefix-key "\C-cg"
        helm-gtags-suggested-key-mapping t)
  
  (require 'helm-gtags)
  ;; Enable helm-gtags-mode
  (add-hook 'dired-mode-hook 'helm-gtags-mode)
  (add-hook 'eshell-mode-hook 'helm-gtags-mode)
  (add-hook 'c-mode-hook 'helm-gtags-mode)
  (add-hook 'c++-mode-hook 'helm-gtags-mode)
  (add-hook 'asm-mode-hook 'helm-gtags-mode)
  
  (define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
  (define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
  (define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
  (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
  (define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
  (define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))
SR Speedbar (file browser / code outlining)

Quick-access file browser that runs along side of a normal window supporting outlines of source code structure.

(when sb:speedbar-enabled
  (use-package sr-speedbar :ensure t)

  ;; Display on the left
  (setq sr-speedbar-right-side nil)

  ;; Setup quick on/off keys
  (global-set-key "\C-cso" 'sr-speedbar-open)
  (global-set-key "\C-csc" 'sr-speedbar-close)
  (global-set-key "\C-cst" 'sr-speedbar-toggle))
Magit (Git integration)
(use-package magit :ensure t)
Screw the gawdy highlighting of diff
(eval-after-load "magit"
	(setq magit-highlight-section 0))
  
Magit wants to hide release notes via elisp now?
(setq magit-last-seen-setup-instructions "1.4.0")
  
Flyspell (spell checking)
(when sb:has-spell
  (add-hook 'flyspell-mode-hook 'flyspell-buffer))
Flycheck
(use-package flycheck :ensure t)
Multiple Major Mode

Support editing source in source (like javascript inside html)

(use-package mmm-mode :ensure t)
Company Mode (COMPlete ANYthing code completion)
(use-package company :ensure t)
C/C++
Appearance / Tabbing
(defun sb:c-general-hook ()
	
	;; Same indent style as used in the linux src tree 
	(c-set-style "linux")

	;; Prefer spaces over tabs, width=4
	(setq c-basic-offset 4
        indent-tabs-mode nil
        default-tab-width 4)
	
	;; Display line numbers
	(linum-mode)
	(setq linum-format "%4d \u2502")

	)

(add-hook 'c-mode-hook 'sb:c-general-hook)
(add-hook 'c++-mode-hook 'sb:c-general-hook)
  
Spell checking for comments, strings, etc
(when sb:has-spell
  (add-hook 'c-mode-hook 'flyspell-prog-mode)
  (add-hook 'c-mode-hook 'flyspell-buffer)
  (add-hook 'c++-mode-hook 'flyspell-prog-mode)
  (add-hook 'c++-mode-hook 'flyspell-buffer))
  
CEDET
(require 'cc-mode)
(require 'semantic)

(global-semanticdb-minor-mode 1)
(global-semantic-idle-scheduler-mode 1)

(defun sb:c-autocompletion ()
  (semantic-mode 1)
  (company-mode))

(add-hook 'c-mode-hook 'sb:c-autocompletion)
(add-hook 'c++-mode-hook 'sb:c-autocompletion)
  
Assembler
(defun sb:asm-mode-hook ()
  (setq c-basic-offset 4
        indent-tabs-mode nil
        default-tab-width 4
        tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 
                                64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))
        ))

(add-hook 'asm-mode-hook 'sb:asm-mode-hook)

;; Spell checking
(when sb:has-spell
  (add-hook 'asm-mode-hook 'flyspell-prog-mode))
Haskell

I don’t use Haskell for much, this is a rather basic setup.

(use-package haskell-mode :ensure t)

;; Not totally sure what doc mode is yet... sounds like a good enough idea
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
          
;;(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;;(add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent) 

(when sb:has-spell
  (add-hook 'haskell-mode-hook 'flyspell-prog-mode))
Agda
(if (executable-find "agda-mode")
    (load-file (let ((coding-system-for-read 'utf-8))
                 (shell-command-to-string "agda-mode locate"))))

(custom-set-variables
 '(agda2-include-dirs 
   '( "/home/sean/code/agda-stdlib/src"
      "/home/sean/.cabal/share/x86_64-linux-ghc-7.10.1/Agda-2.4.2.3/lib/prim/"
      "/home/sean/code/agda-prelude/src"
      "." )))

;; Spell checker
(when sb:has-spell
  (add-hook 'agda-mode-hook 'flyspell-prog-mode))
Emacs Lisp
Set an alternate indent/parens styleDefault appearence
(defun sb:lisp-mode-hook ()

  ;; Display line numbers
  (linum-mode)
  (setq linum-format "%4d \u2502"))

(add-hook 'emacs-lisp-mode-hook 'sb:lisp-mode-hook)

;; Spell checker
(when sb:has-spell
  (add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode))
  
LaTeX

Don’t “word process”, edit src.

Spell checking
(when sb:has-spell
  (add-hook 'LaTeX-mode-hook 'flyspell-mode)
  (add-hook 'LaTeX-mode-hook 'flyspell-buffer))
  
AUCTeX (disabled)

Disabled for now

;(load "auctex.el" nil t t)
;(load "preview-latex.el" nil t t)

;(require 'flymake)

;(defun flymake-get-tex-args (file-name)
;  (list "pdflatex"
;  (list "-file-line-error" "-draftmode" "-interaction=nonstopmode" file-name)))

;(add-hook 'LaTeX-mode-hook 'flymake-mode)

;(setq ispell-program-name "aspell") ; could be ispell as well, depending on your preferences
;(setq ispell-dictionary "english") ; this can obviously be set to any language your spell-checking program supports

;(add-hook 'LaTeX-mode-hook 'flyspell-mode)
;(add-hook 'LaTeX-mode-hook 'flyspell-buffer)

;(setq TeX-auto-save t)
;(setq TeX-parse-self t)
;(setq TeX-save-query nil)

  
TXT
Spell checking
(when sb:has-spell
  (add-hook 'text-mode-hook 'flyspell-mode)
  (add-hook 'text-mode-hook 'flyspell-buffer))
  
Lua
(use-package lua-mode :ensure t)
CMake
(use-package cmake-mode :ensure t)
;; Note that cmake goes at the front of the list because it needs to
;; take precedence over *.txt
(setq auto-mode-alist
      (append
       '(("CMakeLists\\.txt\\'" . cmake-mode))
       '(("\\.cmake\\'" . cmake-mode))
       auto-mode-alist))
Lean
(when sb:lean-enabled
  (use-package dash :ensure t)
  (use-package dash-functional :ensure t)
  (use-package f)
  (use-package s))


;; Have to set this before require or else it only uses its own
;; version. However... setting this is probably a bad idea in
;; general. It's hard to directly control when emacs runs what lean
;; processes, and memory usage can run away from you very easily,
;; locking the entire system.

;; (setq lean-flycheck-checker-options '(
;;                                       "-M"
;;                                       "4096"
;;                                       "--keep-going" "999"
;;                                       "--flycheck"
;;                                       "--flycheck-max-messages" "100"))

;; Find lean-mode.el based on whichever lean binary is first in $PATH.

;; Lean requires 'lean-rootdir' to be set prior to requiring lean-mode
(setq lean-rootdir
      (replace-regexp-in-string
       "\\(bin\\)?.lean.*" ""
       (or (locate-file "lean"
                    (split-string (getenv "PATH") ":")
                    (if (eq system-type 'windows-nt) '(".exe") nil)) "/usr")))

(when sb:lean-enabled
  (let  ((mylean-path (concat (file-name-as-directory lean-rootdir)
                              (file-name-as-directory "share")
                              (file-name-as-directory "emacs")
                              (file-name-as-directory "site-lisp")
                              "lean")))
    (when (file-exists-p (concat (file-name-as-directory mylean-path) "lean-mode.el"))
      (add-to-list 'load-path (expand-file-name mylean-path))
      (require 'lean-mode))))
  
(defun sb:lean-mode-hook ()
  
  ;; Display line numbers
  (linum-mode)
  (setq linum-format "%4d \u2502")
  
  ;; Dont wrap long lines
  (toggle-truncate-lines)

  (local-set-key (kbd "\C-c\C-c") 
                 (lambda ()
                   (interactive)
                   (save-buffer)
                   (let ((current-prefix-arg ""))
                     (lean-execute nil))))
  (local-set-key (kbd "\C-c f") 
                 (lambda ()
                   (interactive)
                   (lean-flycheck-toggle-use)
                   (message "Lean Flychecking is %s"
                            (if lean-flycheck-use "ON" "OFF")))))

(when sb:lean-enabled
  (add-hook 'lean-mode-hook 'sb:lean-mode-hook))

Clojure

Clojure is a LISP for the JVM

It is integrated in emacs via two packages. For editing, highlighting, etc there is clojure-mode. For more advanced integration there is cider.

(use-package clojure-mode :ensure t)
(use-package cider :ensure t)

GnuPG / EasyPG

GPG Agent Issues

Emacs and GPG2 don’t play nicely together. Almost impossible to get a working config going for plain terminal mode and automatic-decryption.

Except… I have no idea how to do this :(

Emacs and GPG2/pinentry can not share a tty. Also, pinentry is impossible to disable from the command line in GPG2.

Markdown

(use-package markdown-mode :ensure t)
Setup autoload

(this should probably happen by default already anyway, but hey…)

	(autoload 'markdown-mode "markdown-mode"
		  "Major mode for editing Markdown files" t)
Use markdown mode for *.md files (and others)
	  (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
	  (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))

Email (mu4e)

(if sb:has-email
    (org-babel-load-file "~/.emacs.d/EmailConfig.org"))

Terminals

(defun sb:term-mode-hook ()

  ;; Terminal mode doesn't quite work with arrows, so define an
  ;; alternate syntax
  (local-set-key (kbd "C-c <left>")  'windmove-left)
  (local-set-key (kbd "C-c <right>") 'windmove-right)
  (local-set-key (kbd "C-c <up>")    'windmove-up)
  (local-set-key (kbd "C-c <down>")  'windmove-down))

(add-hook 'term-mode-hook 'sb:term-mode-hook)


(defun runterm (name)
  (interactive (list (read-from-minibuffer "buffer name:")))
  (ansi-term "/bin/bash" name))

Others

eshell
;; Eshell-prompt (credit to thierryvolpiatto via https://github.com/emacs-helm/helm/issues/1153))
(setq eshell-prompt-function
      #'(lambda nil
          (concat
           (getenv "USER")
           "@"
           (system-name)
           ":"
           (abbreviate-file-name (eshell/pwd))
           (if (= (user-uid) 0) " # " " $ "))))

;; Compatibility 24.2/24.3
(unless (fboundp 'eshell-pcomplete)
  (defalias 'eshell-pcomplete 'pcomplete))
(unless (fboundp 'eshell-complete-lisp-symbol)
  (defalias 'eshell-complete-lisp-symbol 'lisp-complete-symbol))

(add-hook 'eshell-mode-hook #'(lambda ()
                                ;; Helm completion with pcomplete
                                (setq eshell-cmpl-ignore-case t)
                                (eshell-cmpl-initialize)
                                (define-key eshell-mode-map [remap eshell-pcomplete] 'helm-esh-pcomplete)
                                ;; Helm lisp completion
                                (define-key eshell-mode-map [remap eshell-complete-lisp-symbol] 'helm-lisp-completion-at-point)
                                ;; Helm completion on eshell history.
                                (define-key eshell-mode-map (kbd "M-p") 'helm-eshell-history)
                                ;; Eshell prompt
                                (set-face-attribute 'eshell-prompt nil :foreground "DeepSkyBlue")
                                ;; Allow yanking right now instead of returning "Mark set"
                                ;;(push-mark)
                                ))

;; Eshell history size
(setq eshell-history-size 1000) ; Same as env var HISTSIZE.

;; Eshell-banner
(if (not (eq system-type 'windows-nt)) ;; TODO: replace with something other than uname for windows supportf
    (setq eshell-banner-message (format "%s %s\nwith Emacs %s on %s"
                                        (propertize
                                         "Eshell session started on"
                                         'face '((:foreground "Goldenrod")))
                                        (propertize
                                         (format-time-string "%c")
                                         'face '((:foreground "magenta")))
                                        (propertize emacs-version
                                                    'face '((:foreground "magenta")))
                                        (propertize
                                         (with-temp-buffer
                                           (call-process "uname" nil t nil "-r")
                                           (buffer-string))
                                         'face '((:foreground "magenta"))))))
ido | ido-ubiquitous (DEPRECATED by helm)

interactive auto-completion for find-file, M-x, etc

;;  (ido-mode t)
;;  (ido-ubiquitous-mode)