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.

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