My personal dotfiles
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.

README.org 51KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  1. * About
  2. #+TITLE: Wolfe's Literate Emacs Config
  3. #+AUTHOR: Josh Wolfe
  4. #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="https://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
  5. #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="readtheorg.css"/>
  6. #+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  7. #+HTML_HEAD: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
  8. #+HTML_HEAD: <script type="text/javascript" src="https://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.min.js"></script>
  9. #+HTML_HEAD: <script type="text/javascript" src="https://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
  10. #+LATEX_HEADER: \usepackage[margin=0.7in]{geometry}
  11. #+HTML: <a href="https://travis-ci.org/WolfeCub/dotfiles"><img style="width:90px" src="https://travis-ci.org/WolfeCub/dotfiles.svg?branch=master" alt="Build Status"/></a><br><br>
  12. This literate config is best read [[http://wolfecub.github.io/dotfiles/][here]] or in emacs.
  13. This page is generated and kept up to date using a combination of
  14. [[https://travis-ci.org/WolfeCub/dotfiles/][travis ci]] and [[https://github.com/fniessen/org-html-themes][ReadTheOrg]]. If you want to see the script that travis
  15. uses [[https://github.com/WolfeCub/dotfiles/blob/master/.travis/build_site.sh][here]] is the bash script it runs and [[https://github.com/WolfeCub/dotfiles/blob/master/.travis/generate-html.el][this]] is the =.el= file that
  16. it runs through emacs to generate the html page (this was mostly stolen
  17. from IvanMalison).
  18. Included in this section is also my export headers. These are responsible
  19. for including the ReadTheOrg theme as well as some metadata and options
  20. like title, author, table of contents etc. If you wish to see the headers
  21. I'm using, [[https://raw.githubusercontent.com/WolfeCub/dotfiles/master/emacs/.emacs.d/README.org][this]] is the raw org file.
  22. * Variables
  23. Variables come at the beginning so that they're consistently available.
  24. If you don't care about these *[[Startup][click here to skip over them]]*.
  25. ** Config Name
  26. #+BEGIN_SRC emacs-lisp :tangle yes
  27. (defvar wolfe/literate-config-name "README.org"
  28. "The name of my literate config")
  29. #+END_SRC
  30. ** Init File
  31. #+BEGIN_SRC emacs-lisp :tangle yes
  32. (defvar wolfe/init-file (concat user-emacs-directory wolfe/literate-config-name)
  33. "The path to my literate config file")
  34. #+END_SRC
  35. ** Linux Check
  36. #+BEGIN_SRC emacs-lisp :tangle yes
  37. (defvar wolfe/linux? (eq system-type 'gnu/linux)
  38. "Are we on linux?")
  39. #+END_SRC
  40. ** Windows Check
  41. #+BEGIN_SRC emacs-lisp :tangle yes
  42. (defvar wolfe/windows? (eq system-type 'windows-nt)
  43. "Are we on windows?")
  44. #+END_SRC
  45. ** Org Ellipsis
  46. #+BEGIN_SRC emacs-lisp :tangle yes
  47. (defvar wolfe/org-ellipsis
  48. (if (display-graphic-p)
  49. "⤵"
  50. "...")
  51. "The indicates if an `org-mode' tree can be expanded")
  52. #+END_SRC
  53. ** Project Path
  54. #+BEGIN_SRC emacs-lisp :tangle yes
  55. (defvar wolfe/project-path
  56. (cond
  57. (wolfe/linux? "~/Projects/")
  58. (wolfe/windows? "C:/dev/")
  59. (:else nil))
  60. "Path to my projects directory")
  61. #+END_SRC
  62. ** Dropbox Path
  63. #+BEGIN_SRC emacs-lisp :tangle yes
  64. (defvar wolfe/org-dropbox-path
  65. (cond
  66. (wolfe/linux?
  67. "~/Dropbox/org/")
  68. (wolfe/windows?
  69. "C:\\Users\\Josh\\Dropbox\\org\\")
  70. (:else nil))
  71. "Path to my org files inside dropbox")
  72. #+END_SRC
  73. ** Theme Checks
  74. #+BEGIN_SRC emacs-lisp :tangle yes
  75. (defvar wolfe/using-dark t
  76. "Indicates whether we're using my dark theme")
  77. #+END_SRC
  78. #+BEGIN_SRC emacs-lisp :tangle yes
  79. (defvar wolfe/using-light nil
  80. "Indicates whether we're using my light theme")
  81. #+END_SRC
  82. ** Lisp Path Location
  83. #+BEGIN_SRC emacs-lisp :tangle yes
  84. (defvar wolfe/lisp-dir-path "~/.emacs.d/lisp/"
  85. "Path to my custom lisp files")
  86. #+END_SRC
  87. ** Highlight Escapes Modes
  88. #+BEGIN_SRC emacs-lisp :tangle yes
  89. (defvar wolfe/highlight-escapes-mode-list '(python-mode
  90. c-mode
  91. c++-mode
  92. web-mode)
  93. "List of modes to highlight escape characters in")
  94. #+END_SRC
  95. ** IRC Info Path
  96. #+BEGIN_SRC emacs-lisp :tangle yes
  97. (defvar wolfe/irc-info-path "~/.ircinfo.gpg"
  98. "Location of the GPG encrypted file that has my irc login info")
  99. #+END_SRC
  100. * Startup
  101. My graphical settings change depending on whether I'm in terminal
  102. and if a command line flag (=-light=) was specified.
  103. ** Theme Setup
  104. This should be run regardless of whether I'm in terminal vs gui or dark vs light.
  105. #+BEGIN_SRC emacs-lisp :tangle yes
  106. (setq custom-theme-directory "~/.emacs.d/themes")
  107. (defmacro check-and-remove-command-line-arg (argument)
  108. "Checks `command-line-args' for argument and removes it if found returning t or nil"
  109. (if (member argument command-line-args)
  110. (progn
  111. (setq command-line-args (delete argument command-line-args))
  112. t)
  113. nil))
  114. (let ((result (check-and-remove-command-line-arg "-light")))
  115. (setq wolfe/using-light result)
  116. (setq wolfe/using-dark (not result)))
  117. #+END_SRC
  118. ** Dark
  119. Configuration for my dark theme =base16 default dark= which is loaded by default.
  120. *** Common
  121. #+BEGIN_SRC emacs-lisp :tangle yes
  122. (defun wolfe/dark-setup ()
  123. (use-package base16-theme
  124. :config
  125. (load-theme 'base16-default-dark t)
  126. (if (display-graphic-p)
  127. (wolfe/dark-gui-setup)
  128. (wolfe/dark-term-setup))))
  129. #+END_SRC
  130. *** Graphical
  131. #+BEGIN_SRC emacs-lisp :tangle yes
  132. (defun wolfe/dark-gui-setup ()
  133. (defvar my/base16-colors base16-default-dark-colors)
  134. (setq evil-emacs-state-cursor `(,(plist-get my/base16-colors :base0D) box)
  135. evil-insert-state-cursor `(,(plist-get my/base16-colors :base0D) bar)
  136. evil-motion-state-cursor `(,(plist-get my/base16-colors :base0E) box)
  137. evil-normal-state-cursor `(,(plist-get my/base16-colors :base07) box)
  138. evil-replace-state-cursor `(,(plist-get my/base16-colors :base08) bar)
  139. evil-visual-state-cursor `(,(plist-get my/base16-colors :base09) box))
  140. (set-face-attribute 'fringe nil :background nil)
  141. (custom-set-faces
  142. '(region ((t (:background "gray19"))))
  143. '(org-block ((t (:foreground "#d8d8d8"))))
  144. '(org-done ((t (:box (:line-width 1) :weight bold))))
  145. '(org-level-1 ((t (:inherit outline-1 :height 1.3))))
  146. '(org-todo ((t (:box (:line-width 1) :weight bold))))))
  147. #+END_SRC
  148. *** Terminal
  149. #+BEGIN_SRC emacs-lisp :tangle yes
  150. (defun wolfe/dark-term-setup ()
  151. (setq nlinum-format "%d ")
  152. (custom-set-faces
  153. '(line-number ((t (:background "color-18" :foreground "brightblack"))))
  154. '(ivy-current-match ((t (:background "color-18" :foreground "color-16"))))
  155. '(linum ((t (:background "color-18"))))
  156. '(region ((t :background "color-19")))
  157. '(mode-line ((t (:background "color-19" :foreground "brightblue" :box nil))))
  158. '(mode-line-inactive
  159. ((t (:background "color-18" :foreground "color-244"))))))
  160. #+END_SRC
  161. ** Light
  162. Configuration for my light theme =leuven=. This is only loaded when the =-light= flag is
  163. specified on the command line.
  164. *** Common
  165. #+BEGIN_SRC emacs-lisp :tangle yes
  166. (defun wolfe/light-setup ()
  167. (use-package leuven-theme
  168. :config
  169. (custom-set-faces
  170. '(ivy-subdir ((t (:background "gray88")))))
  171. (load-theme 'leuven t)))
  172. #+END_SRC
  173. ** Display check
  174. This checks which setup we're in and calls the appropriate function above.
  175. #+BEGIN_SRC emacs-lisp :tangle yes
  176. (if wolfe/using-light
  177. (wolfe/light-setup)
  178. (wolfe/dark-setup))
  179. #+END_SRC
  180. * General Settings
  181. Basic settings I can't really live without.
  182. ** Load Path
  183. Recursively add =~/.emacs.d/lisp/= to my load path.
  184. #+BEGIN_SRC emacs-lisp :tangle yes
  185. (add-to-list 'load-path wolfe/lisp-dir-path)
  186. (let ((default-directory wolfe/lisp-dir-path))
  187. (normal-top-level-add-subdirs-to-load-path))
  188. #+END_SRC
  189. ** Splash and Startup
  190. This makes sure I'm presented with a nice blank =*scratch*=
  191. buffer when emacs starts up.
  192. #+BEGIN_SRC emacs-lisp :tangle yes
  193. (setq inhibit-splash-screen t
  194. inhibit-startup-message t
  195. initial-scratch-message "") ; No scratch text
  196. (defun display-startup-echo-area-message ()
  197. (message "Welcome to the church of GNU/Emacs"))
  198. #+END_SRC
  199. ** Graphics
  200. *** Bars
  201. I don't really want to have to look at menu bars that I'm not going to use
  202. #+BEGIN_SRC emacs-lisp :tangle yes
  203. (tool-bar-mode -1) ; No toolbar
  204. (scroll-bar-mode -1) ; Hide scrollbars
  205. (menu-bar-mode -1) ; No menubar
  206. #+END_SRC
  207. *** Fonts
  208. Quick macro that tries to load the font. If it loads it return =t= so we
  209. know not to try and load anything else if it returns =nil= then we'll
  210. try a different font.
  211. #+BEGIN_SRC emacs-lisp :tangle yes
  212. (defmacro load-font-if-exists (family size)
  213. (if (member family (font-family-list)) ; Set default font
  214. (progn
  215. (let ((font-and-size (format "%s-%s" family size)))
  216. (add-to-list 'default-frame-alist `(font . ,font-and-size))
  217. (set-face-attribute 'default t :font font-and-size))
  218. t)
  219. nil))
  220. #+END_SRC
  221. I like =Inconsolata-dz= a bit more than =Inconsolata= so use it if installed
  222. otherwise fall back to regular =Inconsolata=.
  223. #+BEGIN_SRC emacs-lisp :tangle yes
  224. (unless (load-font-if-exists "Inconsolata-dz" 17)
  225. (load-font-if-exists "Inconsolata" 17))
  226. #+END_SRC
  227. Force =Fira Code= for all =UTF-8= symbols.
  228. #+BEGIN_SRC emacs-lisp :tangle yes
  229. (let ((utf8-font "Fira Code"))
  230. (set-fontset-font "fontset-startup" '(#x000000 . #x3FFFFF) utf8-font)
  231. (set-fontset-font "fontset-default" '(#x000000 . #x3FFFFF) utf8-font)
  232. (set-fontset-font "fontset-standard" '(#x000000 . #x3FFFFF) utf8-font))
  233. #+END_SRC
  234. Make sure that UTF-8 is used everywhere.
  235. #+BEGIN_SRC emacs-lisp :tangle yes
  236. (set-terminal-coding-system 'utf-8)
  237. (set-keyboard-coding-system 'utf-8)
  238. (set-language-environment 'utf-8)
  239. (set-selection-coding-system 'utf-8)
  240. (setq locale-coding-system 'utf-8)
  241. (prefer-coding-system 'utf-8)
  242. (set-input-method nil)
  243. #+END_SRC
  244. *** Pretty Symbols
  245. In emacs =24.4= we got =prettify-symbols-mode= which replaces things like =lambda=
  246. with =λ=. This can help make the code easier to read. The =inhibit-compacting-font-caches=
  247. stops garbage collect from trying to handle font caches which makes things a lot faster
  248. and saves us ram.
  249. #+BEGIN_SRC emacs-lisp :tangle yes
  250. (setq prettify-symbols-unprettify-at-point 'right-edge)
  251. (setq inhibit-compacting-font-caches t)
  252. #+END_SRC
  253. **** Global
  254. These symbols are the basics that I would like enabled for all =prog-mode= modes.
  255. This function can be called by the mode specific hook to push the defaults.
  256. #+BEGIN_SRC emacs-lisp :tangle yes
  257. (defun wolfe/pretty-symbol-push-default ()
  258. (push '("!=" . ?≠) prettify-symbols-alist)
  259. (push '("<=" . ?≤) prettify-symbols-alist)
  260. (push '(">=" . ?≥) prettify-symbols-alist)
  261. (push '("=>" . ?⇒) prettify-symbols-alist))
  262. #+END_SRC
  263. **** Python
  264. #+BEGIN_SRC emacs-lisp :tangle yes
  265. (add-hook 'python-mode-hook
  266. (lambda ()
  267. (wolfe/pretty-symbol-push-default)
  268. (push '("def" . ?ƒ) prettify-symbols-alist)
  269. (push '("sum" . ?Σ) prettify-symbols-alist)
  270. (push '("**2" . ?²) prettify-symbols-alist)
  271. (push '("**3" . ?³) prettify-symbols-alist)
  272. (push '("None" . ?∅) prettify-symbols-alist)
  273. (push '("in" . ?∈) prettify-symbols-alist)
  274. (push '("not in" . ?∉) prettify-symbols-alist)
  275. (push '("return" . ?➡) prettify-symbols-alist)
  276. (prettify-symbols-mode t)))
  277. #+END_SRC
  278. **** Lisp
  279. #+BEGIN_SRC emacs-lisp :tangle yes
  280. (add-hook 'lisp-mode-hook
  281. (lambda ()
  282. (wolfe/pretty-symbol-push-default)
  283. (push '("defun" . ?ƒ) prettify-symbols-alist)
  284. (prettify-symbols-mode t)))
  285. #+END_SRC
  286. *** Column Marker
  287. #+BEGIN_SRC emacs-lisp :tangle yes
  288. (use-package column-marker
  289. :ensure nil
  290. :config
  291. (add-hook 'prog-mode-hook (lambda () (interactive) (column-marker-1 81)))
  292. (custom-set-faces
  293. '(column-marker-1 ((t (:background "dim gray"))))))
  294. #+END_SRC
  295. *** Highlight Escape Characters
  296. This defines 4 new faces and the appropriate =regexps= that highlight
  297. them and maps them to all the modes in [[Highlight Escapes Modes][=wolfe/highlight-escapes-mode-list=]].
  298. #+BEGIN_SRC emacs-lisp :tangle yes
  299. (defface wolfe/backslash-escape-backslash-face
  300. '((t :inherit font-lock-regexp-grouping-backslash))
  301. "Face for the back-slash component of a back-slash escape."
  302. :group 'font-lock-faces)
  303. (defface wolfe/backslash-escape-char-face
  304. '((t :inherit font-lock-regexp-grouping-construct))
  305. "Face for the charcter component of a back-slash escape."
  306. :group 'font-lock-faces)
  307. (defface wolfe/format-code-format-face
  308. '((t :inherit font-lock-regexp-grouping-backslash))
  309. "Face for the % component of a printf format code."
  310. :group 'font-lock-faces)
  311. (defface wolfe/format-code-directive-face
  312. '((t :inherit font-lock-regexp-grouping-construct))
  313. "Face for the directive component of a printf format code."
  314. :group 'font-lock-faces)
  315. (mapc
  316. (lambda (mode)
  317. (font-lock-add-keywords
  318. mode
  319. '(("\\(\\\\\\)." 1 'wolfe/backslash-escape-backslash-face prepend)
  320. ("\\\\\\(.\\)" 1 'wolfe/backslash-escape-char-face prepend)
  321. ("\\(%\\)." 1 'wolfe/format-code-format-face prepend)
  322. ("%\\(.\\)" 1 'wolfe/format-code-directive-face prepend))))
  323. wolfe/highlight-escapes-mode-list)
  324. #+END_SRC
  325. ** Personal Defaults
  326. Nothing to crazy here just the type of behaviour I personally
  327. expect as default.
  328. #+BEGIN_SRC emacs-lisp :tangle yes
  329. (show-paren-mode t) ; Highlights matching parens
  330. (fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
  331. (blink-cursor-mode -1) ; No need to flash the cursor
  332. (column-number-mode t) ; Show column in mode-line
  333. (delete-selection-mode 1) ; Replace selection on insert
  334. (setq-default truncate-lines t ; Don't wrap
  335. indent-tabs-mode nil)
  336. (setq vc-follow-symlinks t ; Always follow symlinks
  337. tags-revert-without-query t ; Don't ask to reload TAGS file
  338. echo-keystrokes 0.5
  339. custom-file "~/.emacs.d/custom.el" ; Set custom file & don't load it
  340. source-directory "~/Projects/emacs/")
  341. #+END_SRC
  342. ** Misc
  343. *** Vim Scrolloff
  344. This makes scrolling gradual rather than by half page. I find that the
  345. half page scroll really makes me lose where I am in the file so here
  346. I make sure to scroll one line at a time. In addition I want to keep
  347. what I'm working on centered so I start scrolling when the cursor is
  348. 10 lines away from the margin.
  349. This behaviour in general emulates the =scrolloff= option in vim.
  350. #+BEGIN_SRC emacs-lisp :tangle yes
  351. (setq scroll-margin 10
  352. scroll-step 1
  353. scroll-conservatively 10000
  354. scroll-preserve-screen-position 1)
  355. #+END_SRC
  356. *** Shell Tweaks
  357. #+BEGIN_SRC emacs-lisp :tangle yes
  358. (setq explicit-shell-file-name
  359. (if (file-readable-p "/usr/bin/zsh") "/usr/bin/zsh" "/bin/bash"))
  360. (when (eq system-type 'windows-nt)
  361. (setq explicit-shell-file-name "cmdproxy.exe"))
  362. #+END_SRC
  363. ** Mode Line
  364. If we're in GUI emacs we make sure to use =powerline= otherwise we use
  365. a custom mode line configuration.
  366. #+BEGIN_SRC emacs-lisp :tangle yes
  367. (if (display-graphic-p)
  368. (use-package powerline
  369. :init
  370. (defadvice powerline-major-mode (around delight-powerline-major-mode activate)
  371. (let ((inhibit-mode-name-delight nil))
  372. ad-do-it))
  373. :config
  374. (setq powerline-arrow-shape 'curve
  375. powerline-display-buffer-size nil
  376. powerline-display-mule-info nil)
  377. (powerline-default-theme)
  378. (remove-hook 'focus-out-hook 'powerline-unset-selected-window)
  379. (setq powerline-height 24))
  380. (setq-default mode-line-format
  381. (list
  382. " "
  383. ;; is this buffer read-only?
  384. '(:eval (when buffer-read-only
  385. (propertize "RO"
  386. 'face 'font-lock-type-face
  387. 'help-echo "Buffer is read-only")))
  388. ;; was this buffer modified since the last save?
  389. '(:eval (when (buffer-modified-p)
  390. (propertize "M"
  391. 'face 'font-lock-warning-face
  392. 'help-echo "Buffer has been modified")))
  393. " "
  394. ;; the buffer name; the file name as a tool tip
  395. '(:eval (propertize "%b " 'face 'font-lock-keyword-face
  396. 'help-echo (buffer-file-name)))
  397. ;; the current major mode for the buffer.
  398. "["
  399. '(:eval (propertize (format-mode-line mode-name) 'face '(:family "Arial")
  400. 'help-echo buffer-file-coding-system))
  401. '(:eval (propertize (format-mode-line minor-mode-alist)
  402. 'face '(:family "Arial")))
  403. "] "
  404. ;; line and column
  405. "(" ;; '%02' to set to 2 chars at least; prevents flickering
  406. (propertize "%02l" 'face 'font-lock-type-face) ","
  407. (propertize "%02c" 'face 'font-lock-type-face)
  408. ") "
  409. ;; relative position, size of file
  410. "["
  411. (propertize "%p" 'face 'font-lock-constant-face) ;; % above top
  412. "/"
  413. (propertize "%I" 'face 'font-lock-constant-face) ;; size
  414. "] "
  415. ;; add the time, with the date and the emacs uptime in the tooltip
  416. '(:eval (propertize (format-time-string "%H:%M")
  417. 'help-echo
  418. (concat (format-time-string "%c; ")
  419. (emacs-uptime "Uptime:%hh"))))
  420. )))
  421. #+END_SRC
  422. ** Line Numbers
  423. Vim-like relative line numbering. If we're on the latest versions of emacs
  424. (i.e. =26.0.50= or higher) then we should use the native line numbering
  425. otherwise we fall back to =nlinum-relative=.
  426. #+BEGIN_SRC emacs-lisp :tangle yes
  427. (if (fboundp 'display-line-numbers-mode)
  428. (progn
  429. (setq display-line-numbers 'relative)
  430. (add-hook 'prog-mode-hook 'display-line-numbers-mode))
  431. (progn
  432. (use-package nlinum-relative
  433. :config
  434. (nlinum-relative-setup-evil)
  435. (setq nlinum-relative-redisplay-delay 0.25)
  436. (setq nlinum-relative-current-symbol "")
  437. (add-hook 'prog-mode-hook 'nlinum-relative-mode))))
  438. #+END_SRC
  439. * Functions
  440. ** Face Under Point
  441. Returns the font lock face that's under the cursor.
  442. #+BEGIN_SRC emacs-lisp :tangle yes
  443. (defun what-face (pos)
  444. (interactive "d")
  445. (let ((face (or (get-char-property (point) 'read-face-name)
  446. (get-char-property (point) 'face))))
  447. (if face (message "Face: %s" face) (message "No face at %d" pos))))
  448. #+END_SRC
  449. ** Compile Project
  450. Compiles the project without a prompt.
  451. #+BEGIN_SRC emacs-lisp :tangle yes
  452. (defun wolfe/compile-no-prompt ()
  453. (interactive)
  454. (let ((compilation-read-command nil))
  455. (compile (eval compile-command))))
  456. #+END_SRC
  457. ** Compile Dotfiles
  458. Compiles all el files in the =~/.emacs.d= directory.
  459. #+BEGIN_SRC emacs-lisp :tangle yes
  460. (defun wolfe/compile-dot-emacs ()
  461. "Byte-compile dotfiles."
  462. (interactive)
  463. (byte-recompile-directory user-emacs-directory 0))
  464. #+END_SRC
  465. #+BEGIN_SRC emacs-lisp :tangle yes
  466. (defun wolfe/clear-all-elc ()
  467. (interactive)
  468. (shell-command "find ~/.emacs.d/ -name \"*.elc\" -type f -delete"))
  469. #+END_SRC
  470. #+BEGIN_SRC emacs-lisp :tangle yes
  471. (defun wolfe/remove-elc-on-save ()
  472. "If you're saving an emacs-lisp file, likely the .elc is no longer valid."
  473. (add-hook 'after-save-hook
  474. (lambda ()
  475. (if (file-exists-p (concat buffer-file-name "c"))
  476. (delete-file (concat buffer-file-name "c"))))
  477. nil t))
  478. (add-hook 'emacs-lisp-mode-hook 'wolfe/remove-elc-on-save)
  479. #+END_SRC
  480. ** Find Tags
  481. Looks up tag under point.
  482. #+BEGIN_SRC emacs-lisp :tangle yes
  483. (defun wolfe/find-tag ()
  484. "Jump to the tag at point without prompting"
  485. (interactive)
  486. (find-tag (find-tag-default)))
  487. #+END_SRC
  488. #+BEGIN_SRC emacs-lisp :tangle yes
  489. (defun wolfe/create-tags ()
  490. "Create the tags table"
  491. (interactive)
  492. (save-window-excursion (shell-command "etags -R -o ETAGS *")))
  493. #+END_SRC
  494. #+BEGIN_SRC emacs-lisp :tangle yes
  495. (defadvice xref-find-definitions (around refresh-etags activate)
  496. "Rerun etags and reload tags if tag not found and redo find-tag.
  497. If buffer is modified, ask about save before running etags."
  498. (condition-case err
  499. ad-do-it
  500. (error (and (buffer-modified-p) (not (ding))
  501. (save-buffer))
  502. (save-window-excursion (shell-command "etags -R *"))
  503. ad-do-it)))
  504. #+END_SRC
  505. ** Terminal Suspend
  506. Fixes =C-z= in terminal.
  507. #+BEGIN_SRC emacs-lisp :tangle yes
  508. (defun wolfe/controlz ()
  509. (interactive)
  510. (when (eq (display-graphic-p) nil)
  511. (suspend-frame)))
  512. #+END_SRC
  513. ** Dropbox
  514. Utility functions for finding Dropbox directories/files.
  515. #+BEGIN_SRC emacs-lisp :tangle yes
  516. (defun wolfe/org-open (name)
  517. "Opens the file in the dropbox path"
  518. (interactive)
  519. (evil-buffer-new nil (concat wolfe/org-dropbox-path name ".org")))
  520. #+END_SRC
  521. #+BEGIN_SRC emacs-lisp :tangle yes
  522. (defun wolfe/dropbox-start ()
  523. (interactive)
  524. (if (eq nil (file-exists-p "/virtual/wolfejos/dropbox/.dropbox-dist"))
  525. (call-process-shell-command "(python ~/.emacs.d/dropbox.py start -i&)")
  526. (call-process-shell-command "(python ~/.emacs.d/dropbox.py start&)")))
  527. #+END_SRC
  528. #+BEGIN_SRC emacs-lisp :tangle yes
  529. (defun wolfe/dropbox-stop ()
  530. (interactive)
  531. (call-process-shell-command "python ~/.emacs.d/dropbox.py stop&"))
  532. #+END_SRC
  533. ** Reload
  534. For reloading =init.el= file without restarting.
  535. #+BEGIN_SRC emacs-lisp :tangle yes
  536. (defun wolfe/load-init ()
  537. "Reloads init file"
  538. (interactive)
  539. (load-file "~/.emacs.d/init.el"))
  540. #+END_SRC
  541. ** Narrowing
  542. Better narrowing.
  543. #+BEGIN_SRC emacs-lisp :tangle yes
  544. (defun narrow-or-widen-dwim (p)
  545. "Widen if buffer is narrowed, narrow-dwim otherwise.
  546. Dwim means: region, org-src-block, org-subtree, or
  547. defun, whichever applies first. Narrowing to
  548. org-src-block actually calls `org-edit-src-code'.
  549. With prefix P, don't widen, just narrow even if buffer
  550. is already narrowed."
  551. (interactive "P")
  552. (declare (interactive-only))
  553. (cond ((and (buffer-narrowed-p) (not p)) (widen))
  554. ((region-active-p)
  555. (narrow-to-region (region-beginning)
  556. (region-end)))
  557. ((derived-mode-p 'org-mode)
  558. ;; `org-edit-src-code' is not a real narrowing
  559. ;; command. Remove this first conditional if
  560. ;; you don't want it.
  561. (cond ((ignore-errors (org-edit-src-code) t)
  562. (delete-other-windows))
  563. ((ignore-errors (org-narrow-to-block) t))
  564. (t (org-narrow-to-subtree))))
  565. ((derived-mode-p 'latex-mode)
  566. (LaTeX-narrow-to-environment))
  567. (t (narrow-to-defun))))
  568. (defun wolfe/man ()
  569. (if (executable-find "man")
  570. (man (word-at-point))
  571. (woman)))
  572. #+END_SRC
  573. ** Open C# Project File
  574. This function prompts for a file. It then opens that file and looks for a src/
  575. directory above it. The dir can be any number of levels higher. In that folder
  576. it looks for a C# .sln file and starts the an omnisharp server for that project.
  577. #+BEGIN_SRC emacs-lisp :tangle yes
  578. (defun wolfe/csharp-project ()
  579. (interactive)
  580. (setq path (read-file-name "File: " wolfe/project-path))
  581. (setq split-path (split-string path "/"))
  582. (if (member "src" split-path)
  583. (catch 'loop
  584. (dolist (item (reverse split-path))
  585. (if (string-equal item "src")
  586. (throw 'loop nil)
  587. (delete item split-path)))
  588. (message "src/ directory not found")))
  589. (if (or (equal '("c:") split-path) (equal '() split-path))
  590. (message "Could not find src directory for specified project")
  591. (progn
  592. (omnisharp-start-omnisharp-server (mapconcat 'identity split-path "/"))
  593. (find-file path))))
  594. #+END_SRC
  595. ** Hot Expand
  596. Is used in one of my [[Hydra][hydras]] =wolfe/hydra-org-expand=. For inserting org-templates.
  597. #+BEGIN_SRC emacs-lisp :tangle yes
  598. (defun hot-expand (str &optional additional-text)
  599. "Expand org template."
  600. (insert str)
  601. (org-try-structure-completion)
  602. (when additional-text
  603. (insert additional-text)
  604. (next-line)))
  605. #+END_SRC
  606. ** Ag Project If In Project
  607. If we're inside of a projectile project we'll use =projectile-ag= to
  608. search the project otherwise just normal ag frow our working directory
  609. does the job.
  610. #+BEGIN_SRC emacs-lisp :tangle yes
  611. (defun wolfe/ag-try-project ()
  612. (interactive)
  613. (if (projectile-project-p)
  614. (call-interactively 'projectile-ag)
  615. (call-interactively 'ag)))
  616. #+END_SRC
  617. ** Projectile Invalidate From List
  618. Select project from list of projectile projects to invalidate.
  619. #+BEGIN_SRC emacs-lisp :tangle yes
  620. (defun wolfe/projectile-invalidate-list ()
  621. (interactive)
  622. (projectile-invalidate-cache t))
  623. #+END_SRC
  624. ** User Pass Tupple
  625. Uses GPG to decrypt =file= and returns a list of the contents split on spaces.
  626. #+BEGIN_SRC emacs-lisp :tangle yes
  627. (defun wolfe/get-user-pass (file)
  628. (split-string
  629. (car (last (split-string
  630. (shell-command-to-string (concat "gpg --output - --decrypt "
  631. (expand-file-name file)))
  632. "[|\n]" t "[ \n]"))) " "))
  633. #+END_SRC
  634. ** Ag Kill Buffers and Close Window
  635. Kill all the open ag buffers and delete the window I'm in. This is bound
  636. in my [[Ag][=ag config=]] in =ag-mode-map= so it will close the current =ag= window
  637. and all the buffers.
  638. #+BEGIN_SRC emacs-lisp :tangle yes
  639. (defun wolfe/ag-kill-buffers-and-window ()
  640. (interactive)
  641. (ag-kill-buffers)
  642. (delete-window))
  643. #+END_SRC
  644. ** Org Tree Slides Set Transient Map
  645. This function once called will keep a transient map active until =wolfe--enable-transient-map=
  646. is set to nil at which point it will unbind the variable. This is used with [[Org Tree Slide][=org-tree-slide-mode=]]
  647. to add custom bindings regardless of the mode.
  648. #+BEGIN_SRC emacs-lisp :tangle yes
  649. (defun wolfe/org-tree-set-transient-map ()
  650. (interactive)
  651. (if wolfe--enable-transient-map
  652. (let ((map (make-sparse-keymap)))
  653. (define-key map (kbd "<right>") 'org-tree-slide-move-next-tree)
  654. (define-key map (kbd "<left>") 'org-tree-slide-move-previous-tree)
  655. (define-key map (kbd "<up>") 'org-tree-slide-content)
  656. (define-key map (kbd "<down>") 'org-tree-slide-display-header-toggle)
  657. (set-transient-map map nil 'wolfe/org-tree-set-transient-map))
  658. (makeunbound wolfe--enable-transient-map)))
  659. #+END_SRC
  660. * Org Mode
  661. ** General
  662. Setup some basic quality of life org settings.
  663. #+BEGIN_SRC emacs-lisp :tangle yes
  664. (setq org-pretty-entities t
  665. org-src-fontify-natively t
  666. org-src-tab-acts-natively t
  667. org-src-window-setup 'current-window
  668. org-fontify-whole-heading-line t
  669. org-fontify-done-headline t
  670. org-fontify-quote-and-verse-blocks t
  671. org-log-done 'time
  672. org-agenda-use-time-grid nil
  673. org-agenda-skip-deadline-if-done t
  674. org-agenda-skip-scheduled-if-done t
  675. org-ellipsis wolfe/org-ellipsis)
  676. (org-babel-do-load-languages
  677. 'org-babel-load-languages
  678. '((shell . t)
  679. ( dot . t)))
  680. (global-set-key "\C-cl" 'org-store-link)
  681. ;; ispell ignores SRC blocks
  682. (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
  683. (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_LATEX" . "#\\+END_LATEX"))
  684. ;; Refresh images after executing a src block
  685. (add-hook 'org-babel-after-execute-hook
  686. '(lambda ()
  687. (when org-inline-image-overlays
  688. (org-redisplay-inline-images))))
  689. ;; Open PDFs with zathura
  690. (add-hook 'org-mode-hook
  691. '(lambda ()
  692. (setq org-file-apps
  693. (append '(("\\.pdf\\'" . "zathura \"%s\"")) org-file-apps))))
  694. #+END_SRC
  695. ** Bullets
  696. Replaces the asterisks with nice UTF-8 bullets.
  697. #+BEGIN_SRC emacs-lisp :tangle yes
  698. (use-package org-bullets
  699. :config
  700. (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
  701. #+END_SRC
  702. ** Agenda
  703. Setup org agenda for managing my life.
  704. #+BEGIN_SRC emacs-lisp :tangle yes
  705. (use-package org-agenda
  706. :ensure nil
  707. :bind (("C-c a" . org-agenda)
  708. :map org-agenda-mode-map
  709. ("j" . org-agenda-next-item)
  710. ("k" . org-agenda-previous-item))
  711. :config
  712. ;; Formats the agenda into nice columns
  713. (setq org-agenda-prefix-format
  714. '((agenda . " %i %-12t% s %-12(car (last (org-get-outline-path)))")
  715. (timeline . " % s")
  716. (todo . " %i %-12:c")
  717. (tags . " %i %-12:c")
  718. (search . " %i %-12:c")))
  719. ;; Sets location of org files
  720. (setq org-agenda-files '((concat wolfe/org-dropbox-path "everything.org")))
  721. (setq browse-url-browser-function 'browse-url-chromium))
  722. #+END_SRC
  723. ** Export
  724. Setup html for syntax highlighting on export and add the apppropriate
  725. minted package for PDF export.
  726. #+BEGIN_SRC emacs-lisp :tangle yes
  727. (use-package htmlize)
  728. (require 'ox-latex)
  729. (add-to-list 'org-latex-packages-alist '("" "minted"))
  730. (setq org-latex-listings 'minted)
  731. (setq org-latex-pdf-process
  732. '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
  733. "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
  734. "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
  735. #+END_SRC
  736. ** Org Tree Slide
  737. Presentation mode that runs from within an org document. I add a custom hook for [[Org Tree Slides Set Transient Map][a function]] that
  738. repeatedly creates a transient map replacing the controls regardless of my evil mode.
  739. #+BEGIN_SRC emacs-lisp :tangle yes
  740. (use-package org-tree-slide
  741. :config
  742. (add-hook 'org-tree-slide-mode-hook
  743. (lambda ()
  744. (if org-tree-slide-mode
  745. ;; When mode is enabled
  746. (progn (setq org-hide-emphasis-markers t
  747. wolfe--enable-transient-map t)
  748. (wolfe/org-tree-set-transient-map))
  749. ;; When mode is disabled
  750. (setq org-hide-emphasis-markers nil
  751. wolfe--enable-transient-map nil)))))
  752. #+END_SRC
  753. * Keymaps
  754. ** Hydra
  755. Customizable popup menus.
  756. #+BEGIN_SRC emacs-lisp :tangle yes
  757. (use-package hydra)
  758. #+END_SRC
  759. *** Major Modes
  760. **** C#
  761. #+BEGIN_SRC emacs-lisp :tangle yes
  762. (setq wolfe/hydra-csharp
  763. (defhydra hydra-csharp (:color blue)
  764. "Omnisharp"
  765. ("d" omnisharp-go-to-definition "Goto definition")
  766. ("D" omnisharp-go-to-definition-other-window "Pop-open definition")
  767. ("u" omnisharp-find-usages "Find usages")
  768. ("r" omnisharp-rename "Rename symbol")
  769. ("R" omnisharp-reload-solution "Reload solution")
  770. ("i" omnisharp-code-format-region "Indent region")
  771. ("I" omnisharp-code-format-entire-file "Indent entire file")
  772. ))
  773. #+END_SRC
  774. **** Org Mode
  775. #+BEGIN_SRC emacs-lisp :tangle yes
  776. (setq wolfe/hydra-org
  777. (defhydra hydra-org (:color blue)
  778. "Org Mode"
  779. ("t" (funcall wolfe/hydra-org-expand) "Expand template")))
  780. #+END_SRC
  781. **** Org Templates
  782. #+BEGIN_SRC emacs-lisp :tangle yes
  783. (setq wolfe/hydra-org-expand
  784. (defhydra hydra-org-template (:color blue :hint nil)
  785. "
  786. _c_enter _q_uote _L_aTeX:
  787. _l_atex _e_xample _i_ndex:
  788. _a_scii _v_erse _I_NCLUDE:
  789. _s_rc _t_angle _H_TML:
  790. _h_tml _d_ot src _A_SCII:
  791. "
  792. ("s" (hot-expand "<s"))
  793. ("e" (hot-expand "<e"))
  794. ("q" (hot-expand "<q"))
  795. ("v" (hot-expand "<v"))
  796. ("t" (hot-expand "<s" "emacs-lisp :tangle yes"))
  797. ("d" (hot-expand "<s" "dot :file TMP.png :cmdline -Kdot -Tpng"))
  798. ("c" (hot-expand "<c"))
  799. ("l" (hot-expand "<l"))
  800. ("h" (hot-expand "<h"))
  801. ("a" (hot-expand "<a"))
  802. ("L" (hot-expand "<L"))
  803. ("i" (hot-expand "<i"))
  804. ("I" (hot-expand "<I"))
  805. ("H" (hot-expand "<H"))
  806. ("A" (hot-expand "<A"))))
  807. #+END_SRC
  808. *** Minor Modes
  809. **** Projectile
  810. #+BEGIN_SRC emacs-lisp :tangle yes
  811. (setq wolfe/hydra-projectile
  812. (defhydra hydra-projectile (:color blue :columns 4)
  813. "Projectile"
  814. ("f" counsel-projectile-find-file "Find File")
  815. ("s" counsel-projectile-switch-project "Switch Project")
  816. ("k" projectile-kill-buffers "Kill Buffers")
  817. ("c" projectile-invalidate-cache "Clear Cache")
  818. ("d" counsel-projectile-find-dir "Find Directory")
  819. ("o" projectile-multi-occur "Multi Occur")
  820. ("P" projectile-clear-known-projects "Clear Projects")
  821. ("C" wolfe/projectile-invalidate-list "Clear A Cache")
  822. ))
  823. #+END_SRC
  824. **** Jira
  825. #+BEGIN_SRC emacs-lisp :tangle yes
  826. (setq wolfe/hydra-jira
  827. (defhydra hydra-jira (:color blue :columns 4)
  828. "Jira"
  829. ("p" org-jira-get-projects "Get Projects")
  830. ("b" org-jira-browse-issue "Browse Issue")
  831. ("g" org-jira-get-issues "Get Issues")
  832. ("u" org-jira-update-issue "Update Issue")
  833. ("p" org-jira-progress-issue "Update Issue Progress")
  834. ("a" org-jira-assign-issue "Assign Issue")
  835. ("r" org-jira-refresh-issue "Refresh Issue")
  836. ("R" org-jira-refresh-issues-in-buffer "Refresh Issues in Buffer")
  837. ("c" org-jira-create-issue "Create Issue")
  838. ("y" org-jira-copy-current-issue-key "Copy Current Issue Key")
  839. ("s" org-jira-create-subtask "Create Subtask")
  840. ("G" org-jira-get-subtasks "Get Subtasks")
  841. ("U" org-jira-update-comment "Update Comment")
  842. ("t" org-jira-todo-to-jira "Todo to Jira")
  843. ("O" (funcall wolfe/hydra-org-expand) "Org Hydra")))
  844. #+END_SRC
  845. *** Default
  846. #+BEGIN_SRC emacs-lisp :tangle yes
  847. (setq wolfe/hydra-default
  848. (defhydra hydra-default (:color blue)
  849. "Default"
  850. ("o" (funcall wolfe/hydra-org) "Org Mode")
  851. ("#" (funcall wolfe/hydra-csharp) "C# Mode")))
  852. #+END_SRC
  853. *** Selector
  854. #+BEGIN_SRC emacs-lisp :tangle yes
  855. (defun wolfe/hydra-selector ()
  856. (cond
  857. ((derived-mode-p 'csharp-mode) wolfe/hydra-csharp)
  858. ((bound-and-true-p org-jira-mode) wolfe/hydra-jira)
  859. ((derived-mode-p 'org-mode) wolfe/hydra-org)
  860. (:else wolfe/hydra-default)))
  861. #+END_SRC
  862. ** Evil & General
  863. *** General
  864. #+BEGIN_SRC emacs-lisp :tangle yes
  865. (use-package general)
  866. #+END_SRC
  867. *** Evil
  868. #+BEGIN_SRC emacs-lisp :tangle yes
  869. (use-package evil
  870. :demand
  871. :init
  872. (setq evil-want-C-u-scroll t) ; Unbind <C-u> for evil mode's use
  873. (setq evil-want-C-i-jump nil)
  874. :config
  875. (evil-mode t)
  876. (setq evil-split-window-below t
  877. evil-vsplit-window-right t
  878. evil-lookup-func #'wolfe/man)
  879. (setq-default evil-symbol-word-search t)
  880. (custom-set-variables '(evil-search-module (quote evil-search)))
  881. (evil-ex-define-cmd "re[load]" 'wolfe/load-init) ; Custom reload command
  882. (evil-ex-define-cmd "Q" 'save-buffers-kill-terminal) ; For typos
  883. (define-key evil-ex-map "e " 'counsel-find-file) ; Trigger file completion :e
  884. (global-unset-key (kbd "M-SPC")) ; Unbind secondary leader
  885. (general-create-definer wolfe/bind-leader
  886. :keymaps 'global
  887. :states '(normal insert visual emacs)
  888. :prefix "SPC"
  889. :non-normal-prefix "M-SPC")
  890. :general
  891. (:states 'motion
  892. "k" 'evil-previous-visual-line
  893. "j" 'evil-next-visual-line)
  894. (:states 'operator
  895. "k" 'evil-previous-line
  896. "j" 'evil-next-line)
  897. (:states 'visual
  898. "<" (lambda ()
  899. (interactive)
  900. (evil-shift-left (region-beginning) (region-end))
  901. (evil-normal-state)
  902. (evil-visual-restore))
  903. ">" (lambda ()
  904. (interactive)
  905. (evil-shift-right (region-beginning) (region-end))
  906. (evil-normal-state)
  907. (evil-visual-restore)))
  908. (:states 'normal
  909. "C-z" 'wolfe/controlz
  910. "C-l" 'evil-ex-nohighlight)
  911. (:states 'normal :prefix "g"
  912. "a" (lambda (beginning end)
  913. (interactive "r")
  914. (if (use-region-p)
  915. (align beginning end)
  916. (align-current)))
  917. "A" 'align-regexp)
  918. (wolfe/bind-leader
  919. "w" 'save-buffer
  920. "S" 'eval-buffer
  921. "s" 'eval-defun
  922. "b" 'mode-line-other-buffer
  923. "k" 'kill-buffer
  924. "m" 'ivy-switch-buffer
  925. "t" 'wolfe/find-tag
  926. "e" 'iedit-mode
  927. "c" 'wolfe/compile-no-prompt
  928. "n" 'narrow-or-widen-dwim
  929. "a" 'org-agenda
  930. "g" 'magit-status
  931. "f" 'wolfe/ag-try-project
  932. "''" 'org-edit-src-exit
  933. "#" 'wolfe/csharp-project
  934. "p" (lambda() (interactive) (funcall wolfe/hydra-projectile))
  935. ";" (lambda() (interactive) (save-excursion (end-of-line) (insert-char ?\;)))
  936. "id" (lambda() (interactive) (indent-region (point-min) (point-max)))
  937. "o" (lambda() (interactive) (wolfe/org-open "everything"))
  938. "SPC" (lambda() (interactive) (funcall (wolfe/hydra-selector)))
  939. "init" (lambda() (interactive) (evil-buffer-new nil wolfe/init-file))))
  940. #+END_SRC
  941. *** Evil Surround
  942. Tpope's surround
  943. #+BEGIN_SRC emacs-lisp :tangle yes
  944. (use-package evil-surround
  945. :config
  946. (global-evil-surround-mode 1))
  947. #+END_SRC
  948. *** Evil Magit
  949. #+BEGIN_SRC emacs-lisp :tangle yes
  950. (use-package evil-magit)
  951. #+END_SRC
  952. *** Evil Machit
  953. #+BEGIN_SRC emacs-lisp :tangle yes
  954. (use-package evil-matchit
  955. :config
  956. (global-evil-matchit-mode 1))
  957. #+END_SRC
  958. *** Evil Visual Star
  959. This allows me to easily start a =*= or =#= search from a visual selection.
  960. #+BEGIN_SRC emacs-lisp :tangle yes
  961. (use-package evil-visualstar
  962. :config
  963. (global-evil-visualstar-mode))
  964. #+END_SRC
  965. * Project Management
  966. ** Ag
  967. Emacs interface for ag
  968. #+BEGIN_SRC emacs-lisp :tangle yes
  969. (use-package ag
  970. :bind (:map ag-mode-map
  971. ("Q" . wolfe/ag-kill-buffers-and-window)))
  972. #+END_SRC
  973. ** Magit
  974. Magic git interface from within emacs
  975. #+BEGIN_SRC emacs-lisp :tangle yes
  976. (use-package magit
  977. :config
  978. (setq magit-bury-buffer-function
  979. (lambda (con)
  980. (kill-buffer)
  981. (delete-window)))
  982. (global-set-key "\C-x\g" 'magit-status))
  983. #+END_SRC
  984. ** Magithub
  985. #+BEGIN_SRC emacs-lisp :tangle yes
  986. (use-package magithub
  987. :after magit
  988. :config (magithub-feature-autoinject t))
  989. #+END_SRC
  990. ** Projectile
  991. Project management
  992. #+BEGIN_SRC emacs-lisp :tangle yes
  993. (use-package projectile
  994. :config
  995. (use-package counsel-projectile
  996. :config
  997. (counsel-projectile-on))
  998. (setq projectile-enable-caching t)
  999. (setq projectile-indexing-method 'alien)
  1000. (setq projectile-globally-ignored-file-suffixes '(".dll" ".exe" ".o"))
  1001. (setq projectile-globally-ignored-directories '(".git" "node_modules"))
  1002. (projectile-global-mode))
  1003. #+END_SRC
  1004. * Languages
  1005. ** Generic Web
  1006. #+BEGIN_SRC emacs-lisp :tangle yes
  1007. (use-package web-mode
  1008. :config
  1009. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  1010. (add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))
  1011. (add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode))
  1012. (setq web-mode-enable-auto-closing t)
  1013. (setq web-mode-enable-auto-opening t)
  1014. (setq web-mode-enable-auto-indentation t))
  1015. (use-package json-mode)
  1016. #+END_SRC
  1017. #+BEGIN_SRC emacs-lisp :tangle yes
  1018. (use-package company-restclient
  1019. :after company
  1020. :config
  1021. (add-to-list 'company-backends 'company-restclient))
  1022. #+END_SRC
  1023. ** Javascript
  1024. #+BEGIN_SRC emacs-lisp :tangle yes
  1025. (use-package company-tern
  1026. :after company
  1027. :config
  1028. (add-to-list 'company-backends 'company-tern)
  1029. (add-hook 'web-mode-hook 'tern-mode))
  1030. #+END_SRC
  1031. ** Lisp Family
  1032. #+BEGIN_SRC emacs-lisp :tangle yes
  1033. (use-package parinfer
  1034. :bind
  1035. (("C-," . parinfer-toggle-mode))
  1036. :init
  1037. (setq
  1038. parinfer-extensions '(defaults pretty-parens evil smart-tab smart-yank)
  1039. parinfer-lighters '(" Φi" . " Φp"))
  1040. (add-hook 'clojure-mode-hook #'parinfer-mode)
  1041. (add-hook 'emacs-lisp-mode-hook #'parinfer-mode)
  1042. (add-hook 'common-lisp-mode-hook #'parinfer-mode)
  1043. (add-hook 'scheme-mode-hook #'parinfer-mode)
  1044. (add-hook 'lisp-mode-hook #'parinfer-mode))
  1045. #+END_SRC
  1046. ** Racket
  1047. #+BEGIN_SRC emacs-lisp :tangle yes
  1048. (use-package racket-mode)
  1049. #+END_SRC
  1050. ** Latex
  1051. #+BEGIN_SRC emacs-lisp :tangle yes
  1052. (use-package latex-preview-pane
  1053. :ensure f)
  1054. #+END_SRC
  1055. ** C/C++
  1056. #+BEGIN_SRC emacs-lisp :tangle yes
  1057. (setq gdb-many-windows t
  1058. gdb-show-main t
  1059. company-clang-insert-arguments nil)
  1060. (use-package company-irony
  1061. :after company
  1062. :config
  1063. (add-hook 'c++-mode-hook 'irony-mode)
  1064. (add-hook 'c-mode-hook 'irony-mode)
  1065. (eval-after-load 'company
  1066. '(add-to-list 'company-backends 'company-irony)))
  1067. #+END_SRC
  1068. ** C#
  1069. #+BEGIN_SRC emacs-lisp :tangle yes
  1070. (use-package omnisharp
  1071. :after company
  1072. :config
  1073. (setq omnisharp-server-executable-path "C:/emacs/omnisharp/Omnisharp.exe")
  1074. (add-hook 'csharp-mode-hook 'omnisharp-mode)
  1075. (add-to-list 'company-backends 'company-omnisharp))
  1076. #+END_SRC
  1077. ** Python
  1078. #+BEGIN_SRC emacs-lisp :tangle yes
  1079. (use-package company-jedi
  1080. :after company
  1081. :config
  1082. (add-to-list 'company-backends 'company-jedi))
  1083. #+END_SRC
  1084. ** Shell Scripts
  1085. #+BEGIN_SRC emacs-lisp :tangle yes
  1086. (use-package company-shell
  1087. :after company
  1088. :config
  1089. (add-to-list 'company-backends '(company-shell company-shell-env)))
  1090. #+END_SRC
  1091. ** Nim
  1092. #+BEGIN_SRC emacs-lisp :tangle yes
  1093. (use-package nim-mode)
  1094. #+END_SRC
  1095. * Utility
  1096. ** Ranger
  1097. #+BEGIN_SRC emacs-lisp :tangle yes
  1098. (use-package ranger
  1099. :config
  1100. (setq ranger-cleanup-on-disable t)
  1101. (ranger-override-dired-mode t))
  1102. #+END_SRC
  1103. ** Iedit
  1104. Edit all instances of a string
  1105. #+BEGIN_SRC emacs-lisp :tangle yes
  1106. (use-package iedit
  1107. :config
  1108. (setq iedit-toggle-key-default nil))
  1109. #+END_SRC
  1110. ** Restclient
  1111. Postman inside of emacs.
  1112. #+BEGIN_SRC emacs-lisp :tangle yes
  1113. (use-package restclient)
  1114. #+END_SRC
  1115. ** Rainbow Mode
  1116. Shows hex colors inline.
  1117. #+BEGIN_SRC emacs-lisp :tangle yes
  1118. (use-package rainbow-mode)
  1119. #+END_SRC
  1120. ** Help Fns+
  1121. #+BEGIN_SRC emacs-lisp :tangle yes
  1122. (use-package help-fns+)
  1123. #+END_SRC
  1124. ** Org Jira
  1125. #+BEGIN_SRC emacs-lisp :tangle yes
  1126. (use-package org-jira
  1127. :config
  1128. (setq jiralib-url "https://indigoca.atlassian.net"))
  1129. #+END_SRC
  1130. ** Delight
  1131. #+BEGIN_SRC emacs-lisp :tangle yes
  1132. (use-package delight
  1133. :config
  1134. (delight '((emacs-lisp-mode "ξ" :major)
  1135. (lisp-interaction-mode "λ" :major)
  1136. (python-mode "π" :major)
  1137. (org-mode "Ø" :major)
  1138. (company-mode " C" company)
  1139. (ivy-mode " ι" ivy)
  1140. (projectile-mode " ρ" projectile)
  1141. (eldoc-mode " ε" eldoc)
  1142. (flycheck-mode " ƒ" flycheck)
  1143. (undo-tree-mode "" undo-tree)
  1144. (auto-revert-mode "" autorevert))))
  1145. #+END_SRC
  1146. * Completion
  1147. ** Ivy & Counsel
  1148. #+BEGIN_SRC emacs-lisp :tangle yes
  1149. (use-package ivy
  1150. :demand
  1151. :bind (("M-x" . counsel-M-x)
  1152. ("C-x C-f" . counsel-find-file)
  1153. :map ivy-minibuffer-map
  1154. ("TAB" . ivy-next-line)
  1155. ("RET" . ivy-alt-done))
  1156. :init
  1157. (use-package smex)
  1158. (use-package counsel)
  1159. :config
  1160. (setq ivy-re-builders-alist
  1161. '((t . ivy--regex-ignore-order)))
  1162. (setq ivy-wrap t)
  1163. (ivy-mode 1)
  1164. (eval-after-load "hydra" (use-package ivy-hydra)))
  1165. #+END_SRC
  1166. ** Swiper
  1167. #+BEGIN_SRC emacs-lisp :tangle yes
  1168. (use-package swiper
  1169. :bind (("C-s" . swiper)))
  1170. #+END_SRC
  1171. ** Company
  1172. Autocomplete engine
  1173. #+BEGIN_SRC emacs-lisp :tangle yes
  1174. (use-package company
  1175. :bind (:map company-active-map
  1176. ("C-n" . company-select-next)
  1177. ("C-p" . company-select-previous))
  1178. :init
  1179. (global-company-mode)
  1180. :config
  1181. (setq company-idle-delay 0) ; Delay to complete
  1182. (setq company-minimum-prefix-length 1)
  1183. (setq company-selection-wrap-around t) ; Loops around suggestions
  1184. (if (display-graphic-p)
  1185. (define-key company-active-map [tab] 'company-select-next)
  1186. (define-key company-active-map (kbd "C-i") 'company-select-next))
  1187. #+END_SRC
  1188. #+BEGIN_SRC emacs-lisp :tangle yes
  1189. (ignore-errors
  1190. (require 'color)
  1191. (let ((bg (face-attribute 'default :background)))
  1192. (custom-set-faces
  1193. `(company-tooltip ((t (:inherit default :background ,(color-lighten-name bg 2)))))
  1194. `(company-scrollbar-bg ((t (:background ,(color-lighten-name bg 10)))))
  1195. `(company-scrollbar-fg ((t (:background ,(color-lighten-name bg 5)))))
  1196. `(company-tooltip-selection ((t (:inherit font-lock-function-name-face))))
  1197. `(company-tooltip-common ((t (:inherit font-lock-constant-face))))))))
  1198. #+END_SRC
  1199. ** Flycheck Linting
  1200. On the fly syntax checking
  1201. #+BEGIN_SRC emacs-lisp :tangle yes
  1202. (use-package flycheck
  1203. :config
  1204. (global-flycheck-mode)
  1205. (with-eval-after-load 'flycheck
  1206. (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))))
  1207. #+END_SRC
  1208. * Misc
  1209. ** Email
  1210. #+BEGIN_SRC emacs-lisp :tangle yes
  1211. (when (require 'mu4e nil 'noerror)
  1212. (setq mu4e-msg2pdf "/usr/bin/msg2pdf")
  1213. (setq
  1214. ;; set mu4e as default mail client
  1215. mail-user-agent 'mu4e-user-agent
  1216. ;; root mail directory - can't be switched
  1217. ;; with context, can only be set once
  1218. mu4e-maildir "~/.mail"
  1219. mu4e-attachments-dir "~/Downloads/Attachments"
  1220. ;; update command
  1221. mu4e-get-mail-command "mbsync -q -a"
  1222. ;; update database every seven minutes
  1223. mu4e-update-interval (* 60 7)
  1224. ;; use smtpmail (bundled with emacs) for sending
  1225. message-send-mail-function 'smtpmail-send-it
  1226. ;; optionally log smtp output to a buffer
  1227. smtpmail-debug-info t
  1228. ;; close sent message buffers
  1229. message-kill-buffer-on-exit t
  1230. ;; customize list columns
  1231. mu4e-headers-fields '((:flags . 4)
  1232. (:from . 20)
  1233. (:human-date . 10)
  1234. (:subject))
  1235. ;; for mbsync
  1236. mu4e-change-filenames-when-moving t
  1237. ;; pick first context automatically on launch
  1238. mu4e-context-policy 'pick-first
  1239. ;; use current context for new mail
  1240. mu4e-compose-context-policy nil
  1241. mu4e-confirm-quit nil)
  1242. (global-set-key (kbd "<f12>") 'mu4e)
  1243. (global-set-key (kbd "<C-f12>") 'mu4e-update-mail-and-index)
  1244. (setq mu4e-contexts
  1245. `(,(make-mu4e-context
  1246. :name "gmail"
  1247. :match-func (lambda(msg)
  1248. (when msg
  1249. (mu4e-message-contact-field-matches msg :to "@gmail.com")))
  1250. :vars '(
  1251. ;; local directories, relative to mail root
  1252. (mu4e-sent-folder . "/gmail/[Gmail]/.Sent Mail")
  1253. (mu4e-drafts-folder . "/gmail/[Gmail]/.Drafts")
  1254. (mu4e-trash-folder . "/gmail/[Gmail]/.Trash")
  1255. (mu4e-refile-folder . "/gmail/[Gmail]/.All Mail")
  1256. ;; account details
  1257. (user-mail-address . "joshuafwolfe@gmail.com")
  1258. (user-full-name . "Josh Wolfe")
  1259. (mu4e-user-mail-address-list . ( "@gmail.com" ))
  1260. ;; gmail saves every outgoing message automatically
  1261. (mu4e-sent-messages-behavior . delete)
  1262. (mu4e-maildir-shortcuts . (("/gmail/INBOX" . ?j)
  1263. ("/gmail/[Gmail]/.All Mail" . ?a)
  1264. ("/gmail/[Gmail]/.Trash" . ?t)
  1265. ("/gmail/[Gmail]/.Drafts" . ?d)))
  1266. ;; outbound mail server
  1267. (smtpmail-smtp-server . "smtp.gmail.com")
  1268. ;; outbound mail port
  1269. (smtpmail-smtp-service . 465)
  1270. ;; use ssl
  1271. (smtpmail-stream-type . ssl)
  1272. ;; the All Mail folder has a copy of every other folder's contents,
  1273. ;; and duplicates search results, which is confusing
  1274. (mue4e-headers-skip-duplicates . t)))))
  1275. (use-package evil-mu4e))
  1276. #+END_SRC
  1277. ** IRC
  1278. #+BEGIN_SRC emacs-lisp :tangle yes
  1279. (use-package erc
  1280. :ensure nil
  1281. :config
  1282. (add-hook 'window-configuration-change-hook
  1283. '(lambda ()
  1284. (setq erc-fill-column (- (window-width) 2))))
  1285. (add-hook 'erc-mode-hook
  1286. '(lambda ()
  1287. (setq-local scroll-margin 1)))
  1288. (setq erc-rename-buffers t
  1289. erc-interpret-mirc-color t
  1290. erc-lurker-hide-list '("JOIN" "PART" "QUIT")
  1291. erc-autojoin-channels-alist '(("freenode.net" "#emacs")))
  1292. (defun wolfe/irc ()
  1293. (interactive)
  1294. (let* ((tupple (wolfe/get-user-pass wolfe/irc-info-path))
  1295. (user (car tupple))
  1296. (pass (cadr tupple)))
  1297. (erc
  1298. :server "irc.freenode.net"
  1299. :port 6667
  1300. :nick user
  1301. :password pass))))
  1302. #+END_SRC
  1303. ** Meme
  1304. Meme creator from within emacs... what more is there to say?
  1305. #+BEGIN_SRC emacs-lisp :tangle yes
  1306. (use-package meme
  1307. :ensure nil
  1308. :commands (meme meme-file))
  1309. #+END_SRC
  1310. * Backups
  1311. Stores all backups and temp files in =~/.bak.emacs/=
  1312. #+BEGIN_SRC emacs-lisp :tangle yes
  1313. (setq backup-by-copying t) ; Stop shinanigans with links
  1314. (setq backup-directory-alist '((".*" . "~/.bak.emacs/backup/")))
  1315. ;; Creates directory if it doesn't already exist
  1316. (if (eq nil (file-exists-p "~/.bak.emacs/"))
  1317. (make-directory "~/.bak.emacs/"))
  1318. ;; Creates auto directory if it doesn't already exist
  1319. (if (eq nil (file-exists-p "~/.bak.emacs/auto"))
  1320. (make-directory "~/.bak.emacs/auto"))
  1321. ;; backup in one place. flat, no tree structure
  1322. (setq auto-save-file-name-transforms '((".*" "~/.bak.emacs/auto/" t)))
  1323. #+END_SRC
  1324. * Testing
  1325. ** Org Project
  1326. #+BEGIN_SRC emacs-lisp :tangle yes
  1327. (cond ((file-exists-p "~/Projects/org-project/")
  1328. (load-file "~/Projects/org-project/org-project.el")
  1329. (setq org-project-use-ag t))
  1330. ((file-exists-p "C:/dev/SideProjects/org-project/")
  1331. (load-file "C:/dev/SideProjects/org-project/org-project.el")
  1332. (setq org-project-use-ag t)))
  1333. #+END_SRC
  1334. ** Extract Dates
  1335. #+BEGIN_SRC emacs-lisp :tangle yes
  1336. (defun wolfe/extract-dates (file-path)
  1337. "Parse through a file for a list of all the comments"
  1338. (let (already-open
  1339. buf
  1340. start
  1341. (comments '()))
  1342. (setq already-open (find-buffer-visiting file-path)
  1343. buf (find-file-noselect file-path))
  1344. (with-current-buffer buf
  1345. (goto-char (point-min))
  1346. (while (setq start (text-property-any
  1347. (point) (point-max)
  1348. 'face 'org-date))
  1349. (goto-char start)
  1350. (goto-char (next-single-char-property-change (point) 'face))
  1351. (let ((item (string-trim (buffer-substring-no-properties start (point)))))
  1352. (setq comments (cons item comments)))))
  1353. (unless already-open (kill-buffer buf))
  1354. (reverse comments)))
  1355. #+END_SRC