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.

1003 lines
40 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. *** OpenHAB Mode
  200. #+BEGIN_SRC emacs-lisp :results silent
  201. (require 'font-lock)
  202. (defvar openhab-mode-hook nil)
  203. (defvar openhab-mode-map
  204. (let ((map (make-keymap)))
  205. (define-key map "\C-j" 'newline-and-indent)
  206. map)
  207. "Keymap for OPENHAB major mode.")
  208. (add-to-list 'auto-mode-alist '("\\.sitemap\\'" . openhab-mode))
  209. (add-to-list 'auto-mode-alist '("\\.items\\'" . openhab-mode))
  210. (add-to-list 'auto-mode-alist '("\\.rules\\'" . openhab-mode))
  211. (add-to-list 'auto-mode-alist '("\\.things\\'" . openhab-mode))
  212. (defconst openhab-font-lock-keywords
  213. `(
  214. ("\<.*\>" . font-lock-constant-face)
  215. (,(regexp-opt
  216. '(
  217. ;; KEYWORDS
  218. "Selection" "Slider" "List" "Setpoint" "Video" "Chart" "Webview" "Colorpicker"
  219. "Timer" "Number" "String"
  220. "Switch" "Rollershutter" "Number" "String" "Dimmer" "Contact" "DateTime" "Color"
  221. "Text" "Group" "Image" "Frame"
  222. "Thing" "Bridge"
  223. "Time" "System"
  224. "sitemap"
  225. "rule" "when" "then" "end"
  226. "if" "val"
  227. "import" "var" "say" "postUpdate" "switch" "println" "case" "or" "sendCommand"
  228. )
  229. 'words)
  230. (1 font-lock-keyword-face))
  231. (,(regexp-opt
  232. '(
  233. "ON" "OFF" "on" "off"
  234. "AND" "OR" "NAND" "NOR" "AVG" "SUM" "MAX" "MIN"
  235. "true" "false"
  236. )
  237. 'words)
  238. (1 font-lock-constant-face))
  239. (,(regexp-opt
  240. '(
  241. "name" "label" "item" "period" "refresh" "icon" "mappings" "minValue" "maxValue" "step" "switchsupport" "url" "height" "refresh" "visibility" "valuecolor"
  242. )
  243. 'words)
  244. (1 font-lock-type-face))
  245. ("\(.*\)" . font-lock-variable-name-face)
  246. ("[^a-zA-Z0-9_:]\\([0-9]*\\)[^a-zA-Z0-9_:]" . (1 font-lock-variable-name-face))
  247. ("\s@\s" . font-lock-variable-name-face)
  248. ("\s\\([a-zA-Z0-9_:]*\\)\\(\s\\|$\\)" . (1 font-lock-type-face))
  249. ("=\\([a-zA-Z_]*\\)" . (1 font-lock-string-face))
  250. ("\\([a-zA-Z]*\\)=" . (1 font-lock-type-face))
  251. )
  252. "The regexps to highlight in openHAB mode.")
  253. (defvar openhab-mode-syntax-table
  254. (let ((st (make-syntax-table)))
  255. (modify-syntax-entry ?/ ". 12b" st) ;; C-style comments // ...
  256. (modify-syntax-entry ?\n "> b" st) ;; \n ends comment
  257. ;; Block comments /*...*/
  258. (modify-syntax-entry ?\/ ". 14" st)
  259. (modify-syntax-entry ?* ". 23" st)
  260. st)
  261. "Syntax table for openhab-mode.")
  262. (defun openhab-mode ()
  263. "Major mode for editing OPENHAB config files."
  264. (interactive)
  265. (kill-all-local-variables)
  266. (set-syntax-table openhab-mode-syntax-table)
  267. (use-local-map openhab-mode-map)
  268. (set (make-local-variable 'font-lock-defaults) '(openhab-font-lock-keywords nil t))
  269. (electric-pair-mode -1)
  270. (flycheck-mode -1)
  271. (setq major-mode 'openhab-mode)
  272. (setq mode-name "OpenHAB")
  273. (run-hooks 'openhab-mode-hook))
  274. (provide 'openhab-mode)
  275. #+END_SRC
  276. ** Tools
  277. *** General
  278. #+BEGIN_SRC emacs-lisp :results silent
  279. (require 'which-key)
  280. (which-key-setup-minibuffer)
  281. (which-key-mode)
  282. (require 'fic-mode)
  283. (add-hook 'js-mode-hook 'fic-mode)
  284. #+END_SRC
  285. *** Company
  286. #+BEGIN_SRC emacs-lisp :results silent
  287. (require 'company)
  288. (add-hook 'after-init-hook 'global-company-mode)
  289. (setq company-dabbrev-downcase nil)
  290. (setq company-idle-delay 0.1)
  291. #+END_SRC
  292. *** Diminish
  293. #+BEGIN_SRC emacs-lisp :results silent
  294. (require 'diminish)
  295. (diminish 'auto-revert-mode)
  296. (eval-after-load "company" '(diminish 'company-mode))
  297. (eval-after-load "counsel" '(diminish 'counsel-mode))
  298. (eval-after-load "elpy" '(diminish 'elpy-mode))
  299. (eval-after-load "go-mode" '(diminish 'go-mode))
  300. (eval-after-load "go-playground" '(diminish 'go-playground-mode))
  301. (eval-after-load "gorepl-mode" '(diminish 'gorepl-mode))
  302. (eval-after-load "flycheck" '(diminish 'flycheck-mode))
  303. (eval-after-load "ivy" '(diminish 'ivy-mode))
  304. (eval-after-load "projectile" '(diminish 'projectile-mode))
  305. (eval-after-load "which-key" '(diminish 'which-key-mode))
  306. #+END_SRC
  307. *** Dired
  308. #+BEGIN_SRC emacs-lisp :results silent
  309. (defun dired-mode-setup ()
  310. "Will run as hook for `dired-mode'."
  311. (dired-hide-details-mode 1))
  312. (add-hook 'dired-mode-hook 'dired-mode-setup)
  313. #+END_SRC
  314. *** Ivy
  315. #+BEGIN_SRC emacs-lisp :results silent
  316. (require 'ivy-hydra)
  317. (require 'ivy)
  318. (require 'swiper)
  319. (ivy-mode 1)
  320. (counsel-mode)
  321. (setq ivy-use-virtual-buffers t
  322. enable-recursive-minibuffers t
  323. ivy-height 25
  324. ivy-initial-inputs-alist nil
  325. ivy-extra-directories nil)
  326. (global-set-key (kbd "C-s") 'swiper)
  327. (global-set-key (kbd "C-c C-r") 'ivy-resume)
  328. (global-set-key (kbd "M-x") 'counsel-M-x)
  329. (global-set-key (kbd "C-x C-f") 'counsel-find-file)
  330. (global-set-key (kbd "C-c g") 'counsel-git)
  331. (global-set-key (kbd "C-c j") 'counsel-git-grep)
  332. (global-set-key (kbd "C-c k") 'counsel-ag)
  333. (define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
  334. (defun ivy-open-current-typed-path ()
  335. (interactive)
  336. (when ivy--directory
  337. (let* ((dir ivy--directory)
  338. (text-typed ivy-text)
  339. (path (concat dir text-typed)))
  340. (delete-minibuffer-contents)
  341. (ivy--done path))))
  342. (define-key ivy-minibuffer-map (kbd "<return>") 'ivy-alt-done)
  343. (define-key ivy-minibuffer-map (kbd "C-f") 'ivy-open-current-typed-path)
  344. #+END_SRC
  345. *** Magit
  346. #+BEGIN_SRC emacs-lisp :results silent
  347. (require 'magit)
  348. (global-set-key (kbd "C-x g") 'magit-status)
  349. (global-set-key (kbd "C-c g") 'magit-status)
  350. (setq magit-completing-read-function 'ivy-completing-read)
  351. #+END_SRC
  352. *** Mu4e
  353. #+BEGIN_SRC emacs-lisp :results silent
  354. (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu/mu4e")
  355. (require 'mu4e)
  356. ;; default
  357. (setq mu4e-maildir "~/Mail"
  358. mu4e-mu-binary "/usr/local/bin/mu"
  359. mu4e-get-mail-command "offlineimap" ;; Allow updating with the "U" command
  360. mu4e-sent-messages-behavior 'delete ;; Delete sent messages
  361. mu4e-view-show-images t ;; attempt to show images
  362. mu4e-view-image-max-width 400 ;; max image size
  363. message-kill-buffer-on-exit t ;; don't keep messages around
  364. mu4e-use-fancy-chars t ;; use 'fancy' chars
  365. mu4e-update-interval 300 ;; 5 mins
  366. )
  367. (setq mu4e-contexts
  368. `( ,(make-mu4e-context
  369. :name "Vlocity"
  370. :enter-func (lambda () (mu4e-message "Entering Vlocity"))
  371. :leave-func (lambda () (mu4e-message "Leaving Vlocity"))
  372. ;; we match based on the contact-fields of the message
  373. :match-func (lambda (msg)
  374. (when msg
  375. (string= (mu4e-message-field msg :maildir) "/Vlocity")))
  376. :vars '( ( user-mail-address . "lolson@vlocity.com" )
  377. ( smtpmail-mail-address . "lolson@vlocity.com" )
  378. ( user-full-name . "Levi Olson" )
  379. ( mu4e-compose-signature .
  380. (concat
  381. "--\n"
  382. "Levi Olson\n"
  383. "Senior UI Developer"))
  384. ( mu4e-sent-folder . "/Vlocity/[Gmail].Sent Mail" )
  385. ( mu4e-drafts-folder . "/Vlocity/[Gmail].Drafts" )
  386. ( mu4e-trash-folder . "/Vlocity/[Gmail].Trash" )
  387. ( mu4e-maildir-shortcuts . (("/Vlocity/INBOX" . ?i)
  388. ("/Vlocity/[Gmail].Sent Mail" . ?s)
  389. ("/Vlocity/[Gmail].Trash" . ?t)
  390. ("/Vlocity/[Gmail].All Mail" . ?a)))))
  391. ,(make-mu4e-context
  392. :name "Gmail"
  393. :enter-func (lambda () (mu4e-message "Entering Gmail"))
  394. :leave-func (lambda () (mu4e-message "Leaving Gmail"))
  395. ;; this matches maildir /Arkham and its sub-directories
  396. :match-func (lambda (msg)
  397. (when msg
  398. (string= (mu4e-message-field msg :maildir) "/Gmail")))
  399. :vars '( ( user-mail-address . "olson.levi@gmail.com" )
  400. ( smtpmail-mail-address . "olson.levi@gmail.com" )
  401. ( user-full-name . "Levi Olson" )
  402. ( mu4e-compose-signature .
  403. (concat
  404. "--\n"
  405. "Levi\n"))
  406. ( mu4e-sent-folder . "/Gmail/[Gmail].Sent Mail" )
  407. ( mu4e-drafts-folder . "/Gmail/[Gmail].Drafts" )
  408. ( mu4e-trash-folder . "/Gmail/[Gmail].Trash" )
  409. ( mu4e-maildir-shortcuts . (("/Gmail/INBOX" . ?i)
  410. ("/Gmail/[Gmail].Sent Mail" . ?s)
  411. ("/Gmail/[Gmail].Trash" . ?t)
  412. ("/Gmail/[Gmail].All Mail" . ?a))
  413. )))))
  414. ;; (defcustom smtpmail-smtp-user nil
  415. ;; "User name to use when looking up credentials in the authinfo file.
  416. ;; If non-nil, only consider credentials for the specified user."
  417. ;; :version "24.1"
  418. ;; :type '(choice (const nil) string)
  419. ;; :group 'smtpmail)
  420. ;; How to handle HTML emails
  421. ;; (setq mu4e-html2text-command "textutil -stdin -format html -convert txt -stdout")
  422. ;; Add option to view HTML in browser
  423. (add-to-list 'mu4e-headers-actions
  424. '("in browser" . mu4e-action-view-in-browser) t)
  425. (add-to-list 'mu4e-view-actions
  426. '("in browser" . mu4e-action-view-in-browser) t)
  427. #+END_SRC
  428. *** Projectile
  429. #+BEGIN_SRC emacs-lisp :results silent
  430. (require 'projectile)
  431. (require 'counsel-projectile)
  432. (projectile-mode)
  433. (setq projectile-mode-line '(:eval (format " %s" (projectile-project-name)))
  434. projectile-remember-window-configs t
  435. projectile-completion-system 'ivy)
  436. (counsel-projectile-mode)
  437. #+END_SRC
  438. ** Development Specific
  439. *** General
  440. #+BEGIN_SRC emacs-lisp :results silent
  441. (require 'rainbow-delimiters)
  442. (global-flycheck-mode)
  443. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  444. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  445. (setq-default indent-tabs-mode nil
  446. tab-width 4)
  447. (defvaralias 'c-basic-offset 'tab-width)
  448. (defvaralias 'cperl-indent-level 'tab-width)
  449. (electric-pair-mode 1)
  450. (show-paren-mode 1)
  451. (require 'dockerfile-mode)
  452. (add-to-list 'auto-mode-alist '("Dockerfile*\\'" . dockerfile-mode))
  453. (require 'gitignore-mode)
  454. (add-to-list 'auto-mode-alist '("gitignore\\'" . gitignore-mode))
  455. (require 'json-mode)
  456. (add-to-list 'auto-mode-alist '("\\.json\\'" . json-mode))
  457. (require 'web-mode)
  458. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  459. #+END_SRC
  460. *** Python
  461. #+BEGIN_SRC emacs-lisp :results silent
  462. (elpy-enable)
  463. (setq python-shell-interpreter "jupyter"
  464. python-shell-interpreter-args "console --simple-prompt")
  465. (when (require 'flycheck nil t)
  466. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  467. (add-hook 'elpy-mode-hook 'flycheck-mode))
  468. (require 'py-autopep8)
  469. (setq py-autopep8-options '("--ignore=E501"))
  470. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  471. #+END_SRC
  472. *** Go
  473. #+BEGIN_SRC emacs-lisp :results silent
  474. (require 'go-mode)
  475. (require 'go-playground)
  476. (require 'gorepl-mode)
  477. (require 'company-go)
  478. (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  479. (add-hook 'go-mode-hook (lambda ()
  480. (add-hook 'before-save-hook 'gofmt-before-save)
  481. (local-set-key (kbd "M-.") 'godef-jump)
  482. (local-set-key (kbd "M-,") 'pop-tag-mark)
  483. (local-set-key (kbd "C-c C-c") (lambda ()
  484. (interactive)
  485. (ansi-term)
  486. (comint-send-string "*ansi-term*" "make\n")))
  487. (set (make-local-variable 'company-backends) '(company-go))
  488. (setq company-tooltip-limit 20
  489. company-echo-delay 0
  490. company-begin-commands '(self-insert-command))
  491. (gorepl-mode)))
  492. (defun set-exec-path-from-shell-PATH ()
  493. (let ((path-from-shell (replace-regexp-in-string
  494. "[ \t\n]*$"
  495. ""
  496. (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
  497. (setenv "PATH" path-from-shell)
  498. (setq eshell-path-env path-from-shell)
  499. (setq exec-path (split-string path-from-shell path-separator))))
  500. (when window-system (set-exec-path-from-shell-PATH))
  501. (setenv "GOPATH" "/Users/leviolson/go")
  502. (add-to-list 'exec-path "/Users/leviolson/go/bin")
  503. #+END_SRC
  504. *** TypeScript
  505. #+BEGIN_SRC emacs-lisp :results silent
  506. (defun setup-tide-mode ()
  507. "Tide setup function."
  508. (interactive)
  509. (tide-setup)
  510. (flycheck-mode +1)
  511. (setq flycheck-check-syntax-automatically '(save mode-enabled))
  512. (eldoc-mode +1)
  513. (tide-hl-identifier-mode +1)
  514. (company-mode +1))
  515. ;; aligns annotation to the right hand side
  516. (setq company-tooltip-align-annotations t)
  517. ;; formats the buffer before saving
  518. (add-hook 'before-save-hook 'tide-format-before-save)
  519. (add-hook 'typescript-mode-hook #'setup-tide-mode)
  520. (require 'typescript-mode)
  521. (require 'tide)
  522. (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
  523. (add-hook 'typescript-mode-hook
  524. '(lambda ()
  525. (set (make-local-variable 'company-backends) '(company-tide))
  526. (setq company-tooltip-limit 20
  527. company-echo-delay 0
  528. company-begin-commands '(self-insert-command)
  529. tide-format-options '(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t :placeOpenBraceOnNewLineForFunctions nil))
  530. (tide-setup)))
  531. #+END_SRC
  532. **** TSX
  533. #+BEGIN_SRC emacs-lisp :results silent
  534. (require 'web-mode)
  535. (add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
  536. (add-hook 'web-mode-hook
  537. (lambda ()
  538. (when (string-equal "tsx" (file-name-extension buffer-file-name))
  539. (setup-tide-mode))))
  540. ;; enable typescript-tslint checker
  541. (flycheck-add-mode 'typescript-tslint 'web-mode)
  542. #+END_SRC
  543. **** JSX
  544. #+BEGIN_SRC emacs-lisp :results silent
  545. (require 'web-mode)
  546. (add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
  547. (add-hook 'web-mode-hook
  548. (lambda ()
  549. (when (string-equal "jsx" (file-name-extension buffer-file-name))
  550. (setup-tide-mode))))
  551. ;; configure jsx-tide checker to run after your default jsx checker
  552. (flycheck-add-mode 'javascript-eslint 'web-mode)
  553. (flycheck-add-next-checker 'javascript-eslint 'jsx-tide 'append)
  554. #+END_SRC
  555. *** Org
  556. #+BEGIN_SRC emacs-lisp :results silent
  557. (org-babel-do-load-languages
  558. 'org-babel-load-languages
  559. '((js . t)
  560. (shell . t)
  561. (emacs-lisp . t)))
  562. (defvar org-src-tab-acts-natively)
  563. (setq org-src-tab-acts-natively t)
  564. ;; (setenv "NODE_PATH"
  565. ;; (getenv "NODE_PATH"))
  566. (defvar org-confirm-babel-evaluate)
  567. (defun my-org-confirm-babel-evaluate (lang body)
  568. "Execute certain languages without confirming.
  569. Takes LANG to allow and BODY to execute."
  570. (not (or (string= lang "js")
  571. (string= lang "restclient")
  572. (string= lang "emacs-lisp")
  573. (string= lang "shell"))))
  574. (setq org-confirm-babel-evaluate #'my-org-confirm-babel-evaluate)
  575. (add-to-list 'org-structure-template-alist
  576. (list "e" (concat "#+BEGIN_SRC emacs-lisp :results silent\n"
  577. "\n"
  578. "#+END_SRC")))
  579. (add-to-list 'org-structure-template-alist
  580. (list "j" (concat "#+BEGIN_SRC js :cmd \"babel-node\"\n"
  581. "\n"
  582. "#+END_SRC")))
  583. (add-to-list 'org-structure-template-alist
  584. (list "r" (concat "#+BEGIN_SRC restclient :results raw\n"
  585. "\n"
  586. "#+END_SRC")))
  587. #+END_SRC
  588. ** Functions
  589. #+BEGIN_SRC emacs-lisp :results silent
  590. (defun find-user-init-file ()
  591. "Edit the `~/.emacs.d/init.org' file."
  592. (interactive)
  593. (find-file "~/.emacs.d/init.org"))
  594. (defun load-user-init-file ()
  595. "LO: Reload the `~/.emacs.d/init.elc' file."
  596. (interactive)
  597. (load-file "~/.emacs.d/init.elc"))
  598. (defun jump-to-symbol-internal (&optional backwardp)
  599. "Jumps to the next symbol near the point if such a symbol exists. If BACKWARDP is non-nil it jumps backward."
  600. (let* ((point (point))
  601. (bounds (find-tag-default-bounds))
  602. (beg (car bounds)) (end (cdr bounds))
  603. (str (isearch-symbol-regexp (find-tag-default)))
  604. (search (if backwardp 'search-backward-regexp
  605. 'search-forward-regexp)))
  606. (goto-char (if backwardp beg end))
  607. (funcall search str nil t)
  608. (cond ((<= beg (point) end) (goto-char point))
  609. (backwardp (forward-char (- point beg)))
  610. (t (backward-char (- end point))))))
  611. (defun jump-to-previous-like-this ()
  612. "Jumps to the previous occurrence of the symbol at point."
  613. (interactive)
  614. (jump-to-symbol-internal t))
  615. (defun jump-to-next-like-this ()
  616. "Jumps to the next occurrence of the symbol at point."
  617. (interactive)
  618. (jump-to-symbol-internal))
  619. (defun match-paren (arg)
  620. "Go to the matching paren if on a paren; otherwise insert ARG (a literal % sign)."
  621. (interactive "p")
  622. (cond ((looking-at "\\s(") (forward-list 1))
  623. ((looking-back "\\s(" 2) (backward-char 1) (forward-list 1))
  624. ((looking-at "\\s)") (forward-char 1) (backward-list 1))
  625. ((looking-back "\\s)" 2) (backward-list 1))
  626. (t (self-insert-command (or arg 1)))))
  627. (defun kill-this-buffer-unless-scratch ()
  628. "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."
  629. (interactive)
  630. (if (not (string= (buffer-name) "*scratch*"))
  631. (kill-this-buffer)
  632. (delete-region (point-min) (point-max))
  633. (switch-to-buffer (other-buffer))
  634. (bury-buffer "*scratch*")))
  635. (defun delete-backward-sentence ()
  636. "LO: Delete to the beginning of the sentence/line."
  637. (interactive)
  638. (delete-region (point) (progn (backward-sentence) (point))))
  639. (defun delete-backward-to-boundary (arg)
  640. "LO: Delete backward to the previous word boundary. With ARG, do this many times."
  641. (interactive "p")
  642. (let ((a (point))
  643. (b (progn
  644. (backward-word arg)
  645. (forward-word)
  646. (point))))
  647. (if (< a b)
  648. (delete-region a (progn (backward-word arg) (point)))
  649. (if (= a b)
  650. (delete-region a (progn (backward-word arg) (point)))
  651. (delete-region a b)))))
  652. (defun comment-or-uncomment-region-or-line ()
  653. "Comments or uncomments the region or the current line if there's no active region."
  654. (interactive)
  655. (let (beg end)
  656. (if (region-active-p)
  657. (setq beg (region-beginning) end (region-end))
  658. (setq beg (line-beginning-position) end (line-end-position)))
  659. (comment-or-uncomment-region beg end)))
  660. (defun fold-toggle (column)
  661. "Code folding by COLUMN."
  662. (interactive "P")
  663. (set-selective-display
  664. (or column
  665. (unless selective-display
  666. (1+ (current-column))))))
  667. (defun new-line-below ()
  668. "LO: Create a new line below current line."
  669. (interactive)
  670. (move-end-of-line 1)
  671. (newline-and-indent))
  672. (defun new-line-above ()
  673. "LO: Create a new line above current line."
  674. (interactive)
  675. (move-beginning-of-line 1)
  676. (newline)
  677. (forward-line -1))
  678. (defun duplicate-thing (comment)
  679. "LO: Duplicates the current line, or the region if active. If an argument (COMMENT) is given, the duplicated region will be commented out."
  680. (interactive "P")
  681. (save-excursion
  682. (let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
  683. (end (if (region-active-p) (region-end) (point-at-eol))))
  684. (goto-char end)
  685. (unless (region-active-p)
  686. (newline))
  687. (insert (buffer-substring start end))
  688. (when comment (comment-region start end)))))
  689. (defun tidy ()
  690. "LO: Ident, untabify and unwhitespacify current buffer, or region if active."
  691. (interactive)
  692. (let ((beg (if (region-active-p) (region-beginning) (point-min)))
  693. (end (if (region-active-p) (region-end) (point-max))))
  694. (let ((inhibit-message t))
  695. (indent-region beg end))
  696. (whitespace-cleanup)
  697. (untabify beg (if (< end (point-max)) end (point-max)))
  698. (if (region-active-p) (message "Indenting Region...Done") (message "Indenting File...Done"))))
  699. (defun phil-columns ()
  700. "LO: Good 'ol Phil-Columns."
  701. (interactive)
  702. (message "Good 'ol fill-columns")
  703. (with-output-to-temp-buffer "*PHIL-COLUMN*"
  704. (shell-command "mpv --no-video 'https://www.youtube.com/watch?v=YkADj0TPrJA&t=3m16s' > /dev/null 2>&1 & sleep 8; pkill mpv"))
  705. (other-window 1)
  706. (delete-window))
  707. (declare-function first "Goto FIRST shell.")
  708. (declare-function goto-non-shell-buffer "Goto something other than a shell buffer.")
  709. (declare-function switch-shell "Switch shell.")
  710. (let ((last-shell ""))
  711. (defun toggle-shell ()
  712. (interactive)
  713. (cond ((string-match-p "^\\*shell<[1-9][0-9]*>\\*$" (buffer-name))
  714. (goto-non-shell-buffer))
  715. ((get-buffer last-shell) (switch-to-buffer last-shell))
  716. (t (shell (setq last-shell "*shell<1>*")))))
  717. (defun switch-shell (n)
  718. (let ((buffer-name (format "*shell<%d>*" n)))
  719. (setq last-shell buffer-name)
  720. (cond ((get-buffer buffer-name)
  721. (switch-to-buffer buffer-name))
  722. (t (shell buffer-name)
  723. (rename-buffer buffer-name)))))
  724. (defun goto-non-shell-buffer ()
  725. (let* ((r "^\\*shell<[1-9][0-9]*>\\*$")
  726. (shell-buffer-p (lambda (b) (string-match-p r (buffer-name b))))
  727. (non-shells (cl-remove-if shell-buffer-p (buffer-list))))
  728. (when non-shells
  729. (switch-to-buffer (first non-shells))))))
  730. (defadvice shell (after kill-with-no-query nil activate)
  731. "."
  732. (set-process-query-on-exit-flag (get-buffer-process ad-return-value) nil))
  733. (declare-function comint-truncate-buffer ".")
  734. (defun clear-comint ()
  735. "Run `comint-truncate-buffer' with the `comint-buffer-maximum-size' set to zero."
  736. (interactive)
  737. (let ((comint-buffer-maximum-size 0))
  738. (comint-truncate-buffer)))
  739. (defun c-setup ()
  740. "Compile."
  741. (local-set-key (kbd "C-c C-c") 'compile))
  742. #+END_SRC
  743. ** Bindings
  744. #+BEGIN_SRC emacs-lisp :results silent
  745. (require 'company)
  746. (add-hook 'comint-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-comint)))
  747. (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
  748. (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
  749. (add-hook 'c-mode-common-hook 'c-setup)
  750. (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
  751. (defvar company-active-map (make-keymap)
  752. "Company Mode keymap.")
  753. (defvar custom-bindings (make-keymap)
  754. "A keymap of custom bindings.")
  755. (define-key global-map (kbd "M-p") 'jump-to-previous-like-this)
  756. (define-key global-map (kbd "M-n") 'jump-to-next-like-this)
  757. (define-key global-map (kbd "M-<tab>") 'switch-to-next-buffer)
  758. (define-key global-map (kbd "M-<backspace>")'delete-backward-to-boundary)
  759. (define-key global-map (kbd "C-<backspace>")'delete-backward-to-boundary)
  760. (global-set-key (kbd "C-S-<down>") 'mc/mark-next-like-this)
  761. (global-set-key (kbd "C->") 'mc/mark-next-like-this-symbol)
  762. (global-set-key (kbd "C-S-<up>") 'mc/mark-previous-like-this)
  763. (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
  764. (global-set-key (kbd "C-c C->") 'mc/mark-all-like-this)
  765. (global-set-key "%" 'match-paren)
  766. (global-set-key (kbd "C-x .") 'dash-at-point)
  767. (global-set-key (kbd "C-x ,") 'dash-at-point-with-docset)
  768. (global-set-key (kbd "C-s") (lambda () (interactive) (swiper (format "%s" (thing-at-point 'symbol)))))
  769. (global-set-key (kbd "M-m") 'mu4e)
  770. ;; (dolist (n (number-sequence 1 9))
  771. ;; (global-set-key (kbd (concat "M-" (int-to-string n)))
  772. ;; (lambda () (interactive) (switch-shell n))))
  773. (define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
  774. (define-key company-active-map (kbd "C-n") 'company-select-next)
  775. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  776. (define-key company-active-map (kbd "<tab>") 'company-complete)
  777. (define-key custom-bindings (kbd "C-c p") 'counsel-projectile-switch-project)
  778. (define-key custom-bindings (kbd "C-c f") 'counsel-projectile-find-file)
  779. (define-key custom-bindings (kbd "C-c m") 'magit-status)
  780. (define-key custom-bindings (kbd "C-c D") 'define-word-at-point)
  781. (define-key custom-bindings (kbd "C-@") 'er/expand-region)
  782. (define-key custom-bindings (kbd "C-#") 'er/contract-region)
  783. (define-key custom-bindings (kbd "C-S-c C-S-c") 'mc/edit-lines)
  784. (define-key custom-bindings (kbd "C-c b") 'ivy-switch-buffer)
  785. (define-key custom-bindings (kbd "C-c l") 'org-store-link)
  786. (define-key custom-bindings (kbd "C-c t") 'org-set-tags)
  787. (define-key custom-bindings (kbd "M-u") 'upcase-dwim)
  788. (define-key custom-bindings (kbd "M-c") 'capitalize-dwim)
  789. (define-key custom-bindings (kbd "M-l") 'downcase-dwim)
  790. (define-key custom-bindings (kbd "M-o") 'other-window)
  791. (define-key custom-bindings (kbd "C-c s") 'ispell-word)
  792. (define-key custom-bindings (kbd "C-c C-d") 'org-capture)
  793. (define-key custom-bindings (kbd "C-c <up>") 'windmove-up)
  794. (define-key custom-bindings (kbd "C-c <down>") 'windmove-down)
  795. (define-key custom-bindings (kbd "C-c <left>") 'windmove-left)
  796. (define-key custom-bindings (kbd "C-c <right>") 'windmove-right)
  797. (define-key custom-bindings (kbd "C-c a") (lambda () (interactive) (org-agenda nil "n")))
  798. (define-key custom-bindings (kbd "C-c e") 'find-user-init-file)
  799. (define-key custom-bindings (kbd "C-x f") 'phil-columns)
  800. (define-key custom-bindings (kbd "C-x k") 'kill-this-buffer-unless-scratch)
  801. (define-key custom-bindings (kbd "C-c d") 'duplicate-thing)
  802. (define-key custom-bindings (kbd "C-c c") 'comment-or-uncomment-region-or-line)
  803. (define-key custom-bindings (kbd "C-;") 'comment-or-uncomment-region-or-line)
  804. (define-key custom-bindings (kbd "C-o") 'new-line-below)
  805. (define-key custom-bindings (kbd "C-S-o") 'new-line-above)
  806. (define-key custom-bindings (kbd "<C-tab>") 'tidy)
  807. (define-key custom-bindings (kbd "M-q") 'kill-this-buffer)
  808. (define-key custom-bindings (kbd "M-RET") '(lambda () (interactive) (term (getenv "SHELL"))))
  809. (define-minor-mode custom-bindings-mode
  810. "A mode that activates custom-bindings."
  811. t nil custom-bindings)
  812. #+END_SRC
  813. ** UI
  814. #+BEGIN_SRC emacs-lisp :results silent
  815. (cond ((member "PragmataPro Mono Liga" (font-family-list))
  816. (set-face-attribute 'default nil :font "PragmataPro Mono Liga-13")))
  817. #+END_SRC
  818. *** Doom Modeline
  819. #+BEGIN_SRC emacs-lisp :results silent
  820. (require 'doom-modeline)
  821. (doom-modeline-mode 1)
  822. ;; How tall the mode-line should be (only respected in GUI Emacs).
  823. (setq doom-modeline-height 35)
  824. ;; How wide the mode-line bar should be (only respected in GUI Emacs).
  825. (setq doom-modeline-bar-width 4)
  826. ;; Determines the style used by `doom-modeline-buffer-file-name'.
  827. ;;
  828. ;; Given ~/Projects/FOSS/emacs/lisp/comint.el
  829. ;; truncate-upto-project => ~/P/F/emacs/lisp/comint.el
  830. ;; truncate-from-project => ~/Projects/FOSS/emacs/l/comint.el
  831. ;; truncate-with-project => emacs/l/comint.el
  832. ;; truncate-except-project => ~/P/F/emacs/l/comint.el
  833. ;; truncate-upto-root => ~/P/F/e/lisp/comint.el
  834. ;; truncate-all => ~/P/F/e/l/comint.el
  835. ;; relative-from-project => emacs/lisp/comint.el
  836. ;; relative-to-project => lisp/comint.el
  837. ;; file-name => comint.el
  838. ;; buffer-name => comint.el<2> (uniquify buffer name)
  839. ;;
  840. ;; If you are expereicing the laggy issue, especially while editing remote files
  841. ;; with tramp, please try `file-name' style.
  842. ;; Please refer to https://github.com/bbatsov/projectile/issues/657.
  843. (setq doom-modeline-buffer-file-name-style 'truncate-upto-project)
  844. ;; What executable of Python will be used (if nil nothing will be showed).
  845. (setq doom-modeline-python-executable "python")
  846. ;; Whether show `all-the-icons' or not (if nil nothing will be showed).
  847. (setq doom-modeline-icon t)
  848. ;; Whether show the icon for major mode. It respects `doom-modeline-icon'.
  849. (setq doom-modeline-major-mode-icon t)
  850. ;; Display color icons for `major-mode'. It respects `all-the-icons-color-icons'.
  851. (setq doom-modeline-major-mode-color-icon nil)
  852. ;; Whether display minor modes or not. Non-nil to display in mode-line.
  853. (setq doom-modeline-minor-modes nil)
  854. ;; If non-nil, a word count will be added to the selection-info modeline segment.
  855. (setq doom-modeline-enable-word-count nil)
  856. ;; If non-nil, only display one number for checker information if applicable.
  857. (setq doom-modeline-checker-simple-format t)
  858. ;; Whether display perspective name or not. Non-nil to display in mode-line.
  859. (setq doom-modeline-persp-name t)
  860. ;; Whether display `lsp' state or not. Non-nil to display in mode-line.
  861. (setq doom-modeline-lsp t)
  862. ;; Whether display github notifications or not. Requires `ghub` package.
  863. (setq doom-modeline-github nil)
  864. ;; The interval of checking github.
  865. (setq doom-modeline-github-interval (* 30 60))
  866. ;; Whether display environment version or not.
  867. (setq doom-modeline-env-version t)
  868. ;; Whether display mu4e notifications or not. Requires `mu4e-alert' package.
  869. (setq doom-modeline-mu4e t)
  870. #+END_SRC