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.

977 lines
27 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
  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. #+b
  9. * Stuff to add / to fix
  10. - smartparens
  11. The last time I tried it it was weird and blocked me occasionally (like I couldn't remove brackets)
  12. - Spaceline / Powerline or similar
  13. I want a pretty status bar!
  14. - Company
  15. 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
  16. - Markdown mode
  17. There might be more than one package for this.
  18. #+bind:
  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. ** Org tags
  198. The default value is -77, which is weird for smaller width windows. I'd rather have the tags align horizontally with the header.
  199. 45 is a good column number to do that.
  200. #+begin_src emacs-lisp
  201. (setq org-tags-column 45)
  202. #+end_src
  203. ** Org babel languages
  204. This code block is linux specific. Loading languages which aren't available seems to be a problem
  205. #+begin_src emacs-lisp
  206. (cond ((eq system-type 'gnu/linux)
  207. (org-babel-do-load-languages
  208. 'org-babel-load-languages
  209. '((python . t)
  210. (C . t)
  211. (calc . t)
  212. (latex . t)
  213. (java . t)
  214. (ruby . t)
  215. (lisp . t)
  216. (R . t)
  217. (scheme . t)
  218. (shell . t)
  219. (sqlite . t)
  220. (js . t))))
  221. )
  222. #+end_src
  223. #+begin_src emacs-lisp
  224. (defun my-org-confirm-babel-evaluate (lang body)
  225. "Do not confirm evaluation for these languages."
  226. (not (or (string= lang "C")
  227. (string= lang "java")
  228. (string= lang "python")
  229. (string= lang "R")
  230. (string= lang "emacs-lisp")
  231. (string= lang "sqlite"))))
  232. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  233. #+end_src
  234. I want plots!
  235. #+begin_src emacs-lisp
  236. (use-package ess
  237. :ensure t
  238. )
  239. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
  240. (add-hook 'org-mode-hook 'org-display-inline-images)
  241. #+end_src
  242. ** Org babel/source blocks
  243. 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
  244. 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
  245. #+begin_src emacs-lisp
  246. (setq org-src-fontify-natively t
  247. org-src-window-setup 'current-window
  248. org-src-strip-leading-and-trailing-blank-lines t
  249. org-src-preserve-indentation t
  250. org-src-tab-acts-natively t)
  251. #+end_src
  252. * which-key
  253. Greatly increases discovery of functions!
  254. Click [[https://github.com/justbur/emacs-which-key][here]] for source and more info.
  255. Info in Emacs: M-x customize-group which-key
  256. #+begin_src emacs-lisp
  257. (use-package which-key
  258. :ensure t
  259. :diminish which-key-mode
  260. :config
  261. (which-key-mode)
  262. (which-key-setup-side-window-right-bottom)
  263. (which-key-setup-minibuffer)
  264. (setq which-key-idle-delay 0.5)
  265. )
  266. #+end_src
  267. * Ido (currently inactive)
  268. better completion
  269. begin_src emacs-lisp
  270. (use-package ido
  271. :init
  272. (setq ido-enable-flex-matching t)
  273. (setq ido-everywhere t)
  274. (ido-mode t)
  275. (use-package ido-vertical-mode
  276. :ensure t
  277. :defer t
  278. :init
  279. (ido-vertical-mode 1)
  280. (setq ido-vertical-define-keys 'C-n-and-C-p-only)
  281. )
  282. )
  283. end_src
  284. * ivy / counsel / swiper
  285. Flx is required for fuzzy-matching
  286. Is it really necessary?
  287. begin_src emacs-lisp
  288. (use-package flx)
  289. end_src
  290. Ivy displays a window with suggestions for hotkeys and M-x
  291. #+begin_src emacs-lisp
  292. (use-package ivy
  293. :ensure t
  294. :diminish
  295. (ivy-mode . "") ;; does not display ivy in the mode line
  296. :init
  297. (ivy-mode 1)
  298. :bind
  299. ("C-c C-r" . ivy-resume)
  300. :config
  301. (setq ivy-use-virtual-buffers t) ;; recent files and bookmarks in ivy-switch-buffer
  302. (setq ivy-height 20) ;; height of ivy window
  303. (setq ivy-count-format "%d/%d") ;; current and total number
  304. (setq ivy-re-builders-alist ;; regex replaces spaces with *
  305. '((t . ivy--regex-plus)))
  306. )
  307. #+end_src
  308. Counsel replaces:
  309. - M-x
  310. - C-x C-f find-file
  311. - C-c h f describe-function
  312. - C-c h v describe-variable
  313. - M-i imenu
  314. The find-file replacement is nicer to navigate
  315. #+begin_src emacs-lisp
  316. (use-package counsel
  317. :ensure t
  318. :bind* ;; load counsel when pressed
  319. (("M-x" . counsel-M-x)
  320. ("C-x C-f" . counsel-find-file)
  321. ("C-c h f" . counsel-describe-function)
  322. ("C-c h v" . counsel-describe-variable)
  323. ("M-i" . counsel-imenu)
  324. )
  325. )
  326. #+end_src
  327. Swiper ivy-enhances isearch
  328. #+begin_src emacs-lisp
  329. (use-package swiper
  330. :ensure t
  331. :bind
  332. (("C-s" . swiper)
  333. ("C-c C-r" . ivy-resume)
  334. )
  335. )
  336. #+end_src
  337. * Recentf
  338. Requires counsel
  339. #+begin_src emacs-lisp
  340. (use-package recentf
  341. :bind ("C-x C-r" . counsel-recentf)
  342. :config
  343. (recentf-mode t)
  344. (setq recentf-max-saved-items 200)
  345. )
  346. #+end_src
  347. * Latex
  348. Requirements for Linux:
  349. - Latex
  350. - pdf-tools
  351. #+begin_src emacs-lisp
  352. (unless (string-equal user-login-name "POH")
  353. (use-package pdf-tools
  354. :ensure t
  355. :config
  356. (pdf-tools-install)
  357. (setq TeX-view-program-selection '((output-pdf "pdf-tools")))
  358. (setq TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  359. )
  360. )
  361. #+end_src
  362. 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]]
  363. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  364. #+begin_src
  365. latex-preview-pane-update-p()
  366. --- (doc-view-revert-buffer nil t)
  367. +++ (revert-buffer-nil t 'preserve-modes)
  368. #+end_src
  369. After that M-x byte-compile-file
  370. #+begin_src emacs-lisp
  371. (use-package latex-preview-pane
  372. :ensure t
  373. )
  374. (setq auto-mode-alist
  375. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  376. ;; one of these works
  377. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  378. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  379. ;; necessary, because linum-mode isn't compatible and prints errors
  380. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  381. #+end_src
  382. * Programming
  383. ** Common things
  384. List of plugins and settings which are shared between the language plugins
  385. Highlight whitespaces, tabs, empty lines.
  386. #+begin_src emacs-lisp
  387. (use-package whitespace
  388. :demand t
  389. :ensure nil
  390. :init
  391. (dolist (hook '(prog-mode-hook
  392. text-mode-hook
  393. conf-mode-hook))
  394. (add-hook hook #'whitespace-mode))
  395. ;; :hook ;;not working in use-package 2.3
  396. ;; ((prog-mode . whitespace-turn-on)
  397. ;; (text-mode . whitespace-turn-on))
  398. :config
  399. (setq-default whitespace-style '(face empty tab trailing))
  400. )
  401. #+end_src
  402. Disable Eldoc, it interferes with flycheck
  403. #+begin_src emacs-lisp
  404. (use-package eldoc
  405. :ensure nil
  406. :config
  407. (global-eldoc-mode -1)
  408. )
  409. #+end_src
  410. Colorize colors as text with their value
  411. #+begin_src emacs-lisp
  412. (use-package rainbow-mode
  413. :ensure t
  414. :init
  415. (add-hook 'prog-mode-hook 'rainbow-mode t)
  416. ;; :hook prog-mode ;; not working in use-package 2.3
  417. :config
  418. (setq-default rainbow-x-colors-major-mode-list '())
  419. )
  420. #+end_src
  421. ** Magit
  422. [[https://magit.vc/manual/magit/index.html][Link]]
  423. I want to do git stuff here, not in a separate terminal window
  424. Little crashcourse in magit:
  425. - magit-init to init a git project
  426. - magit-status (C-x g) to call the status window
  427. in status buffer:
  428. - s stage files
  429. - u unstage files
  430. - U unstage all files
  431. - a apply changed to staging
  432. - c c commit (type commit message, then C-c C-c to commit)
  433. - b b switch to another branch
  434. - P u git push
  435. - F u git pull
  436. #+begin_src emacs-lisp
  437. (use-package magit
  438. :ensure t
  439. :init
  440. ;; set git-path in work environment
  441. (if (string-equal user-login-name "POH")
  442. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  443. )
  444. :defer t
  445. :bind (("C-x g" . magit-status))
  446. )
  447. #+end_src
  448. ** Company Mode
  449. Complete Anything!
  450. Activate company and make it react nearly instantly
  451. #+begin_src emacs-lisp
  452. (use-package company
  453. :ensure t
  454. :config
  455. (setq-default company-minimum-prefix-length 1
  456. company-tooltip-align-annotation t
  457. company-tooltop-flip-when-above t
  458. company-show-numbers t
  459. company-idle-delay 0.1)
  460. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  461. ;; (define-key company-active-map (kbd "RET") nil)
  462. (company-tng-configure-default)
  463. )
  464. #+end_src
  465. *** Company backend hooks
  466. Backend configuration for python-mode
  467. Common backends are:
  468. - company-files: files & directory
  469. - company-keywords: keywords
  470. - company-capf: ??
  471. - company-abbrev: ??
  472. - company-dabbrev: dynamic abbreviations
  473. - company-ispell: ??
  474. #+begin_src emacs-lisp
  475. (defun company/python-mode-hook()
  476. (set (make-local-variable 'company-backends)
  477. '((company-jedi company-dabbrev company-yasnippet) company-capf company-files))
  478. ;; '((company-jedi company-dabbrev) company-capf company-files))
  479. (company-mode t)
  480. )
  481. #+end_src
  482. (defun add-pcomplete-to-capf ()
  483. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  484. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  485. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  486. Backend for Orgmode
  487. #+begin_src emacs-lisp
  488. (defun company/org-mode-hook()
  489. (set (make-local-variable 'company-backends)
  490. '(company-capf company-files))
  491. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  492. (company-mode t)
  493. )
  494. #+end_src
  495. Backend configuration for lisp-mode
  496. #+begin_src emacs-lisp
  497. (defun company/elisp-mode-hook()
  498. (set (make-local-variable 'company-backends)
  499. '((company-elisp company-dabbrev) company-capf company-files))
  500. (company-mode t)
  501. )
  502. #+end_src
  503. *** Misc Company packages
  504. Addon to sort suggestions by usage
  505. #+begin_src emacs-lisp
  506. (use-package company-statistics
  507. :ensure t
  508. :after company
  509. :config
  510. (company-statistics-mode 1)
  511. )
  512. #+end_src
  513. Get a popup with documentation of the completion candidate.
  514. For the popups the package pos-tip.el is used and automatically installed.
  515. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  516. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  517. #+begin_src emacs-lisp
  518. (use-package company-quickhelp
  519. :ensure t
  520. :after company
  521. :config
  522. (company-quickhelp-mode 1)
  523. )
  524. #+end_src
  525. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  526. ** Projectile
  527. Brings search functions on project level
  528. #+begin_src emacs-lisp
  529. (use-package projectile
  530. :ensure t
  531. :defer t
  532. :bind
  533. (("C-c p p" . projectile-switch-project)
  534. ("C-c p s s" . projectile-ag))
  535. :init
  536. (setq-default
  537. projectile-cache-file (expand-file-name ".projectile-cache" user-emacs-directory)
  538. projectile-known-projects-file (expand-file-name
  539. ".projectile-bookmarks" user-emacs-directory))
  540. :config
  541. (projectile-mode t)
  542. (setq-default
  543. projectile-completion-system 'ivy
  544. projectile-enable-caching t
  545. projectile-mode-line '(:eval (projectile-project-name)))
  546. )
  547. #+end_src
  548. ** Yasnippet
  549. Snippets!
  550. TODO: yas-minor-mode? what's that?
  551. #+begin_src emacs-lisp
  552. (use-package yasnippet
  553. :ensure t
  554. :init
  555. (yas-global-mode)
  556. :mode ("\\.yasnippet" . snippet-mode)
  557. :config
  558. (setq yas-snippet-dirs (concat user-emacs-directory "snippets"))
  559. )
  560. #+end_src
  561. ** Lisp
  562. #+begin_src emacs-lisp
  563. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  564. #+end_src
  565. ** Python
  566. Systemwide following packages need to be installed:
  567. - venv
  568. The virtual environments need to have following modules installed:
  569. - jedi
  570. - epc
  571. - pylint
  572. #+begin_src emacs-lisp
  573. (use-package flycheck
  574. :ensure t
  575. :init
  576. (add-hook 'after-init-hook #'global-flycheck-mode)
  577. (add-hook 'python-mode-hook (lambda ()
  578. (semantic-mode 1)
  579. (flycheck-select-checker 'python-pylint)))
  580. )
  581. #+end_src
  582. Automatically start python-mode when opening a .py-file.
  583. Not sure if python.el is better than python-mode.el.
  584. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  585. 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]].
  586. Also limit the completion backends to those which make sense in Python.
  587. #+begin_src emacs-lisp
  588. (use-package python
  589. :mode ("\\.py\\'" . python-mode)
  590. :interpreter ("python" . python-mode)
  591. :init
  592. (add-hook 'python-mode-hook 'company/python-mode-hook)
  593. :config
  594. (setq python-shell-completion-native-enable nil)
  595. )
  596. #+end_src
  597. Jedi is a backend for python autocompletion and needs to be installed on the server:
  598. - pip install jedi
  599. Code checks need to be installed, too:
  600. - pip install flake8
  601. #+begin_src emacs-lisp
  602. (use-package company-jedi
  603. :defer t
  604. ;; :after company
  605. :ensure t
  606. :config
  607. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  608. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  609. (add-hook 'python-mode-hook 'jedi:setup)
  610. (setq jedi:complete-on-dot t)
  611. (setq jedi:use-shortcuts t)
  612. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  613. )
  614. #+end_src
  615. A wrapper to handle virtual environments.
  616. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  617. TODO: automatically start an inferior python process or switch to it if already created
  618. #+begin_src emacs-lisp
  619. (use-package pyvenv
  620. :ensure t
  621. :init
  622. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  623. :config
  624. (pyvenv-mode t)
  625. (defun my/post-activate-hook()
  626. (setq jedi:environment-root pyvenv-virtual-env)
  627. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  628. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  629. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  630. ;; default traceback, other option M-x jedi:toggle-log-traceback
  631. ;; traceback is in jedi:pop-to-epc-buffer
  632. (jedi:setup)
  633. (company/python-mode-hook)
  634. (setq jedi:server-args '("--log-traceback")))
  635. ;; (add-to-list 'company-backends 'company-jedi)
  636. ;; (add-to-list 'company-backends 'company-anaconda)
  637. ;; (lambda ()
  638. ;; (set (make-local-variable 'company-backends)
  639. ;; '((company-jedi company-dabbrev) company-capf company-files)))
  640. ;; (setq flycheck-checker 'python-pylint))
  641. ;; (flycheck-select-checker 'python-pylint))
  642. ;; (setq flycheck-checker 'python-flake8)
  643. (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook)
  644. )
  645. #+end_src
  646. I want Emacs to automatically start the proper virtual environment.
  647. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  648. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  649. Depends on pyvenv
  650. #+begin_src emacs-lisp
  651. (use-package auto-virtualenv
  652. :ensure t
  653. ;; :after pyvenv
  654. ;; :defer t
  655. :init
  656. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  657. ;; activate on changing buffers
  658. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  659. ;; activate on focus in
  660. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  661. )
  662. #+end_src
  663. Anaconda test
  664. begin_src emacs-lisp
  665. (use-package anaconda-mode
  666. :ensure t
  667. :defer t
  668. :init
  669. (add-hook 'python-mode-hook 'anaconda-mode)
  670. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  671. :config
  672. (setq anaconda-eldoc-mode 1)
  673. )
  674. end_src
  675. begin_src emacs-lisp
  676. (use-package company-anaconda
  677. :ensure t
  678. :defer t
  679. :init
  680. (defun my/company-anaconda-hook()
  681. (add-to-list 'company-backends 'company-anaconda))
  682. (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  683. )
  684. end_src
  685. * Hydra
  686. Hydra allows grouping of commands
  687. #+begin_src emacs-lisp
  688. (use-package hydra
  689. :ensure t
  690. :bind
  691. ("C-c f" . hydra-flycheck/body)
  692. :config
  693. (setq-default hydra-default-hint nil)
  694. )
  695. #+end_src
  696. ** Hydra Flycheck
  697. Flycheck is necessary, obviously
  698. #+begin_src emacs-lisp
  699. (defhydra hydra-flycheck (:color blue)
  700. "
  701. ^
  702. ^Flycheck^ ^Errors^ ^Checker^
  703. ^────────^──────────^──────^────────────^───────^───────────
  704. _q_ quit _<_ previous _?_ describe
  705. _m_ manual _>_ next _d_ disable
  706. _v_ verify setup _f_ check _s_ select
  707. ^^ ^^ ^^
  708. "
  709. ("q" nil)
  710. ("<" flycheck-previous-error :color red)
  711. (">" flycheck-next-error :color red)
  712. ("?" flycheck-describe-checker)
  713. ("d" flycheck-disable-checker)
  714. ("f" flycheck-buffer)
  715. ("m" flycheck-manual)
  716. ("s" flycheck-select-checker)
  717. ("v" flycheck-verify-setup)
  718. )
  719. #+end_src
  720. * Treemacs
  721. A file manager comparable to neotree.
  722. [[https://github.com/Alexander-Miller/treemacs][Github]]
  723. It has some requirements, which gets used here anyway:
  724. - ace-window
  725. - hydra
  726. - projectile
  727. - python
  728. I copied the configuration example from the github site.
  729. No idea what this executable-find is about.
  730. TODO check it out!
  731. #+begin_src emacs-lisp
  732. (use-package treemacs
  733. :ensure t
  734. :defer t
  735. :config
  736. (setq treemacs-change-root-without-asking nil
  737. treemacs-collapse-dirs (if (executable-find "python") 3 0)
  738. treemacs-file-event-delay 5000
  739. treemacs-follow-after-init t
  740. treemacs-follow-recenter-distance 0.1
  741. treemacs-goto-tag-strategy 'refetch-index
  742. treemacs-indentation 2
  743. treemacs-indentation-string " "
  744. treemacs-is-never-other-window nil
  745. treemacs-never-persist nil
  746. treemacs-no-png-images nil
  747. treemacs-recenter-after-file-follow nil
  748. treemacs-recenter-after-tag-follow nil
  749. treemacs-show-hidden-files t
  750. treemacs-silent-filewatch nil
  751. treemacs-silent-refresh nil
  752. treemacs-sorting 'alphabetic-desc
  753. treemacs-tag-follow-cleanup t
  754. treemacs-tag-follow-delay 1.5
  755. treemacs-width 35)
  756. (treemacs-follow-mode t)
  757. (treemacs-filewatch-mode t)
  758. (pcase (cons (not (null (executable-find "git")))
  759. (not (null (executable-find "python3"))))
  760. (`(t . t)
  761. (treemacs-git-mode 'extended))
  762. (`(t . _)
  763. (treemacs-git-mode 'simple)))
  764. :bind
  765. (:map global-map
  766. ([f8] . treemacs-toggle))
  767. )
  768. #+end_src
  769. Treemacs-projectile is useful for uhh.. TODO explain!
  770. #+begin_src emacs-lisp
  771. (use-package treemacs-projectile
  772. :ensure t
  773. :defer t
  774. :config
  775. (setq treemacs-header-function #'treemacs-projectile-create-header)
  776. )
  777. #+end_src
  778. TODO
  779. Hydrastuff or keybindings for functions:
  780. - treemacs-projectile
  781. - treemacs-projectile-toggle
  782. - treemacs-toggle
  783. - treemacs-bookmark
  784. - treemacs-find-file
  785. - treemacs-find-tag
  786. * Window Handling
  787. Some tools to easen the navigation, creation and deletion of windows
  788. ** Ace-Window
  789. #+begin_src emacs-lisp
  790. (use-package ace-window
  791. :ensure t
  792. :init
  793. (global-set-key (kbd "C-x o") 'ace-window)
  794. )
  795. #+end_src
  796. ** Windmove
  797. Windmove easens the navigation between windows.
  798. Here we are setting the default keybindings (shift+arrow)
  799. CURRENTLY NOT WORKING, defaults are blocked.
  800. Also not sure if necessary when using ace-window.
  801. #+begin_src emacs-lisp
  802. (use-package windmove
  803. :ensure t
  804. :config
  805. (windmove-default-keybindings)
  806. )
  807. #+end_src
  808. * Quality of Life