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 43KB

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