Skip to content

Instantly share code, notes, and snippets.

@mookerji
Created February 16, 2014 23:23
Show Gist options
  • Save mookerji/9042119 to your computer and use it in GitHub Desktop.
Save mookerji/9042119 to your computer and use it in GitHub Desktop.
; .emacs file
; Bhaskar Mookerji
;
; Started: Sunday, 3 October 2010
;;;
;;; Static configuration stuff
;;;
(winner-mode 1)
(setq ring-bell-function 'ignore)
; enable syntax highlighting and other formatting functions
(require 'font-lock)
(setq-default fill-column 79)
; Set font:
; http://www.emacswiki.org/emacs/SetFonts
(when (eq system-type 'darwin)
(set-face-attribute 'default nil :family "Inconsolata" :height 145)
)
;; (when (eq system-type 'darwin)
;; (set-face-attribute 'default nil :family "Inconsolata" :height 210)
;; )
;; LaTeX
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master)
;; Setup linenumbers
(global-linum-mode 1)
;; Desktop save mode
;; (setq desktop-save 'if-exists)
;; (desktop-save-mode 1)
(setq desktop-globals-to-save
(append '((extended-command-history . 30)
(file-name-history . 100)
(grep-history . 30)
(compile-history . 30)
(minibuffer-history . 50)
(query-replace-history . 60)
(read-expression-history . 60)
(regexp-history . 60)
(regexp-search-ring . 20)
(search-ring . 20)
(shell-command-history . 50)
tags-file-name
register-alist)))
;; use only one desktop
(setq desktop-path '("~/.emacs.d/"))
(setq desktop-dirname "~/.emacs.d/")
(setq desktop-base-file-name "emacs-desktop")
;; remove desktop after it's been read
(add-hook 'desktop-after-read-hook
'(lambda ()
;; desktop-remove clears desktop-dirname
(setq desktop-dirname-tmp desktop-dirname)
(desktop-remove)
(setq desktop-dirname desktop-dirname-tmp)))
(defun saved-session ()
(file-exists-p (concat desktop-dirname "/" desktop-base-file-name)))
;; use session-restore to restore the desktop manually
(defun session-restore ()
"Restore a saved emacs session."
(interactive)
(if (saved-session)
(desktop-read)
(message "No desktop found.")))
;; use session-save to save the desktop manually
(defun session-save ()
"Save an emacs session."
(interactive)
(if (saved-session)
(if (y-or-n-p "Overwrite existing desktop? ")
(desktop-save-in-desktop-dir)
(message "Session not saved."))
(desktop-save-in-desktop-dir)))
;; ask user whether to restore desktop at start-up
(add-hook 'after-init-hook
'(lambda ()
(if (saved-session)
(if (y-or-n-p "Restore desktop? ")
(session-restore)))))
;; End desktop save mode.
; http://www-users.math.umd.edu/~halbert/dotemacs.html
;; Remove toolbar
(tool-bar-mode -1)
;; Make initial frame as tall as possible
(setq initial-frame-alist '((top . 1) (height . 63)))
(setq column-number-mode t)
;;;
;;; https://sites.google.com/site/steveyegge2/effective-emacs
; Item 1: Swap Caps-Lock and Control
;; Done in OS X
; Item 2: Invoke M-x without the Alt key
(global-set-key "\C-x\C-m" 'execute-extended-command)
(global-set-key "\C-c\C-m" 'execute-extended-command)
; Item 3: Prefer backward-kill-word over Backspace
(global-set-key "\C-w" 'backward-kill-word)
(global-set-key "\C-h" 'delete-backward-char)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)
; Item 4: Use incremental search for Navigation
(global-set-key "\C-x:" 'goto-line)
; Item 5: Use Temp Buffers
;; C-x b + name -> create buffer
; Item 6: Master the buffer and window commands
;; Ctrl-x 2: split-window-vertically
;; Ctrl-x 3: split-window-horizontally
;; Ctrl-x +: balance-windows -- makes all visible windows approximately
;; equal height.
;; Ctrl-x o: other-window
;; Ctrl-x 1: delete-other-windows
;; Ctrl-x Ctrl-b: list-buffers
; Item 7: Lose the UI
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;; (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;; (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
; Item 8: Learn the most important help functions
; Item 9: Master Emacs's regular expressions
(defalias 'qrr 'query-replace-regexp)
(global-set-key "\M-^" 'query-replace-regexp)
; Item 10: Master the fine-grained text manipulation commands
(global-set-key [f5] 'call-last-kbd-macro)
;;;
;; Use ibuffer
(defalias 'list-buffers 'ibuffer)
(iswitchb-mode 1)
; Highlight the current line
(global-hl-line-mode 1)
(setq c-basic-offset 2)
(setq default-tab-width 4)
(setq-default indent-tabs-mode nil)
; When switching branches, this updates emacs version from disk.
(global-auto-revert-mode 1)
; remove whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Org-mode
;; The following lines are always needed. Choose your own keys.
;; Any file that ends with .org will be opened in org-mode
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
; toggle window split
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
(define-key ctl-x-4-map "t" 'toggle-window-split)
;;;
;;; Package management
;;;
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(defun ensure-packages (ps)
(dolist (p ps)
(when (not (package-installed-p p))
(package-install p))))
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar my-packages '(clojure-mode
clojure-test-mode
paredit
magit
markdown-mode
color-theme
color-theme-solarized
rainbow-delimiters
auto-complete
pkg-info
dash
cider
clojure-cheatsheet
ido-hacks
ac-nrepl
ibuffer-vc
idle-highlight-mode))
(ensure-packages my-packages)
; Solarized stuff.
(require 'color-theme)
(require 'color-theme-solarized)
(load-theme 'solarized-dark t)
(require 'auto-complete-config)
(ac-config-default)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
;;; Clojure and Java stuff
(require 'clojure-mode)
(add-hook 'clojure-mode-hook 'paredit-mode)
(setq inferior-lisp-program "/usr/local/bin/lein repl")
(defun turn-on-paredit () (paredit-mode 1))
(add-hook 'clojure-mode-hook 'turn-on-paredit)
(require 'rainbow-delimiters)
(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode)
; Cider configuration.
(add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
(setq nrepl-hide-special-buffers t)
(setq cider-repl-pop-to-buffer-on-connect nil)
(setq cider-popup-stacktraces t)
(setq cider-repl-popup-stacktraces nil)
(setq cider-auto-select-error-buffer nil)
(setq nrepl-buffer-name-separator "-")
(setq nrepl-buffer-name-show-port t)
(setq cider-repl-display-in-current-window nil)
(setq cider-repl-use-clojure-font-lock t)
(add-hook 'cider-repl-mode-hook 'subword-mode)
(add-hook 'cider-repl-mode-hook 'paredit-mode)
(add-hook 'cider-repl-mode-hook 'rainbow-delimiters-mode)
(defun cider-namespace-refresh ()
(interactive)
(cider-interactive-eval
"(require 'clojure.tools.namespace.repl)
(clojure.tools.namespace.repl/refresh)"))
(define-key clojure-mode-map (kbd "M-r") 'cider-namespace-refresh)
(require 'ac-nrepl)
(add-hook 'cider-repl-mode-hook 'ac-nrepl-setup)
;; (add-hook 'cider-interaction-mode-hook 'ac-nrepl-setup)
(eval-after-load "auto-complete"
'(add-to-list 'ac-modes 'cider-repl-mode))
(defun set-auto-complete-as-completion-at-point-function ()
(setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;(add-hook 'cider-repl-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;(add-hook 'cider-interaction-mode-hook 'set-auto-complete-as-completion-at-point-function)
;;(define-key cider-interaction-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc)
(add-hook 'nrepl-mode-hook 'clojure-mode-font-lock-setup)
(add-hook 'nrepl-mode-hook 'esk-turn-on-paredit)
(define-key clojure-mode-map (kbd "C-c v") 'nrepl-eval-buffer)
(define-clojure-indent
(defroutes 'defun)
(GET 2)
(POST 2)
(PUT 2)
(DELETE 2)
(HEAD 2)
(ANY 2)
(context 2))
(add-hook 'java-mode-hook
(lambda ()
"Treat Java 1.5 @-style annotations as comments."
(setq c-comment-start-regexp "(@|/(/|[*][*]?))")
(modify-syntax-entry ?@ "< b" java-mode-syntax-table)))
(add-hook 'java-mode-hook (lambda () (setq c-basic-offset 2)))
; enable idle highlight mode
(add-hook 'emacs-lisp-mode-hook 'idle-highlight-mode)
(add-hook 'clojure-mode-hook 'idle-highlight-mode)
(add-hook 'python-mode-hook 'idle-highlight-mode)
; ido mode?
(require 'ido)
(ido-mode t)
;; (ido-mode 'buffer)
(setq ido-enable-flex-matching t)
(setq ibuffer-shrink-to-minimum-size t)
(setq ibuffer-use-header-line t)
(global-set-key [(f9)] 'ibuffer)
;(setq ido-use-virtual-buffers t
; ido-handle-duplicate-virtual-buffers 2)
;(require 'ido-hacks)
;(ido-hacks-mode)
; version control-based ibuffer grouping
(add-hook 'ibuffer-hook 'ibuffer-vc-set-filter-groups-by-vc-root)
;; http://stackoverflow.com/questions/3124844/what-are-your-favorite-global-key-bindings-in-emacs
;; Align your code in a pretty way.
(global-set-key (kbd "C-x \\") 'align-regexp)
;; Perform general cleanup.
(global-set-key (kbd "C-c n") 'cleanup-buffer)
;; Font size
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
;; Jump to a definition in the current file. (This is awesome.)
;; (global-set-key (kbd "C-x C-i") 'ido-imenu)
;; Indentation help
(global-set-key (kbd "C-x ^") 'join-line)
(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)
;; ;; Start a regular shell if you prefer that.
;; (global-set-key (kbd "C-x M-m") 'shell)
;; ;; Help should search more than just commands
;; (global-set-key (kbd "C-h a") 'apropos)
;; ;; Not yet.
;; ;; Magit rules!
;; (global-set-key (kbd "C-x g") 'magit-status)
;; Activate occur easily inside isearch
;; (define-key isearch-mode-map (kbd "C-o")
;; (lambda () (interactive
;; (let ((case-fold-search isearch-case-fold-search))
;; (occur (if isearch-regexp isearch-string (regexp-quote isearch-string))))))
;; cycle through buffers
(global-set-key (kbd "<C-tab>") 'bury-buffer)
;; use hippie-expand instead of dabbrev
(global-set-key (kbd "M-/") 'hippie-expand)
;; use flyspell
;; swap windows
(global-set-key (kbd "C-c s") 'swap-windows)
;; rename buffer & visited file
(global-set-key (kbd "C-c r") 'rename-file-and-buffer)
(require 'tramp)
(setq tramp-default-method "ssh")
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes (quote ("fc5fcb6f1f1c1bc01305694c59a1a861b008c534cae8d0e48e4d5e81ad718bc6" "1e7e097ec8cb1f8c3a912d7e1e0331caeed49fef6cff220be63bd2a6ba4cc365" default))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment