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.

1125 lines
32 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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. * Stuff to add / to fix
  9. - smartparens
  10. a sane default configuration for navigation, manipulation etc. is still necessary
  11. - Spaceline / Powerline or similar
  12. I want a pretty status bar!
  13. - Markdown mode
  14. There might be more than one package for this.
  15. - Git gutter:
  16. Do some configuration to make it useful (see given source link in the [[*Git][Section]] of gutter)
  17. Maybe only enable it for modes where it is likely I use git?
  18. - Some webmode stuff
  19. * Update config in a running config
  20. Two options:
  21. - reload the open file: M-x load-file, then press twice to accept
  22. the default filename, which is the currently opened
  23. - Point at the end of any sexp and press C-x C-e
  24. * Customize settings
  25. Move the customize settings to its own file, instead of saving
  26. customize settings in [[file:init.el][init.el]].
  27. #+begin_src emacs-lisp
  28. (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  29. (load custom-file)
  30. #+end_src
  31. * Theme
  32. ** Font
  33. Don't add the font in the work environment, which I am logged in as POH
  34. #+begin_src emacs-lisp
  35. (unless (string-equal user-login-name "POH")
  36. (set-face-attribute 'default nil :font "Hack-12")
  37. )
  38. #+end_src
  39. ** Material Theme
  40. The [[https://github.com/cpaulik/emacs-material-theme][Material Theme]] comes in a dark and a light variant. Not too dark
  41. to be strenious though.
  42. #+begin_src emacs-lisp
  43. (use-package material-theme
  44. :if (window-system)
  45. :defer t
  46. :ensure t
  47. ;; :init
  48. ;; (load-theme 'material t)
  49. )
  50. #+end_src
  51. ** Apropospriate Theme
  52. Variants dark and light
  53. #+begin_src emacs-lisp
  54. (use-package apropospriate-theme
  55. :if (window-system)
  56. :defer t
  57. :ensure t
  58. :init
  59. (load-theme 'apropospriate-dark t)
  60. )
  61. #+end_src
  62. * Sane defaults
  63. 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]]
  64. These functions are useful. Activate them.
  65. #+begin_src emacs-lisp
  66. (put 'downcase-region 'disabled nil)
  67. (put 'upcase-region 'disabled nil)
  68. (put 'narrow-to-region 'disabled nil)
  69. (put 'dired-find-alternate-file 'disabled nil)
  70. #+end_src
  71. Answering just 'y' or 'n' should be enough.
  72. #+begin_src emacs-lisp
  73. (defalias 'yes-or-no-p 'y-or-n-p)
  74. #+end_src
  75. Keep all backup and auto-save files in one directory
  76. #+begin_src emacs-lisp
  77. (setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
  78. (setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
  79. #+end_src
  80. UTF-8 please
  81. #+begin_src emacs-lisp
  82. (setq locale-coding-system 'utf-8)
  83. (set-terminal-coding-system 'utf-8)
  84. (set-keyboard-coding-system 'utf-8)
  85. (set-selection-coding-system 'utf-8)
  86. (prefer-coding-system 'utf-8)
  87. #+end_src
  88. Avoid tabs in place of multiple spaces (they look bad in TeX)
  89. and show empty lines
  90. #+begin_src emacs-lisp
  91. (setq-default indent-tabs-mode nil)
  92. (setq-default indicate-empty-lines t)
  93. #+end_src
  94. Turn off blinking cursor
  95. #+begin_src emacs-lisp
  96. (blink-cursor-mode -1)
  97. #+end_src
  98. Don't count two spaces after a period as the end of a sentence.
  99. Just one space is needed
  100. #+begin_src emacs-lisp
  101. (setq sentence-end-double-space nil)
  102. #+end_src
  103. Delete the region when typing, just like as we expect nowadays.
  104. #+begin_src emacs-lisp
  105. (delete-selection-mode t)
  106. #+end_src
  107. Auto-indent when pressing RET, just new-line when C-j
  108. #+begin_src emacs-lisp
  109. (define-key global-map (kbd "RET") 'newline-and-indent)
  110. (define-key global-map (kbd "C-j") 'newline)
  111. #+end_src
  112. Various stuff
  113. #+begin_src emacs-lisp
  114. (show-paren-mode t)
  115. (column-number-mode t)
  116. (setq uniquify-buffer-name-style 'forward)
  117. #+end_src
  118. * Prettier Line Wraps
  119. By default there is no line wrapping. M-q actually modifies the buffer, which might not be wanted.
  120. So: enable visual wrapping and keep indentation if there are any.
  121. #+begin_src emacs-lisp
  122. (global-visual-line-mode)
  123. (diminish 'visual-line-mode)
  124. (use-package adaptive-wrap
  125. :ensure t
  126. :init
  127. (when (fboundp 'adaptive-wrap-prefix-mode)
  128. (defun my-activate-adaptive-wrap-prefix-mode ()
  129. "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  130. (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  131. (add-hook 'visual-line-mode-hook 'my-activate-adaptive-wrap-prefix-mode))
  132. )
  133. #+end_src
  134. * List buffers
  135. Ibuffer is the improved version of list-buffers.
  136. Make ibuffer the default buffer lister. [[http://ergoemacs.org/emacs/emacs_buffer_management.html][Source]]
  137. #+begin_src emacs-lisp
  138. (defalias 'list-buffers 'ibuffer)
  139. #+end_src
  140. Also auto refresh dired, but be quiet about it. [[http://whattheemacsd.com/sane-defaults.el-01.html][Source]]
  141. #+begin_src emacs-lisp
  142. (add-hook 'dired-mode-hook 'auto-revert-mode)
  143. (setq global-auto-revert-non-file-buffers t)
  144. (setq auto-revert-verbose nil)
  145. #+end_src
  146. * Org Mode
  147. ** Installation
  148. 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.]]
  149. Added a hook to complete org functions, company-capf is necessary for this
  150. #+begin_src emacs-lisp
  151. (use-package org
  152. :ensure org-plus-contrib
  153. :init
  154. (add-hook 'org-mode-hook 'company/org-mode-hook)
  155. )
  156. #+end_src
  157. 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:
  158. #+begin_src sh:
  159. var ORG_DIR=(let* ((org-v (cadr (split-string (org-version nil t) "@"))) (len (length org-v))) (substring org-v 1 (- len 2)))
  160. rm ${ORG_DIR}/*.elc
  161. #+end_src
  162. *** Org key bindings
  163. Set up some global key bindings that integrate with Org mode features
  164. #+begin_src emacs-lisp
  165. (bind-key "C-c l" 'org-store-link)
  166. (bind-key "C-c c" 'org-capture)
  167. (bind-key "C-c a" 'org-agenda)
  168. #+end_src
  169. Org overwrites RET and C-j, so I need to disable the rebinds
  170. #+begin_src emacs-lisp
  171. (define-key org-mode-map (kbd "RET") nil) ;;org-return
  172. (define-key org-mode-map (kbd "C-j") nil) ;;org-return-indent
  173. #+end_src
  174. *** Org agenda
  175. For a more detailed example [[https://github.com/sachac/.emacs.d/blob/83d21e473368adb1f63e582a6595450fcd0e787c/Sacha.org#org-agenda][see here]].
  176. #+begin_src emacs-lisp
  177. (setq org-agenda-files
  178. (delq nil
  179. (mapcar (lambda (x) (and (file-exists-p x) x))
  180. '("~/Archiv/Dokumente/Agenda"))
  181. )
  182. )
  183. #+end_src
  184. *** Org capture
  185. #+begin_src emacs-lisp
  186. (bind-key "C-c c" 'org-capture)
  187. (setq org-default-notes-file "~/Archiv/Dokumente/Notizen/notes.org")
  188. #+end_src
  189. ** Org Setup
  190. 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.
  191. See the doc for speed keys by checking out the documentation for speed keys in Org mode.
  192. #+begin_src emacs-lisp
  193. (setq org-use-speed-commands t)
  194. (setq org-image-actual-width 550)
  195. (setq org-highlight-latex-and-related '(latex script entities))
  196. #+end_src
  197. Hide emphasis markup (e.g. / ... / for italics, etc.)
  198. #+begin_src emacs-lisp
  199. (setq org-hide-emphasis-markers t)
  200. #+end_src
  201. Setting some environment paths
  202. #+begin_src emacs-lisp
  203. (if (string-equal user-login-name "POH")
  204. (progn
  205. (defvar PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  206. (defvar PATH_ORG_JOURNAL "p:/Eigene Dateien/Notizen/Journal/")
  207. (defvar PATH_START "p:/Eigene Dateien/Notizen/"))
  208. )
  209. #+end_src
  210. Sort org agenda by deadline and priority
  211. #+begin_src emacs-lisp
  212. (setq org-agenda-sorting-strategy
  213. (quote
  214. ((agenda deadline-up priority-down)
  215. (todo priority-down category-keep)
  216. (tags priority-down category-keep)
  217. (search category-keep)))
  218. )
  219. #+end_src
  220. Custom todo-keywords, depending on environment
  221. #+begin_src emacs-lisp
  222. (if (string-equal user-login-name "POH")
  223. (setq org-todo-keywords
  224. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE")))
  225. )
  226. #+end_src
  227. Set locations of some org files
  228. #+begin_src emacs-lisp
  229. (if (string-equal user-login-name "POH")
  230. (progn
  231. (setq org-default-notes-file (concat PATH_ORG_FILES "notes.org"))
  232. (setq org-agenda-files (list(concat PATH_ORG_FILES "notes.org")
  233. (concat PATH_ORG_FILES "projects.org")
  234. (concat PATH_ORG_FILES "todo.org"))))
  235. )
  236. #+end_src
  237. Work specific org-capture-templates
  238. #+begin_src emacs-lisp
  239. (if (string-equal user-login-name "POH")
  240. (setq org-capture-templates
  241. '(("t" "todo" entry (file (concat PATH_ORG_FILES "todo.org"))
  242. "** TODO %\\n%u\n%a\n")
  243. ("n" "note" entry (file org-default-notes-file))
  244. ("p" "project" entry (file (concat PATH_ORG_FILES "projects.org"))
  245. "** OPEN %?\n%u\n** Beschreibung\n** Zu erledigen\n*** \n** Verlauf\n***" :clock-in t :clock-resume t)
  246. ("u" "Unterbrechung" entry (file org-default-notes-file)
  247. "* Unterbrechnung durch %? :Unterbrechung:\n%t" :clock-in t :clock-resume t)))
  248. )
  249. #+end_src
  250. Customize the org agenda
  251. #+begin_src emacs-lisp
  252. (defun my-org-skip-subtree-if-priority (priority)
  253. "Skip an agenda subtree if it has a priority of PRIORITY.
  254. PRIORITY may be one of the characters ?A, ?B, or ?C."
  255. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  256. (pri-value (* 1000 (- org-lowest-priority priority)))
  257. (pri-current (org-get-priority (thing-at-point 'line t))))
  258. (if (= pri-value pri-current)
  259. subtree-end
  260. nil)))
  261. (setq org-agenda-custom-commands
  262. '(("c" "Simple agenda view"
  263. ((tags "PRIORITY=\"A\""
  264. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  265. (org-agenda-overriding-header "Hohe Priorität:")))
  266. (agenda ""
  267. ((org-agenda-span 7)
  268. (org-agenda-start-on-weekday nil)
  269. (org-agenda-overriding-header "Nächsten 7 Tage:")))
  270. (alltodo ""
  271. ((org-agenda-skip-function '(or (my-org-skip-subtree-if-priority ?A)
  272. (org-agenda-skip-if nil '(scheduled deadline))))
  273. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))
  274. )
  275. #+end_src
  276. ** Org tags
  277. The default value is -77, which is weird for smaller width windows. I'd rather have the tags align horizontally with the header.
  278. 45 is a good column number to do that.
  279. #+begin_src emacs-lisp
  280. (setq org-tags-column 45)
  281. #+end_src
  282. ** Org babel languages
  283. This code block is linux specific. Loading languages which aren't available seems to be a problem
  284. #+begin_src emacs-lisp
  285. (cond ((eq system-type 'gnu/linux)
  286. (org-babel-do-load-languages
  287. 'org-babel-load-languages
  288. '(
  289. (C . t)
  290. (calc . t)
  291. (java . t)
  292. (js . t)
  293. (latex . t)
  294. (ledger . t)
  295. (lisp . t)
  296. (python . t)
  297. (R . t)
  298. (ruby . t)
  299. (scheme . t)
  300. (shell . t)
  301. (sqlite . t)
  302. )
  303. ))
  304. )
  305. #+end_src
  306. #+begin_src emacs-lisp
  307. (defun my-org-confirm-babel-evaluate (lang body)
  308. "Do not confirm evaluation for these languages."
  309. (not (or (string= lang "C")
  310. (string= lang "java")
  311. (string= lang "python")
  312. (string= lang "R")
  313. (string= lang "ledger")
  314. (string= lang "emacs-lisp")
  315. (string= lang "sqlite"))))
  316. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  317. #+end_src
  318. I want plots!
  319. #+begin_src emacs-lisp
  320. (use-package ess
  321. :ensure t
  322. )
  323. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
  324. (add-hook 'org-mode-hook 'org-display-inline-images)
  325. #+end_src
  326. ** Org babel/source blocks
  327. 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
  328. 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
  329. #+begin_src emacs-lisp
  330. (setq org-src-fontify-natively t
  331. org-src-window-setup 'current-window
  332. org-src-strip-leading-and-trailing-blank-lines t
  333. org-src-preserve-indentation t
  334. org-src-tab-acts-natively t)
  335. #+end_src
  336. * which-key
  337. Greatly increases discovery of functions!
  338. Click [[https://github.com/justbur/emacs-which-key][here]] for source and more info.
  339. Info in Emacs: M-x customize-group which-key
  340. #+begin_src emacs-lisp
  341. (use-package which-key
  342. :ensure t
  343. :diminish which-key-mode
  344. :config
  345. (which-key-mode)
  346. (which-key-setup-side-window-right-bottom)
  347. (which-key-setup-minibuffer)
  348. (setq which-key-idle-delay 0.5)
  349. )
  350. #+end_src
  351. * Ido (currently inactive)
  352. better completion
  353. begin_src emacs-lisp
  354. (use-package ido
  355. :init
  356. (setq ido-enable-flex-matching t)
  357. (setq ido-everywhere t)
  358. (ido-mode t)
  359. (use-package ido-vertical-mode
  360. :ensure t
  361. :defer t
  362. :init
  363. (ido-vertical-mode 1)
  364. (setq ido-vertical-define-keys 'C-n-and-C-p-only)
  365. )
  366. )
  367. end_src
  368. * ivy / counsel / swiper
  369. Flx is required for fuzzy-matching
  370. Is it really necessary?
  371. begin_src emacs-lisp
  372. (use-package flx)
  373. end_src
  374. Ivy displays a window with suggestions for hotkeys and M-x
  375. #+begin_src emacs-lisp
  376. (use-package ivy
  377. :ensure t
  378. :diminish
  379. (ivy-mode . "") ;; does not display ivy in the mode line
  380. :init
  381. (ivy-mode 1)
  382. :bind
  383. ("C-c C-r" . ivy-resume)
  384. :config
  385. (setq ivy-use-virtual-buffers t) ;; recent files and bookmarks in ivy-switch-buffer
  386. (setq ivy-height 20) ;; height of ivy window
  387. (setq ivy-count-format "%d/%d") ;; current and total number
  388. (setq ivy-re-builders-alist ;; regex replaces spaces with *
  389. '((t . ivy--regex-plus)))
  390. )
  391. #+end_src
  392. Counsel replaces:
  393. - M-x
  394. - C-x C-f find-file
  395. - C-c h f describe-function
  396. - C-c h v describe-variable
  397. - M-i imenu
  398. The find-file replacement is nicer to navigate
  399. #+begin_src emacs-lisp
  400. (use-package counsel
  401. :ensure t
  402. :bind* ;; load counsel when pressed
  403. (("M-x" . counsel-M-x)
  404. ("C-x C-f" . counsel-find-file)
  405. ("C-c h f" . counsel-describe-function)
  406. ("C-c h v" . counsel-describe-variable)
  407. ("M-i" . counsel-imenu)
  408. )
  409. )
  410. #+end_src
  411. Swiper ivy-enhances isearch
  412. #+begin_src emacs-lisp
  413. (use-package swiper
  414. :ensure t
  415. :bind
  416. (("C-s" . swiper)
  417. ("C-c C-r" . ivy-resume)
  418. )
  419. )
  420. #+end_src
  421. * Recentf
  422. Requires counsel
  423. #+begin_src emacs-lisp
  424. (use-package recentf
  425. :bind ("C-x C-r" . counsel-recentf)
  426. :config
  427. (recentf-mode t)
  428. (setq recentf-max-saved-items 200)
  429. )
  430. #+end_src
  431. * Latex
  432. Requirements for Linux:
  433. - Latex
  434. - pdf-tools
  435. #+begin_src emacs-lisp
  436. (unless (string-equal user-login-name "POH")
  437. (use-package pdf-tools
  438. :ensure t
  439. :config
  440. (pdf-tools-install)
  441. (setq TeX-view-program-selection '((output-pdf "pdf-tools")))
  442. (setq TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  443. )
  444. )
  445. #+end_src
  446. For latex-preview-pane a patch might be necessary (as of 2017-10), see the issue [[https://github.com/jsinglet/latex-preview-pane/issues/37][here]]
  447. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  448. #+begin_src
  449. latex-preview-pane-update-p()
  450. --- (doc-view-revert-buffer nil t)
  451. +++ (revert-buffer-nil t 'preserve-modes)
  452. #+end_src
  453. After that M-x byte-compile-file
  454. #+begin_src emacs-lisp
  455. (use-package latex-preview-pane
  456. :ensure t
  457. )
  458. (setq auto-mode-alist
  459. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  460. ;; one of these works
  461. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  462. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  463. ;; necessary, because linum-mode isn't compatible and prints errors
  464. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  465. #+end_src
  466. * Personal Finances
  467. I picked ledger for my personal accounting and will test if it's beneficial over gnucash.
  468. ..and don't activate the modules at work.
  469. #+begin_src emacs-lisp
  470. (unless (string-equal user-login-name "POH")
  471. (use-package ledger-mode
  472. :ensure t
  473. :mode ("\\.ledger$" . ledger-mode)
  474. :init
  475. (setq clear-whole-transactions t)
  476. )
  477. )
  478. #+end_src
  479. * Programming
  480. ** Common things
  481. List of plugins and settings which are shared between the language plugins
  482. Highlight whitespaces, tabs, empty lines.
  483. #+begin_src emacs-lisp
  484. (use-package whitespace
  485. :demand t
  486. :ensure nil
  487. :init
  488. (dolist (hook '(prog-mode-hook
  489. text-mode-hook
  490. conf-mode-hook))
  491. (add-hook hook #'whitespace-mode))
  492. ;; :hook ;;not working in use-package 2.3
  493. ;; ((prog-mode . whitespace-turn-on)
  494. ;; (text-mode . whitespace-turn-on))
  495. :config
  496. (setq-default whitespace-style '(face empty tab trailing))
  497. )
  498. #+end_src
  499. Disable Eldoc, it interferes with flycheck
  500. #+begin_src emacs-lisp
  501. (use-package eldoc
  502. :ensure nil
  503. :config
  504. (global-eldoc-mode -1)
  505. )
  506. #+end_src
  507. Colorize colors as text with their value
  508. #+begin_src emacs-lisp
  509. (use-package rainbow-mode
  510. :ensure t
  511. :init
  512. (add-hook 'prog-mode-hook 'rainbow-mode t)
  513. ;; :hook prog-mode ;; not working in use-package 2.3
  514. :config
  515. (setq-default rainbow-x-colors-major-mode-list '())
  516. )
  517. #+end_src
  518. Highlight parens etc. for improved readability
  519. #+begin_src emacs-lisp
  520. (use-package rainbow-delimiters
  521. :ensure t
  522. :config
  523. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  524. )
  525. #+end_src
  526. ** Smartparens
  527. Smartparens is a beast on its own, so it's worth having a dedicated section for it
  528. #+begin_src emacs-lisp
  529. (use-package smartparens
  530. :ensure t
  531. :diminish smartparens-mode
  532. :config
  533. (add-hook 'prog-mode-hook 'smartparens-mode)
  534. )
  535. #+end_src
  536. ** Git
  537. [[https://magit.vc/manual/magit/index.html][Link]]
  538. I want to do git stuff here, not in a separate terminal window
  539. Little crashcourse in magit:
  540. - magit-init to init a git project
  541. - magit-status (C-x g) to call the status window
  542. in status buffer:
  543. - s stage files
  544. - u unstage files
  545. - U unstage all files
  546. - a apply changed to staging
  547. - c c commit (type commit message, then C-c C-c to commit)
  548. - b b switch to another branch
  549. - P u git push
  550. - F u git pull
  551. #+begin_src emacs-lisp
  552. (use-package magit
  553. :ensure t
  554. :init
  555. ;; set git-path in work environment
  556. (if (string-equal user-login-name "POH")
  557. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  558. )
  559. :defer t
  560. :bind (("C-x g" . magit-status))
  561. )
  562. #+end_src
  563. Display line changes in gutter based on git history. Enable it everywhere
  564. [[https://github.com/syohex/emacs-git-gutter][Source]]
  565. #+begin_src emacs-lisp
  566. (use-package git-gutter
  567. :ensure t
  568. :config
  569. (global-git-gutter-mode t)
  570. :diminish git-gutter-mode
  571. )
  572. #+end_src
  573. Time machine lets me step through the history of a file as recorded in git.
  574. [[https://github.com/pidu/git-timemachine][Source]]
  575. #+begin_src emacs-lisp
  576. (use-package git-timemachine
  577. :ensure t
  578. )
  579. #+end_src
  580. ** Company Mode
  581. Complete Anything!
  582. Activate company and make it react nearly instantly
  583. #+begin_src emacs-lisp
  584. (use-package company
  585. :ensure t
  586. :config
  587. (setq-default company-minimum-prefix-length 1
  588. company-tooltip-align-annotation t
  589. company-tooltop-flip-when-above t
  590. company-show-numbers t
  591. company-idle-delay 0.1)
  592. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  593. ;; (define-key company-active-map (kbd "RET") nil)
  594. (company-tng-configure-default)
  595. )
  596. #+end_src
  597. *** Company backend hooks
  598. Backend configuration for python-mode
  599. Common backends are:
  600. - company-files: files & directory
  601. - company-keywords: keywords
  602. - company-capf: ??
  603. - company-abbrev: ??
  604. - company-dabbrev: dynamic abbreviations
  605. - company-ispell: ??
  606. #+begin_src emacs-lisp
  607. (defun company/python-mode-hook()
  608. (set (make-local-variable 'company-backends)
  609. '((company-jedi company-dabbrev company-yasnippet) company-capf company-files))
  610. ;; '((company-jedi company-dabbrev) company-capf company-files))
  611. (company-mode t)
  612. )
  613. #+end_src
  614. (defun add-pcomplete-to-capf ()
  615. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  616. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  617. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  618. Backend for Orgmode
  619. #+begin_src emacs-lisp
  620. (defun company/org-mode-hook()
  621. (set (make-local-variable 'company-backends)
  622. '(company-capf company-files))
  623. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  624. (company-mode t)
  625. )
  626. #+end_src
  627. Backend configuration for lisp-mode
  628. #+begin_src emacs-lisp
  629. (defun company/elisp-mode-hook()
  630. (set (make-local-variable 'company-backends)
  631. '((company-elisp company-dabbrev) company-capf company-files))
  632. (company-mode t)
  633. )
  634. #+end_src
  635. *** Misc Company packages
  636. Addon to sort suggestions by usage
  637. #+begin_src emacs-lisp
  638. (use-package company-statistics
  639. :ensure t
  640. :after company
  641. :config
  642. (company-statistics-mode 1)
  643. )
  644. #+end_src
  645. Get a popup with documentation of the completion candidate.
  646. For the popups the package pos-tip.el is used and automatically installed.
  647. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  648. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  649. #+begin_src emacs-lisp
  650. (use-package company-quickhelp
  651. :ensure t
  652. :after company
  653. :config
  654. (company-quickhelp-mode 1)
  655. )
  656. #+end_src
  657. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  658. ** Projectile
  659. Brings search functions on project level
  660. #+begin_src emacs-lisp
  661. (use-package projectile
  662. :ensure t
  663. :defer t
  664. :bind
  665. (("C-c p p" . projectile-switch-project)
  666. ("C-c p s s" . projectile-ag))
  667. :init
  668. (setq-default
  669. projectile-cache-file (expand-file-name ".projectile-cache" user-emacs-directory)
  670. projectile-known-projects-file (expand-file-name
  671. ".projectile-bookmarks" user-emacs-directory))
  672. :config
  673. (projectile-mode t)
  674. (setq-default
  675. projectile-completion-system 'ivy
  676. projectile-enable-caching t
  677. projectile-mode-line '(:eval (projectile-project-name)))
  678. )
  679. #+end_src
  680. ** Yasnippet
  681. Snippets!
  682. TODO: yas-minor-mode? what's that?
  683. #+begin_src emacs-lisp
  684. (use-package yasnippet
  685. :ensure t
  686. :init
  687. (yas-global-mode)
  688. :mode ("\\.yasnippet" . snippet-mode)
  689. :config
  690. (setq yas-snippet-dirs (concat user-emacs-directory "snippets"))
  691. )
  692. #+end_src
  693. ** Lisp
  694. #+begin_src emacs-lisp
  695. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  696. #+end_src
  697. ** Python
  698. Systemwide following packages need to be installed:
  699. - venv
  700. The virtual environments need to have following modules installed:
  701. - jedi
  702. - epc
  703. - pylint
  704. #+begin_src emacs-lisp
  705. (use-package flycheck
  706. :ensure t
  707. :init
  708. (add-hook 'after-init-hook #'global-flycheck-mode)
  709. (add-hook 'python-mode-hook (lambda ()
  710. (semantic-mode 1)
  711. (flycheck-select-checker 'python-pylint)))
  712. )
  713. #+end_src
  714. Automatically start python-mode when opening a .py-file.
  715. Not sure if python.el is better than python-mode.el.
  716. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  717. The custom function is to run inferiour processes (do I really need that?), see [[https://emacs.stackexchange.com/questions/16361/how-to-automatically-run-inferior-process-when-loading-major-mode][here]].
  718. Also limit the completion backends to those which make sense in Python.
  719. #+begin_src emacs-lisp
  720. (use-package python
  721. :mode ("\\.py\\'" . python-mode)
  722. :interpreter ("python" . python-mode)
  723. :init
  724. (add-hook 'python-mode-hook 'company/python-mode-hook)
  725. :config
  726. (setq python-shell-completion-native-enable nil)
  727. )
  728. #+end_src
  729. Jedi is a backend for python autocompletion and needs to be installed on the server:
  730. - pip install jedi
  731. Code checks need to be installed, too:
  732. - pip install flake8
  733. #+begin_src emacs-lisp
  734. (use-package company-jedi
  735. :defer t
  736. ;; :after company
  737. :ensure t
  738. :config
  739. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  740. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  741. (add-hook 'python-mode-hook 'jedi:setup)
  742. (setq jedi:complete-on-dot t)
  743. (setq jedi:use-shortcuts t)
  744. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  745. )
  746. #+end_src
  747. A wrapper to handle virtual environments.
  748. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  749. TODO: automatically start an inferior python process or switch to it if already created
  750. #+begin_src emacs-lisp
  751. (use-package pyvenv
  752. :ensure t
  753. :init
  754. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  755. :config
  756. (pyvenv-mode t)
  757. (defun my/post-activate-hook()
  758. (setq jedi:environment-root pyvenv-virtual-env)
  759. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  760. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  761. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  762. ;; default traceback, other option M-x jedi:toggle-log-traceback
  763. ;; traceback is in jedi:pop-to-epc-buffer
  764. (jedi:setup)
  765. (company/python-mode-hook)
  766. (setq jedi:server-args '("--log-traceback")))
  767. ;; (add-to-list 'company-backends 'company-jedi)
  768. ;; (add-to-list 'company-backends 'company-anaconda)
  769. ;; (lambda ()
  770. ;; (set (make-local-variable 'company-backends)
  771. ;; '((company-jedi company-dabbrev) company-capf company-files)))
  772. ;; (setq flycheck-checker 'python-pylint))
  773. ;; (flycheck-select-checker 'python-pylint))
  774. ;; (setq flycheck-checker 'python-flake8)
  775. (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook)
  776. )
  777. #+end_src
  778. I want Emacs to automatically start the proper virtual environment.
  779. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  780. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  781. Depends on pyvenv
  782. #+begin_src emacs-lisp
  783. (use-package auto-virtualenv
  784. :ensure t
  785. ;; :after pyvenv
  786. ;; :defer t
  787. :init
  788. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  789. ;; activate on changing buffers
  790. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  791. ;; activate on focus in
  792. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  793. )
  794. #+end_src
  795. Anaconda test
  796. begin_src emacs-lisp
  797. (use-package anaconda-mode
  798. :ensure t
  799. :defer t
  800. :init
  801. (add-hook 'python-mode-hook 'anaconda-mode)
  802. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  803. :config
  804. (setq anaconda-eldoc-mode 1)
  805. )
  806. end_src
  807. begin_src emacs-lisp
  808. (use-package company-anaconda
  809. :ensure t
  810. :defer t
  811. :init
  812. (defun my/company-anaconda-hook()
  813. (add-to-list 'company-backends 'company-anaconda))
  814. (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  815. )
  816. end_src
  817. * Hydra
  818. Hydra allows grouping of commands
  819. #+begin_src emacs-lisp
  820. (use-package hydra
  821. :ensure t
  822. :bind
  823. ("C-c f" . hydra-flycheck/body)
  824. :config
  825. (setq-default hydra-default-hint nil)
  826. )
  827. #+end_src
  828. ** Hydra Flycheck
  829. Flycheck is necessary, obviously
  830. #+begin_src emacs-lisp
  831. (defhydra hydra-flycheck (:color blue)
  832. "
  833. ^
  834. ^Flycheck^ ^Errors^ ^Checker^
  835. ^────────^──────────^──────^────────────^───────^───────────
  836. _q_ quit _<_ previous _?_ describe
  837. _m_ manual _>_ next _d_ disable
  838. _v_ verify setup _f_ check _s_ select
  839. ^^ ^^ ^^
  840. "
  841. ("q" nil)
  842. ("<" flycheck-previous-error :color red)
  843. (">" flycheck-next-error :color red)
  844. ("?" flycheck-describe-checker)
  845. ("d" flycheck-disable-checker)
  846. ("f" flycheck-buffer)
  847. ("m" flycheck-manual)
  848. ("s" flycheck-select-checker)
  849. ("v" flycheck-verify-setup)
  850. )
  851. #+end_src
  852. * Treemacs
  853. A file manager comparable to neotree.
  854. [[https://github.com/Alexander-Miller/treemacs][Github]]
  855. It has some requirements, which gets used here anyway:
  856. - ace-window
  857. - hydra
  858. - projectile
  859. - python
  860. I copied the configuration example from the github site.
  861. No idea what this executable-find is about.
  862. TODO check it out!
  863. #+begin_src emacs-lisp
  864. (use-package treemacs
  865. :ensure t
  866. :defer t
  867. :config
  868. (setq treemacs-change-root-without-asking nil
  869. treemacs-collapse-dirs (if (executable-find "python") 3 0)
  870. treemacs-file-event-delay 5000
  871. treemacs-follow-after-init t
  872. treemacs-follow-recenter-distance 0.1
  873. treemacs-goto-tag-strategy 'refetch-index
  874. treemacs-indentation 2
  875. treemacs-indentation-string " "
  876. treemacs-is-never-other-window nil
  877. treemacs-never-persist nil
  878. treemacs-no-png-images nil
  879. treemacs-recenter-after-file-follow nil
  880. treemacs-recenter-after-tag-follow nil
  881. treemacs-show-hidden-files t
  882. treemacs-silent-filewatch nil
  883. treemacs-silent-refresh nil
  884. treemacs-sorting 'alphabetic-desc
  885. treemacs-tag-follow-cleanup t
  886. treemacs-tag-follow-delay 1.5
  887. treemacs-width 35)
  888. (treemacs-follow-mode t)
  889. (treemacs-filewatch-mode t)
  890. (pcase (cons (not (null (executable-find "git")))
  891. (not (null (executable-find "python3"))))
  892. (`(t . t)
  893. (treemacs-git-mode 'extended))
  894. (`(t . _)
  895. (treemacs-git-mode 'simple)))
  896. :bind
  897. (:map global-map
  898. ([f8] . treemacs-toggle))
  899. )
  900. #+end_src
  901. Treemacs-projectile is useful for uhh.. TODO explain!
  902. #+begin_src emacs-lisp
  903. (use-package treemacs-projectile
  904. :ensure t
  905. :defer t
  906. :config
  907. (setq treemacs-header-function #'treemacs-projectile-create-header)
  908. )
  909. #+end_src
  910. TODO
  911. Hydrastuff or keybindings for functions:
  912. - treemacs-projectile
  913. - treemacs-projectile-toggle
  914. - treemacs-toggle
  915. - treemacs-bookmark
  916. - treemacs-find-file
  917. - treemacs-find-tag
  918. * Window Handling
  919. Some tools to easen the navigation, creation and deletion of windows
  920. ** Ace-Window
  921. #+begin_src emacs-lisp
  922. (use-package ace-window
  923. :ensure t
  924. :init
  925. (global-set-key (kbd "C-x o") 'ace-window)
  926. )
  927. #+end_src
  928. ** Windmove
  929. Windmove easens the navigation between windows.
  930. Here we are setting the default keybindings (shift+arrow)
  931. CURRENTLY NOT WORKING, defaults are blocked.
  932. Also not sure if necessary when using ace-window.
  933. #+begin_src emacs-lisp
  934. (use-package windmove
  935. :ensure t
  936. :config
  937. (windmove-default-keybindings)
  938. )
  939. #+end_src
  940. * Quality of Life