Optimization
Set the number of bytes of consing before garbage collection Small hack to make the init time a bit faster
(setq gc-cons-threshold 100000000)Folder Structure
Set the default load-directory
(let ((default-directory "~/.emacs.d/"))
(normal-top-level-add-subdirs-to-load-path))Since init.el is generated from init.org, I don’t want customize writing to init.org. Define a separate file for customized variables and faces:
(setq custom-file "~/.emacs.d/customized.el")
(load custom-file)Packages
(require 'package)
(setq package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(package-initialize)Install all necessary packages
(defun install-packages (packages)
(when (not (null packages))
(let ((pkg (car packages)))
(unless (package-installed-p 'pkg)
(package-install pkg))
(install-packages (cdr packages)))))
(defun initial-install ()
(interactive)
(install-packages package-selected-packages))Load use-package
(require 'use-package)Environments
(setenv "GOROOT" "/usr/local/go")
(setenv "EDITOR" "emacs")
(setenv "VISUAL" "emacs")
(setenv "PATH" (concat (getenv "PATH") ":" (expand-file-name "~/bin")))
(setenv "PATH" (concat (getenv "PATH") ":" "/usr/local/go/bin"))
(setenv "GOPATH" (if (getenv "GOPATH") (getenv "GOPATH") (getenv "HOME")))
(setenv "DOT" (expand-file-name "~/dot"))
(setq exec-path
(append exec-path
'("/usr/local/go/bin" "/home/satran/bin" "/home/satran/scripts")))Behaviour
Automatically tangle init.org so that it generates init.el
(defun tangle-init ()
"If the current buffer is 'init.org' the code-blocks are
tangled, and the tangled file is compiled."
(when (equal (buffer-file-name)
(expand-file-name
(concat (file-name-as-directory (getenv "DOT"))
"emacs/init.org")))
;; Avoid running hooks when tangling.
(let ((prog-mode-hook nil))
(org-babel-tangle))))
(add-hook 'after-save-hook 'tangle-init)These are a few settings that I believe simplify keybindings or enable those that are by default disabled.
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'dired-find-alternate-file 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)Set the window title to be the buffer
(setq frame-title-format "%b")Set the window frame size
(add-to-list 'default-frame-alist '(height . 50))
(add-to-list 'default-frame-alist '(width . 84))Automatically indent code after RET
(electric-indent-mode +1)Have those awesome matching pairs
(electric-pair-mode t)Highlight matching parenthesis
(show-paren-mode 1)Settings for enforcing to use UNIX endlines
(set-default-coding-systems 'utf-8-unix)
(prefer-coding-system 'utf-8-unix)
;;(set-default default-buffer-file-coding-system 'utf-8-unix)Set such that emacs does not use the ugly word-wrapping
(global-visual-line-mode 1)Show time in the mode line
(display-time-mode t)Use vertical splitting more often than horizontal
(setq split-height-threshold 200)C-v and M-v don’t undo each other, because the point position isn’t preserved. Fix that.
(setq scroll-preserve-screen-position 'always)Do not pollute the working directory. Add it to emacs folder.
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
(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)))Custom function to split frame into 3 windows evenly
(defun split-3-even ()
"split frame into 3 even windows"
(interactive)
(dotimes (number 2)
(split-window-right))
(balance-windows))Save history
(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))When you start typing and text is selected, replace it with what you are typing, or pasting, or whatever.
(delete-selection-mode 1)Change typing yes to y and no to n in minibuffer
(fset 'yes-or-no-p 'y-or-n-p)Disable beep when doing incorrect actions
(setq ring-bell-function 'ignore)Looks
Custom font
(set-default-font "-*-terminus-*-*-*-*-24-*-*-*-*-*-*-*")Use gtk tooltips when available
(setq x-gtk-use-system-tooltips t)Set columns
(column-number-mode 1)Disable splash screen
(setq inhibit-startup-message t)Set the cursor to a bar
(setq-default cursor-type 'bar)Highlighting current line
(global-hl-line-mode 1)Clean up the UI, no menubar, scrollbars and toolbar
(add-to-list 'default-frame-alist '(menu-bar-lines . 0))
(add-to-list 'default-frame-alist '(tool-bar-lines . 0))
(add-to-list 'default-frame-alist '(vertical-scroll-bars . nil))Disable the gaudy colors in shell
(setq ansi-color-names-vector ; better contrast colors
["black" "red4" "chartreuse4" "goldenrod3"
"DodgerBlue4" "magenta4" "cyan4" "white"])
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)This is specifically for stumpwm and ratpoison. The annoying space between frames.
(setq frame-resize-pixelwise t)Adding custom theme directory and include elpa themes as well
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(add-to-list 'custom-theme-load-path "~/.emacs.d/elpa")Solarized theme specific variables
(setq solarized-scale-org-headlines nil)
(setq solarized-use-less-bold t)
(setq solarized-use-more-italic nil)
(setq solarized-emphasize-indicators nil)
(setq solarized-scale-org-headlines nil)
(setq solarized-use-variable-pitch nil)Cycle between a dark and light theme
(setq dark-theme 'gotham)
(setq light-theme 'github)
(setq current-theme light-theme)
(defun flip-color ()
"Flip the color theme"
(interactive)
(disable-theme current-theme)
(setq current-theme
(if (equal current-theme dark-theme) light-theme dark-theme))
(load-theme current-theme t))
(load-theme current-theme t)Use variable font faces in certain buffer
(defun looks/set-variable-font ()
"Sets a variable font in current buffer"
(interactive)
(setq buffer-face-mode-face '(:family "Cantarell"))
(buffer-face-mode))
(add-hook 'Info-mode-hook 'looks/set-variable-font)
(add-hook 'org-mode-hook 'looks/set-variable-font)Autocomplete
(use-package auto-complete-config
:config (ac-config-default))
;; Bash completion
(use-package bash-completion
:config (bash-completion-setup))Languages
C
Set C style to k&r
(setq c-default-style "linux")CTags settings
(setq path-to-ctags "/usr/bin/etags")
(defun create-tags (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(let ((full-dir-name (directory-file-name dir-name)))
(shell-command
(format "find %s -iname \"*.[c,h]\" | xargs %s -f %s/TAGS -R"
full-dir-name path-to-ctags full-dir-name))))Better GDB settings
(setq gdb-many-windows t)Eldoc mode for C
(use-package c-eldoc
:config (setq c-eldoc-includes "`pkg-config glib-2.0 tokyocabinet --cflags` -I./ -I../ ")
(load "c-eldoc")
(add-hook 'c-mode-hook 'c-turn-on-eldoc-mode))Clojure
(use-package cider
:config
(add-hook 'cider-mode-hook #'eldoc-mode)
(add-hook 'clojurescript-mode #'paredit-mode)
(add-hook 'clojure-mode-hook #'paredit-mode))CSV
(add-hook 'csv-mode-hook (lambda () (visual-line-mode nil)))Go
Go tools required for go mode to function correctly
go get -u github.com/rogpeppe/godef
go get -u github.com/nsf/gocode
go get -u golang.org/x/tools/cmd/goimports(use-package go-eldoc)
(use-package go-autocomplete)
(use-package go-mode
:config
(setq gofmt-command "goimports")
(add-hook 'before-save-hook 'gofmt-before-save)
(add-hook 'go-mode-hook 'flycheck-mode)
(add-hook 'go-mode-hook 'go-eldoc-setup)
(add-hook 'go-mode-hook (lambda ()
(local-set-key (kbd "C-c C-r") 'go-remove-unused-imports)))
(add-hook 'go-mode-hook (lambda ()
(local-set-key (kbd "C-c i") 'go-goto-imports)))
(add-hook 'go-mode-hook (lambda ()
(local-set-key (kbd "M-.") 'godef-jump)))
(add-hook 'go-mode-hook (lambda ()
(local-set-key (kbd "M-,") 'godef-jump-other-window))))
;;(add-hook 'go-mode-hook (lambda () (define-key evil-normal-state-map "g." 'godef-jump)))
;;(add-hook 'go-mode-hook (lambda () (define-key evil-normal-state-map "g," 'godef-jump-other-window)))Utility to run tests when the file changes
(require 'filenotify)
(defun go-files? (files)
(if (null files)
nil
(if (string-match "^[^\.].*\.go$" (file-name-nondirectory (car files))) t
(go-files? (cdr files)))))
(defvar-local go-test-process "go-test")
(defvar-local go-test-process-buffer "go-test")
(defun run-go-tests (event)
(if (go-files? (cdr (cdr event)))
(let ((bf (get-buffer go-test-process-buffer)))
(when (not (null bf))
(if (null (get-process go-test-process-buffer))
(start-process go-test-process go-test-process-buffer "go" "test" "-v" "./...")))
(temp-buffer-window-show go-test-process-buffer))))
(defun run-tests-on-change ()
(interactive)
(get-buffer-create go-test-process-buffer)
(file-notify-add-watch
(substring (pwd) 10) '(change) 'run-go-tests))Lisp
(add-to-list 'load-path "/bin/sbcl")
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
(setq inferior-lisp-program "/bin/sbcl")
(use-package paredit
:config
(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t))
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)
;;(load (expand-file-name "~/quicklisp/slime-helper.el"))
Python
(require 'python)
(setq python-shell-interpreter "ipython")
(setq python-shell-interpreter-args "--simple-prompt -i")
(use-package elpy)
(add-hook 'python-mode-hook 'elpy-enable)
(add-hook 'python-after-save-hook 'elpy-format-code)Mu4e
(add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e")
(require 'mu4e)
(require 'org-mu4e)
(setq org-mu4e-link-query-in-headers-mode nil)
;; default
(setq mu4e-maildir "~/mail")
(require 'mu4e-contrib)
(setq mu4e-html2text-command 'mu4e-shr2text)
(setq mu4e-html2text-command "html2text --reference-links")
(setq mu4e-get-mail-command "true"
mu4e-update-interval 300)
(setq mu4e-headers-fields (quote ((:subject . 50) (:human-date . 12) (:from-or-to . 18))))
(setq mu4e-view-show-images t)
(when (fboundp 'imagemagick-register-types)
(imagemagick-register-types))
(setq mu4e-headers-visible-columns 80)
;;(setq mu4e-headers-include-related t)
(setq mu4e-headers-skip-duplicates t)
(setq mu4e-headers-visible-columns 80)
(setq mu4e-split-view (quote horizontal))
(setq mu4e-view-fields (quote (:from :subject :date :tags :attachments)))
;; don't save message to Sent Messages, Gmail/IMAP takes care of this
(setq mu4e-sent-messages-behavior 'delete)
(setq mu4e-maildir-shortcuts
'(("/ranjeev/INBOX" . ?i)
("/ranjeev/[Gmail].All Mail" . ?a)))
;; something about ourselves
(setq
user-full-name "Satyajit Ranjeev"
mu4e-compose-signature
(concat
"satran\n"
"http://satran.in\n"))
(setq mu4e-drafts-folder "/ranjeev/[Gmail].Drafts"
mu4e-sent-folder "/ranjeev/[Gmail].Sent Mail"
mu4e-trash-folder "/ranjeev/[Gmail].Trash"
user-mail-address "s@ranjeev.in")
(defvar my-mu4e-account-alist
'(("ranjeev"
(mu4e-drafts-folder "/ranjeev/[Gmail].Drafts")
(mu4e-sent-folder "/ranjeev/[Gmail].Sent Mail")
(mu4e-trash-folder "/ranjeev/[Gmail].Trash")
(user-mail-address "s@ranjeev.in")
(smtpmail-smtp-user "s@ranjeev.in"))))
(require 'smtpmail)
;; alternatively, for emacs-24 you can use:
(setq message-send-mail-function 'smtpmail-send-it
smtpmail-stream-type 'starttls
smtpmail-default-smtp-server "smtp.gmail.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587)
;; don't keep message buffers around
(setq message-kill-buffer-on-exit t)
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(let* ((account
(if mu4e-compose-parent-message
(let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
(string-match "/\\(.*?\\)/" maildir)
(match-string 1 maildir))
(completing-read (format "Compose with account: (%s) "
(mapconcat #'(lambda (var) (car var))
my-mu4e-account-alist "/"))
(mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
nil t nil nil (caar my-mu4e-account-alist))))
(account-vars (cdr (assoc account my-mu4e-account-alist))))
(if account-vars
(mapc #'(lambda (var)
(set (car var) (cadr var)))
account-vars)
(error "No email account found"))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
Modes
ERC
(defun jmn-erc-format-nick (&optional user channel-data)
"Like `erc-format-nick' but trim/pad nick to a fixed length.
- Based on xwl-erc-format-nick"
(let ((nick (erc-format-nick user channel-data)))
(setq nick (substring nick 0 5))
(setq nick (format "%5s" nick))
nick))
;; Use with below (or customize):
(setq erc-format-nick-function 'jmn-erc-format-nick)
(defun start-irc ()
"Connect to IRC."
(interactive)
(erc-tls :server "irc.freenode.net" :port 6697
:nick "satran" :full-name "Satyajit Ranjeev"))
EWW
(setq eww-search-prefix "https://google.com/search?q=")
(defalias 'gk-urls-external-browser 'browse-url-xdg-open)
(defun gk-browse-url (&rest args)
"Prompt for whether or not to browse with EWW, if no browse
with external browser."
(apply
(if (y-or-n-p "Browse with EWW? ")
'eww-browse-url
'gk-urls-external-browser)
args))
(setq browse-url-browser-function #'gk-browse-url)Ibuffer
(setq ibuffer-saved-filter-groups
(quote (("default"
("go" (mode . go-mode))
("dired" (mode . dired-mode))
("org" (name . "^.*org$"))
("shell" (or (mode . eshell-mode) (mode . shell-mode)))
("emacs-conf" (mode . emacs-lisp-mode))
("emacs" (or
(name . "^\\*scratch\\*$")
(name . "^\\*Completions\\*$")
(name . "^\\*Messages\\*$")))
))))
(add-hook 'ibuffer-mode-hook
(lambda ()
(ibuffer-auto-mode 1)
(ibuffer-switch-to-saved-filter-groups "default")))
;; Don't show filter groups if there are no buffers in that group
(setq ibuffer-show-empty-filter-groups nil)
;; Don't ask for confirmation to delete marked buffers
(setq ibuffer-expert t)Org
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(add-hook 'org-mode-hook 'turn-on-font-lock)
(add-hook 'org-mode-hook 'auto-fill-mode)
(add-hook 'org-mode-hook 'org-indent-mode)
(setq org-log-done t)
(setq org-catch-invisible-edits t)
(use-package org-bullets
:config
(setq org-bullets-bullet-list (quote ("○" "◦" "•" "•" "•")))
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
(setq org-babel-default-header-args (cons '(:padline . "no") (assq-delete-all :padline org-babel-default-header-args)))
(setq org-agenda-files '("/ssh:satran.hopto.org#1223:~/org/log.org"))
;;(setq org-refile-targets
;; '((nil :maxlevel . 3)
;; (org-agenda-files :maxlevel . 3)))
(setq org-default-notes-file "/ssh:satran.hopto.org#1223:~/org/log.org")
(setq org-capture-templates
'(("t" "todo" entry (file+datetree "/ssh:satran.hopto.org#1223:~/org/log.org")
"* TODO %?\n")
("l" "log" entry (file+datetree "/ssh:satran.hopto.org#1223:~/org/log.org")
"* %?\n")
("n" "note" entry (file "/ssh:satran.hopto.org#1223:~/org/log.org")
"* %?\n")
("m" "TODO with link" entry (file+datetree "/ssh:satran.hopto.org#1223:~/org/log.org")
"* TODO %?, Link: %a")
("s" "schedule" entry (file+datetree+prompt "/ssh:satran.hopto.org#1223:~/org/log.org")
"* SCH %?\nSCHEDULED: %T\n")))
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(sh . t)))
(setq org-todo-keywords
'((sequence "TODO" "SCH" "SOMEDAY" "|" "DONE" "CANCELLED")))Shell
(setq eshell-directory-name "/home/satran/.emacs.d/eshell")
(setq eshell-prompt-function (lambda () (concat "% ")))
(setq eshell-prompt-regexp "% ")
(defun eshell-clear-buffer ()
"Clear terminal"
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)
(eshell-send-input)))
(add-hook 'eshell-mode-hook
'(lambda()
(local-set-key (kbd "C-S-l") 'eshell-clear-buffer)))
;; Disable hl-line for eshell and ansi-terms
(add-hook 'eshell-mode-hook
(lambda ()
(setq-local global-hl-line-mode nil)
(font-lock-mode t)))
(add-hook 'term-mode-hook
(lambda () (setq-local global-hl-line-mode nil)))
(add-hook 'term-mode-hook
(lambda () (font-lock-mode t)))
(add-hook 'shell-mode-hook
(lambda ()
(font-lock-mode t)
(local-set-key (kbd "M-n") 'comint-next-matching-input-from-input)))
(add-hook 'shell-mode-hook
(lambda () (local-set-key (kbd "M-p") 'comint-previous-matching-input-from-input)))
;; Have shell open in the same window
;; (add-to-list 'display-buffer-alist
;; '("^\\*shell\\*$" . (display-buffer-same-window)))
(defvar name-counter 0)
(defun new-shell-name ()
(setq name-counter (+ 1 name-counter))
(concat "shell-" (number-to-string name-counter)))
(defun new-shell ()
(interactive)
(shell (new-shell-name)))
(global-set-key (kbd "C-S-z") 'new-shell)
(defvar previous-command nil)
(defun replace-with-shell-output ()
(interactive)
(let ((cmd (read-shell-command "Shell command on region: " previous-command))
(buffer (current-buffer)))
(setq previous-command cmd)
(shell-command-on-region
(region-beginning) (region-end) cmd buffer t)))
(global-set-key (kbd "<M-return>") 'replace-with-shell-output)
(autoload 'bash-completion-dynamic-complete
"bash-completion"
"BASH completion hook")
(add-hook 'shell-dynamic-complete-functions
'bash-completion-dynamic-complete)
Epub
(push '("\\.epub\\'" . nov-mode) auto-mode-alist)GodMode
Set Alt-Space to activate god-mode and i to exit out of it.
(use-package god-mode
:config
(global-set-key (kbd "M-SPC") 'god-local-mode)
(define-key god-local-mode-map (kbd "i") 'god-local-mode)
(add-hook 'god-mode-enabled-hook 'my-update-cursor)
(add-hook 'god-mode-disabled-hook 'my-update-cursor))Change the cursor type based on whether god-mode is tangled
(defun my-update-cursor ()
(setq cursor-type (if (or god-local-mode buffer-read-only)
'box
'bar)))Dired
Do what I Mean to true
(setq dired-dwim-target t)(use-package dired-details
:config (dired-details-install)
(setq dired-details-hidden-string " --- "))For all the 4k monitors set the resolution high
(setq doc-view-resolution 300)
(use-package pdf-tools
:config (pdf-tools-install))Helm
(use-package helm
:init (setq helm-M-x-fuzzy-match t)
:config (helm-mode 1)
:bind (("M-x" . helm-M-x)
("C-x r b" . helm-filtered-bookmarks)
("C-x C-f" . helm-find-files)))IDO
(ido-mode t)
(use-package ido-vertical-mode
:config (ido-vertical-mode 1))
;; Do the fuzzy matching bit
(setq ido-enable-flex-matching t)
;; Preventing auto-searches unless called explicitly
(setq ido-auto-merge-work-directories-length -1)
;; disable auto searching for files unless called explicitly
(setq ido-auto-merge-delay-time 99999)
;; Keybindings to move up and down similar to emacs buffers
(setq ido-vertical-define-keys (quote C-n-C-p-up-down-left-right))
;; Smex
(use-package smex
:config (autoload 'smex "smex")
:bind (("M-x" . smex)))Neo
(use-package neotree
:config
(global-set-key [f12] 'neotree-toggle)
(setq neo-theme 'arrow))Keybindings
;; Full screen in Linux
(defun fullscreen ()
(interactive)
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen) nil 'fullboth))
(progn
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) ;; no toolbar
(menu-bar-mode -1) ;;no menubar
(scroll-bar-mode -1) ;; no scroll bar
))
;; Move past a given character, like vims f
(defun move-past-next-char (x)
"Move the next occurrence of the character x"
(interactive "k")
(search-forward x))
;; Global Keybindings
(global-set-key (kbd "C-z") 'shell)
(global-set-key (kbd "C-M-z") 'ansi-term)
(global-set-key (kbd "C-x C-j") 'next-buffer)
(global-set-key (kbd "C-x C-k") 'previous-buffer)
(global-set-key (kbd "C-x g") 'magit-status)
;; Settings keybindings for Scroll line by line.
(global-set-key (kbd "C-M-g") 'scroll-up-line)
(global-set-key (kbd "C-M-y") 'scroll-down-line)
(global-set-key (kbd "C-S-f") 'speedbar-get-focus)
;; Shortcut for compiling
(global-set-key [(f9)] 'compile)
;; More reasonable next windows
(global-set-key "\C-x\C-n" 'next-multiframe-window)
(global-set-key "\C-x\C-p" 'previous-multiframe-window)
(global-set-key (kbd "C-x n") 'next-multiframe-window)
(global-set-key (kbd "C-x p") 'previous-multiframe-window)
(global-set-key "\C-\M-f" 'move-past-next-char)
(global-set-key (kbd "<C-return>") 'plumb)
(global-set-key [f11] 'fullscreen)
(global-set-key (kbd "M-[") 'insert-pair)
(global-set-key (kbd "M-{") 'insert-pair)
(global-set-key (kbd "M-\"") 'insert-pair)
;; Move across split windows using the shit+arrow keys
(windmove-default-keybindings)
(global-set-key (kbd "C-x C-b") 'ibuffer)Functions
;; A lot of times I have tried quitting emacs and then realized that I
;; forgot to do something to a buffer. This is to fix it. Source
;; [[http://trey-jackson.blogspot.de/2010/04/emacs-tip-36-abort-minibuffer-when.html][here]]
(defun stop-using-minibuffer ()
"kill the minibuffer"
(when (and (>= (recursion-depth) 1) (active-minibuffer-window))
(abort-recursive-edit)))
(add-hook 'mouse-leave-buffer-hook 'stop-using-minibuffer)
(defun move-line (n)
"Move the current line up or down by N lines."
(interactive "p")
(setq col (current-column))
(beginning-of-line) (setq start (point))
(end-of-line) (forward-char) (setq end (point))
(let ((line-text (delete-and-extract-region start end)))
(forward-line n)
(insert line-text)
;; restore point to original column in moved line
(forward-line -1)
(forward-char col)))
(defun move-line-up (n)
"Move the current line up by N lines."
(interactive "p")
(move-line (if (null n) -1 (- n))))
(defun move-line-down (n)
"Move the current line down by N lines."
(interactive "p")
(move-line (if (null n) 1 n)))
(global-set-key (kbd "M-<up>") 'move-line-up)
(global-set-key (kbd "M-<down>") 'move-line-down)Shortcuts to open files
(defun shortcuts/open-log ()
(interactive)
(find-file org-default-notes-file))
(defun shortcuts/open-emacs-init ()
(interactive)
(find-file "~/.emacs.d/init.org"))Plan 9
;;; plumb.el implements plumbing similar to plan9
(defun re-seq (regexp string)
"Get a list of all regexp matches in a string"
(save-match-data
(let ((pos 0)
matches)
(while (string-match regexp string pos)
(push (match-string 0 string) matches)
(setq pos (match-end 0)))
matches)))
(defun plumb ()
"sort of the plumber found in plan9"
(interactive)
(let ((file "")
(line-no 1)
(input (thing-at-point 'line))
(regexp "\\([_~0-9a-zA-Z\-\\.\\/]+\\):\?\\([0-9]*\\)"))
(dolist (line (re-seq regexp input))
(message "%s" line)
(string-match regexp line)
(setq file (match-string 1 line))
(setq line-no (match-string 2 line))
(if (and (not (string-equal file "")) (file-exists-p file))
(progn
(message "%s:%s" file line-no)
(find-file-other-window file)
(beginning-of-buffer)
(if line-no (forward-line (- (string-to-number line-no) 1))))))))
(defun git-diff (&optional name)
(interactive)
(shell-command (concat "git diff " name)
(switch-to-buffer (make-temp-name "diff")))
(diff-mode))Vi keybindings
(evil-mode t)
(define-key evil-normal-state-map " xs" 'save-buffer)
(define-key evil-normal-state-map " xk" 'kill-buffer)
(define-key evil-normal-state-map " xf" 'find-file)
(define-key evil-normal-state-map " xb" 'ido-switch-buffer)
(define-key evil-normal-state-map " xn" 'next-multiframe-window)
(define-key evil-normal-state-map " xp" 'previous-multiframe-window)
(define-key evil-normal-state-map " x0" 'delete-window)
(define-key evil-normal-state-map " x1" 'delete-other-windows)
(define-key evil-normal-state-map " x2" 'split-window-below)
(define-key evil-normal-state-map " x3" 'split-window-right)
(define-key evil-normal-state-map " x " 'pop-global-mark)
(define-key evil-normal-state-map ":" 'smex)
(define-key evil-normal-state-map "\C-z" 'shell)
(define-key evil-normal-state-map "\C-v" 'scroll-up)
(define-key evil-normal-state-map "\C-e" 'end-of-line)Use emacs state rather than insert mode of evil https://stackoverflow.com/questions/25542097/emacs-evil-mode-how-to-change-insert-state-to-emacs-state-automatically#28985130
(setq evil-insert-state-map (make-sparse-keymap))
(define-key evil-insert-state-map (kbd "<escape>") 'evil-normal-state)
(define-key evil-insert-state-map (kbd "M-SPC") 'evil-normal-state)References
Things I am just figuring out
Transpose two lines C-x C-t Transpose two words M-t