Gentoo installation script
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.

emacs.el 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. ;; /etc/emacs/default.el
  2. ;; When Emacs is opened we should first adjust the appearance to what we
  3. ;; desire so that while configurations are being parsed we do not see the
  4. ;; default theme. We will disable various tool bars before they
  5. ;; initialize, then set the theme and font appearance.
  6. (when (fboundp 'menu-bar-mode) (menu-bar-mode -1))
  7. (when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
  8. (when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
  9. (load-theme 'tango-dark)
  10. (set-face-attribute
  11. 'default nil
  12. :family "Monospace" :weight 'normal
  13. :width 'normal :height 96)
  14. ;; In this section we will set some ideal default behaviors such as
  15. ;; inhibiting any unwanted initial buffers, forcing utf-8 encoding,
  16. ;; showing column numbers in the mode line, enabling the visual-bell
  17. ;; which disables the audible bell, and moving custom configuration
  18. ;; to another file as to not append this to the bottom of this file.
  19. (setq
  20. ;; Misc
  21. initial-scratch-message nil
  22. inhibit-splash-screen t
  23. inhibit-startup-buffer-menu t
  24. custom-file "~/.emacs.d/custom.el"
  25. ;; Encoding
  26. prefer-coding-system 'utf-8
  27. set-default-coding-systems 'utf-8
  28. set-language-environment "UTF-8"
  29. set-locale-environment "en_US.UTF-8")
  30. ;; Whenever possible, we should not load custom configurations until
  31. ;; after Emacs has finished initializing. This section relies on the
  32. ;; 'after-init-hook' to accomplish this.
  33. (add-hook
  34. 'after-init-hook
  35. (lambda()
  36. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  37. (add-hook 'lisp-mode-hook
  38. (lambda()
  39. (add-hook 'before-save-hook
  40. (lambda() (untabify (point-min)(point-max))))
  41. (linum-mode)))
  42. (add-hook 'prog-mode-hook
  43. (lambda()
  44. (linum-mode)))
  45. (add-hook 'text-mode-hook
  46. (lambda()
  47. (add-hook 'before-save-hook
  48. (lambda() (untabify (point-min)(point-max))))
  49. (linum-mode)))
  50. (add-hook 'c-mode-hook
  51. (lambda()
  52. (add-to-list 'auto-mode-alist '("\\.h\\'" . c-mode))
  53. (setq indent-tabs-mode 1)))
  54. (add-hook 'c++-mode-hook
  55. (lambda()
  56. (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
  57. (setq indent-tabs-mode 1)))
  58. (add-hook 'python-mode-hook
  59. (lambda()
  60. (add-hook 'before-save-hook
  61. (lambda() (untabify (point-min)(point-max))))
  62. (linum-mode)))
  63. (setq
  64. ;; Cut/Paste
  65. require-final-newline t
  66. save-interprogram-paste-before-kill t
  67. select-enable-primary nil
  68. ;; Display
  69. column-number-mode t
  70. visible-bell t
  71. ;; Indentation
  72. c-basic-offset 4
  73. cperl-indent-level 4
  74. js-indent-level 4
  75. tab-width 4
  76. indent-tabs-mode nil
  77. ;; Mouse
  78. mouse-wheel-follow-mouse 't
  79. mouse-wheel-progressive-speed nil
  80. mouse-wheel-scroll-amount '(3 ((shift) . 3))
  81. mouse-yank-at-point t
  82. ;; Scrolling
  83. auto-window-vscroll nil
  84. scroll-conservatively 101
  85. scroll-down-aggressively 0.0
  86. scroll-margin 0
  87. scroll-preserve-screen-position 1
  88. scroll-step 1
  89. scroll-up-aggressively 0.0)
  90. ;; Shorter y/n prompts
  91. (fset 'yes-or-no-p 'y-or-n-p)
  92. ;; Globally enable word-wrap
  93. (global-visual-line-mode t)
  94. ;; Highlight matching parenthesis
  95. (show-paren-mode t)
  96. ;; Enable mouse support in terminal
  97. (xterm-mouse-mode t)
  98. ;; Environment Variables
  99. (setenv "EDITOR" "emacsclient")
  100. (setenv "GIT_EDITOR" "emacsclient")
  101. (setenv "GOPATH" (getenv "GOPATH"))
  102. (setenv "MANPATH" (getenv "MANPATH"))
  103. (setenv "PATH" (getenv "PATH"))
  104. (setenv "PROMPT_COMMAND" "")
  105. (setenv "SHELL" (getenv "SHELL"))
  106. (setenv "TERM" (getenv "TERM"))
  107. ;; Buffers
  108. (global-set-key (kbd "C-x x") 'kill-buffer-and-window)
  109. (global-set-key (kbd "<C-tab>") 'next-buffer)
  110. (global-set-key (kbd "<C-iso-lefttab>") 'previous-buffer)
  111. (global-set-key (kbd "M--") (lambda() (interactive)
  112. (split-window-vertically)
  113. (other-window 1 nil)
  114. (switch-to-next-buffer)))
  115. (global-set-key (kbd "M-=") (lambda() (interactive)
  116. (split-window-horizontally)
  117. (other-window 1 nil)
  118. (switch-to-next-buffer)))
  119. ;; Comment or uncomment the highlighted region
  120. (global-set-key (kbd "C-c c") 'comment-or-uncomment-region)
  121. ;; Mouse
  122. (global-set-key (kbd "<mouse-4>") (lambda() (interactive)
  123. (scroll-down 3)))
  124. (global-set-key (kbd "<mouse-5>") (lambda() (interactive)
  125. (scroll-up 3)))
  126. ;; Movement
  127. (global-set-key (kbd "<M-down>") 'windmove-down)
  128. (global-set-key (kbd "<M-left>") 'windmove-left)
  129. (global-set-key (kbd "<M-right>") 'windmove-right)
  130. (global-set-key (kbd "<M-up>") 'windmove-up)
  131. (global-set-key (kbd "C-c <down>") 'windmove-down)
  132. (global-set-key (kbd "C-c <left>") 'windmove-left)
  133. (global-set-key (kbd "C-c <right>") 'windmove-right)
  134. (global-set-key (kbd "C-c <up>") 'windmove-up)
  135. ;; Autoload custom file
  136. (if (file-exists-p custom-file)
  137. (load custom-file)
  138. (write-region "" nil custom-file))))
  139. ;; Package management in Emacs has a few hiccups and this section is
  140. ;; meant to mitigate them. We will set the repositories to use and the
  141. ;; order in which to use them so that we are using stable packages
  142. ;; whenever possible. Additionally, we will install use-package if it is
  143. ;; not already present and set 'ensure' on all future use-package
  144. ;; declarations.
  145. (require 'package)
  146. (setq package-user-dir "~/.emacs.d/pkg/"
  147. package-archives
  148. '(("GNU ELPA" . "http://elpa.gnu.org/packages/")
  149. ("MELPA Stable" . "https://stable.melpa.org/packages/")
  150. ("MELPA" . "https://melpa.org/packages/"))
  151. package-archive-priorities
  152. '(("MELPA Stable" . 3)
  153. ("GNU ELPA" . 2)
  154. ("MELPA" . 1)))
  155. (package-initialize)
  156. (unless (package-installed-p 'use-package)
  157. (package-refresh-contents)
  158. (package-install 'use-package))
  159. (require 'use-package)
  160. (setq use-package-always-ensure t)
  161. ;; This section contains use-package definitions for any package that
  162. ;; currently ships with Emacs. If the package does not exist such as
  163. ;; with older versions, they will be installed. Extra consideration has
  164. ;; been taken to only apply settings when a package is used as to reduce
  165. ;; the time needed to initialize Emacs.
  166. (use-package async
  167. :config (async-bytecomp-package-mode '(all)))
  168. (use-package auto-compile
  169. :config
  170. (auto-compile-on-load-mode)
  171. (auto-compile-on-save-mode))
  172. (use-package auto-dictionary)
  173. (use-package eshell
  174. :config
  175. (setq eshell-cmpl-cycle-completions nil
  176. eshell-error-if-no-glob t
  177. eshell-hist-ignoredups t
  178. eshell-history-size 4096
  179. eshell-prefer-lisp-functions t
  180. eshell-save-history-on-exit t
  181. eshell-scroll-to-bottom-on-input nil
  182. eshell-scroll-to-bottom-on-output nil
  183. eshell-scroll-show-maximum-output nil
  184. eshell-visual-commands
  185. '("alsamixer" "htop" "top" "nano" "vi" "vim" "less" "ssh" "tail"
  186. "watch")
  187. eshell-prompt-regexp "^[^#$\n]*[#$] "
  188. eshell-prompt-function
  189. (lambda nil
  190. (concat
  191. "[" (user-login-name) "@" (system-name) " "
  192. (if (string= (eshell/pwd) (getenv "HOME"))
  193. "~" (eshell/basename (eshell/pwd)))
  194. "]"
  195. (if (= (user-uid) 0) "# " "$ "))))
  196. (defun eshell/clear()
  197. (interactive)
  198. (recenter 0))
  199. (defun eshell-new()
  200. "Open a new instance of eshell."
  201. (interactive)
  202. (eshell 'N)))
  203. (use-package eww
  204. :config
  205. (setq browse-url-browser-function 'eww-browse-url
  206. shr-blocked-images "")
  207. (defun eww-toggle-images()
  208. "Toggle blocking images in eww."
  209. (interactive)
  210. (if (bound-and-true-p shr-blocked-images)
  211. (setq shr-blocked-images nil)
  212. (setq shr-blocked-images ""))
  213. (eww-reload))
  214. (defun eww-new()
  215. "Open a new instance of eww."
  216. (interactive)
  217. (let ((url (read-from-minibuffer "Enter URL or keywords: ")))
  218. (switch-to-buffer (generate-new-buffer "*eww*"))
  219. (eww-mode)
  220. (eww url))))
  221. (use-package gnus
  222. :config
  223. (gnus-add-configuration
  224. '(article
  225. (horizontal 1.0
  226. (vertical 25 (group 1.0))
  227. (vertical 1.0
  228. (summary 0.25 point)
  229. (article 1.0)))))
  230. (gnus-add-configuration
  231. '(summary
  232. (horizontal 1.0
  233. (vertical 25 (group 1.0))
  234. (vertical 1.0 (summary 1.0 point))))))
  235. (use-package ibuffer
  236. :bind ("C-x C-b" . ibuffer)
  237. :config
  238. (add-hook 'ibuffer-hook
  239. (lambda()
  240. (ibuffer-do-sort-by-alphabetic)
  241. (ibuffer-do-sort-by-major-mode)
  242. (ibuffer-auto-mode t))))
  243. (use-package scratch
  244. :config
  245. (defun scratch-new()
  246. "Open a new scratch buffer."
  247. (interactive)
  248. (switch-to-buffer (generate-new-buffer "*scratch*"))
  249. (lisp-mode)))
  250. (use-package server
  251. :bind ("C-x C-c" . server-stop)
  252. :config (unless (server-running-p)(server-start))
  253. (defun server-kill()
  254. "Delete current Emacs server, then kill Emacs"
  255. (interactive)
  256. (if (y-or-n-p "Kill Emacs without saving? ")
  257. (kill-emacs)))
  258. (defun server-stop()
  259. "Prompt to save buffers, then kill Emacs."
  260. (interactive)
  261. (if (y-or-n-p "Quit Emacs? ")
  262. (save-buffers-kill-emacs)))
  263. (defun server-update()
  264. "Refresh package contents, then update all packages."
  265. (interactive)
  266. (package-initialize)
  267. (unless package-archive-contents
  268. (package-refresh-contents))
  269. (package-utils-upgrade-all)))
  270. (use-package xclip
  271. :config (xclip-mode 1))
  272. ;; This section defines additional packages which typically do not ship
  273. ;; with emacs that will be installed and configured when issued.
  274. (use-package circe
  275. :config
  276. (if (file-exists-p "~/.emacs.d/circe.el")
  277. (load-file "~/.emacs.d/circe.el"))
  278. (setq circe-default-part-message ""
  279. circe-default-quit-message ""
  280. circe-format-server-topic "*** Topic change by {userhost}: {topic-diff}"
  281. circe-reduce-lurker-spam t
  282. circe-use-cycle-completion t
  283. lui-fill-type nil
  284. lui-flyspell-alist '((".*" "american"))
  285. lui-flyspell-p t
  286. lui-time-stamp-format "%H:%M:%S"
  287. lui-time-stamp-position 'left-margin)
  288. (require 'circe-chanop)
  289. (enable-circe-color-nicks)
  290. (defun my-circe-set-margin() (setq left-margin-width 9))
  291. (setf (cdr (assoc 'continuation fringe-indicator-alist)) nil)
  292. (defun my-lui-setup()
  293. (setq fringes-outside-margins t
  294. left-margin-width 9
  295. word-wrap t
  296. wrap-prefix ""))
  297. (defun my-circe-prompt()
  298. (lui-set-prompt
  299. (concat (propertize
  300. (concat (buffer-name) ">")
  301. 'face 'circe-prompt-face) " ")))
  302. (defun my-circe-message-option-chanserv (nick user host command args)
  303. (when (and (string= "ChanServ" nick)
  304. (string-match "^\\[#.+?\\]" (cadr args)))
  305. '((dont-display . t))))
  306. (add-hook 'circe-chat-mode-hook 'my-circe-prompt)
  307. (add-hook 'circe-message-option-functions 'my-circe-message-option-chanserv)
  308. (add-hook 'lui-mode-hook (lambda() (my-lui-setup) (my-circe-set-margin))))
  309. (use-package cmake-ide
  310. :config (cmake-ide-setup))
  311. (use-package company
  312. :config
  313. (add-hook 'prog-mode-hook 'company-mode)
  314. (add-hook 'text-mode-hook 'company-mode))
  315. (use-package company-irony
  316. :config (add-to-list 'company-backends 'company-irony))
  317. (use-package company-irony-c-headers
  318. :config
  319. (add-to-list 'company-backends
  320. '(company-irony-c-headers company-irony)))
  321. (use-package counsel
  322. :bind (("<f1> f" . counsel-describe-function)
  323. ("<f1> l" . counsel-find-library)
  324. ("<f1> v" . counsel-describe-variable)
  325. ("<f2> i" . counsel-info-lookup-symbol)
  326. ("<f2> u" . counsel-unicode-char)
  327. ("C-S-o" . counsel-rhythmbox)
  328. ("C-c g" . counsel-git)
  329. ("C-c j" . counsel-git-grep)
  330. ("C-c l" . counsel-ag)
  331. ("C-r" . counsel-minibuffer-history)
  332. ("C-x C-f" . counsel-find-file)
  333. ("C-x l" . counsel-locate)
  334. ("M-x" . counsel-M-x)))
  335. (use-package diff-hl
  336. :config
  337. (add-hook 'prog-mode-hook 'diff-hl-mode)
  338. (add-hook 'text-mode-hook 'diff-hl-mode))
  339. (use-package elfeed
  340. :bind ("C-x w" . elfeed)
  341. :config
  342. (setq elfeed-search-filter "@1-week-ago +unread "
  343. url-queue-timeout 30)
  344. (if (file-exists-p "~/.emacs.d/elfeed.el")
  345. (load-file "~/.emacs.d/elfeed.el")))
  346. (use-package eww-lnum
  347. :config
  348. (define-key eww-mode-map "f" 'eww-lnum-follow)
  349. (define-key eww-mode-map "F" 'eww-lnum-universal))
  350. (use-package flycheck
  351. :config (add-hook 'prog-mode-hook 'flycheck-mode))
  352. (use-package flymake)
  353. (use-package flyspell
  354. :config
  355. (add-hook 'flyspell-mode-hook (auto-dictionary-mode 1))
  356. (add-hook 'markdown-mode-hook 'flyspell-mode)
  357. (add-hook 'prog-mode-hook 'flyspell-prog-mode)
  358. (add-hook 'text-mode-hook 'flyspell-mode))
  359. (use-package go-mode
  360. :config
  361. (add-hook 'before-save-hook 'gofmt-before-save)
  362. (add-hook 'go-mode-hook
  363. (lambda()
  364. (setq tab-width 4
  365. indent-tabs-mode 1))))
  366. (use-package highlight-indent-guides
  367. :config
  368. (add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
  369. (setq highlight-indent-guides-method 'character))
  370. (use-package irony
  371. :config
  372. (add-hook 'c++-mode-hook 'irony-mode)
  373. (add-hook 'c-mode-hook 'irony-mode)
  374. (add-hook 'objc-mode-hook 'irony-mode)
  375. (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
  376. (define-key irony-mode-map [remap completion-at-point] 'counsel-irony)
  377. (define-key irony-mode-map [remap complete-symbol] 'counsel-irony)
  378. (setq irony-additional-clang-options '("-std=c++14")))
  379. (use-package ivy
  380. :bind (("C-c C-r" . ivy-resume)
  381. ("<f6>" . ivy-resume))
  382. :config
  383. (ivy-mode 1)
  384. (setq ivy-use-virtual-buffers t
  385. enable-recursive-minibuffers t))
  386. (use-package magit)
  387. (use-package no-littering
  388. :config
  389. (setq auto-save-file-name-transforms
  390. `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
  391. (use-package nov
  392. :config (add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)))
  393. (use-package pdf-tools)
  394. (use-package rainbow-delimiters
  395. :config
  396. (add-hook 'markdown-mode-hook 'rainbow-delimiters-mode)
  397. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  398. (add-hook 'text-mode-hook 'rainbow-delimiters-mode))
  399. (use-package ranger)
  400. (use-package smartparens
  401. :config
  402. (add-hook 'markdown-mode-hook 'smartparens-mode)
  403. (add-hook 'prog-mode-hook 'smartparens-mode)
  404. (add-hook 'text-mode-hook 'smartparens-mode)
  405. (setq sp-highlight-pair-overlay nil
  406. sp-highlight-wrap-overlay nil
  407. sp-highlight-wrap-tag-overlay nil))
  408. (use-package swiper
  409. :bind ("C-s" . swiper))
  410. (use-package undo-tree
  411. :config (global-undo-tree-mode))