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.

253 lines
7.4 KiB

  1. #+TITLE: Emacs Configuration
  2. #+AUTHOR: Marc Pohling
  3. * Personal Information
  4. #+begin_src emacs-lisp
  5. (setq user-full-name "Marc Pohling"
  6. user-mail-address "marc.pohling@googlemail.com")
  7. #+end_src
  8. * Update config in a running config
  9. Two options:
  10. - reload the open file: M-x load-file, then press twice to accept
  11. the default filename, which is the currently opened
  12. - Point at the end of any sexp and press C-x C-e
  13. * Customize settings
  14. Move the customize settings to its own file, instead of saving
  15. customize settings in [[file:init.el][init.el]].
  16. #+begin_src emacs-lisp
  17. (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  18. (load custom-file)
  19. #+end_src
  20. * Theme
  21. ** Material Theme
  22. The [[https://github.com/cpaulik/emacs-material-theme][Material Theme]] comes in a dark and a light variant. Not too dark
  23. to be strenious though.
  24. #+begin_src emacs-lisp
  25. (use-package material-theme
  26. :if (window-system)
  27. :defer t
  28. :ensure t
  29. :init
  30. (load-theme 'material t)
  31. )
  32. #+end_src
  33. * Sane defaults
  34. Sources for this section include [[https://github.com/magnars/.emacs.d/blob/master/settings/sane-defaults.el][Magnars Sveen]] and [[http://pages.sachachua.com/.emacs.d/Sacha.html][Sacha Chua]]
  35. These functions are useful. Activate them.
  36. #+begin_src emacs-lisp
  37. (put 'downcase-region 'disabled nil)
  38. (put 'upcase-region 'disabled nil)
  39. (put 'narrow-to-region 'disabled nil)
  40. (put 'dired-find-alternate-file 'disabled nil)
  41. #+end_src
  42. Answering just 'y' or 'n' should be enough.
  43. #+begin_src emacs-lisp
  44. (defalias 'yes-or-no-p 'y-or-n-p)
  45. #+end_src
  46. Keep all backup and auto-save files in one directory
  47. #+begin_src emacs-lisp
  48. (setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
  49. (setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
  50. #+end_src
  51. UTF-8 please
  52. #+begin_src emacs-lisp
  53. (setq locale-coding-system 'utf-8)
  54. (set-terminal-coding-system 'utf-8)
  55. (set-keyboard-coding-system 'utf-8)
  56. (set-selection-coding-system 'utf-8)
  57. (prefer-coding-system 'utf-8)
  58. #+end_src
  59. Avoid tabs in place of multiple spaces (they look bad in TeX)
  60. and show empty lines
  61. #+begin_src emacs-lisp
  62. (setq-default indent-tabs-mode nil)
  63. (setq-default indicate-empty-lines t)
  64. #+end_src
  65. Turn off blinking cursor
  66. #+begin_src emacs-lisp
  67. (blink-cursor-mode -1)
  68. #+end_src
  69. Don't count two spaces after a period as the end of a sentence.
  70. Just one space is needed
  71. #+begin_src emacs-lisp
  72. (setq sentence-end-double-space nil)
  73. #+end_src
  74. Delete the region when typing, just like as we expect nowadays.
  75. #+begin_src emacs-lisp
  76. (delete-selection-mode t)
  77. #+end_src
  78. Various stuff
  79. #+begin_src emacs-lisp
  80. (show-paren-mode t)
  81. (column-number-mode t)
  82. (global-visual-line-mode)
  83. (diminish 'visual-line-mode)
  84. (setq uniquify-buffer-name-style 'forward)
  85. #+end_src
  86. * List buffers
  87. Ibuffer is the improved version of list-buffers.
  88. Make ibuffer the default buffer lister. [[http://ergoemacs.org/emacs/emacs_buffer_management.html][Source]]
  89. #+begin_src emacs-lisp
  90. (defalias 'list-buffers 'ibuffer)
  91. #+end_src
  92. Also auto refresh dired, but be quiet about it. [[http://whattheemacsd.com/sane-defaults.el-01.html][Source]]
  93. #+begin_src emacs-lisp
  94. (add-hook 'dired-mode-hook 'auto-revert-mode)
  95. (setq global-auto-revert-non-file-buffers t)
  96. (setq auto-revert-verbose nil)
  97. #+end_src
  98. * Recentf
  99. #+begin_src emacs-lisp
  100. (use-package recentf
  101. :bind ("C-x C-r" . helm-recentf)
  102. :config
  103. (recentf-mode t)
  104. (setq recentf-max-saved-items 200)
  105. )
  106. #+end_src
  107. * Org Mode
  108. ** Installation
  109. Although org mode ships with Emacs, the latest version can be installed externally. The configuration here follows the [[http://orgmode.org/elpa.html][Org mode ELPA Installation instructions.]]
  110. #+begin_src emacs-lisp
  111. (use-package org
  112. :ensure org-plus-contrib)
  113. #+end_src
  114. To avoid problems executing source blocks out of the box. [[https://emacs.stackexchange.com/a/28604][Others have the same problem, too]]. The solution is to remove the .elc files form the package directory:
  115. #+begin_src sh:var ORG_DIR=(let* ((org-v (cadr (split-string (org-version nil t) "@"))) (len (length org-v))) (substring org-v 1 (- len 2)))
  116. rm ${ORG_DIR}/*.elc
  117. #+end_src
  118. *** Org activation bindings
  119. Set up some global key bindings that integrate with Org mode features
  120. #+begin_src emacs-lisp
  121. (bind-key "C-c l" 'org-store-link)
  122. (bind-key "C-c c" 'org-capture)
  123. (bind-key "C-c a" 'org-agenda)
  124. #+end_src
  125. *** Org agenda
  126. For a more detailed example [[https://github.com/sachac/.emacs.d/blob/83d21e473368adb1f63e582a6595450fcd0e787c/Sacha.org#org-agenda][see here]].
  127. #+begin_src emacs-lisp
  128. (setq org-agenda-files
  129. (delq nil
  130. (mapcar (lambda (x) (and (file-exists-p x) x))
  131. '("~/Archiv/Dokumente/Agenda"))
  132. )
  133. )
  134. #+end_src
  135. *** Org capture
  136. #+begin_src emacs-lisp
  137. (bind-key "C-c c" 'org-capture)
  138. (setq org-default-notes-file "~/Archiv/Dokumente/Notizen/notes.org")
  139. #+end_src
  140. ** Org Setup
  141. Speed commands are a nice and quick way to perform certain actions while at the beginning of a heading. It's not activated by default.
  142. See the doc for speed keys by checking out the documentation for speed keys in Org mode.
  143. #+begin_src emacs-lisp
  144. (setq org-use-speed-commands t)
  145. (setq org-image-actual-width 550)
  146. (setq org-highlight-latex-and-related '(latex script entities))
  147. #+end_src
  148. ** Org tags
  149. The default value is -77, which is weird for smaller width windows. I'd rather have the tags align horizontally with the header.
  150. 45 is a good column number to do that.
  151. #+begin_src emacs-lisp
  152. (setq org-tags-column 45)
  153. #+end_src
  154. ** Org babel languages
  155. #+begin_src emacs-lisp
  156. (org-babel-do-load-languages
  157. 'org-babel-load-languages
  158. '((python . t)
  159. (C . t)
  160. (calc . t)
  161. (latex . t)
  162. (java . t)
  163. (ruby . t)
  164. (lisp . t)
  165. (scheme . t)
  166. (shell . t)
  167. (sqlite . t)
  168. (js . t)))
  169. (defun my-org-confirm-babel-evaluate (lang body)
  170. "Do not confirm evaluation for these languages."
  171. (not (or (string= lang "C")
  172. (string= lang "java")
  173. (string= lang "python")
  174. (string= lang "emacs-lisp")
  175. (string= lang "sqlite"))))
  176. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  177. #+end_src
  178. ** Org babel/source blocks
  179. I like to have source blocks properly syntax highlighted and with the editing popup window staying within the same window so all the windows don't jump around. Also, having the top and bottom trailing lines in the block is a waste of space, so we can remove them
  180. I noticed that fontification doesn't work with markdown mode when the block is indented after editing it in the org src buffer - the leading #s for headers don't get fontified properly because they apppear as Org comments. Setting ~org-src-preserve-identation~ makes things consistent as it doesn't pad source blocks with leading spaces
  181. #+begin_src emacs-lisp
  182. (setq org-src-fontify-natively t
  183. org-src-window-setup 'current-window
  184. org-src-strip-leading-and-trailing-blank-lines t
  185. org-src-preserve-indentation t
  186. org-src-tab-acts-natively t)
  187. #+end_src
  188. * which-key
  189. Greatly increases discovery of functions!
  190. Click [[https://github.com/justbur/emacs-which-key][here]] for source and more info.
  191. Info in Emacs: M-x customize-group which-key
  192. #+begin_src emacs-lisp
  193. (use-package which-key
  194. :ensure t
  195. :diminish which-key-mode
  196. :config
  197. (which-key-mode)
  198. (which-key-setup-side-window-right-bottom)
  199. (which-key-setup-minibuffer)
  200. (setq which-key-idle-delay 0.5)
  201. )
  202. #+end_src