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.

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