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.

909 lines
25 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
  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. ** Font
  22. #+begin_src emacs-lisp
  23. (set-face-attribute 'default nil :font "Hack-12")
  24. #+end_src
  25. ** Material Theme
  26. The [[https://github.com/cpaulik/emacs-material-theme][Material Theme]] comes in a dark and a light variant. Not too dark
  27. to be strenious though.
  28. #+begin_src emacs-lisp
  29. (use-package material-theme
  30. :if (window-system)
  31. :defer t
  32. :ensure t
  33. ;; :init
  34. ;; (load-theme 'material t)
  35. )
  36. #+end_src
  37. ** Apropospriate Theme
  38. Variants dark and light
  39. #+begin_src emacs-lisp
  40. (use-package apropospriate-theme
  41. :if (window-system)
  42. :defer t
  43. :ensure t
  44. :init
  45. (load-theme 'apropospriate-dark t)
  46. )
  47. #+end_src
  48. * Sane defaults
  49. 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]]
  50. These functions are useful. Activate them.
  51. #+begin_src emacs-lisp
  52. (put 'downcase-region 'disabled nil)
  53. (put 'upcase-region 'disabled nil)
  54. (put 'narrow-to-region 'disabled nil)
  55. (put 'dired-find-alternate-file 'disabled nil)
  56. #+end_src
  57. Answering just 'y' or 'n' should be enough.
  58. #+begin_src emacs-lisp
  59. (defalias 'yes-or-no-p 'y-or-n-p)
  60. #+end_src
  61. Keep all backup and auto-save files in one directory
  62. #+begin_src emacs-lisp
  63. (setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
  64. (setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
  65. #+end_src
  66. UTF-8 please
  67. #+begin_src emacs-lisp
  68. (setq locale-coding-system 'utf-8)
  69. (set-terminal-coding-system 'utf-8)
  70. (set-keyboard-coding-system 'utf-8)
  71. (set-selection-coding-system 'utf-8)
  72. (prefer-coding-system 'utf-8)
  73. #+end_src
  74. Avoid tabs in place of multiple spaces (they look bad in TeX)
  75. and show empty lines
  76. #+begin_src emacs-lisp
  77. (setq-default indent-tabs-mode nil)
  78. (setq-default indicate-empty-lines t)
  79. #+end_src
  80. Turn off blinking cursor
  81. #+begin_src emacs-lisp
  82. (blink-cursor-mode -1)
  83. #+end_src
  84. Don't count two spaces after a period as the end of a sentence.
  85. Just one space is needed
  86. #+begin_src emacs-lisp
  87. (setq sentence-end-double-space nil)
  88. #+end_src
  89. Delete the region when typing, just like as we expect nowadays.
  90. #+begin_src emacs-lisp
  91. (delete-selection-mode t)
  92. #+end_src
  93. Auto-indent when pressing RET, just new-line when C-j
  94. #+begin_src emacs-lisp
  95. (define-key global-map (kbd "RET") 'newline-and-indent)
  96. (define-key global-map (kbd "C-j") 'newline)
  97. #+end_src
  98. Various stuff
  99. #+begin_src emacs-lisp
  100. (show-paren-mode t)
  101. (column-number-mode t)
  102. (global-visual-line-mode)
  103. (diminish 'visual-line-mode)
  104. (setq uniquify-buffer-name-style 'forward)
  105. #+end_src
  106. * List buffers
  107. Ibuffer is the improved version of list-buffers.
  108. Make ibuffer the default buffer lister. [[http://ergoemacs.org/emacs/emacs_buffer_management.html][Source]]
  109. #+begin_src emacs-lisp
  110. (defalias 'list-buffers 'ibuffer)
  111. #+end_src
  112. Also auto refresh dired, but be quiet about it. [[http://whattheemacsd.com/sane-defaults.el-01.html][Source]]
  113. #+begin_src emacs-lisp
  114. (add-hook 'dired-mode-hook 'auto-revert-mode)
  115. (setq global-auto-revert-non-file-buffers t)
  116. (setq auto-revert-verbose nil)
  117. #+end_src
  118. * Org Mode
  119. ** Installation
  120. 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.]]
  121. Added a hook to complete org functions, company-capf is necessary for this
  122. #+begin_src emacs-lisp
  123. (use-package org
  124. :ensure org-plus-contrib
  125. :init
  126. (add-hook 'org-mode-hook
  127. (lambda ()
  128. (add-to-list 'company-backends 'company-capf)
  129. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  130. (company-mode t)))
  131. )
  132. #+end_src
  133. 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:
  134. #+begin_src sh:
  135. var ORG_DIR=(let* ((org-v (cadr (split-string (org-version nil t) "@"))) (len (length org-v))) (substring org-v 1 (- len 2)))
  136. rm ${ORG_DIR}/*.elc
  137. #+end_src
  138. *** Org key bindings
  139. Set up some global key bindings that integrate with Org mode features
  140. #+begin_src emacs-lisp
  141. (bind-key "C-c l" 'org-store-link)
  142. (bind-key "C-c c" 'org-capture)
  143. (bind-key "C-c a" 'org-agenda)
  144. #+end_src
  145. Org overwrites RET and C-j, so I need to disable the rebinds
  146. #+begin_src emacs-lisp
  147. (define-key org-mode-map (kbd "RET") nil) ;;org-return
  148. (define-key org-mode-map (kbd "C-j") nil) ;;org-return-indent
  149. #+end_src
  150. *** Org agenda
  151. For a more detailed example [[https://github.com/sachac/.emacs.d/blob/83d21e473368adb1f63e582a6595450fcd0e787c/Sacha.org#org-agenda][see here]].
  152. #+begin_src emacs-lisp
  153. (setq org-agenda-files
  154. (delq nil
  155. (mapcar (lambda (x) (and (file-exists-p x) x))
  156. '("~/Archiv/Dokumente/Agenda"))
  157. )
  158. )
  159. #+end_src
  160. *** Org capture
  161. #+begin_src emacs-lisp
  162. (bind-key "C-c c" 'org-capture)
  163. (setq org-default-notes-file "~/Archiv/Dokumente/Notizen/notes.org")
  164. #+end_src
  165. ** Org Setup
  166. 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.
  167. See the doc for speed keys by checking out the documentation for speed keys in Org mode.
  168. #+begin_src emacs-lisp
  169. (setq org-use-speed-commands t)
  170. (setq org-image-actual-width 550)
  171. (setq org-highlight-latex-and-related '(latex script entities))
  172. #+end_src
  173. ** Org tags
  174. The default value is -77, which is weird for smaller width windows. I'd rather have the tags align horizontally with the header.
  175. 45 is a good column number to do that.
  176. #+begin_src emacs-lisp
  177. (setq org-tags-column 45)
  178. #+end_src
  179. ** Org babel languages
  180. #+begin_src emacs-lisp
  181. (org-babel-do-load-languages
  182. 'org-babel-load-languages
  183. '((python . t)
  184. (C . t)
  185. (calc . t)
  186. (latex . t)
  187. (java . t)
  188. (ruby . t)
  189. (lisp . t)
  190. (R . t)
  191. (scheme . t)
  192. (shell . t)
  193. (sqlite . t)
  194. (js . t)))
  195. (defun my-org-confirm-babel-evaluate (lang body)
  196. "Do not confirm evaluation for these languages."
  197. (not (or (string= lang "C")
  198. (string= lang "java")
  199. (string= lang "python")
  200. (string= lang "R")
  201. (string= lang "emacs-lisp")
  202. (string= lang "sqlite"))))
  203. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  204. #+end_src
  205. I want plots!
  206. #+begin_src emacs-lisp
  207. (use-package ess
  208. :ensure t
  209. )
  210. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
  211. (add-hook 'org-mode-hook 'org-display-inline-images)
  212. #+end_src
  213. ** Org babel/source blocks
  214. 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
  215. 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
  216. #+begin_src emacs-lisp
  217. (setq org-src-fontify-natively t
  218. org-src-window-setup 'current-window
  219. org-src-strip-leading-and-trailing-blank-lines t
  220. org-src-preserve-indentation t
  221. org-src-tab-acts-natively t)
  222. #+end_src
  223. * which-key
  224. Greatly increases discovery of functions!
  225. Click [[https://github.com/justbur/emacs-which-key][here]] for source and more info.
  226. Info in Emacs: M-x customize-group which-key
  227. #+begin_src emacs-lisp
  228. (use-package which-key
  229. :ensure t
  230. :diminish which-key-mode
  231. :config
  232. (which-key-mode)
  233. (which-key-setup-side-window-right-bottom)
  234. (which-key-setup-minibuffer)
  235. (setq which-key-idle-delay 0.5)
  236. )
  237. #+end_src
  238. * Ido (currently inactive)
  239. better completion
  240. begin_src emacs-lisp
  241. (use-package ido
  242. :init
  243. (setq ido-enable-flex-matching t)
  244. (setq ido-everywhere t)
  245. (ido-mode t)
  246. (use-package ido-vertical-mode
  247. :ensure t
  248. :defer t
  249. :init
  250. (ido-vertical-mode 1)
  251. (setq ido-vertical-define-keys 'C-n-and-C-p-only)
  252. )
  253. )
  254. end_src
  255. * ivy / counsel / swiper
  256. Flx is required for fuzzy-matching
  257. Is it really necessary?
  258. begin_src emacs-lisp
  259. (use-package flx)
  260. end_src
  261. Ivy displays a window with suggestions for hotkeys and M-x
  262. #+begin_src emacs-lisp
  263. (use-package ivy
  264. :ensure t
  265. :diminish
  266. (ivy-mode . "") ;; does not display ivy in the mode line
  267. :init
  268. (ivy-mode 1)
  269. :bind
  270. ("C-c C-r" . ivy-resume)
  271. :config
  272. (setq ivy-use-virtual-buffers t) ;; recent files and bookmarks in ivy-switch-buffer
  273. (setq ivy-height 20) ;; height of ivy window
  274. (setq ivy-count-format "%d/%d") ;; current and total number
  275. (setq ivy-re-builders-alist ;; regex replaces spaces with *
  276. '((t . ivy--regex-plus)))
  277. )
  278. #+end_src
  279. Counsel replaces:
  280. - M-x
  281. - C-x C-f find-file
  282. - C-c h f describe-function
  283. - C-c h v describe-variable
  284. - M-i imenu
  285. The find-file replacement is nicer to navigate
  286. #+begin_src emacs-lisp
  287. (use-package counsel
  288. :ensure t
  289. :bind* ;; load counsel when pressed
  290. (("M-x" . counsel-M-x)
  291. ("C-x C-f" . counsel-find-file)
  292. ("C-c h f" . counsel-describe-function)
  293. ("C-c h v" . counsel-describe-variable)
  294. ("M-i" . counsel-imenu)
  295. )
  296. )
  297. #+end_src
  298. Swiper ivy-enhances isearch
  299. #+begin_src emacs-lisp
  300. (use-package swiper
  301. :ensure t
  302. :bind
  303. (("C-s" . swiper)
  304. ("C-c C-r" . ivy-resume)
  305. )
  306. )
  307. #+end_src
  308. * Recentf
  309. Requires counsel
  310. #+begin_src emacs-lisp
  311. (use-package recentf
  312. :bind ("C-x C-r" . counsel-recentf)
  313. :config
  314. (recentf-mode t)
  315. (setq recentf-max-saved-items 200)
  316. )
  317. #+end_src
  318. * Latex
  319. Requirements for Linux:
  320. - Latex
  321. - pdf-tools
  322. #+begin_src emacs-lisp
  323. (use-package pdf-tools
  324. :ensure t
  325. :config
  326. (pdf-tools-install)
  327. (setq TeX-view-program-selection '((output-pdf "pdf-tools")))
  328. (setq TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  329. )
  330. #+end_src
  331. 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]]
  332. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  333. #+begin_src
  334. latex-preview-pane-update-p()
  335. --- (doc-view-revert-buffer nil t)
  336. +++ (revert-buffer-nil t 'preserve-modes)
  337. #+end_src
  338. After that M-x byte-compile-file
  339. #+begin_src emacs-lisp
  340. (use-package latex-preview-pane
  341. :ensure t
  342. )
  343. (setq auto-mode-alist
  344. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  345. ;; one of these works
  346. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  347. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  348. ;; necessary, because linum-mode isn't compatible and prints errors
  349. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  350. #+end_src
  351. * Programming
  352. ** Common things
  353. List of plugins and settings which are shared between the language plugins
  354. Highlight whitespaces, tabs, empty lines.
  355. #+begin_src emacs-lisp
  356. (use-package whitespace
  357. :demand t
  358. :ensure nil
  359. :init
  360. (dolist (hook '(prog-mode-hook
  361. text-mode-hook
  362. conf-mode-hook))
  363. (add-hook hook #'whitespace-mode))
  364. ;; :hook ;;not working in use-package 2.3
  365. ;; ((prog-mode . whitespace-turn-on)
  366. ;; (text-mode . whitespace-turn-on))
  367. :config
  368. (setq-default whitespace-style '(face empty tab trailing))
  369. )
  370. #+end_src
  371. Disable Eldoc, it interferes with flycheck
  372. #+begin_src emacs-lisp
  373. (use-package eldoc
  374. :ensure nil
  375. :config
  376. (global-eldoc-mode -1)
  377. )
  378. #+end_src
  379. Colorize colors as text with their value
  380. #+begin_src emacs-lisp
  381. (use-package rainbow-mode
  382. :ensure t
  383. :init
  384. (add-hook 'prog-mode-hook 'rainbow-mode t)
  385. ;; :hook prog-mode ;; not working in use-package 2.3
  386. :config
  387. (setq-default rainbow-x-colors-major-mode-list '())
  388. )
  389. #+end_src
  390. ** Magit
  391. [[https://magit.vc/manual/magit/index.html][Link]]
  392. I want to do git stuff here, not in a separate terminal window
  393. Little crashcourse in magit:
  394. - magit-init to init a git project
  395. - magit-status (C-x g) to call the status window
  396. in status buffer:
  397. - s stage files
  398. - u unstage files
  399. - U unstage all files
  400. - a apply changed to staging
  401. - c c commit (type commit message, then C-c C-c to commit)
  402. - b b switch to another branch
  403. - P u git push
  404. - F u git pull
  405. #+begin_src emacs-lisp
  406. (use-package magit
  407. :ensure t
  408. :defer t
  409. :bind (("C-x g" . magit-status))
  410. )
  411. #+end_src
  412. ** Company Mode
  413. Complete Anything!
  414. Activate company and make it react nearly instantly
  415. #+begin_src emacs-lisp
  416. (use-package company
  417. :ensure t
  418. :config
  419. (setq-default company-minimum-prefix-length 1
  420. company-tooltip-align-annotation t
  421. company-tooltop-flip-when-above t
  422. company-show-numbers t
  423. company-idle-delay 0.1)
  424. )
  425. #+end_src
  426. *** Company backend hooks
  427. Backend configuration for python-mode
  428. Common backends are:
  429. - company-files: files & directory
  430. - company-keywords: keywords
  431. - company-capf: ??
  432. - company-abbrev: ??
  433. - company-dabbrev: dynamic abbreviations
  434. - company-ispell: ??
  435. #+begin_src emacs-lisp
  436. (defun company/python-mode-hook()
  437. (set (make-local-variable 'company-backends)
  438. '((company-jedi company-dabbrev company-yasnippet) company-capf company-files))
  439. ;; '((company-jedi company-dabbrev) company-capf company-files))
  440. (company-mode t)
  441. )
  442. #+end_src
  443. Backend configuration for lisp-mode
  444. #+begin_src emacs-lisp
  445. (defun company/elisp-mode-hook()
  446. (set (make-local-variable 'company-backends)
  447. '((company-elisp company-dabbrev) company-capf company-files))
  448. (company-mode t)
  449. )
  450. #+end_src
  451. *** Misc Company packages
  452. Addon to sort suggestions by usage
  453. #+begin_src emacs-lisp
  454. (use-package company-statistics
  455. :ensure t
  456. :after company
  457. :config
  458. (company-statistics-mode 1)
  459. )
  460. #+end_src
  461. Get a popup with documentation of the completion candidate.
  462. For the popups the package pos-tip.el is used and automatically installed.
  463. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  464. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  465. #+begin_src emacs-lisp
  466. (use-package company-quickhelp
  467. :ensure t
  468. :after company
  469. :config
  470. (company-quickhelp-mode 1)
  471. )
  472. #+end_src
  473. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  474. ** Projectile
  475. Brings search functions on project level
  476. #+begin_src emacs-lisp
  477. (use-package projectile
  478. :ensure t
  479. :defer t
  480. :bind
  481. (("C-c p p" . projectile-switch-project)
  482. ("C-c p s s" . projectile-ag))
  483. :init
  484. (setq-default
  485. projectile-cache-file (expand-file-name ".projectile-cache" user-emacs-directory)
  486. projectile-known-projects-file (expand-file-name
  487. ".projectile-bookmarks" user-emacs-directory))
  488. :config
  489. (projectile-mode t)
  490. (setq-default
  491. projectile-completion-system 'ivy
  492. projectile-enable-caching t
  493. projectile-mode-line '(:eval (projectile-project-name)))
  494. )
  495. #+end_src
  496. ** Yasnippet
  497. Snippets!
  498. TODO: yas-minor-mode? what's that?
  499. #+begin_src emacs-lisp
  500. (use-package yasnippet
  501. :ensure t
  502. :init
  503. (yas-global-mode)
  504. :mode ("\\.yasnippet" . snippet-mode)
  505. :config
  506. (setq yas-snippet-dirs (concat user-emacs-directory "snippets"))
  507. )
  508. #+end_src
  509. ** Lisp
  510. #+begin_src emacs-lisp
  511. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  512. #+end_src
  513. ** Python
  514. Systemwide following packages need to be installed:
  515. - venv
  516. The virtual environments need to have following modules installed:
  517. - jedi
  518. - epc
  519. - pylint
  520. #+begin_src emacs-lisp
  521. (use-package flycheck
  522. :ensure t
  523. :init
  524. (add-hook 'after-init-hook #'global-flycheck-mode)
  525. (add-hook 'python-mode-hook (lambda ()
  526. (semantic-mode 1)
  527. (flycheck-select-checker 'python-pylint)))
  528. )
  529. #+end_src
  530. Automatically start python-mode when opening a .py-file.
  531. Not sure if python.el is better than python-mode.el.
  532. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  533. 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]].
  534. Also limit the completion backends to those which make sense in Python.
  535. #+begin_src emacs-lisp
  536. (use-package python
  537. :mode ("\\.py\\'" . python-mode)
  538. :interpreter ("python" . python-mode)
  539. :init
  540. (add-hook 'python-mode-hook 'company/python-mode-hook)
  541. :config
  542. (setq python-shell-completion-native-enable nil)
  543. )
  544. #+end_src
  545. Jedi is a backend for python autocompletion and needs to be installed on the server:
  546. - pip install jedi
  547. Code checks need to be installed, too:
  548. - pip install flake8
  549. #+begin_src emacs-lisp
  550. (use-package company-jedi
  551. :defer t
  552. ;; :after company
  553. :ensure t
  554. :config
  555. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  556. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  557. (add-hook 'python-mode-hook 'jedi:setup)
  558. (setq jedi:complete-on-dot t)
  559. (setq jedi:use-shortcuts t)
  560. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  561. )
  562. #+end_src
  563. A wrapper to handle virtual environments.
  564. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  565. TODO: automatically start an inferior python process or switch to it if already created
  566. #+begin_src emacs-lisp
  567. (use-package pyvenv
  568. :ensure t
  569. :init
  570. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  571. :config
  572. (pyvenv-mode t)
  573. (defun my/post-activate-hook()
  574. (setq jedi:environment-root pyvenv-virtual-env)
  575. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  576. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  577. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  578. ;; default traceback, other option M-x jedi:toggle-log-traceback
  579. ;; traceback is in jedi:pop-to-epc-buffer
  580. (jedi:setup)
  581. (company/python-mode-hook)
  582. (setq jedi:server-args '("--log-traceback")))
  583. ;; (add-to-list 'company-backends 'company-jedi)
  584. ;; (add-to-list 'company-backends 'company-anaconda)
  585. ;; (lambda ()
  586. ;; (set (make-local-variable 'company-backends)
  587. ;; '((company-jedi company-dabbrev) company-capf company-files)))
  588. ;; (setq flycheck-checker 'python-pylint))
  589. ;; (flycheck-select-checker 'python-pylint))
  590. ;; (setq flycheck-checker 'python-flake8)
  591. (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook)
  592. )
  593. #+end_src
  594. I want Emacs to automatically start the proper virtual environment.
  595. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  596. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  597. Depends on pyvenv
  598. #+begin_src emacs-lisp
  599. (use-package auto-virtualenv
  600. :ensure t
  601. ;; :after pyvenv
  602. ;; :defer t
  603. :init
  604. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  605. ;; activate on changing buffers
  606. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  607. ;; activate on focus in
  608. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  609. )
  610. #+end_src
  611. Anaconda test
  612. begin_src emacs-lisp
  613. (use-package anaconda-mode
  614. :ensure t
  615. :defer t
  616. :init
  617. (add-hook 'python-mode-hook 'anaconda-mode)
  618. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  619. :config
  620. (setq anaconda-eldoc-mode 1)
  621. )
  622. end_src
  623. begin_src emacs-lisp
  624. (use-package company-anaconda
  625. :ensure t
  626. :defer t
  627. :init
  628. (defun my/company-anaconda-hook()
  629. (add-to-list 'company-backends 'company-anaconda))
  630. (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  631. )
  632. end_src
  633. * Hydra
  634. Hydra allows grouping of commands
  635. #+begin_src emacs-lisp
  636. (use-package hydra
  637. :ensure t
  638. :bind
  639. ("C-c f" . hydra-flycheck/body)
  640. :config
  641. (setq-default hydra-default-hint nil)
  642. )
  643. #+end_src
  644. ** Hydra Flycheck
  645. Flycheck is necessary, obviously
  646. #+begin_src emacs-lisp
  647. (defhydra hydra-flycheck (:color blue)
  648. "
  649. ^
  650. ^Flycheck^ ^Errors^ ^Checker^
  651. ^────────^──────────^──────^────────────^───────^───────────
  652. _q_ quit _<_ previous _?_ describe
  653. _m_ manual _>_ next _d_ disable
  654. _v_ verify setup _f_ check _s_ select
  655. ^^ ^^ ^^
  656. "
  657. ("q" nil)
  658. ("<" flycheck-previous-error :color red)
  659. (">" flycheck-next-error :color red)
  660. ("?" flycheck-describe-checker)
  661. ("d" flycheck-disable-checker)
  662. ("f" flycheck-buffer)
  663. ("m" flycheck-manual)
  664. ("s" flycheck-select-checker)
  665. ("v" flycheck-verify-setup)
  666. )
  667. #+end_src
  668. * Treemacs
  669. A file manager comparable to neotree.
  670. [[https://github.com/Alexander-Miller/treemacs][Github]]
  671. It has some requirements, which gets used here anyway:
  672. - ace-window
  673. - hydra
  674. - projectile
  675. - python
  676. I copied the configuration example from the github site.
  677. No idea what this executable-find is about.
  678. TODO check it out!
  679. #+begin_src emacs-lisp
  680. (use-package treemacs
  681. :ensure t
  682. :defer t
  683. :config
  684. (setq treemacs-change-root-without-asking nil
  685. treemacs-collapse-dirs (if (executable-find "python") 3 0)
  686. treemacs-file-event-delay 5000
  687. treemacs-follow-after-init t
  688. treemacs-follow-recenter-distance 0.1
  689. treemacs-goto-tag-strategy 'refetch-index
  690. treemacs-indentation 2
  691. treemacs-indentation-string " "
  692. treemacs-is-never-other-window nil
  693. treemacs-never-persist nil
  694. treemacs-no-png-images nil
  695. treemacs-recenter-after-file-follow nil
  696. treemacs-recenter-after-tag-follow nil
  697. treemacs-show-hidden-files t
  698. treemacs-silent-filewatch nil
  699. treemacs-silent-refresh nil
  700. treemacs-sorting 'alphabetic-desc
  701. treemacs-tag-follow-cleanup t
  702. treemacs-tag-follow-delay 1.5
  703. treemacs-width 35)
  704. (treemacs-follow-mode t)
  705. (treemacs-filewatch-mode t)
  706. (pcase (cons (not (null (executable-find "git")))
  707. (not (null (executable-find "python3"))))
  708. (`(t . t)
  709. (treemacs-git-mode 'extended))
  710. (`(t . _)
  711. (treemacs-git-mode 'simple)))
  712. :bind
  713. (:map global-map
  714. ([f8] . treemacs-toggle))
  715. )
  716. #+end_src
  717. Treemacs-projectile is useful for uhh.. TODO explain!
  718. #+begin_src emacs-lisp
  719. (use-package treemacs-projectile
  720. :ensure t
  721. :defer t
  722. :config
  723. (setq treemacs-header-function #'treemacs-projectile-create-header)
  724. )
  725. #+end_src
  726. TODO
  727. Hydrastuff or keybindings for functions:
  728. - treemacs-projectile
  729. - treemacs-projectile-toggle
  730. - treemacs-toggle
  731. - treemacs-bookmark
  732. - treemacs-find-file
  733. - treemacs-find-tag
  734. * Window Handling
  735. Some tools to easen the navigation, creation and deletion of windows
  736. ** Ace-Window
  737. #+begin_src emacs-lisp
  738. (use-package ace-window
  739. :ensure t
  740. :init
  741. (global-set-key (kbd "C-x o") 'ace-window)
  742. )
  743. #+end_src
  744. ** Windmove
  745. Windmove easens the navigation between windows.
  746. Here we are setting the default keybindings (shift+arrow)
  747. CURRENTLY NOT WORKING, defaults are blocked.
  748. Also not sure if necessary when using ace-window.
  749. #+begin_src emacs-lisp
  750. (use-package windmove
  751. :ensure t
  752. :config
  753. (windmove-default-keybindings)
  754. )
  755. #+end_src
  756. * Quality of Life