genehack's emacs configuration files and libraries
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.

442 lines
12KB

  1. ;;; builtins.el -- Customizations of built-in (non-third party) options.
  2. ;;; Commentary:
  3. ;;;; Large packages (eg Gnus, ERC, etc.) should get dedicated files but
  4. ;;;; for standard stuff where one or two options get frobbed, this is
  5. ;;;; the place.
  6. ;;; Code:
  7. (require 'use-package)
  8. ;;; ANSI-MODE FOR SHELLS
  9. (ansi-color-for-comint-mode-on)
  10. ;;; AUTO-SAVES AND BACKUPS
  11. (eval-when-compile (defvar genehack/emacs-tmp-dir))
  12. (setq auto-save-list-file-prefix (concat genehack/emacs-tmp-dir "auto-save-list/.saves-"))
  13. (setq auto-save-file-name-transforms `((".*" ,genehack/emacs-tmp-dir t)))
  14. (setq backup-by-copying t)
  15. (defvar genehack/backup-dir (concat genehack/emacs-tmp-dir "saves/" )
  16. "Place to put file backups.")
  17. (setq backup-directory-alist `((".*" . ,genehack/backup-dir)))
  18. (setq delete-old-versions t)
  19. (setq kept-new-versions 6)
  20. (setq kept-old-versions 2)
  21. (setq version-control t)
  22. ;;; BUFFER-MODE
  23. (defun genehack/set-up-buffer-mode ()
  24. "My customizations for 'Buffer-menu-mode'."
  25. (setq show-trailing-whitespace nil))
  26. (add-hook 'Buffer-menu-mode-hook 'genehack/set-up-buffer-mode)
  27. ;;; CALENDAR
  28. (use-package calendar
  29. :defer t
  30. :config
  31. (setq calendar-mark-holidays-flag t))
  32. ;;; CURSOR
  33. (setq-default cursor-type 'box)
  34. ;;; DEBUGGING
  35. (setq debug-on-error t)
  36. ;;; DESKTOP
  37. (desktop-save-mode 1)
  38. ;;; DIRED
  39. (defun genehack/bind-key-for-wdired ()
  40. "Add a keybinding for wdired in 'dired-mode'."
  41. (local-set-key (kbd "E") 'wdired-change-to-wdired-mode))
  42. ;;;; having all-the-icons mode on is pretty, but having the icons in
  43. ;;;; the buffer fucks up wdired something fierce. let's advise the
  44. ;;;; functions that take us into and out of wdired mode so they remove
  45. ;;;; the icons and then put them back.
  46. (defun genehack/disable-all-the-icons ()
  47. "Disable all-the-icons."
  48. (all-the-icons-dired-mode 0))
  49. (defun genehack/restore-all-the-icons ()
  50. "Restore all-the-icons."
  51. (all-the-icons-dired-mode 1))
  52. (advice-add 'wdired-change-to-wdired-mode :before #'genehack/disable-all-the-icons)
  53. (advice-add 'wdired-finish-edit :after #'genehack/restore-all-the-icons)
  54. (advice-add 'wdired-abort-changes :after #'genehack/restore-all-the-icons)
  55. ;;;; these are in 'builtins' because they modify dired, which is a
  56. ;;;; built-in mode
  57. (use-package all-the-icons :ensure t)
  58. (use-package all-the-icons-dired :ensure t)
  59. (use-package dired
  60. :after all-the-icons-dired
  61. :defer t
  62. :commands dired
  63. :config
  64. (define-key dired-mode-map (vector 'remap 'beginning-of-buffer) 'dired-back-to-top)
  65. (define-key dired-mode-map (vector 'remap 'end-of-buffer) 'dired-jump-to-bottom)
  66. (add-hook 'dired-mode-hook 'genehack/bind-key-for-wdired)
  67. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  68. (add-hook 'dired-mode-hook 'dired-hide-details-mode)
  69. (setq-default dired-listing-switches "-alhv --time-style=long-iso")
  70. (setq dired-recursive-copies 'always))
  71. (use-package dired-x
  72. :after dired
  73. :defer t
  74. :commands dired-jump)
  75. ;;;; http://whattheemacsd.com//setup-dired.el-02.html
  76. (require 'dired)
  77. (defun dired-back-to-top ()
  78. "Jump to the top file in a dired buffer."
  79. (interactive)
  80. (goto-char (point-min))
  81. ;; because the number of header lines varies depending on whether
  82. ;; mode info is shown or hidden, find the double-dot directory entry
  83. ;; and go forward one line -- heuristic, but will always work.
  84. (search-forward "..")
  85. (dired-next-line 1))
  86. (defun dired-jump-to-bottom ()
  87. "Jump to the last file in a dired buffer."
  88. (interactive)
  89. (goto-char (point-max))
  90. (dired-next-line -1))
  91. ;;; DISABLE / ENABLE
  92. (put 'downcase-region 'disabled nil)
  93. (put 'overwrite-mode 'disabled t)
  94. (put 'upcase-region 'disabled nil)
  95. ;;; ELDOC
  96. (use-package eldoc
  97. :defer t
  98. :diminish (eldoc-mode . " el"))
  99. ;;; EXECUTABLE-UPON-SAVE MAGIC
  100. ;;;; from <http://www.emacswiki.org/cgi-bin/wiki/MakingScriptsExecutableOnSave>
  101. (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
  102. ;;; FFAP
  103. (use-package ffap
  104. :disabled t
  105. :defer t
  106. :config
  107. (ffap-bindings))
  108. ;;; FONT-LOCK
  109. (use-package font-lock
  110. :defer t
  111. :config
  112. (setq-default font-lock-maximum-decoration t
  113. font-lock-maximum-size nil)
  114. (setq jit-lock-stealth-time 5
  115. jit-lock-defer-contextually t
  116. jit-lock-stealth-nice 0.5)
  117. :init
  118. (global-font-lock-mode 1))
  119. ;;; FRAME RESIZE
  120. ;;;; see https://www.reddit.com/r/emacs/comments/f3ed3r/how_is_doom_emacs_so_damn_fast/fhicvbj/
  121. (setq frame-inhibit-implied-resize t)
  122. ;;; GENERAL INDENTATION RELATED OPTIONS
  123. (setq-default indent-tabs-mode nil)
  124. (setq tab-always-indent 'complete)
  125. (setq sentence-end-double-space nil)
  126. (defvar modes-for-indentation-munging
  127. '(c++-mode
  128. c-mode
  129. cperl-mode
  130. emacs-lisp-mode
  131. go-mode
  132. js-mode
  133. js2-mode
  134. objc-mode
  135. perl-mode
  136. python-mode
  137. rspec-mode
  138. ruby-mode
  139. scala-mode
  140. web-mode)
  141. "List of modes to set up to do indent-on-paste.
  142. Also remove-leading-whitespace-on-kill-line tricks")
  143. ;;;; re-indent when pasting back into programming-related major modes
  144. ;;;; based on <http://www.emacswiki.org/emacs-en/AutoIndentation>
  145. (defun genehack/indent-region (&optional ARG)
  146. "Re-indent on paste in configured modes.
  147. Ignores `ARG'."
  148. (and (not current-prefix-arg)
  149. (member major-mode modes-for-indentation-munging)
  150. (let ((mark-even-if-inactive transient-mark-mode))
  151. (indent-region (region-beginning) (region-end) nil))))
  152. (advice-add 'yank :after #'genehack/indent-region)
  153. (advice-add 'yank-pop :after #'genehack/indent-region)
  154. ;;;; based on <http://www.emacswiki.org/emacs-en/AutoIndentation>
  155. (defun genehack/trim-on-kill (&optional ARG)
  156. "Remove excess white space when killing newlines in configured modes.
  157. Ignores `ARG'."
  158. (if (member major-mode modes-for-indentation-munging)
  159. (if (and (eolp) (not (bolp)))
  160. (progn (forward-char 1)
  161. (just-one-space 0)
  162. (backward-char 1)))))
  163. (advice-add 'kill-line :before #'genehack/trim-on-kill)
  164. ;;; GLOBAL AUTO-REVERT
  165. (use-package autorevert
  166. :defer t
  167. :diminish (autorevert-mode . " a")
  168. :config
  169. ;; Also auto refresh dired, but be quiet about it
  170. (setq global-auto-revert-non-file-buffers t)
  171. (setq auto-revert-verbose nil)
  172. :init
  173. (global-auto-revert-mode t))
  174. ;;; HTML
  175. (add-hook 'html-mode-hook 'turn-off-auto-fill)
  176. ;;; IBUFFER
  177. ;;;; this is in 'builtins' because it modifies ibuffer, which is a
  178. ;;;; built-in mode
  179. (use-package all-the-icons-ibuffer
  180. :ensure t
  181. :defer t
  182. :init (all-the-icons-ibuffer-mode 1))
  183. (use-package ibuffer
  184. :defer t
  185. :config
  186. (setq ibuffer-default-sorting-mode 'major-mode))
  187. ;;; KEYSTROKE ECHO
  188. (setq echo-keystrokes 0.1)
  189. ;;; LINE NUMBERS
  190. (column-number-mode 1)
  191. ;;; MAC STUFF
  192. (when (eq system-type 'darwin)
  193. (setq mac-command-modifier 'meta)
  194. (setq mac-option-modifier nil)
  195. (setq browse-url-browser-function 'browse-url-default-macosx-browser)
  196. (setq delete-by-moving-to-trash t))
  197. ;;; MESSAGE LOG
  198. (setq message-log-max 5000)
  199. ;;; (MENU/SCROLLBAR/TOOLBAR)-MODE
  200. (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
  201. (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
  202. (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
  203. ;;; MOUSE WHEEL
  204. (if (fboundp 'mouse-wheel-mode) (mouse-wheel-mode -1))
  205. ;;; NXML-MODE
  206. (use-package nxml-mode
  207. :defer t
  208. :config
  209. (fset 'xml-mode 'nxml-mode)
  210. (setq nxml-bind-meta-tab-to-complete-flag nil)
  211. :mode "\\.\\(rng\\|rss\\|xml\\|xsd\\|xslt\\)\\'"
  212. :magic "<\\?xml ")
  213. ;;; ORG MODE
  214. (use-package org
  215. :defer t
  216. :disabled t
  217. :defines
  218. org-agenda-custom-commands
  219. org-agenda-files
  220. org-capture-templates
  221. org-default-notes-file
  222. org-directory
  223. org-log-done
  224. org-refile-targets
  225. org-return-follows-link
  226. org-tag-alist
  227. org-todo-keywords
  228. :config
  229. (setq org-agenda-custom-commands
  230. '(("a" "active" todo "ACTIVE")
  231. ("n" "next actions" tags-todo "NEXT")
  232. ("w" "waiting for" todo "WAITING")))
  233. (setq org-agenda-files '("~/org" "~/org/home" "~/org/oss" "~/org/work"))
  234. (setq org-capture-templates
  235. '(("t" "todo" entry (file+headline "" "* INBOX") "** TODO %?\n %i\n %a")))
  236. (setq org-default-notes-file (concat org-directory "/jfdi.org"))
  237. (setq org-log-done 'time)
  238. (setq org-refile-targets '((org-agenda-files . (:maxlevel . 2))))
  239. (setq org-return-follows-link t)
  240. (setq org-tag-alist '(("@work" . ?w) ("@home" . ?h) ("@oss" . ?o) ("NEXT" . ?n)))
  241. (setq org-todo-keywords '((sequence "TODO(t)" "ACTIVE(a)" "|" "DONE(d!)")
  242. (sequence "WAITING(w!/@)" "|")))
  243. (defun jfdi ()
  244. "JFDI!"
  245. (interactive)
  246. (find-file "~/org/jfdi.org")))
  247. ;;; PAREN MATCH
  248. (use-package paren
  249. :defer t
  250. :config
  251. (show-paren-mode t)
  252. (setq show-paren-style 'expression))
  253. ;;; PS PRINT
  254. (setq ps-print-color-p nil)
  255. ;;; SAVE-HIST
  256. (use-package savehist
  257. :defer t
  258. :config
  259. (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring)
  260. savehist-file (expand-file-name "savehist" genehack/emacs-tmp-dir))
  261. :init
  262. (savehist-mode t))
  263. ;;; SAVEPLACE
  264. (use-package saveplace
  265. :defer t
  266. :config
  267. (setq save-place-file (expand-file-name "saveplace" genehack/emacs-tmp-dir))
  268. :init
  269. (setq-default save-place t))
  270. ;;; SERVER
  271. (server-start)
  272. ;;; SGML-MODE
  273. (use-package sgml-mode
  274. :defer t
  275. :config
  276. (define-key sgml-mode-map "\C-c\C-b" nil))
  277. ;;; SIZE INDICATION MODE
  278. (size-indication-mode t)
  279. ;;; SPELL CHECKING
  280. ;;;; (note that exec-path probably needs to be munged before this is run)
  281. (defun genehack/find-in-exec-path (program)
  282. "Find PROGRAM in 'exec-path'."
  283. (let ((found nil))
  284. (dolist (path exec-path)
  285. (if (file-exists-p (concat path "/" program))
  286. (setq found t)))
  287. found))
  288. (defun genehack/spelling-not-found ()
  289. "Display message when *spell program can't be found."
  290. (interactive)
  291. (message "Spell check not enabled; neither aspell nor ispell found in path."))
  292. (defvar genehack/found-spelling-program nil
  293. "Boolean indicating whether or not a spelling program was found in 'exec-path'.")
  294. (use-package ispell
  295. :defer t
  296. :config
  297. (if (genehack/find-in-exec-path "aspell")
  298. (progn
  299. (setq-default ispell-program-name "aspell")
  300. (setq ispell-extra-args '("--sug-mode=ultra"))
  301. (setq genehack/found-spelling-program t))
  302. (if (genehack/find-in-exec-path "ispell")
  303. (progn
  304. (setq-default ispell-program-name "ispell")
  305. (setq ispell-extra-args '("-W 3"))
  306. (setq genehack/found-spelling-program t))))
  307. (if (eq genehack/found-spelling-program t)
  308. (progn
  309. (autoload 'ispell-word "ispell" "check word spelling." t)
  310. (autoload 'ispell-region "ispell" "check region spelling." t)
  311. (autoload 'ispell-buffer "ispell" "check buffer spelling." t)
  312. (require 'flyspell))
  313. (defalias 'ispell-word 'genehack/spelling-not-found)
  314. (defalias 'ispell-region 'genehack/spelling-not-found)
  315. (defalias 'ispell-buffer 'genehack/spelling-not-found)))
  316. ;;; TERM-MODE
  317. (use-package term
  318. :defer t
  319. :config
  320. (add-hook 'term-mode-hook 'genehack/set-up-term-mode))
  321. (defun genehack/set-up-term-mode ()
  322. "My customizations for 'term-mode'."
  323. (yas-minor-mode -1)
  324. (setq show-trailing-whitespace nil)
  325. (setq term-buffer-maximum-size 10000))
  326. ;;; TEXT-MODE
  327. (defun genehack/set-up-text-mode ()
  328. "My customizations for 'text-mode'."
  329. (require 'filladapt)
  330. (auto-fill-mode 1)
  331. (filladapt-mode 1)
  332. (if (eq genehack/found-spelling-program t)
  333. (flyspell-mode 1)))
  334. (add-hook 'text-mode-hook 'genehack/set-up-text-mode)
  335. ;;; TIME DISPLAY
  336. (use-package time
  337. :defer t
  338. :defines
  339. display-time-24hr-format
  340. :config
  341. (setq display-time-24hr-format t)
  342. (setq display-time-day-and-date t)
  343. :init
  344. (display-time))
  345. ;;; TITLE BARS
  346. (setq frame-title-format "<%b> == (%f) [mode: %m]")
  347. ;;; TRANSIENT MARK MODE
  348. (transient-mark-mode 1)
  349. ;;; TRASH
  350. (setq delete-by-moving-to-trash t)
  351. ;;; UNIQUIFY
  352. (use-package uniquify
  353. :defer t
  354. :config
  355. (setq uniquify-buffer-name-style 'reverse
  356. uniquify-separator "/"
  357. uniquify-after-kill-buffer-p t))
  358. ;;; UTF8
  359. (setq locale-coding-system 'utf-8)
  360. (set-terminal-coding-system 'utf-8)
  361. (set-keyboard-coding-system 'utf-8)
  362. (set-selection-coding-system 'utf-8)
  363. (prefer-coding-system 'utf-8)
  364. ;;; VC
  365. (setq vc-follow-symlinks t)
  366. ;;; WHITESPACE
  367. (use-package whitespace
  368. :defer t
  369. :config
  370. (setq whitespace-style '(face tabs spaces trailing lines-tail
  371. space-before-tab newline indentation empty
  372. space-after-tab space-mark tab-mark newline-mark)))
  373. ;;; YANK
  374. (setq-default mouse-yank-at-point t)
  375. ;;; YES-OR-NO
  376. (defalias 'yes-or-no-p 'y-or-n-p)
  377. (provide 'builtins)
  378. ;;; builtins.el ends here