init.el 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. ;; Requires:
  2. ;; aspell
  3. ;; ----------- Default Variables -----------
  4. ;; Global variables
  5. (defvar backup-directory (concat user-emacs-directory "backups"))
  6. (unless (file-exists-p backup-directory)
  7. (make-directory backup-directory))
  8. (setq-default inhibit-startup-screen t
  9. column-number-mode t
  10. scroll-error-top-bottom t
  11. show-paren-delay 0.25
  12. tab-width 4
  13. indent-tabs-mode nil
  14. x-select-enable-clipboard t
  15. backup-directory-alist `(("." . ,backup-directory))
  16. delete-old-versions t)
  17. ;; (global-linum-mode)
  18. ;; Delete selected text when typing (normal editor behavior)
  19. (delete-selection-mode t)
  20. (defun mapcar-dot* (f list)
  21. (loop for (a . b) on list
  22. collect (funcall f a)
  23. unless (listp b)
  24. collect (funcall f b)))
  25. ;; ------------- Keybindings -------------
  26. (defun smart-beginning-of-line ()
  27. "Move point to first non-whitespace character or beginning-of-line.
  28. Move point to the first non-whitespace character on this line.
  29. If point was already at that position, move point to beginning of line."
  30. (interactive "^")
  31. ;(if (version< "22" emacs-version) (interactive "^") (interactive))
  32. (let ((oldpos (point)))
  33. (beginning-of-line-text); goes to first significant character
  34. ;(back-to-indentation); goes to first non-whitespace
  35. (and (= oldpos (point))
  36. (beginning-of-line))))
  37. (global-set-key [home] 'smart-beginning-of-line)
  38. (global-set-key (kbd "C-c /") 'comment-or-uncomment-region)
  39. (global-set-key (kbd "C-c C-k") 'compile)
  40. ;; ----------- Package Managing -----------
  41. ;; The package manager
  42. (require 'package)
  43. ;; Add package sources
  44. (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
  45. ("org" . "https://orgmode.org/elpa/")
  46. ("melpa" . "https://melpa.org/packages/")
  47. ("melpa-stable" . "https://stable.melpa.org/packages/"))
  48. package-archive-priorities '(("melpa" . 1)))
  49. (package-initialize)
  50. (unless (package-installed-p 'use-package)
  51. (package-refresh-contents)
  52. (package-install 'use-package))
  53. (require 'use-package)
  54. (setq use-package-always-ensure t)
  55. ;; ---------- Use X11 clipboard -----------
  56. (use-package xclip
  57. :if (executable-find "xclip")
  58. :config (xclip-mode 1))
  59. ;; ---------- Color Themes ----------
  60. (use-package color-theme
  61. :init
  62. ;; TODO: Fixes error about missing directory. Don't know why.
  63. (unless (file-exists-p "~/.emacs.d/elpa/color-theme-20070910.1007/themes")
  64. (make-directory "~/.emacs.d/elpa/color-theme-20070910.1007/themes"))
  65. :config
  66. (color-theme-initialize))
  67. (use-package base16-theme
  68. :requires color-theme
  69. :config (load-theme 'base16-tomorrow-night t))
  70. ;; --------- Parentheses Matching ---------
  71. (show-paren-mode)
  72. (use-package highlight-parentheses
  73. :config
  74. (define-globalized-minor-mode global-highlight-parentheses-mode
  75. highlight-parentheses-mode
  76. (lambda ()
  77. (highlight-parentheses-mode t)))
  78. (global-highlight-parentheses-mode t))
  79. (use-package autopair
  80. :config
  81. (autopair-global-mode))
  82. ;; ------------ xTerm Mouse ------------
  83. ;; Disable because it became annoying, sounds cool though.
  84. (use-package mouse
  85. :disabled
  86. :config
  87. (xterm-mouse-mode t))
  88. ;; ----------- Ensime -----------
  89. ;; Java/Scala featues. Includes:
  90. ;; * Inferred types
  91. ;; * Autocomplete
  92. ;; * Syntax highlighting
  93. ;; * Jump to source/docs
  94. ;; * Refactoring
  95. ;; * Error detection
  96. (use-package scala-mode
  97. :mode "\\.scala\\'")
  98. (use-package company)
  99. (use-package ensime
  100. :if (version<= "24.4" emacs-version)
  101. :requires company
  102. :hook (scala-mode java-mode)
  103. :config (setq ensime-startup-notification nil)
  104. :pin melpa-stable)
  105. ; --------- C Syntax checker ---------
  106. (use-package flycheck-irony
  107. :hook c-mode
  108. :mode ("\\.c\\'" "\\.h\\'"))
  109. ;; ------------ Web Mode ------------
  110. (use-package multi-web-mode
  111. :init
  112. (setq mweb-default-major-mode 'html-mode
  113. mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
  114. (js-mode "<script[^>]*>" "</script>")
  115. (css-mode "<style[^>]*>" "</style>"))
  116. mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
  117. ; :mode (mapcar-dot* (format "\\.%s\\'" ext '("php" "htm" "html" "ctp" "phtml" "php4" "php5")))
  118. :config
  119. (multi-web-global-mode 1))
  120. ;; ------------ Git Mode ------------
  121. (when (version<= "24.4" emacs-version)
  122. (use-package magit
  123. :bind ("C-x g" . magit-status)))
  124. ;; ----------- Rust Mode ------------
  125. (use-package rust-mode
  126. :mode ("\\.rs\\'"))
  127. (use-package rust-playground
  128. :requires rust-mode)
  129. (use-package cargo
  130. :after rust-mode)
  131. (use-package flycheck-rust
  132. :after rust-mode)
  133. ;; ----------- i3 Support ----------
  134. (use-package i3wm
  135. :disabled
  136. :if (equal (getenv "DESKTOP_SESSION") "i3"))
  137. ;; --------- Racket Mode ----------
  138. (use-package racket-mode)
  139. ;; ---------- C# Mode -------------
  140. (use-package csharp-mode
  141. :if (version<= "24.4" emacs-version)
  142. :mode ("\\.cs\\'"))
  143. ;; ------- Markdown Mode ----------
  144. (when (version<= "24.4" emacs-version)
  145. (use-package markdown-mode
  146. :mode ("\\.markdown\\'" "\\.md\\'")))
  147. ;; ---- StackOverflow Client ------
  148. (use-package sx
  149. :disabled)
  150. ;; -------- Spellcheck ------------
  151. (defun flyspell-detect-ispell-args (&optional run-together)
  152. (cond ((string-match "aspell$" ispell-program-name)
  153. (append (list "--sug-mode=ultra" "--lang=en_US") (if run-together '("--run-together" "--run-together-limit=5" "--run-together-min=2"))))
  154. ((string-match "hunspell$" ispell-program-name)
  155. "-d en_US")))
  156. (use-package flyspell-correct-popup
  157. :bind ("M-s" . ispell-word)
  158. :hook ((text-mode . flyspell-mode)
  159. (prog-mode . flyspell-prog-mode)
  160. ((flyspell-mode flyspell-prog-mode) . flyspell-buffer))
  161. :config
  162. (cond
  163. ((executable-find "aspell")
  164. (setq ispell-program-name "aspell"))
  165. ((executable-find "hunspell")
  166. (setq ispell-program-name "hunspell")
  167. (setq ispell-local-dictionary "en_US")
  168. (setq ispell-local-dictionary-alist '(("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_US") nil utf-8))))
  169. (t
  170. (setq ispell-program-name nil)))
  171. (setq-default ispell-extra-args (flyspell-detect-ispell-args t))
  172. (setq-default flyspell-issue-message-flag nil))
  173. ;; -------- REST Client ---------
  174. (use-package restclient
  175. :commands (restclient-copy-curl-command
  176. restclient-http-send-current
  177. restclient-http-send-current-raw
  178. restclient-http-send-current-stay-in-window
  179. restclient-jump-next
  180. restclient-jump-prev
  181. restclient-mark-current
  182. restclient-mode
  183. restclient-narrow-to-current
  184. restclient-outline-mode
  185. restclient-toggle-body-visibility
  186. restclient-toggle-body-visibility-or-indent))
  187. ;; ------- Highlight TODO -------
  188. (use-package hl-todo
  189. :commands (hl-todo-mode
  190. hl-todo-next
  191. hl-todo-occur
  192. hl-todo-previous)
  193. :hook (prog-mode . hl-todo-mode))
  194. ;; ---- Printer Integration -----
  195. (use-package printing
  196. :bind ("M-p" . print-buffer)
  197. :commands (print-buffer
  198. print-region
  199. lpr-buffer
  200. lpr-customize
  201. lpr-region)
  202. :config
  203. (pr-update-menus t))
  204. (custom-set-variables
  205. ;; custom-set-variables was added by Custom.
  206. ;; If you edit it by hand, you could mess it up, so be careful.
  207. ;; Your init file should contain only one such instance.
  208. ;; If there is more than one, they won't work right.
  209. '(package-selected-packages
  210. (quote
  211. (company xclip hl-todo comment-tags restclient markdown-mode autopair highlight-parentheses flyspell-correct-popup rust-mode rust-playground slime-volleyball use-package multi-web-mode magit ensime color-theme base16-theme))))
  212. (custom-set-faces
  213. ;; custom-set-faces was added by Custom.
  214. ;; If you edit it by hand, you could mess it up, so be careful.
  215. ;; Your init file should contain only one such instance.
  216. ;; If there is more than one, they won't work right.
  217. )