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.

904 lines
33 KiB

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