2014-11-04 01:38:48 +00:00
#+TITLE : Emacs Configuration
2015-01-28 16:04:11 +00:00
#+STARTUP : indent
2014-11-04 01:38:48 +00:00
* Startup
2014-11-13 04:22:14 +00:00
** Disable the emacs startup screen.
2015-01-29 00:29:03 +00:00
#+name : startup
2015-01-28 16:04:11 +00:00
#+BEGIN_SRC emacs-lisp
(setq inhibit-startup-screen +1)
#+END_SRC
2015-04-30 02:13:51 +00:00
* UI
** Theme
2015-01-28 16:04:11 +00:00
#+name : look-and-feel
#+BEGIN_SRC emacs-lisp
(use-package solarized-theme
:ensure t
:init (load-theme 'solarized-dark 't))
#+END_SRC
2015-01-08 02:51:11 +00:00
** Helm
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package helm
:ensure t
:diminish helm-mode
:bind (("M-x" . helm-M-x)
("M-y" . helm-show-kill-ring)
("C-x b" . helm-mini)
("C-x C-b" . helm-buffers-list)
("C-x C-f" . helm-find-files)
("C-x C-r" . helm-recentf)
("C-x c o" . helm-occur)
("C-x c s" . helm-swoop))
2015-02-25 22:03:28 +00:00
:config (progn
(require 'helm-config)
(helm-mode 1)
(add-hook 'eshell-mode-hook
(lambda ()
(define-key eshell-mode-map (kbd "TAB") 'helm-esh-pcomplete)
(define-key eshell-mode-map (kbd "C-c C-l") 'helm-eshell-history)))))
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-01-28 15:55:58 +00:00
*** helm-descbinds
2015-01-29 00:29:03 +00:00
#+name : packages
2015-01-28 16:04:11 +00:00
#+BEGIN_SRC emacs-lisp
(use-package helm-descbinds
:ensure t
:bind (("C-h b" . helm-descbinds)
("C-h w" . helm-descbinds)))
#+END_SRC
2015-02-03 15:55:29 +00:00
*** helm-ag
Helm search plugin for [[Ag%20(The%20Silver%20Searcher) ][Ag (The Silver Searcher) ]]
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-02-25 22:03:28 +00:00
(use-package helm-ag
:ensure t
:defer t)
2015-02-03 15:55:29 +00:00
#+END_SRC
2015-04-02 14:53:49 +00:00
*** helm-projectile
Helm projectile integration
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package helm-projectile
:ensure t
:defer t)
#+END_SRC
2015-04-27 13:52:21 +00:00
*** helm-flyspell
#+name : packages
#+begin_src emacs-lisp
(use-package helm-flyspell
:ensure t
:commands helm-flyspell-correct
:init (eval-after-load 'flyspell
'(define-key flyspell-mode-map (kbd "C-;") 'helm-flyspell-correct)))
#+end_src
2015-01-28 15:55:58 +00:00
** Ace Jump
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-02-25 22:03:28 +00:00
(use-package ace-jump-mode
:ensure t
:defer t)
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-01-28 15:55:58 +00:00
*** ace-isearch
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package ace-isearch
:ensure t
2015-02-25 22:03:28 +00:00
:config (global-ace-isearch-mode t))
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-01-28 15:55:58 +00:00
*** ace-window
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package ace-window
:ensure t
:bind ("C-x o" . ace-window))
#+END_SRC
2015-01-29 00:29:14 +00:00
** Guide Key
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package guide-key
:ensure t
:diminish guide-key-mode
2015-02-25 22:03:28 +00:00
:config (progn
(setq guide-key/guide-key-sequence t)
(guide-key-mode 1)))
2015-01-29 00:29:14 +00:00
#+END_SRC
2014-11-04 01:38:48 +00:00
** Expand Region
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package expand-region
:ensure t
:bind ("C-=" . er/expand-region))
#+END_SRC
2015-04-30 02:13:51 +00:00
** Powerline
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package powerline
:ensure t
:init (powerline-default-theme))
#+END_SRC
** Projectile
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package projectile
:ensure t
:config (progn (setq projectile-mode-line
'(:eval (format " [%s]" (projectile-project-name))))
(require 'helm-projectile)
(helm-projectile-on)
(projectile-global-mode)))
#+END_SRC
* Coding
** Languages
*** Lisps
#+name : lisps
| Mode | Description |
|------------+---------------------------|
| lisp | Common Lisp |
| emacs-lisp | Emacs Lisp |
| scheme | Scheme |
| lfe | Lisp-Flavored Erlang |
| clojure | Clojure |
| hy | Hy (Lisp-flavored Python) |
#+name : programming
#+BEGIN_SRC emacs-lisp :noweb yes
;; SLIME
(if (file-exists-p "~/quicklisp/slime-helper.el")
(load (expand-file-name "~/quicklisp/slime-helper.el")))
(setq inferior-lisp-program "clisp")
(use-package paredit
:ensure t)
(use-package rainbow-identifiers
:ensure t)
(use-package rainbow-delimiters
:ensure t)
(let ((lisp-mode-hooks
(mapcar (lambda (lisp)
(intern (concat lisp "-mode-hook")))
(mapcar 'car (cddr '<<lisps() >>)))))
(mapc (lambda (hook)
(message (format "Installing LISP mode hook for %S" hook))
(add-hook hook (lambda ()
(show-paren-mode t)
(electric-indent-mode t)
(paredit-mode t)
(rainbow-delimiters-mode t)
(rainbow-identifiers-mode t))))
(cons 'eval-expression-minibuffer-setup-hook
lisp-mode-hooks)))
#+END_SRC
**** Lisp-Flavored Erlang
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package lfe-mode
:ensure t
:mode "\\.lfe$")
#+END_SRC
**** Clojure
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package clojure-mode
:ensure t
:mode (("\\.clj[sx]?$" . clojure-mode)
("\\.edn$" . clojure-mode)))
#+END_SRC
***** Cider
Communicates with the clojure REPL.
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package cider
:ensure t
:commands (cider-jack-in cider))
#+END_SRC
**** Hy
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package hy-mode
:ensure t
:mode "\\.hy$")
#+END_SRC
*** Erlang
A distributed, fault-tolerant functional language.
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package erlang
:ensure t
:mode ("\.[eh]rl$" . erlang-mode)
:config (add-hook 'erlang-mode-hook
(lambda ()
(setq inferior-erlang-machine-options '("-sname" "emacs"
"-hidden")))))
#+END_SRC
*** Haskell
A strongly typed, pure functional language.
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package haskell-mode
:ensure t
:mode "\.hs$")
#+END_SRC
*** PHP
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package web-mode
:ensure t
:mode "\\.html?$")
(use-package php-mode
:ensure t
:mode (("\\.php$" . php-mode)
("\\.inc$" . php-mode))
:config (add-hook 'php-mode-hook (lambda ()
"Customize PHP indentation"
(c-set-offset 'arglist-cont-nonempty 'c-lineup-arglist)
(c-set-offset 'substatement-open 0)
(c-set-offset 'case-label '+))))
#+END_SRC
2015-05-07 01:40:47 +00:00
*** Python
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package python-mode
:ensure t
:mode "\.py$")
#+END_SRC
**** Cython
2015-04-30 02:13:51 +00:00
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package cython-mode
:ensure t
2015-05-07 01:40:47 +00:00
:mode "\.pyx$")
2015-04-30 02:13:51 +00:00
#+END_SRC
*** Ruby
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package rvm
:ensure t
:config (rvm-use-default))
#+END_SRC
*** Yaml
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package yaml-mode
:ensure t
:mode "\.yml$")
#+END_SRC
*** Docker
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package dockerfile-mode
:ensure t
:mode "^Dockerfile$")
#+END_SRC
*** Graphviz
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package graphviz-dot-mode
:ensure t
:mode "\.dot$")
#+END_SRC
** Tools
*** Autocomplete
#+name : autocomplete
#+BEGIN_SRC emacs-lisp
(use-package auto-complete
:ensure t
:config
(progn (global-auto-complete-mode t)
(require 'auto-complete-config)
(ac-config-default)
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab >")))
#+END_SRC
*** Flycheck
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package flycheck
:ensure t
:init
(add-hook 'after-init-hook #'global-flycheck-mode))
#+END_SRC
2015-04-30 02:13:51 +00:00
*** Web Mode
2015-04-27 13:52:21 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package web-mode
2015-04-27 13:52:21 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:mode ("\\.html$" . web-mode)
:config (add-hook 'web-mode-hook (lambda ()
(setq web-mode-markup-indent-offset 4)
(setq web-mode-css-indent-offset 4)
(setq web-mode-code-indent-offset 4))))
2015-04-27 13:52:21 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
*** Yasnippet
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package yasnippet
2015-01-28 16:04:11 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:diminish yas-minor-mode
:config (yas-global-mode 1))
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
*** Ag (The Silver Searcher)
This is a code searching tool that replaces =ack= , and is an order of
magnitude faster.
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package ag
2015-01-28 16:04:11 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:defer t)
#+END_SRC
** Libraries
*** Dash
A modern list api for Emacs. No 'cl required.
2015-01-28 16:04:11 +00:00
2015-04-30 02:13:51 +00:00
#+name : programming
#+BEGIN_SRC emacs-lisp
(use-package dash
:ensure t
:config (dash-enable-font-lock))
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
* Writing
** Formats
*** Org
**** Modules
2015-01-28 16:04:11 +00:00
#+name : org-module-table
| org-habit |
#+name : packages
#+BEGIN_SRC emacs-lisp :noweb yes
(let ((modules (mapcar (lambda (m) (intern (car m)))
'<<org-module-table() >>)))
(mapcar (lambda (m) (add-to-list 'org-modules m))
modules))
(org-load-modules-maybe t)
#+END_SRC
2015-04-30 02:13:51 +00:00
**** Tasks
***** Keep logs in their own drawer
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(setq org-log-into-drawer t)
#+END_SRC
2015-04-30 02:13:51 +00:00
***** Log completion
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(setq org-log-done 'time)
#+END_SRC
2015-04-30 02:13:51 +00:00
***** Habits
2015-01-28 16:04:11 +00:00
Shift the consistency graph over a bit to make room for task
names.
#+name : packages
#+BEGIN_SRC emacs-lisp
(setq org-habit-graph-column 70)
(setq org-habit-show-habits-only-for-today nil)
#+END_SRC
2015-04-30 02:13:51 +00:00
**** Refiling
2015-01-28 16:04:11 +00:00
#+BEGIN_SRC emacs-lisp
(setq org-refile-targets '((org-agenda-files . (:maxlevel . 6))))
#+END_SRC
2015-04-30 02:13:51 +00:00
**** Babel
***** Syntax highlighting
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(setq-default org-src-fontify-natively t)
#+END_SRC
2015-04-30 02:13:51 +00:00
***** Language evaluation
2014-12-09 23:23:25 +00:00
2015-01-28 16:04:11 +00:00
Org-babel evaluation will be turned on for the following
languages. Setting ~Confirm Evaluation~ to ~No~ disables the
[[http://orgmode.org/manual/Code-evaluation-security.html ][security prompt ]] for that language.
#+name : org-babel-languages
| Language | Alias | Confirm Evaluation? | Description |
|--------------+-------+---------------------+---------------------------------|
| emacs-lisp | | Yes | Emacs Lisp |
| graphviz-dot | dot | No | Directed and undirected graphs |
2015-04-15 17:57:29 +00:00
| gnuplot | | No | Graphs |
2015-01-28 16:04:11 +00:00
| ditaa | | No | Ascii diagrams |
| plantuml | | No | Flow charts |
| mscgen | | No | Message sequence charts |
| haskell | | Yes | A pure, functional language |
| python | | Yes | A dynamic, all-purpose language |
| ruby | | Yes | A dynamic, all-purpose language |
| sh | | Yes | Shell scripts |
#+name : packages
#+BEGIN_SRC emacs-lisp :noweb yes
(defvar my/org-babel-evaluated-languages ())
(defvar my/org-src-lang-modes ())
(defvar my/org-babel-no-confirm-languages ())
(defun my/org-confirm-babel-evaluate (lang body)
(not (member (intern lang) my/org-babel-no-confirm-languages)))
(let ((language-table (cddr '<<org-babel-languages() >>)))
(mapcar (lambda (lang-pair)
(let* ((alias (if (not (string= (cadr lang-pair) "")) (cadr lang-pair)))
(lang (intern (car lang-pair)))
(lang-or-alias (if alias (intern alias) lang))
(confirm (not (string= (cl-caddr lang-pair) "No"))))
(if alias
(add-to-list 'my/org-src-lang-modes (cons alias lang)))
(if (not confirm)
(add-to-list 'my/org-babel-no-confirm-languages lang-or-alias))
(add-to-list 'my/org-babel-evaluated-languages lang-or-alias)
lang-or-alias))
language-table))
(mapcar (lambda (alias)
(add-to-list 'org-src-lang-modes alias))
my/org-src-lang-modes)
(org-babel-do-load-languages
'org-babel-load-languages
(mapcar (lambda (lang)
(cons lang t))
my/org-babel-evaluated-languages))
(setq org-confirm-babel-evaluate 'my/org-confirm-babel-evaluate)
#+END_SRC
2015-04-30 02:13:51 +00:00
*** LaTeX
**** AUCTeX
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package tex-site
:ensure auctex)
#+END_SRC
**** LaTeX-Extra
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package latex-extra
:ensure t
:diminish latex-extra-mode
:commands latex-extra-mode
:init (add-hook 'LaTeX-mode-hook #'latex-extra-mode))
#+END_SRC
*** Markdown
2015-04-30 01:23:30 +00:00
#+name : packages
#+begin_src emacs-lisp
(use-package markdown-mode
:ensure t
:mode "\\.md$")
#+end_src
2015-04-30 02:13:51 +00:00
** Tools
*** Flyspell
2015-04-15 17:57:16 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package flyspell
2015-04-15 17:57:16 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:commands flyspell-mode
:diminish flyspell-mode
:init (mapcar (lambda (mode-hook)
(add-to-list mode-hook #'flyspell-mode))
'(text-mode-hook
org-mode-hook)))
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
*** Unfill
Re-flowing paragraphs with =fill-paragraph= is nice, but there are
occasions when it's useful to do the inverse, and get rid of the line
breaks.
2015-02-03 15:55:29 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package unfill
2015-01-28 16:04:11 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:commands (unfill-paragraph
unfill-region)
:bind ("M-Q" . unfill-paragraph))
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
*** Writegood
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package writegood-mode
:ensure t
:commands writegood-mode
:diminish writegood-mode
:init (mapcar (lambda (mode-hook)
(add-hook mode-hook #'writegood-mode))
'(text-mode-hook
org-mode-hook)))
2015-01-28 16:04:11 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
* Mail
2014-11-12 06:15:33 +00:00
** BBDB
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package bbdb
:ensure t
2015-01-29 02:25:09 +00:00
:init (progn (require 'bbdb)
(bbdb-initialize 'gnus 'message)
(bbdb-mua-auto-update-init 'gnus 'message)
(setq bbdb-message-all-addresses t)
(add-hook 'gnus-summary-mode-hook
(lambda ()
(define-key gnus-summary-mode-map
(kbd ";") 'bbdb-mua-edit-field)))))
2015-01-28 16:04:11 +00:00
#+END_SRC
2014-11-11 06:35:30 +00:00
** Gnus
2015-01-28 16:04:11 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
(use-package gnus
:commands gnus
:init (progn (defun my/configure-gnus ()
<<gnus >>
)
(setq gnus-before-startup-hook 'my/configure-gnus)))
#+END_SRC
2014-11-11 06:35:30 +00:00
*** Avoid rich-text messages
2015-01-28 16:04:11 +00:00
#+name : gnus
#+BEGIN_SRC emacs-lisp
(setq mm-discouraged-alternatives '("text/html" "text/richtext"))
#+END_SRC
2014-11-11 06:35:30 +00:00
*** Summary view formatting
2015-01-28 16:04:11 +00:00
Taken from http://groups.google.com/group/gnu.emacs.gnus/browse_thread/thread/a673a74356e7141f
#+name : gnus
#+BEGIN_SRC emacs-lisp
(when window-system
(setq gnus-sum-thread-tree-indent " ")
(setq gnus-sum-thread-tree-root "") ;; "● ")
(setq gnus-sum-thread-tree-false-root "") ;; "◯ ")
(setq gnus-sum-thread-tree-single-indent "") ;; "◎ ")
(setq gnus-sum-thread-tree-vertical "│")
(setq gnus-sum-thread-tree-leaf-with-other "├─► ")
(setq gnus-sum-thread-tree-single-leaf "╰─► "))
(setq gnus-summary-line-format
(concat
"%0{%U%R%z%}"
"%3{│%}" "%1{%d%}" "%3{│%}" ;; date
" "
"%4{%-20,20f%}" ;; name
" "
"%3{│%}"
" "
"%1{%B%}"
"%s\n"))
(setq gnus-summary-display-arrow t)
#+END_SRC
2014-11-11 06:35:30 +00:00
*** Inline images
2015-01-28 16:04:11 +00:00
#+name : gnus
#+BEGIN_SRC emacs-lisp
(add-to-list 'mm-attachment-override-types "image/.*")
(setq mm-inline-large-images t)
#+END_SRC
2015-04-30 02:13:51 +00:00
* Publishing
** Htmlize
2015-04-23 04:01:49 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package htmlize
2015-04-23 04:01:49 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:defer t
:commands (htmlize-region htmlize-buffer htmlize-file))
2015-04-23 04:01:49 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
* Source Control
** Git-Gutter
2015-04-24 14:23:04 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package git-gutter
2015-04-24 14:23:04 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:diminish git-gutter-mode
:config
(progn
(global-git-gutter-mode t)
(defadvice ediff-make-temp-file (before make-temp-file-suspend-ll
activate compile preactivate)
"Disable git-gutter when running ediff"
(global-git-gutter-mode 0))
(add-hook 'ediff-cleanup-hook
'(lambda ()
(global-git-gutter-mode t)))))
2015-04-02 15:39:37 +00:00
#+END_SRC
2015-04-30 02:13:51 +00:00
** Magit
2015-04-02 15:39:37 +00:00
#+name : packages
#+BEGIN_SRC emacs-lisp
2015-04-30 02:13:51 +00:00
(use-package magit
2015-01-28 16:04:11 +00:00
:ensure t
2015-04-30 02:13:51 +00:00
:diminish magit-auto-revert-mode
:commands (magit-init
magit-status
magit-diff
magit-commit)
:config
(progn
(defadvice magit-status (around magit-fullscreen activate)
(window-configuration-to-register :magit-fullscreen)
ad-do-it
(delete-other-windows))
(defadvice magit-quit-window (around magit-restore-screen activate)
ad-do-it
(jump-to-register :magit-fullscreen))))
2015-01-28 16:04:11 +00:00
2015-04-30 02:13:51 +00:00
(use-package magit-blame
:ensure magit
:commands (magit-blame-mode))
2015-04-03 19:40:41 +00:00
#+END_SRC
2014-11-04 01:38:48 +00:00
* Other functionality
2015-01-05 15:28:26 +00:00
** Disable tab indenting by default
2015-01-28 16:04:11 +00:00
#+name : other
#+BEGIN_SRC emacs-lisp
(setq-default indent-tabs-mode nil)
#+END_SRC
2014-11-04 01:38:48 +00:00
** Rename file and buffer
2015-01-28 16:04:11 +00:00
Taken from [[http://emacsredux.com/blog/2013/05/04/rename-file-and-buffer/ ][Emacs Redux ]]
#+name : other
#+BEGIN_SRC emacs-lisp
;; emacsredux.com
(defun rename-file-and-buffer ()
"Rename the current buffer and file it is visiting."
(interactive)
(let ((filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(message "Buffer is not visiting a file!")
(let ((new-name (read-file-name "New name: " filename)))
(cond
((vc-backend filename) (vc-rename-file filename new-name))
(t
(rename-file filename new-name t)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)))))))
#+END_SRC
2014-11-04 01:38:48 +00:00
** Eval and Replace
2015-01-28 16:04:11 +00:00
Taken from [[http://emacsredux.com/blog/2013/06/21/eval-and-replace/ ][Emacs Redux ]]
#+name : other
#+BEGIN_SRC emacs-lisp
(defun eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(condition-case nil
(prin1 (eval (read (current-kill 0)))
(current-buffer))
(error (message "Invalid expression")
(insert (current-kill 0)))))
(global-set-key (kbd "C-)") 'eval-and-replace)
#+END_SRC
2014-11-04 01:38:48 +00:00
** Smarter navigation to the beginning of a line
2015-01-28 16:04:11 +00:00
Taken from [[http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/ ][Emacs Redux ]]
#+name : other
#+BEGIN_SRC emacs-lisp
(defun smarter-move-beginning-of-line (arg)
"Move point back to indentation of beginning of line.
Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.
If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there."
(interactive "^p")
(setq arg (or arg 1))
;; Move lines first
(when (/= arg 1)
(let ((line-move-visual nil))
(forward-line (1- arg))))
(let ((orig-point (point)))
(back-to-indentation)
(when (= orig-point (point))
(move-beginning-of-line 1))))
;; remap C-a to `smarter-move-beginning-of-line'
(global-set-key [remap move-beginning-of-line]
'smarter-move-beginning-of-line)
#+END_SRC
2014-11-04 01:38:48 +00:00
** Edit file with sudo
2015-01-28 16:04:11 +00:00
Taken from [[http://www.emacswiki.org/TrampMode#toc32 ][EmacsWiki ]]
#+name : other
#+BEGIN_SRC emacs-lisp
(require 'dired)
(defun sudo-edit-current-file ()
(interactive)
(let ((my-file-name) ; fill this with the file to open
(position)) ; if the file is already open save position
(if (equal major-mode 'dired-mode) ; test if we are in dired-mode
(progn
(setq my-file-name (dired-get-file-for-visit))
(find-alternate-file (prepare-tramp-sudo-string my-file-name)))
(setq my-file-name (buffer-file-name); hopefully anything else is an already opened file
position (point))
(find-alternate-file (prepare-tramp-sudo-string my-file-name))
(goto-char position))))
(defun prepare-tramp-sudo-string (tempfile)
(if (file-remote-p tempfile)
(let ((vec (tramp-dissect-file-name tempfile)))
(tramp-make-tramp-file-name
"sudo"
(tramp-file-name-user nil)
(tramp-file-name-host vec)
(tramp-file-name-localname vec)
(format "ssh:%s@%s|"
(tramp-file-name-user vec)
(tramp-file-name-host vec))))
(concat "/sudo:root@localhost:" tempfile)))
(define-key dired-mode-map [s-return] 'sudo-edit-current-file)
#+END_SRC
2014-11-12 06:12:46 +00:00
** Backups
2015-01-28 16:04:11 +00:00
Borrowed from Sacha Chua
https://github.com/sachac/ .emacs.d/
2014-11-12 06:12:46 +00:00
2015-01-28 16:04:11 +00:00
This is one of the things people usually want to change right away. By default, Emacs saves backup files in the current directory. These are the files ending in =~= that are cluttering up your directory lists. The following code stashes them all in =~/.emacs.d/backups= , where I can find them with =C-x C-f= (=find-file= ) if I really need to.
2014-11-12 06:12:46 +00:00
2015-01-28 16:04:11 +00:00
#+name : other
#+begin_src emacs-lisp
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
#+end_src
2014-11-12 06:12:46 +00:00
2015-01-28 16:04:11 +00:00
Disk space is cheap. Save lots.
2014-11-12 06:12:46 +00:00
2015-01-28 16:04:11 +00:00
#+name : other
#+begin_src emacs-lisp
(setq delete-old-versions -1)
(setq version-control t)
(setq vc-make-backup-files t)
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/ " t)))
#+end_src
2014-11-12 06:12:46 +00:00
** History
2015-01-28 16:04:11 +00:00
From http://www.wisdomandwonder.com/wordpress/wp-content/uploads/2014/03/C3F.html
#+name : other
#+begin_src emacs-lisp
(setq savehist-file "~/.emacs.d/savehist")
(savehist-mode 1)
(setq history-length t)
(setq history-delete-duplicates t)
(setq savehist-save-minibuffer-history 1)
(setq savehist-additional-variables
'(kill-ring
search-ring
regexp-search-ring))
#+end_src
2014-11-12 06:12:46 +00:00
** Copy filename to clipboard
2015-01-28 16:04:11 +00:00
http://emacsredux.com/blog/2013/03/27/copy-filename-to-the-clipboard/
https://github.com/bbatsov/prelude
#+name : other
#+begin_src emacs-lisp
(defun prelude-copy-file-name-to-clipboard ()
"Copy the current buffer file name to the clipboard."
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(when filename
(kill-new filename)
(message "Copied buffer file name '%s' to the clipboard." filename))))
#+end_src
2015-04-19 05:16:40 +00:00
** Prompt for 'y or n' instead of 'yes or no'
Because typing out "yes" and "no" is irritating.
#+name : other
#+BEGIN_SRC emacs-lisp
(defalias 'yes-or-no-p #'y-or-n-p)
#+END_SRC
2014-11-04 01:38:48 +00:00
* Custom settings
2015-01-28 16:04:11 +00:00
Store options set via =customize-*= in a separate file (Emacs stores
them in =init.el= by default).
#+name : custom-settings
#+BEGIN_SRC emacs-lisp
(setq custom-file "~/.emacs.d/custom.el")
(if (file-exists-p custom-file)
(load custom-file))
#+END_SRC
2014-11-04 01:38:48 +00:00
* Auto-loading elisp files
2015-01-28 16:04:11 +00:00
Any elisp files dropped into =~/.emacs.local.d/= will be
automatically loaded.
I usually use this is a testing ground for new configuration before
adding it here, and also for any personal / sensitive configuration.
#+name : auto-load
#+BEGIN_SRC emacs-lisp
(defun my/load-elisp-directory (path)
(let ((file-pattern "\\.elc?$"))
(when (file-directory-p path)
(mapcar (lambda (lisp-file)
(load-file lisp-file))
(directory-files (expand-file-name path) t file-pattern)))))
(my/load-elisp-directory "~/ .emacs.local.d")
#+END_SRC
2014-11-04 01:38:48 +00:00
* Configuration file layout
2015-01-28 16:04:11 +00:00
Here I define the emacs.el file that gets generated by the code in
this org file.
#+BEGIN_SRC emacs-lisp :tangle yes :noweb no-export :exports code
;;;; Do not modify this file by hand. It was automatically generated
;;;; from `emacs.org` in the same directory. See that file for more
;;;; information.
;;;;
<<startup >>
<<look-and-feel >>
<<packages >>
<<programming >>
2015-04-24 14:23:04 +00:00
<<autocomplete >>
2015-01-28 16:04:11 +00:00
<<other >>
<<auto-load >>
<<custom-settings >>
#+END_SRC