Human Readable Emacs Configuration using Org mode
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.

1002 lines
39 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #+TITLE: Emacs Configuration
  2. #+AUTHOR: Levi Olson
  3. #+EMAIL: olson.levi@gmail.com
  4. #+DATE: <2019-01-30 Wed>
  5. #+LANGUAGE: en
  6. #+BABEL: :cache yes
  7. #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="public/style.css" />
  8. #+EXPORT_FILE_NAME: index.html
  9. #+PROPERTY: header-args :tangle yes
  10. #+OPTIONS: num:10 whn:nil toc:10 H:10
  11. #+STARTUP: content
  12. * Summary
  13. I've really been wanting to have a nicely formatted emacs config file and this is my attempt at it.
  14. * Required Magic
  15. ** Lexical Binding
  16. #+BEGIN_SRC emacs-lisp :results silent
  17. ;;; -*- lexical-binding: t -*-
  18. ;;; DO NOT EDIT THIS FILE DIRECTLY
  19. ;;; EDIT ~init.org~ instead
  20. #+END_SRC
  21. ** The Magical Glue
  22. The following auto compiles the emacs-lisp within the =init.org= file.
  23. Simply run `org-babel-tangle` to make it RAIN!
  24. #+BEGIN_SRC emacs-lisp :results silent
  25. ;; (setq byte-compile-warnings nil)
  26. (defun tangle-init ()
  27. "If the current buffer is 'init.org' the code-blocks are tangled, and the tangled file is compiled."
  28. (when (equal (buffer-file-name)
  29. (expand-file-name (concat user-emacs-directory "init.org")))
  30. ;; Avoid running hooks when tangling.
  31. (let ((prog-mode-hook nil))
  32. (org-babel-tangle)
  33. (byte-compile-file (concat user-emacs-directory "init.el")))))
  34. (add-hook 'after-save-hook 'tangle-init)
  35. #+END_SRC
  36. * Config
  37. ** Packages
  38. #+BEGIN_SRC emacs-lisp :results silent
  39. (require 'package)
  40. (package-initialize)
  41. (defvar my-packages
  42. '(all-the-icons
  43. anzu
  44. base16-theme
  45. bbdb
  46. better-defaults
  47. company
  48. company-go
  49. counsel
  50. counsel-projectile
  51. dash-at-point
  52. dashboard
  53. diminish
  54. dockerfile-mode
  55. doom-modeline
  56. doom-themes
  57. ein
  58. eldoc-eval
  59. elpy
  60. emmet-mode
  61. expand-region
  62. fic-mode
  63. gitignore-mode
  64. go-mode
  65. go-playground
  66. gorepl-mode
  67. flycheck
  68. iedit
  69. ivy
  70. ivy-hydra
  71. json-mode
  72. magit
  73. material-theme
  74. multiple-cursors
  75. nnir-est
  76. projectile
  77. py-autopep8
  78. rainbow-delimiters
  79. rust-mode
  80. shrink-path
  81. tide
  82. typescript-mode
  83. use-package
  84. web-mode
  85. which-key))
  86. (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
  87. (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))
  88. (when (not package-archive-contents)
  89. (package-refresh-contents))
  90. (package-initialize)
  91. (dolist (p my-packages)
  92. (when (not (package-installed-p p))
  93. (package-install p)))
  94. #+END_SRC
  95. ** Server
  96. #+BEGIN_SRC emacs-lisp :results silent :tangle no
  97. (require 'edit-server)
  98. (edit-server-start)
  99. #+END_SRC
  100. ** Better Defaults
  101. #+BEGIN_SRC emacs-lisp :results silent
  102. (require 'better-defaults)
  103. ;; Instead of the annoying giant warning icon, just flash the modeline.
  104. ;; (this happens when you do something like C-g)
  105. (setq ring-bell-function
  106. (lambda ()
  107. (let ((orig-fg (face-foreground 'mode-line)))
  108. (set-face-foreground 'mode-line "#F2804F")
  109. (run-with-idle-timer 0.1 nil
  110. (lambda (fg) (set-face-foreground 'mode-line fg))
  111. orig-fg))))
  112. (defun set-frame-size-according-to-resolution ()
  113. "Set the Emacs window size on startup."
  114. (interactive)
  115. (if window-system
  116. (progn
  117. ;; WIDTH
  118. (if (> (x-display-pixel-width) 1280)
  119. ;; Large Screen (only show 120 cols)
  120. (add-to-list 'default-frame-alist (cons 'width 240))
  121. ;; Small Screen (fill window)
  122. (add-to-list 'default-frame-alist (cons 'width (/ (x-display-pixel-width) (frame-char-width)))))
  123. ;; HEIGHT
  124. (if (> (x-display-pixel-height) 1080)
  125. ;; Large Screen (only fill half screen)
  126. (add-to-list 'default-frame-alist (cons 'height (/ (/ (x-display-pixel-height) 2)
  127. (frame-char-height))))
  128. ;; Small Screen (fill window)
  129. (add-to-list 'default-frame-alist (cons 'height (/ (x-display-pixel-height) (frame-char-height)))))
  130. )))
  131. (set-frame-size-according-to-resolution)
  132. (defun window-px-width ()
  133. "Get the width of the Emacs window in pixels."
  134. (interactive)
  135. (* (* (window-total-width) 2.874) (frame-char-width)))
  136. (defun window-px-left-pos ()
  137. "Calculate the left position of the Emacs window."
  138. (interactive)
  139. (/ (- (x-display-pixel-width) (window-px-width)) 2))
  140. (add-to-list 'default-frame-alist (cons 'top 0))
  141. (add-to-list 'default-frame-alist (cons 'left 1000))
  142. #+END_SRC
  143. ** Enable Disabled Commands
  144. #+BEGIN_SRC emacs-lisp :results silent
  145. (put 'narrow-to-region 'disabled nil)
  146. (put 'upcase-region 'disabled nil)
  147. (put 'downcase-region 'disabled nil)
  148. #+END_SRC
  149. ** Splash Screen
  150. #+BEGIN_SRC emacs-lisp :results silent
  151. (require 'dashboard)
  152. (dashboard-setup-startup-hook)
  153. ;; Set the title
  154. (setq dashboard-banner-logo-title "Let's begin...")
  155. ;; Set the banner
  156. (setq dashboard-startup-banner "~/.emacs.d/public/emacs-logo-512.png")
  157. ;; Value can be
  158. ;; 'official which displays the official emacs logo
  159. ;; 'logo which displays an alternative emacs logo
  160. ;; 1, 2 or 3 which displays one of the text banners
  161. ;; "path/to/your/image.png" which displays whatever image you would prefer
  162. ;; Content is not centered by default. To center, set
  163. (setq dashboard-center-content t)
  164. ;; To disable shortcut "jump" indicators for each section, set
  165. (setq dashboard-show-shortcuts t)
  166. (setq show-week-agenda-p t)
  167. (setq dashboard-items '((recents . 5)
  168. (bookmarks . 5)
  169. (projects . 5)
  170. (agenda . 5)
  171. (registers . 5)))
  172. ;; (setq inhibit-splash-screen nil
  173. ;; fancy-splash-image "~/.emacs.d/public/emacs-logo-256.png"
  174. ;; fancy-splash-image-file "~/.emacs.d/public/emacs-logo-256.png")
  175. #+END_SRC
  176. ** Basic Customization
  177. #+BEGIN_SRC emacs-lisp :results silent
  178. (defvar backup-dir (expand-file-name "~/.emacs.d/backup/"))
  179. (defvar autosave-dir (expand-file-name "~/.emacs.d/autosave/"))
  180. (setq initial-scratch-message nil
  181. backup-directory-alist (list (cons ".*" backup-dir))
  182. auto-save-list-file-prefix autosave-dir
  183. auto-save-file-name-transforms `((".*" ,autosave-dir t)))
  184. (menu-bar-mode 0)
  185. (scroll-bar-mode 0)
  186. (tool-bar-mode 0)
  187. ;; (load-theme 'doom-city-lights t)
  188. ;; (load-theme 'doom-dracula t)
  189. ;; (load-theme 'doom-nord t)
  190. (load-theme 'doom-one t)
  191. ;; (load-theme 'doom-spacegrey t)
  192. ;; (load-theme 'base16-ocean t)
  193. (load-theme 'base16-onedark t)
  194. (global-linum-mode t)
  195. (global-auto-revert-mode t)
  196. (defalias 'yes-or-no-p 'y-or-n-p)
  197. #+END_SRC
  198. ** Custom Modes
  199. #+BEGIN_SRC emacs-lisp :results silent
  200. (require 'font-lock)
  201. (defvar openhab-mode-hook nil)
  202. (defvar openhab-mode-map
  203. (let ((map (make-keymap)))
  204. (define-key map "\C-j" 'newline-and-indent)
  205. map)
  206. "Keymap for OPENHAB major mode.")
  207. (add-to-list 'auto-mode-alist '("\\.sitemap\\'" . openhab-mode))
  208. (add-to-list 'auto-mode-alist '("\\.items\\'" . openhab-mode))
  209. (add-to-list 'auto-mode-alist '("\\.rules\\'" . openhab-mode))
  210. (add-to-list 'auto-mode-alist '("\\.things\\'" . openhab-mode))
  211. (defconst openhab-font-lock-keywords
  212. `(
  213. ("\<.*\>" . font-lock-constant-face)
  214. (,(regexp-opt
  215. '(
  216. ;; KEYWORDS
  217. "Selection" "Slider" "List" "Setpoint" "Video" "Chart" "Webview" "Colorpicker"
  218. "Timer" "Number" "String"
  219. "Switch" "Rollershutter" "Number" "String" "Dimmer" "Contact" "DateTime" "Color"
  220. "Text" "Group" "Image" "Frame"
  221. "Thing" "Bridge"
  222. "Time" "System"
  223. "sitemap"
  224. "rule" "when" "then" "end"
  225. "if" "val"
  226. "import" "var" "say" "postUpdate" "switch" "println" "case" "or" "sendCommand"
  227. )
  228. 'words)
  229. (1 font-lock-keyword-face))
  230. (,(regexp-opt
  231. '(
  232. "ON" "OFF" "on" "off"
  233. "AND" "OR" "NAND" "NOR" "AVG" "SUM" "MAX" "MIN"
  234. "true" "false"
  235. )
  236. 'words)
  237. (1 font-lock-constant-face))
  238. (,(regexp-opt
  239. '(
  240. "name" "label" "item" "period" "refresh" "icon" "mappings" "minValue" "maxValue" "step" "switchsupport" "url" "height" "refresh" "visibility" "valuecolor"
  241. )
  242. 'words)
  243. (1 font-lock-type-face))
  244. ("\(.*\)" . font-lock-variable-name-face)
  245. ("[^a-zA-Z0-9_:]\\([0-9]*\\)[^a-zA-Z0-9_:]" . (1 font-lock-variable-name-face))
  246. ("\s@\s" . font-lock-variable-name-face)
  247. ("\s\\([a-zA-Z0-9_:]*\\)\\(\s\\|$\\)" . (1 font-lock-type-face))
  248. ("=\\([a-zA-Z_]*\\)" . (1 font-lock-string-face))
  249. ("\\([a-zA-Z]*\\)=" . (1 font-lock-type-face))
  250. )
  251. "The regexps to highlight in openHAB mode.")
  252. (defvar openhab-mode-syntax-table
  253. (let ((st (make-syntax-table)))
  254. (modify-syntax-entry ?/ ". 12b" st) ;; C-style comments // ...
  255. (modify-syntax-entry ?\n "> b" st) ;; \n ends comment
  256. ;; Block comments /*...*/
  257. (modify-syntax-entry ?\/ ". 14" st)
  258. (modify-syntax-entry ?* ". 23" st)
  259. st)
  260. "Syntax table for openhab-mode.")
  261. (defun openhab-mode ()
  262. "Major mode for editing OPENHAB config files."
  263. (interactive)
  264. (kill-all-local-variables)
  265. (set-syntax-table openhab-mode-syntax-table)
  266. (use-local-map openhab-mode-map)
  267. (set (make-local-variable 'font-lock-defaults) '(openhab-font-lock-keywords nil t))
  268. (electric-pair-mode -1)
  269. (flycheck-mode -1)
  270. (setq major-mode 'openhab-mode)
  271. (setq mode-name "OpenHAB")
  272. (run-hooks 'openhab-mode-hook))
  273. (provide 'openhab-mode)
  274. #+END_SRC
  275. ** Tools
  276. *** General
  277. #+BEGIN_SRC emacs-lisp :results silent
  278. (require 'which-key)
  279. (which-key-setup-minibuffer)
  280. (which-key-mode)
  281. (require 'fic-mode)
  282. (add-hook 'js-mode-hook 'fic-mode)
  283. #+END_SRC
  284. *** Company
  285. #+BEGIN_SRC emacs-lisp :results silent
  286. (require 'company)
  287. (add-hook 'after-init-hook 'global-company-mode)
  288. (setq company-dabbrev-downcase nil)
  289. (setq company-idle-delay 0.1)
  290. #+END_SRC
  291. *** Diminish
  292. #+BEGIN_SRC emacs-lisp :results silent
  293. (require 'diminish)
  294. (diminish 'auto-revert-mode)
  295. (eval-after-load "company" '(diminish 'company-mode))
  296. (eval-after-load "counsel" '(diminish 'counsel-mode))
  297. (eval-after-load "elpy" '(diminish 'elpy-mode))
  298. (eval-after-load "go-mode" '(diminish 'go-mode))
  299. (eval-after-load "go-playground" '(diminish 'go-playground-mode))
  300. (eval-after-load "gorepl-mode" '(diminish 'gorepl-mode))
  301. (eval-after-load "flycheck" '(diminish 'flycheck-mode))
  302. (eval-after-load "ivy" '(diminish 'ivy-mode))
  303. (eval-after-load "projectile" '(diminish 'projectile-mode))
  304. (eval-after-load "which-key" '(diminish 'which-key-mode))
  305. #+END_SRC
  306. *** Dired
  307. #+BEGIN_SRC emacs-lisp :results silent
  308. (defun dired-mode-setup ()
  309. "Will run as hook for `dired-mode'."
  310. (dired-hide-details-mode 1))
  311. (add-hook 'dired-mode-hook 'dired-mode-setup)
  312. #+END_SRC
  313. *** Ivy
  314. #+BEGIN_SRC emacs-lisp :results silent
  315. (require 'ivy-hydra)
  316. (require 'ivy)
  317. (require 'swiper)
  318. (ivy-mode 1)
  319. (counsel-mode)
  320. (setq ivy-use-virtual-buffers t
  321. enable-recursive-minibuffers t
  322. ivy-height 25
  323. ivy-initial-inputs-alist nil
  324. ivy-extra-directories nil)
  325. (global-set-key (kbd "C-s") 'swiper)
  326. (global-set-key (kbd "C-c C-r") 'ivy-resume)
  327. (global-set-key (kbd "M-x") 'counsel-M-x)
  328. (global-set-key (kbd "C-x C-f") 'counsel-find-file)
  329. (global-set-key (kbd "C-c g") 'counsel-git)
  330. (global-set-key (kbd "C-c j") 'counsel-git-grep)
  331. (global-set-key (kbd "C-c k") 'counsel-ag)
  332. (define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
  333. (defun ivy-open-current-typed-path ()
  334. (interactive)
  335. (when ivy--directory
  336. (let* ((dir ivy--directory)
  337. (text-typed ivy-text)
  338. (path (concat dir text-typed)))
  339. (delete-minibuffer-contents)
  340. (ivy--done path))))
  341. (define-key ivy-minibuffer-map (kbd "<return>") 'ivy-alt-done)
  342. (define-key ivy-minibuffer-map (kbd "C-f") 'ivy-open-current-typed-path)
  343. #+END_SRC
  344. *** Magit
  345. #+BEGIN_SRC emacs-lisp :results silent
  346. (require 'magit)
  347. (global-set-key (kbd "C-x g") 'magit-status)
  348. (global-set-key (kbd "C-c g") 'magit-status)
  349. (setq magit-completing-read-function 'ivy-completing-read)
  350. #+END_SRC
  351. *** Mu4e
  352. #+BEGIN_SRC emacs-lisp :results silent
  353. (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu/mu4e")
  354. (require 'mu4e)
  355. ;; default
  356. (setq mu4e-maildir "~/Mail"
  357. mu4e-mu-binary "/usr/local/bin/mu"
  358. mu4e-get-mail-command "offlineimap" ;; Allow updating with the "U" command
  359. mu4e-sent-messages-behavior 'delete ;; Delete sent messages
  360. mu4e-view-show-images t ;; attempt to show images
  361. mu4e-view-image-max-width 400 ;; max image size
  362. message-kill-buffer-on-exit t ;; don't keep messages around
  363. mu4e-use-fancy-chars t ;; use 'fancy' chars
  364. mu4e-update-interval 300 ;; 5 mins
  365. )
  366. (setq mu4e-contexts
  367. `( ,(make-mu4e-context
  368. :name "Vlocity"
  369. :enter-func (lambda () (mu4e-message "Entering Vlocity"))
  370. :leave-func (lambda () (mu4e-message "Leaving Vlocity"))
  371. ;; we match based on the contact-fields of the message
  372. :match-func (lambda (msg)
  373. (when msg
  374. (string= (mu4e-message-field msg :maildir) "/Vlocity")))
  375. :vars '( ( user-mail-address . "lolson@vlocity.com" )
  376. ( smtpmail-mail-address . "lolson@vlocity.com" )
  377. ( user-full-name . "Levi Olson" )
  378. ( mu4e-compose-signature .
  379. (concat
  380. "--\n"
  381. "Levi Olson\n"
  382. "Senior UI Developer"))
  383. ( mu4e-sent-folder . "/Vlocity/[Gmail].Sent Mail" )
  384. ( mu4e-drafts-folder . "/Vlocity/[Gmail].Drafts" )
  385. ( mu4e-trash-folder . "/Vlocity/[Gmail].Trash" )
  386. ( mu4e-maildir-shortcuts . (("/Vlocity/INBOX" . ?i)
  387. ("/Vlocity/[Gmail].Sent Mail" . ?s)
  388. ("/Vlocity/[Gmail].Trash" . ?t)
  389. ("/Vlocity/[Gmail].All Mail" . ?a)))))
  390. ,(make-mu4e-context
  391. :name "Gmail"
  392. :enter-func (lambda () (mu4e-message "Entering Gmail"))
  393. :leave-func (lambda () (mu4e-message "Leaving Gmail"))
  394. ;; this matches maildir /Arkham and its sub-directories
  395. :match-func (lambda (msg)
  396. (when msg
  397. (string= (mu4e-message-field msg :maildir) "/Gmail")))
  398. :vars '( ( user-mail-address . "olson.levi@gmail.com" )
  399. ( smtpmail-mail-address . "olson.levi@gmail.com" )
  400. ( user-full-name . "Levi Olson" )
  401. ( mu4e-compose-signature .
  402. (concat
  403. "--\n"
  404. "Levi\n"))
  405. ( mu4e-sent-folder . "/Gmail/[Gmail].Sent Mail" )
  406. ( mu4e-drafts-folder . "/Gmail/[Gmail].Drafts" )
  407. ( mu4e-trash-folder . "/Gmail/[Gmail].Trash" )
  408. ( mu4e-maildir-shortcuts . (("/Gmail/INBOX" . ?i)
  409. ("/Gmail/[Gmail].Sent Mail" . ?s)
  410. ("/Gmail/[Gmail].Trash" . ?t)
  411. ("/Gmail/[Gmail].All Mail" . ?a))
  412. )))))
  413. ;; (defcustom smtpmail-smtp-user nil
  414. ;; "User name to use when looking up credentials in the authinfo file.
  415. ;; If non-nil, only consider credentials for the specified user."
  416. ;; :version "24.1"
  417. ;; :type '(choice (const nil) string)
  418. ;; :group 'smtpmail)
  419. ;; How to handle HTML emails
  420. ;; (setq mu4e-html2text-command "textutil -stdin -format html -convert txt -stdout")
  421. ;; Add option to view HTML in browser
  422. (add-to-list 'mu4e-headers-actions
  423. '("in browser" . mu4e-action-view-in-browser) t)
  424. (add-to-list 'mu4e-view-actions
  425. '("in browser" . mu4e-action-view-in-browser) t)
  426. #+END_SRC
  427. *** Projectile
  428. #+BEGIN_SRC emacs-lisp :results silent
  429. (require 'projectile)
  430. (require 'counsel-projectile)
  431. (projectile-mode)
  432. (setq projectile-mode-line '(:eval (format " %s" (projectile-project-name)))
  433. projectile-remember-window-configs t
  434. projectile-completion-system 'ivy)
  435. (counsel-projectile-mode)
  436. #+END_SRC
  437. ** Development Specific
  438. *** General
  439. #+BEGIN_SRC emacs-lisp :results silent
  440. (require 'rainbow-delimiters)
  441. (global-flycheck-mode)
  442. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  443. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  444. (setq-default indent-tabs-mode nil
  445. tab-width 4)
  446. (defvaralias 'c-basic-offset 'tab-width)
  447. (defvaralias 'cperl-indent-level 'tab-width)
  448. (electric-pair-mode 1)
  449. (show-paren-mode 1)
  450. (require 'dockerfile-mode)
  451. (add-to-list 'auto-mode-alist '("Dockerfile*\\'" . dockerfile-mode))
  452. (require 'gitignore-mode)
  453. (add-to-list 'auto-mode-alist '("gitignore\\'" . gitignore-mode))
  454. (require 'json-mode)
  455. (add-to-list 'auto-mode-alist '("\\.json\\'" . json-mode))
  456. (require 'web-mode)
  457. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  458. #+END_SRC
  459. *** Python
  460. #+BEGIN_SRC emacs-lisp :results silent
  461. (elpy-enable)
  462. (setq python-shell-interpreter "jupyter"
  463. python-shell-interpreter-args "console --simple-prompt")
  464. (when (require 'flycheck nil t)
  465. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  466. (add-hook 'elpy-mode-hook 'flycheck-mode))
  467. (require 'py-autopep8)
  468. (setq py-autopep8-options '("--ignore=E501"))
  469. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  470. #+END_SRC
  471. *** Go
  472. #+BEGIN_SRC emacs-lisp :results silent
  473. (require 'go-mode)
  474. (require 'go-playground)
  475. (require 'gorepl-mode)
  476. (require 'company-go)
  477. (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  478. (add-hook 'go-mode-hook (lambda ()
  479. (add-hook 'before-save-hook 'gofmt-before-save)
  480. (local-set-key (kbd "M-.") 'godef-jump)
  481. (local-set-key (kbd "M-,") 'pop-tag-mark)
  482. (local-set-key (kbd "C-c C-c") (lambda ()
  483. (interactive)
  484. (ansi-term)
  485. (comint-send-string "*ansi-term*" "make\n")))
  486. (set (make-local-variable 'company-backends) '(company-go))
  487. (setq company-tooltip-limit 20
  488. company-echo-delay 0
  489. company-begin-commands '(self-insert-command))
  490. (gorepl-mode)))
  491. (defun set-exec-path-from-shell-PATH ()
  492. (let ((path-from-shell (replace-regexp-in-string
  493. "[ \t\n]*$"
  494. ""
  495. (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
  496. (setenv "PATH" path-from-shell)
  497. (setq eshell-path-env path-from-shell)
  498. (setq exec-path (split-string path-from-shell path-separator))))
  499. (when window-system (set-exec-path-from-shell-PATH))
  500. (setenv "GOPATH" "/Users/leviolson/go")
  501. (add-to-list 'exec-path "/Users/leviolson/go/bin")
  502. #+END_SRC
  503. *** TypeScript
  504. #+BEGIN_SRC emacs-lisp :results silent
  505. (defun setup-tide-mode ()
  506. "Tide setup function."
  507. (interactive)
  508. (tide-setup)
  509. (flycheck-mode +1)
  510. (setq flycheck-check-syntax-automatically '(save mode-enabled))
  511. (eldoc-mode +1)
  512. (tide-hl-identifier-mode +1)
  513. (company-mode +1))
  514. ;; aligns annotation to the right hand side
  515. (setq company-tooltip-align-annotations t)
  516. ;; formats the buffer before saving
  517. (add-hook 'before-save-hook 'tide-format-before-save)
  518. (add-hook 'typescript-mode-hook #'setup-tide-mode)
  519. (require 'typescript-mode)
  520. (require 'tide)
  521. (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
  522. (add-hook 'typescript-mode-hook
  523. '(lambda ()
  524. (set (make-local-variable 'company-backends) '(company-tide))
  525. (setq company-tooltip-limit 20
  526. company-echo-delay 0
  527. company-begin-commands '(self-insert-command)
  528. tide-format-options '(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t :placeOpenBraceOnNewLineForFunctions nil))
  529. (tide-setup)))
  530. #+END_SRC
  531. **** TSX
  532. #+BEGIN_SRC emacs-lisp :results silent
  533. (require 'web-mode)
  534. (add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
  535. (add-hook 'web-mode-hook
  536. (lambda ()
  537. (when (string-equal "tsx" (file-name-extension buffer-file-name))
  538. (setup-tide-mode))))
  539. ;; enable typescript-tslint checker
  540. (flycheck-add-mode 'typescript-tslint 'web-mode)
  541. #+END_SRC
  542. **** JSX
  543. #+BEGIN_SRC emacs-lisp :results silent
  544. (require 'web-mode)
  545. (add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
  546. (add-hook 'web-mode-hook
  547. (lambda ()
  548. (when (string-equal "jsx" (file-name-extension buffer-file-name))
  549. (setup-tide-mode))))
  550. ;; configure jsx-tide checker to run after your default jsx checker
  551. (flycheck-add-mode 'javascript-eslint 'web-mode)
  552. (flycheck-add-next-checker 'javascript-eslint 'jsx-tide 'append)
  553. #+END_SRC
  554. *** Org
  555. #+BEGIN_SRC emacs-lisp :results silent
  556. (org-babel-do-load-languages
  557. 'org-babel-load-languages
  558. '((js . t)
  559. (shell . t)
  560. (emacs-lisp . t)))
  561. (defvar org-src-tab-acts-natively)
  562. (setq org-src-tab-acts-natively t)
  563. ;; (setenv "NODE_PATH"
  564. ;; (getenv "NODE_PATH"))
  565. (defvar org-confirm-babel-evaluate)
  566. (defun my-org-confirm-babel-evaluate (lang body)
  567. "Execute certain languages without confirming.
  568. Takes LANG to allow and BODY to execute."
  569. (not (or (string= lang "js")
  570. (string= lang "restclient")
  571. (string= lang "emacs-lisp")
  572. (string= lang "shell"))))
  573. (setq org-confirm-babel-evaluate #'my-org-confirm-babel-evaluate)
  574. (add-to-list 'org-structure-template-alist
  575. (list "e" (concat "#+BEGIN_SRC emacs-lisp :results silent\n"
  576. "\n"
  577. "#+END_SRC")))
  578. (add-to-list 'org-structure-template-alist
  579. (list "j" (concat "#+BEGIN_SRC js :cmd \"babel-node\"\n"
  580. "\n"
  581. "#+END_SRC")))
  582. (add-to-list 'org-structure-template-alist
  583. (list "r" (concat "#+BEGIN_SRC restclient :results raw\n"
  584. "\n"
  585. "#+END_SRC")))
  586. #+END_SRC
  587. ** Functions
  588. #+BEGIN_SRC emacs-lisp :results silent
  589. (defun find-user-init-file ()
  590. "Edit the `~/.emacs.d/init.org' file."
  591. (interactive)
  592. (find-file "~/.emacs.d/init.org"))
  593. (defun load-user-init-file ()
  594. "LO: Reload the `~/.emacs.d/init.elc' file."
  595. (interactive)
  596. (load-file "~/.emacs.d/init.elc"))
  597. (defun jump-to-symbol-internal (&optional backwardp)
  598. "Jumps to the next symbol near the point if such a symbol exists. If BACKWARDP is non-nil it jumps backward."
  599. (let* ((point (point))
  600. (bounds (find-tag-default-bounds))
  601. (beg (car bounds)) (end (cdr bounds))
  602. (str (isearch-symbol-regexp (find-tag-default)))
  603. (search (if backwardp 'search-backward-regexp
  604. 'search-forward-regexp)))
  605. (goto-char (if backwardp beg end))
  606. (funcall search str nil t)
  607. (cond ((<= beg (point) end) (goto-char point))
  608. (backwardp (forward-char (- point beg)))
  609. (t (backward-char (- end point))))))
  610. (defun jump-to-previous-like-this ()
  611. "Jumps to the previous occurrence of the symbol at point."
  612. (interactive)
  613. (jump-to-symbol-internal t))
  614. (defun jump-to-next-like-this ()
  615. "Jumps to the next occurrence of the symbol at point."
  616. (interactive)
  617. (jump-to-symbol-internal))
  618. (defun match-paren (arg)
  619. "Go to the matching paren if on a paren; otherwise insert ARG (a literal % sign)."
  620. (interactive "p")
  621. (cond ((looking-at "\\s(") (forward-list 1))
  622. ((looking-back "\\s(" 2) (backward-char 1) (forward-list 1))
  623. ((looking-at "\\s)") (forward-char 1) (backward-list 1))
  624. ((looking-back "\\s)" 2) (backward-list 1))
  625. (t (self-insert-command (or arg 1)))))
  626. (defun kill-this-buffer-unless-scratch ()
  627. "Works like `kill-this-buffer' unless the current buffer is the *scratch* buffer. In which case the buffer content is deleted and the buffer is buried."
  628. (interactive)
  629. (if (not (string= (buffer-name) "*scratch*"))
  630. (kill-this-buffer)
  631. (delete-region (point-min) (point-max))
  632. (switch-to-buffer (other-buffer))
  633. (bury-buffer "*scratch*")))
  634. (defun delete-backward-sentence ()
  635. "LO: Delete to the beginning of the sentence/line."
  636. (interactive)
  637. (delete-region (point) (progn (backward-sentence) (point))))
  638. (defun delete-backward-to-boundary (arg)
  639. "LO: Delete backward to the previous word boundary. With ARG, do this many times."
  640. (interactive "p")
  641. (let ((a (point))
  642. (b (progn
  643. (backward-word arg)
  644. (forward-word)
  645. (point))))
  646. (if (< a b)
  647. (delete-region a (progn (backward-word arg) (point)))
  648. (if (= a b)
  649. (delete-region a (progn (backward-word arg) (point)))
  650. (delete-region a b)))))
  651. (defun comment-or-uncomment-region-or-line ()
  652. "Comments or uncomments the region or the current line if there's no active region."
  653. (interactive)
  654. (let (beg end)
  655. (if (region-active-p)
  656. (setq beg (region-beginning) end (region-end))
  657. (setq beg (line-beginning-position) end (line-end-position)))
  658. (comment-or-uncomment-region beg end)))
  659. (defun fold-toggle (column)
  660. "Code folding by COLUMN."
  661. (interactive "P")
  662. (set-selective-display
  663. (or column
  664. (unless selective-display
  665. (1+ (current-column))))))
  666. (defun new-line-below ()
  667. "LO: Create a new line below current line."
  668. (interactive)
  669. (move-end-of-line 1)
  670. (newline-and-indent))
  671. (defun new-line-above ()
  672. "LO: Create a new line above current line."
  673. (interactive)
  674. (move-beginning-of-line 1)
  675. (newline)
  676. (forward-line -1))
  677. (defun duplicate-thing (comment)
  678. "LO: Duplicates the current line, or the region if active. If an argument (COMMENT) is given, the duplicated region will be commented out."
  679. (interactive "P")
  680. (save-excursion
  681. (let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
  682. (end (if (region-active-p) (region-end) (point-at-eol))))
  683. (goto-char end)
  684. (unless (region-active-p)
  685. (newline))
  686. (insert (buffer-substring start end))
  687. (when comment (comment-region start end)))))
  688. (defun tidy ()
  689. "LO: Ident, untabify and unwhitespacify current buffer, or region if active."
  690. (interactive)
  691. (let ((beg (if (region-active-p) (region-beginning) (point-min)))
  692. (end (if (region-active-p) (region-end) (point-max))))
  693. (let ((inhibit-message t))
  694. (indent-region beg end))
  695. (whitespace-cleanup)
  696. (untabify beg (if (< end (point-max)) end (point-max)))
  697. (if (region-active-p) (message "Indenting Region...Done") (message "Indenting File...Done"))))
  698. (defun phil-columns ()
  699. "LO: Good 'ol Phil-Columns."
  700. (interactive)
  701. (message "Good 'ol fill-columns")
  702. (with-output-to-temp-buffer "*PHIL-COLUMN*"
  703. (shell-command "mpv --no-video 'https://www.youtube.com/watch?v=YkADj0TPrJA&t=3m16s' > /dev/null 2>&1 & sleep 8; pkill mpv"))
  704. (other-window 1)
  705. (delete-window))
  706. (declare-function first "Goto FIRST shell.")
  707. (declare-function goto-non-shell-buffer "Goto something other than a shell buffer.")
  708. (declare-function switch-shell "Switch shell.")
  709. (let ((last-shell ""))
  710. (defun toggle-shell ()
  711. (interactive)
  712. (cond ((string-match-p "^\\*shell<[1-9][0-9]*>\\*$" (buffer-name))
  713. (goto-non-shell-buffer))
  714. ((get-buffer last-shell) (switch-to-buffer last-shell))
  715. (t (shell (setq last-shell "*shell<1>*")))))
  716. (defun switch-shell (n)
  717. (let ((buffer-name (format "*shell<%d>*" n)))
  718. (setq last-shell buffer-name)
  719. (cond ((get-buffer buffer-name)
  720. (switch-to-buffer buffer-name))
  721. (t (shell buffer-name)
  722. (rename-buffer buffer-name)))))
  723. (defun goto-non-shell-buffer ()
  724. (let* ((r "^\\*shell<[1-9][0-9]*>\\*$")
  725. (shell-buffer-p (lambda (b) (string-match-p r (buffer-name b))))
  726. (non-shells (cl-remove-if shell-buffer-p (buffer-list))))
  727. (when non-shells
  728. (switch-to-buffer (first non-shells))))))
  729. (defadvice shell (after kill-with-no-query nil activate)
  730. "."
  731. (set-process-query-on-exit-flag (get-buffer-process ad-return-value) nil))
  732. (declare-function comint-truncate-buffer ".")
  733. (defun clear-comint ()
  734. "Run `comint-truncate-buffer' with the `comint-buffer-maximum-size' set to zero."
  735. (interactive)
  736. (let ((comint-buffer-maximum-size 0))
  737. (comint-truncate-buffer)))
  738. (defun c-setup ()
  739. "Compile."
  740. (local-set-key (kbd "C-c C-c") 'compile))
  741. #+END_SRC
  742. ** Bindings
  743. #+BEGIN_SRC emacs-lisp :results silent
  744. (require 'company)
  745. (add-hook 'comint-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-comint)))
  746. (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
  747. (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
  748. (add-hook 'c-mode-common-hook 'c-setup)
  749. (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
  750. (defvar company-active-map (make-keymap)
  751. "Company Mode keymap.")
  752. (defvar custom-bindings (make-keymap)
  753. "A keymap of custom bindings.")
  754. (define-key global-map (kbd "M-p") 'jump-to-previous-like-this)
  755. (define-key global-map (kbd "M-n") 'jump-to-next-like-this)
  756. (define-key global-map (kbd "M-<tab>") 'switch-to-next-buffer)
  757. (define-key global-map (kbd "M-<backspace>")'delete-backward-to-boundary)
  758. (define-key global-map (kbd "C-<backspace>")'delete-backward-to-boundary)
  759. (global-set-key (kbd "C-S-<down>") 'mc/mark-next-like-this)
  760. (global-set-key (kbd "C->") 'mc/mark-next-like-this-symbol)
  761. (global-set-key (kbd "C-S-<up>") 'mc/mark-previous-like-this)
  762. (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
  763. (global-set-key (kbd "C-c C->") 'mc/mark-all-like-this)
  764. (global-set-key "%" 'match-paren)
  765. (global-set-key (kbd "C-x .") 'dash-at-point)
  766. (global-set-key (kbd "C-x ,") 'dash-at-point-with-docset)
  767. (global-set-key (kbd "C-s") (lambda () (interactive) (swiper (format "%s" (thing-at-point 'symbol)))))
  768. (global-set-key (kbd "M-m") 'mu4e)
  769. ;; (dolist (n (number-sequence 1 9))
  770. ;; (global-set-key (kbd (concat "M-" (int-to-string n)))
  771. ;; (lambda () (interactive) (switch-shell n))))
  772. (define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
  773. (define-key company-active-map (kbd "C-n") 'company-select-next)
  774. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  775. (define-key company-active-map (kbd "<tab>") 'company-complete)
  776. (define-key custom-bindings (kbd "C-c p") 'counsel-projectile-switch-project)
  777. (define-key custom-bindings (kbd "C-c f") 'counsel-projectile-find-file)
  778. (define-key custom-bindings (kbd "C-c m") 'magit-status)
  779. (define-key custom-bindings (kbd "C-c D") 'define-word-at-point)
  780. (define-key custom-bindings (kbd "C-@") 'er/expand-region)
  781. (define-key custom-bindings (kbd "C-#") 'er/contract-region)
  782. (define-key custom-bindings (kbd "C-S-c C-S-c") 'mc/edit-lines)
  783. (define-key custom-bindings (kbd "C-c b") 'ivy-switch-buffer)
  784. (define-key custom-bindings (kbd "C-c l") 'org-store-link)
  785. (define-key custom-bindings (kbd "C-c t") 'org-set-tags)
  786. (define-key custom-bindings (kbd "M-u") 'upcase-dwim)
  787. (define-key custom-bindings (kbd "M-c") 'capitalize-dwim)
  788. (define-key custom-bindings (kbd "M-l") 'downcase-dwim)
  789. (define-key custom-bindings (kbd "M-o") 'other-window)
  790. (define-key custom-bindings (kbd "C-c s") 'ispell-word)
  791. (define-key custom-bindings (kbd "C-c C-d") 'org-capture)
  792. (define-key custom-bindings (kbd "C-c <up>") 'windmove-up)
  793. (define-key custom-bindings (kbd "C-c <down>") 'windmove-down)
  794. (define-key custom-bindings (kbd "C-c <left>") 'windmove-left)
  795. (define-key custom-bindings (kbd "C-c <right>") 'windmove-right)
  796. (define-key custom-bindings (kbd "C-c a") (lambda () (interactive) (org-agenda nil "n")))
  797. (define-key custom-bindings (kbd "C-c e") 'find-user-init-file)
  798. (define-key custom-bindings (kbd "C-x f") 'phil-columns)
  799. (define-key custom-bindings (kbd "C-x k") 'kill-this-buffer-unless-scratch)
  800. (define-key custom-bindings (kbd "C-c d") 'duplicate-thing)
  801. (define-key custom-bindings (kbd "C-c c") 'comment-or-uncomment-region-or-line)
  802. (define-key custom-bindings (kbd "C-;") 'comment-or-uncomment-region-or-line)
  803. (define-key custom-bindings (kbd "C-o") 'new-line-below)
  804. (define-key custom-bindings (kbd "C-S-o") 'new-line-above)
  805. (define-key custom-bindings (kbd "<C-tab>") 'tidy)
  806. (define-key custom-bindings (kbd "M-q") 'kill-this-buffer)
  807. (define-key custom-bindings (kbd "M-RET") '(lambda () (interactive) (term (getenv "SHELL"))))
  808. (define-minor-mode custom-bindings-mode
  809. "A mode that activates custom-bindings."
  810. t nil custom-bindings)
  811. #+END_SRC
  812. ** UI
  813. #+BEGIN_SRC emacs-lisp :results silent
  814. (cond ((member "PragmataPro Mono Liga" (font-family-list))
  815. (set-face-attribute 'default nil :font "PragmataPro Mono Liga-13")))
  816. #+END_SRC
  817. *** Doom Modeline
  818. #+BEGIN_SRC emacs-lisp :results silent
  819. (require 'doom-modeline)
  820. (doom-modeline-mode 1)
  821. ;; How tall the mode-line should be (only respected in GUI Emacs).
  822. (setq doom-modeline-height 35)
  823. ;; How wide the mode-line bar should be (only respected in GUI Emacs).
  824. (setq doom-modeline-bar-width 4)
  825. ;; Determines the style used by `doom-modeline-buffer-file-name'.
  826. ;;
  827. ;; Given ~/Projects/FOSS/emacs/lisp/comint.el
  828. ;; truncate-upto-project => ~/P/F/emacs/lisp/comint.el
  829. ;; truncate-from-project => ~/Projects/FOSS/emacs/l/comint.el
  830. ;; truncate-with-project => emacs/l/comint.el
  831. ;; truncate-except-project => ~/P/F/emacs/l/comint.el
  832. ;; truncate-upto-root => ~/P/F/e/lisp/comint.el
  833. ;; truncate-all => ~/P/F/e/l/comint.el
  834. ;; relative-from-project => emacs/lisp/comint.el
  835. ;; relative-to-project => lisp/comint.el
  836. ;; file-name => comint.el
  837. ;; buffer-name => comint.el<2> (uniquify buffer name)
  838. ;;
  839. ;; If you are expereicing the laggy issue, especially while editing remote files
  840. ;; with tramp, please try `file-name' style.
  841. ;; Please refer to https://github.com/bbatsov/projectile/issues/657.
  842. (setq doom-modeline-buffer-file-name-style 'truncate-upto-project)
  843. ;; What executable of Python will be used (if nil nothing will be showed).
  844. (setq doom-modeline-python-executable "python")
  845. ;; Whether show `all-the-icons' or not (if nil nothing will be showed).
  846. (setq doom-modeline-icon t)
  847. ;; Whether show the icon for major mode. It respects `doom-modeline-icon'.
  848. (setq doom-modeline-major-mode-icon t)
  849. ;; Display color icons for `major-mode'. It respects `all-the-icons-color-icons'.
  850. (setq doom-modeline-major-mode-color-icon nil)
  851. ;; Whether display minor modes or not. Non-nil to display in mode-line.
  852. (setq doom-modeline-minor-modes nil)
  853. ;; If non-nil, a word count will be added to the selection-info modeline segment.
  854. (setq doom-modeline-enable-word-count nil)
  855. ;; If non-nil, only display one number for checker information if applicable.
  856. (setq doom-modeline-checker-simple-format t)
  857. ;; Whether display perspective name or not. Non-nil to display in mode-line.
  858. (setq doom-modeline-persp-name t)
  859. ;; Whether display `lsp' state or not. Non-nil to display in mode-line.
  860. (setq doom-modeline-lsp t)
  861. ;; Whether display github notifications or not. Requires `ghub` package.
  862. (setq doom-modeline-github nil)
  863. ;; The interval of checking github.
  864. (setq doom-modeline-github-interval (* 30 60))
  865. ;; Whether display environment version or not.
  866. (setq doom-modeline-env-version t)
  867. ;; Whether display mu4e notifications or not. Requires `mu4e-alert' package.
  868. (setq doom-modeline-mu4e t)
  869. #+END_SRC