~/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

.emacs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. ;;; ~/.emacs
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;; Better Defaults ;;;;
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5. (when (fboundp 'menu-bar-mode) (menu-bar-mode -1))
  6. (when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
  7. (when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
  8. (load-theme 'tango-dark)
  9. (set-face-attribute
  10. 'default nil
  11. :family "Monospace"
  12. :height 90
  13. :weight 'normal
  14. :width 'normal)
  15. ;; Startup
  16. (setq
  17. initial-scratch-message nil
  18. inhibit-splash-screen t
  19. inhibit-startup-buffer-menu t
  20. column-number-mode t
  21. visible-bell t
  22. ;; Autosave/Backups
  23. auto-save-default nil
  24. auto-save-file-name-transforms `((".*" "~/.emacs.d/backup/" t))
  25. backup-directory-alist `((".*" . "~/.emacs.d/backup/"))
  26. create-lockfiles nil
  27. delete-by-moving-to-trash t
  28. delete-old-versions t
  29. delete-selection-mode t
  30. kept-new-versions 2
  31. vc-follow-symlinks t
  32. vc-make-backup-files t
  33. version-control t
  34. ;; Cut/Paste
  35. require-final-newline t
  36. save-interprogram-paste-before-kill t
  37. select-enable-primary nil
  38. ;; Encoding
  39. prefer-coding-system 'utf-8
  40. set-default-coding-systems 'utf-8
  41. set-language-environment "UTF-8"
  42. set-locale-environment "en_US.UTF-8"
  43. ;; Indentation
  44. c-basic-offset 2
  45. cperl-indent-level 2
  46. js-indent-level 2
  47. indent-tabs-mode nil
  48. tab-width 2
  49. ;; Mouse
  50. mouse-wheel-follow-mouse 't
  51. mouse-wheel-progressive-speed nil
  52. mouse-wheel-scroll-amount '(3 ((shift) . 3))
  53. mouse-yank-at-point t
  54. ;; Scrolling
  55. auto-window-vscroll nil
  56. scroll-conservatively 101
  57. scroll-down-aggressively 0.0
  58. scroll-margin 0
  59. scroll-preserve-screen-position 1
  60. scroll-step 1
  61. scroll-up-aggressively 0.0)
  62. (add-hook 'lisp-mode-hook 'linum-mode)
  63. (add-hook 'prog-mode-hook 'linum-mode)
  64. (add-hook 'text-mode-hook 'linum-mode)
  65. (setq custom-file "~/.emacs.d/custom.el")
  66. (if (file-exists-p custom-file)
  67. (load custom-file)
  68. (write-region "" nil custom-file))
  69. (fset 'yes-or-no-p 'y-or-n-p)
  70. (global-visual-line-mode t)
  71. (show-paren-mode t)
  72. (xterm-mouse-mode t)
  73. (add-hook
  74. 'before-save-hook
  75. (lambda()
  76. (delete-trailing-whitespace)
  77. (if (not indent-tabs-mode)
  78. (untabify (point-min)(point-max))
  79. nil)))
  80. ;;; Repositories ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  81. (require 'package)
  82. (setq
  83. package-user-dir "~/.emacs.d/pkg/"
  84. package-archives
  85. '(("GNU ELPA" . "http://elpa.gnu.org/packages/")
  86. ("MELPA Stable" . "https://stable.melpa.org/packages/")
  87. ("MELPA" . "https://melpa.org/packages/"))
  88. package-archive-priorities
  89. '(("MELPA Stable" . 3)
  90. ("GNU ELPA" . 2)
  91. ("MELPA" . 1)))
  92. (package-initialize)
  93. (unless (package-installed-p 'use-package)
  94. (package-refresh-contents)
  95. (package-install 'use-package))
  96. (require 'use-package)
  97. (setq use-package-always-ensure t)
  98. (use-package package-utils)
  99. ;;; Server ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  100. (require 'server)
  101. (unless (server-running-p)
  102. (server-start))
  103. (defun server-reinstall()
  104. "Remove packages, then run server-reload"
  105. (interactive)
  106. (if (file-exists-p "~/.emacs.d/pkg")
  107. (delete-directory "~/.emacs.d/pkg" t))
  108. (server-reload))
  109. (defun server-kill()
  110. "Delete current Emacs server, then kill Emacs"
  111. (interactive)
  112. (server-force-delete)
  113. (kill-emacs))
  114. (defun server-reload()
  115. "Reload init file"
  116. (interactive)
  117. (if (file-exists-p "~/.emacs.d/init.el")
  118. (load-file "~/.emacs.d/init.el")
  119. (if (file-exists-p "~/.emacs")
  120. (load-file "~/.emacs")))
  121. (eshell-exports))
  122. (defun server-stop()
  123. "Prompt to save buffers, then kill Emacs."
  124. (interactive)
  125. (save-buffers-kill-emacs))
  126. (defun server-update()
  127. "Refresh package contents, then update all packages."
  128. (interactive)
  129. (package-initialize)
  130. (unless package-archive-contents
  131. (package-refresh-contents))
  132. (package-utils-upgrade-all))
  133. (global-set-key
  134. (kbd "C-x C-c")
  135. (lambda() (interactive)
  136. (if (y-or-n-p "Quit Emacs? ")
  137. (server-stop))))
  138. ;;; Eshell ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  139. (defun eshell-clear()
  140. "Clear the eshell buffer"
  141. (let ((inhibit-read-only t))
  142. (erase-buffer)
  143. (eshell-send-input)))
  144. (defun eshell-exports()
  145. "Store desired environment variables for eshell."
  146. (setenv "EDITOR" "emacsclient")
  147. (setenv "GIT_EDITOR" "emacsclient")
  148. (setenv "PATH" (getenv "PATH"))
  149. (setenv "PROMPT_COMMAND" "")
  150. (setenv "SHELL" (getenv "SHELL"))
  151. (setenv "TERM" (getenv "TERM")))
  152. (defun eshell-new()
  153. "Open a new instance of eshell."
  154. (interactive)
  155. (eshell 'N))
  156. ;;; Eww ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  157. (defun eww-disable-images()
  158. "Block all images from loading in eww."
  159. (interactive)
  160. (setq shr-blocked-images "")
  161. (eww-reload))
  162. (defun eww-enable-images()
  163. "Stop blocking images in eww."
  164. (interactive)
  165. (setq shr-blocked-images nil)
  166. (eww-reload))
  167. (defun eww-toggle-images()
  168. "Toggle blocking images in eww."
  169. (interactive)
  170. (if (bound-and-true-p shr-blocked-images)
  171. (eww-enable-images)
  172. (eww-disable-images)))
  173. (defun eww-new()
  174. "Open a new instance of eww."
  175. (interactive)
  176. (let ((url (read-from-minibuffer "Enter URL or keywords: ")))
  177. (switch-to-buffer (generate-new-buffer "*eww*"))
  178. (eww-mode)
  179. (eww url)))
  180. (defun eww-new-url()
  181. "Open link under cursor in new instance of eww"
  182. (interactive)
  183. (let ((url (shr-copy-url)))
  184. (switch-to-buffer (generate-new-buffer "*eww*"))
  185. (eww-mode)
  186. (eww url)))
  187. ;;; Scratch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  188. (defun scratch-new()
  189. "Open a new scratch buffer."
  190. (interactive)
  191. (switch-to-buffer (generate-new-buffer "*scratch*"))
  192. (lisp-mode))
  193. ;;; Input ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  194. (global-set-key (kbd "C-c c") 'comment-or-uncomment-region)
  195. (global-set-key (kbd "C-x C-b") 'ibuffer)
  196. (global-set-key (kbd "C-x x") 'kill-buffer-and-window)
  197. (global-set-key (kbd "<C-tab>") 'next-buffer)
  198. (global-set-key (kbd "<C-iso-lefttab>") 'previous-buffer)
  199. (global-set-key (kbd "<M-down>") 'windmove-down)
  200. (global-set-key (kbd "<M-left>") 'windmove-left)
  201. (global-set-key (kbd "<M-right>") 'windmove-right)
  202. (global-set-key (kbd "<M-up>") 'windmove-up)
  203. (global-set-key (kbd "C-c <down>") 'windmove-down)
  204. (global-set-key (kbd "C-c <left>") 'windmove-left)
  205. (global-set-key (kbd "C-c <right>") 'windmove-right)
  206. (global-set-key (kbd "C-c <up>") 'windmove-up)
  207. (global-set-key (kbd "<mouse-4>") (lambda() (interactive)(scroll-down 4)))
  208. (global-set-key (kbd "<mouse-5>") (lambda() (interactive)(scroll-up 4)))
  209. (global-set-key
  210. (kbd "M--")
  211. (lambda() (interactive)
  212. (split-window-vertically)
  213. (other-window 1 nil)
  214. (switch-to-next-buffer)))
  215. (global-set-key
  216. (kbd "M-=")
  217. (lambda() (interactive)
  218. (split-window-horizontally)
  219. (other-window 1 nil)
  220. (switch-to-next-buffer)))
  221. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  222. ;;;; Better Packages ;;;;
  223. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  224. ;;; Editor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  225. (use-package diff-hl
  226. :config
  227. (add-hook 'prog-mode-hook 'diff-hl-mode)
  228. (add-hook 'text-mode-hook 'diff-hl-mode))
  229. (use-package highlight-indent-guides
  230. :config
  231. (add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
  232. (setq highlight-indent-guides-method 'character))
  233. (use-package ibuffer
  234. :config
  235. (add-hook
  236. 'ibuffer-hook
  237. (lambda()
  238. (ibuffer-do-sort-by-alphabetic)
  239. (ibuffer-do-sort-by-major-mode))))
  240. (use-package rainbow-delimiters
  241. :config
  242. (add-hook 'markdown-mode-hook 'rainbow-delimiters-mode)
  243. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  244. (add-hook 'text-mode-hook 'rainbow-delimiters-mode))
  245. (use-package smartparens
  246. :config
  247. (add-hook 'markdown-mode-hook 'smartparens-mode)
  248. (add-hook 'prog-mode-hook 'smartparens-mode)
  249. (add-hook 'text-mode-hook 'smartparens-mode)
  250. (setq
  251. sp-highlight-pair-overlay nil
  252. sp-highlight-wrap-overlay nil
  253. sp-highlight-wrap-tag-overlay nil))
  254. ;;; Languages ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  255. (use-package elpy
  256. :config
  257. (add-hook
  258. 'elpy-mode-hook
  259. (lambda()
  260. (setq
  261. tab-width 4
  262. indent-tabs-mode 1)))
  263. (elpy-enable))
  264. (use-package geiser)
  265. (use-package go-mode
  266. :config
  267. (add-hook 'before-save-hook 'gofmt-before-save)
  268. (add-hook
  269. 'go-mode-hook
  270. (lambda()
  271. (setq
  272. tab-width 4
  273. indent-tabs-mode 1))))
  274. (use-package rtags)
  275. ;;; Utilities ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  276. (use-package async
  277. :config
  278. (async-bytecomp-package-mode '(all)))
  279. (use-package auto-compile
  280. :config
  281. (auto-compile-on-load-mode)
  282. (auto-compile-on-save-mode))
  283. (use-package auto-dictionary)
  284. (use-package cmake-ide
  285. :config
  286. (cmake-ide-setup))
  287. (use-package company
  288. :config
  289. (add-hook 'prog-mode-hook 'company-mode)
  290. (add-hook 'text-mode-hook 'company-mode))
  291. (use-package company-go
  292. :config
  293. (setq
  294. company-tooltip-limit 20
  295. company-idle-delay .5
  296. company-echo-delay 0
  297. company-begin-commands '(self-insert-command)))
  298. (use-package counsel
  299. :bind
  300. (("M-x" . counsel-M-x)
  301. ("C-x C-f" . counsel-find-file)
  302. ("<f1> f" . counsel-describe-function)
  303. ("<f1> v" . counsel-describe-variable)
  304. ("<f1> l" . counsel-find-library)
  305. ("<f2> i" . counsel-info-lookup-symbol)
  306. ("<f2> u" . counsel-unicode-char)
  307. ("C-c g" . counsel-git)
  308. ("C-c j" . counsel-git-grep)
  309. ("C-c l" . counsel-ag)
  310. ("C-x l" . counsel-locate)
  311. ("C-S-o" . counsel-rhythmbox))
  312. :config
  313. (define-key read-expression-map (kbd "C-r") 'counsel-expression-history))
  314. (use-package flycheck
  315. :config
  316. (add-hook 'prog-mode-hook 'flycheck-mode))
  317. (use-package flymake)
  318. (use-package flyspell
  319. :config
  320. (add-hook 'flyspell-mode-hook (auto-dictionary-mode 1))
  321. (add-hook 'markdown-mode-hook 'flyspell-mode)
  322. (add-hook 'prog-mode-hook 'flyspell-mode)
  323. (add-hook 'text-mode-hook 'flyspell-mode))
  324. (use-package ivy
  325. :bind
  326. (("C-c C-r" . ivy-resume)
  327. ("<f6>" . ivy-resume))
  328. :config
  329. (ivy-mode 1)
  330. (setq
  331. ivy-use-virtual-buffers t
  332. enable-recursive-minibuffers t))
  333. (use-package swiper
  334. :bind
  335. ("C-s" . swiper))
  336. (use-package undo-tree)
  337. (use-package xclip
  338. :config
  339. (xclip-mode 1))
  340. ;;; Misc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  341. (use-package circe
  342. :config
  343. (add-hook 'circe-chat-mode-hook 'my-circe-prompt)
  344. (add-hook 'circe-message-option-functions 'my-circe-message-option-chanserv)
  345. (add-hook 'lui-mode-hook (lambda() (my-lui-setup)(my-circe-set-margin)))
  346. (require 'circe-chanop)
  347. (enable-circe-color-nicks)
  348. (setq
  349. circe-default-part-message ""
  350. circe-default-quit-message ""
  351. circe-format-server-topic "*** Topic change by {userhost}: {topic-diff}"
  352. circe-reduce-lurker-spam t
  353. circe-use-cycle-completion t
  354. lui-fill-type nil
  355. lui-flyspell-alist '((".*" "american"))
  356. lui-flyspell-p t
  357. lui-time-stamp-format "%H:%M"
  358. lui-time-stamp-position 'left-margin)
  359. (defun my-circe-set-margin() (setq left-margin-width 6))
  360. (setf (cdr (assoc 'continuation fringe-indicator-alist)) nil)
  361. (defun my-lui-setup()
  362. (setq
  363. fringes-outside-margins t
  364. left-margin-width 6
  365. word-wrap t
  366. wrap-prefix " "))
  367. (defun my-circe-prompt()
  368. (lui-set-prompt
  369. (concat (propertize
  370. (concat (buffer-name) ">")
  371. 'face 'circe-prompt-face)
  372. " ")))
  373. (defun my-circe-message-option-chanserv (nick user host command args)
  374. (when (and (string= "ChanServ" nick)
  375. (string-match "^\\[#.+?\\]" (cadr args)))
  376. '((dont-display . t))))
  377. (if (file-exists-p "~/.emacs.d/circe.el")
  378. (load-file "~/.emacs.d/circe.el")))
  379. (use-package elfeed
  380. :bind
  381. ("C-x w" . elfeed)
  382. :config
  383. (setq
  384. elfeed-search-filter "@1-week-ago +unread "
  385. url-queue-timeout 30)
  386. (if (file-exists-p "~/.emacs.d/elfeed.el")
  387. (load-file "~/.emacs.d/elfeed.el")))
  388. (use-package eshell
  389. :config
  390. (add-hook
  391. 'eshell-mode-hook
  392. (lambda()
  393. (add-hook 'eshell-mode-hook 'eshell-exports)
  394. (add-to-list 'eshell-visual-commands "htop")
  395. (add-to-list 'eshell-visual-commands "less")
  396. (add-to-list 'eshell-visual-commands "nano")
  397. (add-to-list 'eshell-visual-commands "ssh")
  398. (add-to-list 'eshell-visual-commands "tail")
  399. (add-to-list 'eshell-visual-commands "top")
  400. (add-to-list 'eshell-visual-commands "vi")
  401. (add-to-list 'eshell-visual-commands "vim")
  402. (add-to-list 'eshell-visual-commands "watch")
  403. (eshell/alias "clear" "eshell-clear")
  404. (eshell/alias "cp" "cp -ip $*")
  405. (eshell/alias "cr" "cp -ipr $*")
  406. (eshell/alias "hurl" "curl --fail --location --remote-name-all --progress-bar $*")
  407. (eshell/alias "df" "df -h $*")
  408. (eshell/alias "di" "df -hi $*")
  409. (eshell/alias "dit" "dig +noall +nocmd +answer +multiline $*")
  410. (eshell/alias "du" "du -h --max-depth=1 | sort -hr $*")
  411. (eshell/alias "free" "free -h $*")
  412. (eshell/alias "l" "ls -hSC --color=auto --group-directories-first $*")
  413. (eshell/alias "la" "ls -ahSC --color=auto --group-directories-first $*")
  414. (eshell/alias "ll" "ls -halS --color=auto --group-directories-first $*")
  415. (eshell/alias "ls" "ls -hSC --color=auto --group-directories-first $*")
  416. (eshell/alias "mkcd" "mkdir -vp $1; cd $1")
  417. (eshell/alias "mkdir" "mkdir -vp $*")
  418. (eshell/alias "pss" "ps aux | grep -v grep | sort -hrk3 $*")
  419. (eshell/alias "psw" "watch 'ps aux | grep -v grep | sort -hrk3'")
  420. (eshell/alias "rf" "rm -rf $*")
  421. (eshell/alias "rm" "rm -i $*")
  422. (eshell/alias "rr" "rm -ir $*")
  423. (eshell/alias "mkgz" "tar -vzcf $1.tar.gz $1")
  424. (eshell/alias "mkxz" "tar -vcJf $1.tar.xz $1")
  425. (eshell/alias "untar" "tar -vxf $*")))
  426. (setq
  427. eshell-cmpl-cycle-completions nil
  428. eshell-error-if-no-glob t
  429. eshell-hist-ignoredups t
  430. eshell-history-size 4096
  431. eshell-prefer-lisp-functions t
  432. eshell-prompt-function
  433. (lambda nil
  434. (concat
  435. "[" (user-login-name)"@"(system-name)" "
  436. (if (= (length (eshell/pwd))
  437. (length (getenv "HOME")))
  438. "~"
  439. (eshell/basename (eshell/pwd)))
  440. "]"
  441. (if (= (user-uid) 0) "# " "$ ")))
  442. eshell-prompt-regexp "^[^#$\n]*[#$] "
  443. eshell-save-history-on-exit t
  444. eshell-scroll-to-bottom-on-input 'all))
  445. (use-package eww-lnum
  446. :config
  447. (setq
  448. browse-url-browser-function 'eww-browse-url
  449. shr-blocked-images "")
  450. (define-key eww-mode-map "f" 'eww-lnum-follow)
  451. (define-key eww-mode-map "F" 'eww-lnum-universal))
  452. (use-package gnus
  453. :config
  454. (gnus-add-configuration
  455. '(article
  456. (horizontal 1.0
  457. (vertical 25
  458. (group 1.0))
  459. (vertical 1.0
  460. (summary 0.25 point)
  461. (article 1.0)))))
  462. (gnus-add-configuration
  463. '(summary
  464. (horizontal 1.0
  465. (vertical 25 (group 1.0))
  466. (vertical 1.0 (summary 1.0 point)))))
  467. (if (file-exists-p "~/.emacs.d/gnus.el")
  468. (load-file "~/.emacs.d/gnus.el")))
  469. (use-package markdown-mode)
  470. (use-package ranger)