My personal .emacs.d folder

init.el 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. ;;;; Copyright © 2013-2017 Lily Carpenter
  2. ;;;; All rights reserved.
  3. ;;;; Web: https://azrazalea.net
  4. ;;;; Email: azra-license@azrazalea.net
  5. ;;;; This config is free software: you can redistribute it and/or modify
  6. ;;;; it under the terms of the GNU Lesser General Public License as published by
  7. ;;;; the Free Software Foundation, either version 3 of the License, or
  8. ;;;; (at your option) any later version.
  9. ;;;; This config is distributed in the hope that it will be useful,
  10. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;;;; GNU Lesser General Public License for more details.
  13. ;;;; You should have received a copy of the GNU Lesser General Public License
  14. ;;;; along with this config. If not, see <http://www.gnu.org/licenses/>.
  15. ;;;;
  16. (package-initialize)
  17. (server-start)
  18. (require 'misc)
  19. (let ((third-party "~/.emacs.d/third-party/"))
  20. (add-to-list 'load-path third-party)
  21. (mapcar #'(lambda (path)
  22. (add-to-list 'load-path (concat third-party path))
  23. (byte-recompile-directory (concat third-party path)))
  24. '("diminish" "lfe-mode"))
  25. (byte-recompile-directory third-party))
  26. (add-hook 'after-init-hook (lambda ()
  27. (require 'use-package)
  28. (require 'bind-key)
  29. (require 'diminish)
  30. (require 'lfe-start)
  31. (load "~/.emacs.d/packages")
  32. (diminish 'whitespace-mode)
  33. (diminish 'auto-revert-mode)
  34. (light-colors)
  35. (scroll-bar-mode -1)))
  36. (add-hook 'emacs-startup-hook (lambda ()
  37. (when (file-exists-p "~/.emacs.d/local_vars.el")
  38. (message "Loading local vars")
  39. (load "~/.emacs.d/local_vars"))))
  40. (put 'erase-buffer 'disabled nil)
  41. (require 'recentf)
  42. ;;;; Load other configuration files
  43. (defun darwin? ()
  44. (eq system-type 'darwin))
  45. (defun linux? ()
  46. (eq system-type 'gnu/linux))
  47. (defun fixed-buffer-width ()
  48. (cond ((not window-system) 78)
  49. (t 100)))
  50. (load "~/.emacs.d/config.d/keys")
  51. (put 'scroll-left 'disabled nil)
  52. ;;; Toolbar setup
  53. (when (not (darwin?))
  54. (display-time))
  55. (when (darwin?)
  56. (setenv "PATH"
  57. (concat (getenv "PATH")
  58. ":/usr/local/bin"))
  59. (setq exec-path (append exec-path '("/usr/local/bin"))))
  60. (setenv "PATH"
  61. (concat (getenv "HOME") "/bin:" (getenv "PATH")))
  62. (column-number-mode 1)
  63. (blink-cursor-mode 0)
  64. (setenv "MANWIDTH" (number-to-string (fixed-buffer-width)))
  65. (custom-set-variables
  66. ;; custom-set-variables was added by Custom.
  67. ;; If you edit it by hand, you could mess it up, so be careful.
  68. ;; Your init file should contain only one such instance.
  69. ;; If there is more than one, they won't work right.
  70. '(Info-additional-directory-list (quote ("/usr/local/share/info" "~/gcl-info/")))
  71. '(TeX-auto-save t)
  72. '(TeX-command-extra-options "\"-shell-escape\"")
  73. '(TeX-parse-self t)
  74. '(ansi-color-faces-vector
  75. [default default default italic underline success warning error])
  76. '(ansi-color-names-vector
  77. ["#002b36" "#dc322f" "#859900" "#b58900" "#268bd2" "#d33682" "#2aa198" "#839496"])
  78. '(async-bytecomp-package-mode t)
  79. '(auth-sources (quote ("~/.authinfo.gpg")))
  80. '(auto-revert-use-notify nil)
  81. '(blink-cursor-mode nil)
  82. '(browse-url-browser-function (quote kill-url))
  83. '(c-basic-offset 4)
  84. '(c-default-style "linux")
  85. '(compilation-message-face (quote default))
  86. '(compilation-scroll-output t)
  87. '(css-indent-offset 2)
  88. '(cua-global-mark-cursor-color "#2aa198")
  89. '(cua-normal-cursor-color "#839496")
  90. '(cua-overwrite-cursor-color "#b58900")
  91. '(cua-read-only-cursor-color "#859900")
  92. '(custom-safe-themes
  93. (quote
  94. ("c5d6d43251953cea30a007acf7a6fbca71384558a11fe3d95953ac056a8510dc" "cd03a600a5f470994ba01dd3d1ff52d5809b59b4a37357fa94ca50a6f7f07473" "3ac266781ee0ac3aa74a6913a1506924cad669f111564507249f0ffa7c5e4b53" "71ecffba18621354a1be303687f33b84788e13f40141580fa81e7840752d31bf" "c74e83f8aa4c78a121b52146eadb792c9facc5b1f02c917e3dbb454fca931223" "c5a044ba03d43a725bd79700087dea813abcb6beb6be08c7eb3303ed90782482" "3a727bdc09a7a141e58925258b6e873c65ccf393b2240c51553098ca93957723" "d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879" "8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "e16a771a13a202ee6e276d06098bc77f008b73bbac4d526f160faa2d76c1dd0e" default)))
  95. '(default-frame-alist (quote ((font . "Fira Code"))))
  96. '(display-time-24hr-format t)
  97. '(display-time-day-and-date t)
  98. '(display-time-mode t)
  99. '(elfeed-feeds
  100. (quote
  101. ("https://lwn.net/headlines/rss" "https://news.ycombinator.com/rss" "http://planet.lisp.org/rss20.xml")))
  102. '(epg-gpg-program "gpg2")
  103. '(erc-autojoin-channels-alist nil)
  104. '(erc-autojoin-mode nil)
  105. '(erc-email-userid "azra-freenode@azrazalea.net")
  106. '(erc-enable-logging nil)
  107. '(erc-fill-column 100)
  108. '(erc-fill-mode t)
  109. '(erc-interpret-mirc-color t)
  110. '(erc-join-buffer (quote bury))
  111. '(erc-kill-buffer-on-part t)
  112. '(erc-kill-queries-on-quit t)
  113. '(erc-kill-server-buffer-on-quit t)
  114. '(erc-modules
  115. (quote
  116. (autojoin button completion fill irccontrols list match menu move-to-prompt netsplit networks noncommands readonly ring services stamp spelling track)))
  117. '(erc-networks-mode t)
  118. '(erc-nick "azrazalea")
  119. '(erc-port 65523)
  120. '(erc-prompt-for-nickserv-password nil)
  121. '(erc-prompt-for-password nil)
  122. '(erc-server "azrazalea.net")
  123. '(erc-services-mode t)
  124. '(erc-track-faces-priority-list
  125. (quote
  126. (erc-error-face erc-current-nick-face erc-keyword-face erc-nick-msg-face erc-direct-msg-face erc-dangerous-host-face erc-prompt-face)))
  127. '(erc-track-priority-faces-only (quote all))
  128. '(erc-user-full-name "Lily Carpenter")
  129. '(eshell-cmpl-compare-entry-function (quote string-lessp))
  130. '(fci-rule-color "#073642")
  131. '(fill-column 80)
  132. '(fortune-file "/usr/share/games/fortunes/")
  133. '(gnus-alias-allow-forward-as-reply t)
  134. '(gnus-alias-default-identity "personal")
  135. '(gnus-alias-identity-alist
  136. (quote
  137. (("personal" "" "\"Lily Carpenter\" <azra@azrazalea.net>" "" nil "" "")
  138. ("personal gmail" "" "\"Lily Carpenter\" <azrazalea@gmail.com>" "" nil "" "")
  139. ("lily" "" "\"Lily Carpenter\" <lily@azrazalea.net>" "" nil "" ""))))
  140. '(gnus-secondary-select-methods
  141. (quote
  142. ((nnml "")
  143. (nnimap "azrazalea-gmail"
  144. (nnimap-address "imap.gmail.com")
  145. (nnimap-server-port "imaps")
  146. (nnimap-stream ssl)))))
  147. '(gnus-select-method
  148. (quote
  149. (nnimap "azra-azrazalea.net"
  150. (nnimap-address "mail.azrazalea.net")
  151. (nnimap-server-port "imaps")
  152. (nnimap-stream ssl))))
  153. '(gnus-sum-thread-tree-false-root "")
  154. '(gnus-sum-thread-tree-indent " ")
  155. '(gnus-sum-thread-tree-leaf-with-other "├► ")
  156. '(gnus-sum-thread-tree-root "")
  157. '(gnus-sum-thread-tree-single-leaf "╰► ")
  158. '(gnus-sum-thread-tree-vertical "│")
  159. '(gnus-summary-line-format
  160. "%U%R%z %(%&user-date class=\"comment\">; %-15,15f %B%s%)
  161. ")
  162. '(gnus-summary-thread-gathering-function (quote gnus-gather-threads-by-references))
  163. '(gnus-thread-sort-functions (quote (gnus-thread-sort-by-date)))
  164. '(gnus-user-date-format-alist (quote ((t . "%Y-%m-%d %H:%M"))))
  165. '(helm-M-x-fuzzy-match t)
  166. '(helm-buffers-fuzzy-matching t)
  167. '(helm-ff-file-name-history-use-recentf t)
  168. '(helm-ff-search-library-in-sexp t)
  169. '(helm-move-to-line-cycle-in-source t)
  170. '(helm-recentf-fuzzy-match t)
  171. '(helm-scroll-amount 8)
  172. '(helm-split-window-in-side-p t)
  173. '(highlight-changes-colors (quote ("#d33682" "#6c71c4")))
  174. '(highlight-symbol-colors
  175. (--map
  176. (solarized-color-blend it "#fdf6e3" 0.25)
  177. (quote
  178. ("#b58900" "#2aa198" "#dc322f" "#6c71c4" "#859900" "#cb4b16" "#268bd2"))))
  179. '(highlight-symbol-foreground-color "#586e75")
  180. '(highlight-tail-colors
  181. (quote
  182. (("#073642" . 0)
  183. ("#546E00" . 20)
  184. ("#00736F" . 30)
  185. ("#00629D" . 50)
  186. ("#7B6000" . 60)
  187. ("#8B2C02" . 70)
  188. ("#93115C" . 85)
  189. ("#073642" . 100))))
  190. '(hl-bg-colors
  191. (quote
  192. ("#DEB542" "#F2804F" "#FF6E64" "#F771AC" "#9EA0E5" "#69B7F0" "#69CABF" "#B4C342")))
  193. '(hl-fg-colors
  194. (quote
  195. ("#fdf6e3" "#fdf6e3" "#fdf6e3" "#fdf6e3" "#fdf6e3" "#fdf6e3" "#fdf6e3" "#fdf6e3")))
  196. '(indent-tabs-mode nil)
  197. '(inf-ruby-default-implementation "pry")
  198. '(inhibit-startup-screen t)
  199. '(js-indent-level 2)
  200. '(js2-basic-offset 2)
  201. '(js2-bounce-indent-p nil)
  202. '(js2-global-externs
  203. (quote
  204. ("beforeEach" "describe" "it" "angular" "_" "inject" "expect" "module")))
  205. '(js2-mode-indent-ignore-first-tab t)
  206. '(magit-commit-arguments nil)
  207. '(magit-default-tracking-name-function (quote magit-default-tracking-name-branch-only))
  208. '(magit-diff-use-overlays nil)
  209. '(magit-log-arguments (quote ("--graph" "--decorate" "--show-signature" "-n256")))
  210. '(magit-tag-arguments (quote ("--sign")))
  211. '(magit-use-overlays nil)
  212. '(menu-bar-mode nil)
  213. '(message-send-mail-function (quote smtpmail-multi-send-it))
  214. '(mouse-wheel-progressive-speed t)
  215. '(mouse-wheel-scroll-amount (quote (6 ((shift) . 6))))
  216. '(nrepl-message-colors
  217. (quote
  218. ("#dc322f" "#cb4b16" "#b58900" "#546E00" "#B4C342" "#00629D" "#2aa198" "#d33682" "#6c71c4")))
  219. '(org-agenda-files (quote ("~/org/home.org")))
  220. '(org-babel-load-languages (quote ((dot . t) (sh . t))))
  221. '(org-log-done t)
  222. '(org-src-fontify-natively t)
  223. '(org-todo-keywords
  224. (quote
  225. ((sequence "TODO" "PROGRESS" "REVIEW" "|" "DONE" "ABORTED"))))
  226. '(package-archives
  227. (quote
  228. (("melpa" . "https://melpa.org/packages/")
  229. ("marmalade" . "https://marmalade-repo.org/packages/")
  230. ("gnu" . "https://elpa.gnu.org/packages/"))))
  231. '(package-selected-packages
  232. (quote
  233. (wttrin sly rust-mode inf-ruby nlinum helm flycheck clojure-mode async yasnippet yari yaml-mode web-mode w3m use-package undo-tree twittering-mode toml-mode tide sws-mode solarized-theme smtpmail-multi smartparens smart-mode-line sly-company shen-mode scss-mode sane-term ruby-electric ruby-block rubocop rspec-mode robe reverse-theme refheap rbenv rainbow-identifiers rainbow-delimiters pkg-info-dummy-package php-mode paradox notify nlinum-relative multi-term markdown-mode magit macrostep lua-mode leuven-theme less-css-mode json-mode js2-mode jade-mode info+ helm-projectile helm-company helm-ag haml-mode go-mode gnus-desktop-notify gnus-alias gitignore-mode gitconfig-mode gitattributes-mode geiser exec-path-from-shell elfeed cyberpunk-theme company-quickhelp column-enforce-mode color-theme cider cargo auctex alchemist ag ace-jump-mode 4clojure)))
  234. '(paradox-github-token t)
  235. '(pos-tip-background-color "#eee8d5")
  236. '(pos-tip-foreground-color "#586e75")
  237. '(projectile-completion-system (quote helm))
  238. '(projectile-enable-caching t)
  239. '(projectile-global-mode t)
  240. '(projectile-switch-project-action (quote projectile-dired))
  241. '(projectile-use-git-grep t)
  242. '(rainbow-identifiers-choose-face-function (quote rainbow-identifiers-cie-l*a*b*-choose-face))
  243. '(rainbow-identifiers-cie-l*a*b*-saturation 50)
  244. '(reftex-plug-into-AUCTeX t)
  245. '(require-final-newline t)
  246. '(rspec-use-rake-when-possible t)
  247. '(rspec-use-spring-when-possible nil)
  248. '(rspec-use-zeus-when-possible nil)
  249. '(ruby-block-highlight-toggle t)
  250. '(ruby-deep-arglist nil)
  251. '(ruby-deep-indent-paren nil)
  252. '(safe-local-variable-values
  253. (quote
  254. ((Package . CLIM-CLX)
  255. (indent-tabs)
  256. (Lowercase . Yes)
  257. (Base . 10)
  258. (Package . CLIM-DEMO)
  259. (Syntax . ANSI-Common-Lisp)
  260. (Package . MCCLIM-TRUETYPE)
  261. (Package . CLIM-INTERNALS)
  262. (Syntax . Common-Lisp)
  263. (eval modify-syntax-entry 43 "'")
  264. (eval modify-syntax-entry 36 "'")
  265. (eval modify-syntax-entry 126 "'")
  266. (bug-reference-bug-regexp . "<https?://\\(debbugs\\|bugs\\)\\.gnu\\.org/\\([0-9]+\\)>")
  267. (TeX-command-extra-options . "-shell-escape"))))
  268. '(sane-term-shell-command "zsh")
  269. '(save-place t nil (saveplace))
  270. '(scroll-bar-mode nil)
  271. '(scroll-conservatively 75)
  272. '(scroll-step 1)
  273. '(scss-compile-at-save nil)
  274. '(send-mail-function (quote smtpmail-multi-send-it))
  275. '(show-paren-mode t)
  276. '(size-indication-mode t)
  277. '(smartrep-mode-line-active-bg (solarized-color-blend "#859900" "#073642" 0.2))
  278. '(sml/name-width 35)
  279. '(sml/theme (quote respectful))
  280. '(smtpmail-multi-accounts
  281. (quote
  282. ((Personal\ Gmail "azrazalea" "smtp.gmail.com" 587 nil nil nil nil nil)
  283. (Personal "azra" "mail.azrazalea.net" 587 nil starttls nil nil nil))))
  284. '(smtpmail-multi-associations
  285. (quote
  286. (("gmail.com" Personal\ Gmail)
  287. ("azrazalea.net" Personal))))
  288. '(smtpmail-multi-default-account (quote Personal))
  289. '(smtpmail-smtp-server "mail.azrazalea.net")
  290. '(smtpmail-smtp-service 587)
  291. '(smtpmail-smtp-user "azra")
  292. '(smtpmail-stream-type (quote ssl))
  293. '(socks-server (quote ("default" "localhost" 9999 5)))
  294. '(sp-lisp-modes
  295. (quote
  296. (cider-repl-mode clojure-mode clojurec-mode clojurescript-mode clojurex-mode common-lisp-mode emacs-lisp-mode eshell-mode geiser-repl-mode inf-clojure-mode inferior-emacs-lisp-mode inferior-lisp-mode inferior-scheme-mode lisp-interaction-mode lisp-mode monroe-mode racket-mode racket-repl-mode scheme-interaction-mode scheme-mode slime-repl-mode stumpwm-mode lfe-mode)))
  297. '(term-bind-key-alist
  298. (quote
  299. (("C-c C-c" . term-interrupt-subjob)
  300. ("C-p" . previous-line)
  301. ("C-n" . next-line)
  302. ("C-s" . isearch-forward)
  303. ("C-r" . isearch-backward)
  304. ("C-m" . term-send-raw)
  305. ("M-f" . term-send-forward-word)
  306. ("M-b" . term-send-backward-word)
  307. ("M-o" . term-send-backspace)
  308. ("M-p" . term-send-up)
  309. ("M-n" . term-send-down)
  310. ("M-M" . term-send-forward-kill-word)
  311. ("M-N" . term-send-backward-kill-word)
  312. ("M-r" . term-send-reverse-search-history)
  313. ("M-," . term-send-input)
  314. ("M-." . comint-dynamic-complete)
  315. ("C-c C-j" . term-line-mode)
  316. ("C-c C-k" . term-char-mode)
  317. ("C-c C-e" . term-send-escape))))
  318. '(term-default-bg-color (face-background (quote default)))
  319. '(term-default-fg-color (face-foreground (quote default)))
  320. '(tool-bar-mode nil)
  321. '(tramp-default-method "ssh")
  322. '(typescript-indent-level 2)
  323. '(uniquify-buffer-name-style (quote forward) nil (uniquify))
  324. '(use-package-always-ensure t)
  325. '(user-full-name "Lily Carpenter")
  326. '(user-mail-address "")
  327. '(vc-annotate-background nil)
  328. '(vc-annotate-background-mode nil)
  329. '(vc-annotate-color-map
  330. (quote
  331. ((20 . "#dc322f")
  332. (40 . "#CF4F1F")
  333. (60 . "#C26C0F")
  334. (80 . "#b58900")
  335. (100 . "#AB8C00")
  336. (120 . "#A18F00")
  337. (140 . "#989200")
  338. (160 . "#8E9500")
  339. (180 . "#859900")
  340. (200 . "#729A1E")
  341. (220 . "#609C3C")
  342. (240 . "#4E9D5B")
  343. (260 . "#3C9F79")
  344. (280 . "#2aa198")
  345. (300 . "#299BA6")
  346. (320 . "#2896B5")
  347. (340 . "#2790C3")
  348. (360 . "#268bd2"))))
  349. '(vc-annotate-very-old-color nil)
  350. '(visible-bell t)
  351. '(web-mode-code-indent-offset 2)
  352. '(web-mode-css-indent-offset 2)
  353. '(web-mode-enable-auto-closing t)
  354. '(web-mode-enable-auto-indentation t)
  355. '(web-mode-enable-auto-opening t)
  356. '(web-mode-enable-auto-pairing nil)
  357. '(web-mode-enable-auto-quoting t)
  358. '(web-mode-enable-current-element-highlight t)
  359. '(web-mode-markup-indent-offset 2)
  360. '(weechat-color-list
  361. (quote
  362. (unspecified "#002b36" "#073642" "#990A1B" "#dc322f" "#546E00" "#859900" "#7B6000" "#b58900" "#00629D" "#268bd2" "#93115C" "#d33682" "#00736F" "#2aa198" "#839496" "#657b83")))
  363. '(whitespace-style (quote (face empty tabs trailing)))
  364. '(woman-bold-headings t)
  365. '(woman-fill-column (fixed-buffer-width))
  366. '(woman-fill-frame t)
  367. '(wttrin-default-cities (quote ("63043" "65802")))
  368. '(xterm-color-names
  369. ["#eee8d5" "#dc322f" "#859900" "#b58900" "#268bd2" "#d33682" "#2aa198" "#073642"])
  370. '(xterm-color-names-bright
  371. ["#fdf6e3" "#cb4b16" "#93a1a1" "#839496" "#657b83" "#6c71c4" "#586e75" "#002b36"]))
  372. (setenv "TERM" "xterm-color")
  373. (defun dark-colors (&optional frame)
  374. (interactive)
  375. (package-install? 'solarized-theme)
  376. (disable-theme 'solarized-light)
  377. (disable-theme 'cyberpunk)
  378. (disable-theme 'leuven)
  379. (load-theme 'solarized-dark))
  380. (defun presentation-font ()
  381. (interactive)
  382. (set-frame-font "Fira Code 24"))
  383. (defun dark-colors-presentation (&optional frame)
  384. (interactive)
  385. (package-install? 'reverse-theme)
  386. (disable-theme 'solarized-light)
  387. (disable-theme 'solarized-dark)
  388. (disable-theme 'leuven)
  389. (load-theme 'reverse))
  390. (defun light-colors (&optional frame)
  391. (interactive)
  392. (package-install? 'solarized-theme)
  393. (disable-theme 'solarized-dark)
  394. (disable-theme 'reverse)
  395. (disable-theme 'leuven)
  396. (load-theme 'solarized-light))
  397. (defun light-colors-presentation (&optional frame)
  398. (interactive)
  399. (package-install? 'leuven-theme)
  400. (disable-theme 'solarized-dark)
  401. (disable-theme 'solarized-light)
  402. (disable-theme 'reverse)
  403. (load-theme 'leuven))
  404. (defun ssh (ssh-to)
  405. (interactive "sSSH to: ")
  406. (let ((multi-term-program "ssh")
  407. (multi-term-buffer-name ssh-to)
  408. (multi-term-program-switches ssh-to))
  409. (multi-term)))
  410. (defun ssh-proxy (ssh-to port)
  411. (interactive "sSSH to: \nsPort[9999]: ")
  412. (if (string= "" port)
  413. (setq port "9999"))
  414. (make-comint-in-buffer "ssh-proxy" nil "ssh" nil "-CND" port ssh-to))
  415. (defun ssh-copy-id (ssh-to)
  416. (interactive "sSSH to: ")
  417. (make-comint-in-buffer "ssh-copy-id" nil "ssh-copy-id" nil ssh-to))
  418. (defvar hexcolour-keywords
  419. '(("#[[:xdigit:]]\\{6\\}"
  420. (0 (put-text-property (match-beginning 0)
  421. (match-end 0)
  422. 'face (list :background
  423. (match-string-no-properties 0)))))))
  424. (defun hexcolour-add-to-font-lock ()
  425. (font-lock-add-keywords nil hexcolour-keywords))
  426. (add-hook 'less-css-mode-hook 'hexcolour-add-to-font-lock)
  427. (require 'erc-services)
  428. (erc-services-mode 1)
  429. (add-to-list 'erc-modules 'log 'scrolltobottom)
  430. (erc-update-modules)
  431. (erc-spelling-mode 1)
  432. ;;; TeX and LaTeX
  433. (add-to-list 'auto-mode-alist '("\\.latex$" . latex-mode))
  434. ;;; Git
  435. (add-to-list 'auto-mode-alist '("\\.gitconfig" . conf-mode))
  436. ;;; Buffers
  437. (put 'downcase-region 'disabled nil)
  438. (put 'narrow-to-region 'disabled nil)
  439. ;;; GPG stuff.
  440. (require 'epa-file)
  441. ;; With this, you can find-file something.gpg and it will just work.
  442. (epa-file-enable)
  443. ;;; Whitespace mode
  444. (require 'whitespace)
  445. (global-whitespace-mode 0)
  446. (mapc (lambda (mode-hook)
  447. (add-hook mode-hook 'whitespace-mode))
  448. '(c-mode-hook
  449. c++-mode-hook
  450. emacs-lisp-mode-hook
  451. lisp-mode-hook
  452. python-mode-hook
  453. ruby-mode-hook))
  454. (define-key global-map (kbd "RET") 'newline-and-indent)
  455. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  456. (add-hook 'prog-mode-hook
  457. (lambda ()
  458. (font-lock-add-keywords nil
  459. '(("\\<\\(FIXME\\|TODO\\|BUG\\|XXX\\):" 1 font-lock-warning-face prepend)))))
  460. (defun kill-url (url &rest _ignore)
  461. "Append URL to kill ring, so that user can take appropriate action."
  462. (interactive)
  463. (kill-new url))
  464. ;;; Custom Functions
  465. ;; Originally from stevey, adapted to support moving to a new directory.
  466. ;; <http://stackoverflow.com/a/1834038/693712>
  467. (defun rename-file-and-buffer (new-name)
  468. "Renames both current buffer and file it's visiting to NEW-NAME."
  469. (interactive
  470. (progn
  471. (if (not (buffer-file-name))
  472. (error "Buffer '%s' is not visiting a file!" (buffer-name)))
  473. (list (read-file-name (format "Rename %s to: " (file-name-nondirectory
  474. (buffer-file-name)))))))
  475. (if (equal new-name "")
  476. (error "Aborted rename"))
  477. (setq new-name (if (file-directory-p new-name)
  478. (expand-file-name (file-name-nondirectory
  479. (buffer-file-name))
  480. new-name)
  481. (expand-file-name new-name)))
  482. ;; If the file isn't saved yet, skip the file rename, but still update the
  483. ;; buffer name and visited file.
  484. (if (file-exists-p (buffer-file-name))
  485. (rename-file (buffer-file-name) new-name 1))
  486. (let ((was-modified (buffer-modified-p)))
  487. ;; This also renames the buffer, and works with uniquify
  488. (set-visited-file-name new-name)
  489. (if was-modified
  490. (save-buffer)
  491. ;; Clear buffer-modified flag caused by set-visited-file-name
  492. (set-buffer-modified-p nil))
  493. (message "Renamed to %s." new-name)))
  494. ;; From http://emacsredux.com/blog/2013/04/03/delete-file-and-buffer/
  495. ;; License unknown
  496. (defun delete-file-and-buffer ()
  497. "Kill the current buffer and deletes the file it is visiting."
  498. (interactive)
  499. (let ((filename (buffer-file-name)))
  500. (when filename
  501. (if (vc-backend filename)
  502. (vc-delete-file filename)
  503. (progn
  504. (delete-file filename)
  505. (message "Deleted file %s" filename)
  506. (kill-buffer))))))
  507. ;; http://www.emacswiki.org/emacs/ElispCookbook
  508. ;; Under Trim Whitespace
  509. (defun chomp (str)
  510. "Chomp leading and tailing whitespace from STR."
  511. (replace-regexp-in-string (rx (or (: bos (* (any " \t\n")))
  512. (: (* (any " \t\n")) eos)))
  513. ""
  514. str))
  515. ;; Gets current git top dir
  516. (defun git-top-dir ()
  517. (projectile-project-root))
  518. ;; Run rspecs at root of git
  519. (defun git-run-rspecs ()
  520. (interactive)
  521. (let ((default-directory (git-top-dir)))
  522. (if (and default-directory (file-directory-p default-directory))
  523. (let ((buffer-name "*rspec output*"))
  524. (if (get-buffer buffer-name)
  525. (with-current-buffer buffer-name
  526. (erase-buffer)))
  527. (start-process "git-rspec" buffer-name "rspec")
  528. (display-buffer buffer-name))
  529. (error "No valid top git directory found"))))
  530. ;; Rebase all whitespace seperated branches on top of each other,
  531. ;; from left to right. Current branch will be on the bottom
  532. (defun git-tree-rebase (branches)
  533. (interactive "sWhitespace seperated list of branches: ")
  534. (let ((branches (split-string branches))
  535. (prev-branch (magit-get-current-branch)))
  536. (dolist (cur-branch branches)
  537. (let ((rc (shell-command (format "git checkout %s; git rebase %s" cur-branch prev-branch))))
  538. (if (not (equal rc 0))
  539. (error "Failed to rebase %s on %s" cur-branch prev-branch)))
  540. (setq prev-branch cur-branch))))
  541. ;; Force update all whitespace seperated branches
  542. (defun git-fix-tree (branches)
  543. (interactive "sWhitespace seperated list of branches: ")
  544. (let ((branches (split-string branches)))
  545. (dolist (branch branches)
  546. (let ((rc (shell-command (format "git push origin :%s; git push origin %s" branch branch))))
  547. (if (not (equal rc 0))
  548. (error "Failed to fix branch %s" branch))))))
  549. ;; Get current branch
  550. (defun git-current-branch ()
  551. (let ((default-directory (git-top-dir)))
  552. (if default-directory
  553. (chomp (shell-command-to-string "git rev-parse --abbrev-ref HEAD"))
  554. (error "Failed to get top directory of repo"))))
  555. ;; Set experimental to current branch and push
  556. (defun git-set-experimental ()
  557. (interactive)
  558. (let* ((current-branch (git-current-branch))
  559. (rc (shell-command (format "git branch -f experimental %s;" current-branch))))
  560. (if (not (equal rc 0))
  561. (error "Failed to move branch experimental to %s" current-branch)))
  562. (git-fix-tree "experimental"))
  563. ;; Check entire git repo's ruby syntax
  564. (require 'find-lisp)
  565. (defun git-check-ruby ()
  566. (interactive)
  567. (let ((default-directory (git-top-dir)))
  568. (if (and default-directory (file-directory-p default-directory))
  569. (let ((buffer-name "*syntax checker*"))
  570. (if (get-buffer buffer-name)
  571. (with-current-buffer buffer-name
  572. (erase-buffer)))
  573. (dolist (file (find-lisp-find-files default-directory "\\.rb$"))
  574. (start-process "ruby-syntax-check" buffer-name "ruby" "-c" file))
  575. (display-buffer buffer-name))
  576. (error "Syntax check failed."))))
  577. ;; Check whether or not a git repo is dirty
  578. (defun git-dirty? (directory)
  579. (let* ((default-directory directory)
  580. (status (shell-command-to-string "git status -s"))
  581. (good-status '("" " M .gitmodules\n" "M .gitmodules\n"))
  582. (result t))
  583. (if (member status good-status)
  584. (setq result nil))
  585. result))
  586. ;; Update a git repo
  587. (defun update-git (directory)
  588. (let* ((default-directory directory)
  589. (orig-branch (magit-get-current-branch))
  590. rc)
  591. (setq rc (shell-command "git checkout master && git pull"))
  592. (if (not (equal rc 0))
  593. (error "Error: Failed to update repo %s" directory))
  594. (setq rc (shell-command (format "git checkout %s" orig-branch)))
  595. (if (not (equal rc 0))
  596. (error "Error: Failed to checkout original branch %s in repo %s" orig-branch directory))))
  597. ;; Update all repos in the home directory
  598. (defun update-all-repos ()
  599. (interactive)
  600. (let* ((directory (concat (getenv "HOME") "/git-repos"))
  601. (files (directory-files-and-attributes directory t)))
  602. (dolist (file files)
  603. (cond
  604. ;; Ignore . and ..
  605. ((or (string-match "\\.$" (car file)) (string-match "\\.\\.$" (car file))))
  606. ;; Directories with non dirty git need to be checked for git info
  607. ((and (eq t (car (cdr file))) (not (git-dirty? (format "%s/" (car file)))))
  608. (update-git (format "%s/" (car file))))))))
  609. (defun kill-dired-buffers ()
  610. (interactive)
  611. (mapc (lambda (buffer)
  612. (when (eq 'dired-mode (buffer-local-value 'major-mode buffer))
  613. (kill-buffer buffer)))
  614. (buffer-list)))
  615. (defun kill-tramp-buffers ()
  616. (interactive)
  617. (tramp-cleanup-all-connections)
  618. (tramp-cleanup-all-buffers))
  619. (defun git-all-files ()
  620. (let ((default-directory (git-top-dir)))
  621. (split-string (shell-command-to-string "git ls-tree -r --name-only --full-name HEAD"))))
  622. ;; A proper projectile replace with regex support
  623. (defun git-replace-regexp (from to)
  624. (interactive "sFrom regexp: \nsTo regexp: ")
  625. (let ((files '(delq nil (mapcar (lambda (directory)
  626. (let ((file (concat (projectile-project-root) directory)))
  627. (if (file-writable-p file)
  628. file)))
  629. (git-all-files)))))
  630. (tags-query-replace from to nil files)))
  631. ;; From http://stackoverflow.com/a/7250027/693712
  632. (defun smart-line-beginning ()
  633. "Move point to the beginning of text on the current line; if that is already
  634. the current position of point, then move it to the beginning of the line."
  635. (interactive)
  636. (let ((pt (point)))
  637. (beginning-of-line-text)
  638. (when (eq pt (point))
  639. (beginning-of-line))))
  640. (add-hook 'prog-mode-hook (lambda () (local-set-key (kbd "C-a") 'smart-line-beginning)))
  641. ;;; Eshell Functions
  642. ;; Taken from <http://www.emacswiki.org/emacs/EshellFunctions>
  643. (defun eshell/emacs (&rest args)
  644. "Open a file in emacs. Some habits die hard."
  645. (if (null args)
  646. ;; If I just ran "emacs", I probably expect to be launching
  647. ;; Emacs, which is rather silly since I'm already in Emacs.
  648. ;; So just pretend to do what I ask.
  649. (bury-buffer)
  650. ;; We have to expand the file names or else naming a directory in an
  651. ;; argument causes later arguments to be looked for in that directory,
  652. ;; not the starting directory
  653. (mapc #'find-file (mapcar #'expand-file-name (eshell-flatten-list (reverse args))))))
  654. (defun format-commands (&rest commands)
  655. (mapcar (lambda (command)
  656. (shell-command (apply 'format command)))
  657. commands))
  658. (defun eshell/git-branch-here (branch)
  659. (format-commands `("git push origin :%s" ,branch)
  660. `("git branch -d %s" ,branch)
  661. `("git checkout -b %s" ,branch)
  662. `("git push origin %s:%s" ,branch ,branch)))
  663. (defun eshell/git-experimental-here ()
  664. (eshell/git-branch-here "experimental"))
  665. ;;; Spell Checking
  666. (add-hook 'prog-mode-hook 'flyspell-prog-mode)
  667. (mapcar #'(lambda (mode-hook)
  668. (add-hook mode-hook 'flyspell-mode))
  669. '(latex-mode-hook
  670. magit-log-edit-mode-hook
  671. org-mode-hook
  672. message-mode-hook))
  673. ;;; Maxima
  674. (add-to-list 'load-path "/usr/share/maxima/5.32.1/emacs/")
  675. (autoload 'maxima-mode "maxima" "Maxima mode" t)
  676. (autoload 'imaxima "imaxima" "Frontend for maxima with Image support" t)
  677. (autoload 'maxima "maxima" "Maxima interaction" t)
  678. (autoload 'imath-mode "imath" "Imath mode for math formula input" t)
  679. (setq imaxima-use-maxima-mode-flag t
  680. imaxima-pt-size 12
  681. imaxima-fnt-size "large"
  682. imaxima-max-scale nil
  683. imaxima-linearize-flag nil)
  684. (add-to-list 'auto-mode-alist '("\\.ma[cx]" . maxima-mode))
  685. (global-prettify-symbols-mode)
  686. ;;; Fira code
  687. ;; This works when using emacs --daemon + emacsclient
  688. (add-hook 'after-make-frame-functions (lambda (frame) (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")))
  689. (add-hook 'after-make-frame-functions (lambda (frame) (set-fontset-font t nil (font-spec :size 20 :name "Symbola"))))
  690. ;; This works when using emacs without server/client
  691. (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")
  692. (set-fontset-font t nil (font-spec :size 20 :name "Symbola"))
  693. (defconst fira-code-font-lock-keywords-alist
  694. (mapcar (lambda (regex-char-pair)
  695. `(,(car regex-char-pair)
  696. (0 (prog1 ()
  697. (compose-region (match-beginning 1)
  698. (match-end 1)
  699. ;; The first argument to concat is a string containing a literal tab
  700. ,(concat " " (list (decode-char 'ucs (cadr regex-char-pair)))))))))
  701. '(("\\(www\\)" #Xe100)
  702. ("[^/]\\(\\*\\*\\)[^/]" #Xe101)
  703. ("\\(\\*\\*\\*\\)" #Xe102)
  704. ("\\(\\*\\*/\\)" #Xe103)
  705. ("\\(\\*>\\)" #Xe104)
  706. ("[^*]\\(\\*/\\)" #Xe105)
  707. ("\\(\\\\\\\\\\)" #Xe106)
  708. ("\\(\\\\\\\\\\\\\\)" #Xe107)
  709. ("\\({-\\)" #Xe108)
  710. ("\\(\\[\\]\\)" #Xe109)
  711. ("\\(::\\)" #Xe10a)
  712. ("\\(:::\\)" #Xe10b)
  713. ("[^=]\\(:=\\)" #Xe10c)
  714. ("\\(!!\\)" #Xe10d)
  715. ("\\(!=\\)" #Xe10e)
  716. ("\\(!==\\)" #Xe10f)
  717. ("\\(-}\\)" #Xe110)
  718. ("\\(--\\)" #Xe111)
  719. ("\\(---\\)" #Xe112)
  720. ("\\(-->\\)" #Xe113)
  721. ("[^-]\\(->\\)" #Xe114)
  722. ("\\(->>\\)" #Xe115)
  723. ("\\(-<\\)" #Xe116)
  724. ("\\(-<<\\)" #Xe117)
  725. ("\\(-~\\)" #Xe118)
  726. ("\\(#{\\)" #Xe119)
  727. ("\\(#\\[\\)" #Xe11a)
  728. ("\\(##\\)" #Xe11b)
  729. ("\\(###\\)" #Xe11c)
  730. ("\\(####\\)" #Xe11d)
  731. ("\\(#(\\)" #Xe11e)
  732. ("\\(#\\?\\)" #Xe11f)
  733. ("\\(#_\\)" #Xe120)
  734. ("\\(#_(\\)" #Xe121)
  735. ("\\(\\.-\\)" #Xe122)
  736. ("\\(\\.=\\)" #Xe123)
  737. ("\\(\\.\\.\\)" #Xe124)
  738. ("\\(\\.\\.<\\)" #Xe125)
  739. ("\\(\\.\\.\\.\\)" #Xe126)
  740. ("\\(\\?=\\)" #Xe127)
  741. ("\\(\\?\\?\\)" #Xe128)
  742. ("\\(;;\\)" #Xe129)
  743. ("\\(/\\*\\)" #Xe12a)
  744. ("\\(/\\*\\*\\)" #Xe12b)
  745. ("\\(/=\\)" #Xe12c)
  746. ("\\(/==\\)" #Xe12d)
  747. ("\\(/>\\)" #Xe12e)
  748. ("\\(//\\)" #Xe12f)
  749. ("\\(///\\)" #Xe130)
  750. ("\\(&&\\)" #Xe131)
  751. ("\\(||\\)" #Xe132)
  752. ("\\(||=\\)" #Xe133)
  753. ("[^|]\\(|=\\)" #Xe134)
  754. ("\\(|>\\)" #Xe135)
  755. ("\\(\\^=\\)" #Xe136)
  756. ("\\(\\$>\\)" #Xe137)
  757. ("\\(\\+\\+\\)" #Xe138)
  758. ("\\(\\+\\+\\+\\)" #Xe139)
  759. ("\\(\\+>\\)" #Xe13a)
  760. ("\\(=:=\\)" #Xe13b)
  761. ("[^!/]\\(==\\)[^>]" #Xe13c)
  762. ("\\(===\\)" #Xe13d)
  763. ("\\(==>\\)" #Xe13e)
  764. ("[^=]\\(=>\\)" #Xe13f)
  765. ("\\(=>>\\)" #Xe140)
  766. ("\\(<=\\)" #Xe141)
  767. ("\\(=<<\\)" #Xe142)
  768. ("\\(=/=\\)" #Xe143)
  769. ("\\(>-\\)" #Xe144)
  770. ("\\(>=\\)" #Xe145)
  771. ("\\(>=>\\)" #Xe146)
  772. ("[^-=]\\(>>\\)" #Xe147)
  773. ("\\(>>-\\)" #Xe148)
  774. ("\\(>>=\\)" #Xe149)
  775. ("\\(>>>\\)" #Xe14a)
  776. ("\\(<\\*\\)" #Xe14b)
  777. ("\\(<\\*>\\)" #Xe14c)
  778. ("\\(<|\\)" #Xe14d)
  779. ("\\(<|>\\)" #Xe14e)
  780. ("\\(<\\$\\)" #Xe14f)
  781. ("\\(<\\$>\\)" #Xe150)
  782. ("\\(<!--\\)" #Xe151)
  783. ("\\(<-\\)" #Xe152)
  784. ("\\(<--\\)" #Xe153)
  785. ("\\(<->\\)" #Xe154)
  786. ("\\(<\\+\\)" #Xe155)
  787. ("\\(<\\+>\\)" #Xe156)
  788. ("\\(<=\\)" #Xe157)
  789. ("\\(<==\\)" #Xe158)
  790. ("\\(<=>\\)" #Xe159)
  791. ("\\(<=<\\)" #Xe15a)
  792. ("\\(<>\\)" #Xe15b)
  793. ("[^-]\\(<<\\)" #Xe15c)
  794. ("\\(<<-\\)" #Xe15d)
  795. ("\\(<<=\\)" #Xe15e)
  796. ("\\(<<<\\)" #Xe15f)
  797. ("\\(<~\\)" #Xe160)
  798. ("\\(<~~\\)" #Xe161)
  799. ("\\(</\\)" #Xe162)
  800. ("\\(</>\\)" #Xe163)
  801. ("\\(~@\\)" #Xe164)
  802. ("\\(~-\\)" #Xe165)
  803. ("\\(~=\\)" #Xe166)
  804. ("\\(~>\\)" #Xe167)
  805. ("[^<]\\(~~\\)" #Xe168)
  806. ("\\(~~>\\)" #Xe169)
  807. ("\\(%%\\)" #Xe16a)
  808. ;; ("\\(x\\)" #Xe16b)
  809. ("[^:=]\\(:\\)[^:=]" #Xe16c)
  810. ("[^\\+<>]\\(\\+\\)[^\\+<>]" #Xe16d)
  811. ("[^\\*/<>]\\(\\*\\)[^\\*/<>]" #Xe16f))))
  812. (defun add-fira-code-symbol-keywords ()
  813. (font-lock-add-keywords nil fira-code-font-lock-keywords-alist))
  814. (add-hook 'prog-mode-hook
  815. #'add-fira-code-symbol-keywords)
  816. (defun bf-pretty-print-xml-region (begin end)
  817. "Pretty format XML markup in region. You need to have nxml-mode
  818. http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
  819. this. The function inserts linebreaks to separate tags that have
  820. nothing but whitespace between them. It then indents the markup
  821. by using nxml's indentation rules."
  822. (interactive "r")
  823. (save-excursion
  824. (nxml-mode)
  825. (goto-char begin)
  826. (while (search-forward-regexp "\>[ \\t]*\<" nil t)
  827. (backward-char) (insert "\n"))
  828. (indent-region begin end))
  829. (message "Ah, much better!"))
  830. (custom-set-faces
  831. ;; custom-set-faces was added by Custom.
  832. ;; If you edit it by hand, you could mess it up, so be careful.
  833. ;; Your init file should contain only one such instance.
  834. ;; If there is more than one, they won't work right.
  835. )
  836. (defun package-install? (package-name)
  837. (when (not (package-installed-p package-name))
  838. (package-install package-name)))
  839. (defun insert-random-uuid ()
  840. (interactive)
  841. (lexical-let ((string (replace-regexp-in-string "\n" "" (shell-command-to-string "uuidgen"))))
  842. (insert string)
  843. (kill-new string)))