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.

957 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
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. #+begin_src emacs-lisp
  34. (set-face-attribute 'default nil :font "Hack-12")
  35. #+end_src
  36. ** Material Theme
  37. The [[https://github.com/cpaulik/emacs-material-theme][Material Theme]] comes in a dark and a light variant. Not too dark
  38. to be strenious though.
  39. #+begin_src emacs-lisp
  40. (use-package material-theme
  41. :if (window-system)
  42. :defer t
  43. :ensure t
  44. ;; :init
  45. ;; (load-theme 'material t)
  46. )
  47. #+end_src
  48. ** Apropospriate Theme
  49. Variants dark and light
  50. #+begin_src emacs-lisp
  51. (use-package apropospriate-theme
  52. :if (window-system)
  53. :defer t
  54. :ensure t
  55. :init
  56. (load-theme 'apropospriate-dark t)
  57. )
  58. #+end_src
  59. * Sane defaults
  60. 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]]
  61. These functions are useful. Activate them.
  62. #+begin_src emacs-lisp
  63. (put 'downcase-region 'disabled nil)
  64. (put 'upcase-region 'disabled nil)
  65. (put 'narrow-to-region 'disabled nil)
  66. (put 'dired-find-alternate-file 'disabled nil)
  67. #+end_src
  68. Answering just 'y' or 'n' should be enough.
  69. #+begin_src emacs-lisp
  70. (defalias 'yes-or-no-p 'y-or-n-p)
  71. #+end_src
  72. Keep all backup and auto-save files in one directory
  73. #+begin_src emacs-lisp
  74. (setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
  75. (setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
  76. #+end_src
  77. UTF-8 please
  78. #+begin_src emacs-lisp
  79. (setq locale-coding-system 'utf-8)
  80. (set-terminal-coding-system 'utf-8)
  81. (set-keyboard-coding-system 'utf-8)
  82. (set-selection-coding-system 'utf-8)
  83. (prefer-coding-system 'utf-8)
  84. #+end_src
  85. Avoid tabs in place of multiple spaces (they look bad in TeX)
  86. and show empty lines
  87. #+begin_src emacs-lisp
  88. (setq-default indent-tabs-mode nil)
  89. (setq-default indicate-empty-lines t)
  90. #+end_src
  91. Turn off blinking cursor
  92. #+begin_src emacs-lisp
  93. (blink-cursor-mode -1)
  94. #+end_src
  95. Don't count two spaces after a period as the end of a sentence.
  96. Just one space is needed
  97. #+begin_src emacs-lisp
  98. (setq sentence-end-double-space nil)
  99. #+end_src
  100. Delete the region when typing, just like as we expect nowadays.
  101. #+begin_src emacs-lisp
  102. (delete-selection-mode t)
  103. #+end_src
  104. Auto-indent when pressing RET, just new-line when C-j
  105. #+begin_src emacs-lisp
  106. (define-key global-map (kbd "RET") 'newline-and-indent)
  107. (define-key global-map (kbd "C-j") 'newline)
  108. #+end_src
  109. Various stuff
  110. #+begin_src emacs-lisp
  111. (show-paren-mode t)
  112. (column-number-mode t)
  113. (setq uniquify-buffer-name-style 'forward)
  114. #+end_src
  115. * Prettier Line Wraps
  116. By default there is no line wrapping. M-q actually modifies the buffer, which might not be wanted.
  117. So: enable visual wrapping and keep indentation if there are any.
  118. #+begin_src emacs-lisp
  119. (global-visual-line-mode)
  120. (diminish 'visual-line-mode)
  121. (use-package adaptive-wrap
  122. :ensure t
  123. :init
  124. (when (fboundp 'adaptive-wrap-prefix-mode)
  125. (defun my-activate-adaptive-wrap-prefix-mode ()
  126. "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  127. (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  128. (add-hook 'visual-line-mode-hook 'my-activate-adaptive-wrap-prefix-mode))
  129. )
  130. #+end_src
  131. * List buffers
  132. Ibuffer is the improved version of list-buffers.
  133. Make ibuffer the default buffer lister. [[http://ergoemacs.org/emacs/emacs_buffer_management.html][Source]]
  134. #+begin_src emacs-lisp
  135. (defalias 'list-buffers 'ibuffer)
  136. #+end_src
  137. Also auto refresh dired, but be quiet about it. [[http://whattheemacsd.com/sane-defaults.el-01.html][Source]]
  138. #+begin_src emacs-lisp
  139. (add-hook 'dired-mode-hook 'auto-revert-mode)
  140. (setq global-auto-revert-non-file-buffers t)
  141. (setq auto-revert-verbose nil)
  142. #+end_src
  143. * Org Mode
  144. ** Installation
  145. 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.]]
  146. Added a hook to complete org functions, company-capf is necessary for this
  147. #+begin_src emacs-lisp
  148. (use-package org
  149. :ensure org-plus-contrib
  150. :init
  151. (add-hook 'org-mode-hook 'company/org-mode-hook)
  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. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  446. ;; (define-key company-active-map (kbd "RET") nil)
  447. (company-tng-configure-default)
  448. )
  449. #+end_src
  450. *** Company backend hooks
  451. Backend configuration for python-mode
  452. Common backends are:
  453. - company-files: files & directory
  454. - company-keywords: keywords
  455. - company-capf: ??
  456. - company-abbrev: ??
  457. - company-dabbrev: dynamic abbreviations
  458. - company-ispell: ??
  459. #+begin_src emacs-lisp
  460. (defun company/python-mode-hook()
  461. (set (make-local-variable 'company-backends)
  462. '((company-jedi company-dabbrev company-yasnippet) company-capf company-files))
  463. ;; '((company-jedi company-dabbrev) company-capf company-files))
  464. (company-mode t)
  465. )
  466. #+end_src
  467. (defun add-pcomplete-to-capf ()
  468. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  469. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  470. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  471. Backend for Orgmode
  472. #+begin_src emacs-lisp
  473. (defun company/org-mode-hook()
  474. (set (make-local-variable 'company-backends)
  475. '(company-capf company-files))
  476. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  477. (company-mode t)
  478. )
  479. #+end_src
  480. Backend configuration for lisp-mode
  481. #+begin_src emacs-lisp
  482. (defun company/elisp-mode-hook()
  483. (set (make-local-variable 'company-backends)
  484. '((company-elisp company-dabbrev) company-capf company-files))
  485. (company-mode t)
  486. )
  487. #+end_src
  488. *** Misc Company packages
  489. Addon to sort suggestions by usage
  490. #+begin_src emacs-lisp
  491. (use-package company-statistics
  492. :ensure t
  493. :after company
  494. :config
  495. (company-statistics-mode 1)
  496. )
  497. #+end_src
  498. Get a popup with documentation of the completion candidate.
  499. For the popups the package pos-tip.el is used and automatically installed.
  500. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  501. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  502. #+begin_src emacs-lisp
  503. (use-package company-quickhelp
  504. :ensure t
  505. :after company
  506. :config
  507. (company-quickhelp-mode 1)
  508. )
  509. #+end_src
  510. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  511. ** Projectile
  512. Brings search functions on project level
  513. #+begin_src emacs-lisp
  514. (use-package projectile
  515. :ensure t
  516. :defer t
  517. :bind
  518. (("C-c p p" . projectile-switch-project)
  519. ("C-c p s s" . projectile-ag))
  520. :init
  521. (setq-default
  522. projectile-cache-file (expand-file-name ".projectile-cache" user-emacs-directory)
  523. projectile-known-projects-file (expand-file-name
  524. ".projectile-bookmarks" user-emacs-directory))
  525. :config
  526. (projectile-mode t)
  527. (setq-default
  528. projectile-completion-system 'ivy
  529. projectile-enable-caching t
  530. projectile-mode-line '(:eval (projectile-project-name)))
  531. )
  532. #+end_src
  533. ** Yasnippet
  534. Snippets!
  535. TODO: yas-minor-mode? what's that?
  536. #+begin_src emacs-lisp
  537. (use-package yasnippet
  538. :ensure t
  539. :init
  540. (yas-global-mode)
  541. :mode ("\\.yasnippet" . snippet-mode)
  542. :config
  543. (setq yas-snippet-dirs (concat user-emacs-directory "snippets"))
  544. )
  545. #+end_src
  546. ** Lisp
  547. #+begin_src emacs-lisp
  548. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  549. #+end_src
  550. ** Python
  551. Systemwide following packages need to be installed:
  552. - venv
  553. The virtual environments need to have following modules installed:
  554. - jedi
  555. - epc
  556. - pylint
  557. #+begin_src emacs-lisp
  558. (use-package flycheck
  559. :ensure t
  560. :init
  561. (add-hook 'after-init-hook #'global-flycheck-mode)
  562. (add-hook 'python-mode-hook (lambda ()
  563. (semantic-mode 1)
  564. (flycheck-select-checker 'python-pylint)))
  565. )
  566. #+end_src
  567. Automatically start python-mode when opening a .py-file.
  568. Not sure if python.el is better than python-mode.el.
  569. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  570. 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]].
  571. Also limit the completion backends to those which make sense in Python.
  572. #+begin_src emacs-lisp
  573. (use-package python
  574. :mode ("\\.py\\'" . python-mode)
  575. :interpreter ("python" . python-mode)
  576. :init
  577. (add-hook 'python-mode-hook 'company/python-mode-hook)
  578. :config
  579. (setq python-shell-completion-native-enable nil)
  580. )
  581. #+end_src
  582. Jedi is a backend for python autocompletion and needs to be installed on the server:
  583. - pip install jedi
  584. Code checks need to be installed, too:
  585. - pip install flake8
  586. #+begin_src emacs-lisp
  587. (use-package company-jedi
  588. :defer t
  589. ;; :after company
  590. :ensure t
  591. :config
  592. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  593. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  594. (add-hook 'python-mode-hook 'jedi:setup)
  595. (setq jedi:complete-on-dot t)
  596. (setq jedi:use-shortcuts t)
  597. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  598. )
  599. #+end_src
  600. A wrapper to handle virtual environments.
  601. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  602. TODO: automatically start an inferior python process or switch to it if already created
  603. #+begin_src emacs-lisp
  604. (use-package pyvenv
  605. :ensure t
  606. :init
  607. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  608. :config
  609. (pyvenv-mode t)
  610. (defun my/post-activate-hook()
  611. (setq jedi:environment-root pyvenv-virtual-env)
  612. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  613. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  614. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  615. ;; default traceback, other option M-x jedi:toggle-log-traceback
  616. ;; traceback is in jedi:pop-to-epc-buffer
  617. (jedi:setup)
  618. (company/python-mode-hook)
  619. (setq jedi:server-args '("--log-traceback")))
  620. ;; (add-to-list 'company-backends 'company-jedi)
  621. ;; (add-to-list 'company-backends 'company-anaconda)
  622. ;; (lambda ()
  623. ;; (set (make-local-variable 'company-backends)
  624. ;; '((company-jedi company-dabbrev) company-capf company-files)))
  625. ;; (setq flycheck-checker 'python-pylint))
  626. ;; (flycheck-select-checker 'python-pylint))
  627. ;; (setq flycheck-checker 'python-flake8)
  628. (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook)
  629. )
  630. #+end_src
  631. I want Emacs to automatically start the proper virtual environment.
  632. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  633. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  634. Depends on pyvenv
  635. #+begin_src emacs-lisp
  636. (use-package auto-virtualenv
  637. :ensure t
  638. ;; :after pyvenv
  639. ;; :defer t
  640. :init
  641. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  642. ;; activate on changing buffers
  643. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  644. ;; activate on focus in
  645. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  646. )
  647. #+end_src
  648. Anaconda test
  649. begin_src emacs-lisp
  650. (use-package anaconda-mode
  651. :ensure t
  652. :defer t
  653. :init
  654. (add-hook 'python-mode-hook 'anaconda-mode)
  655. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  656. :config
  657. (setq anaconda-eldoc-mode 1)
  658. )
  659. end_src
  660. begin_src emacs-lisp
  661. (use-package company-anaconda
  662. :ensure t
  663. :defer t
  664. :init
  665. (defun my/company-anaconda-hook()
  666. (add-to-list 'company-backends 'company-anaconda))
  667. (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  668. )
  669. end_src
  670. * Hydra
  671. Hydra allows grouping of commands
  672. #+begin_src emacs-lisp
  673. (use-package hydra
  674. :ensure t
  675. :bind
  676. ("C-c f" . hydra-flycheck/body)
  677. :config
  678. (setq-default hydra-default-hint nil)
  679. )
  680. #+end_src
  681. ** Hydra Flycheck
  682. Flycheck is necessary, obviously
  683. #+begin_src emacs-lisp
  684. (defhydra hydra-flycheck (:color blue)
  685. "
  686. ^
  687. ^Flycheck^ ^Errors^ ^Checker^
  688. ^────────^──────────^──────^────────────^───────^───────────
  689. _q_ quit _<_ previous _?_ describe
  690. _m_ manual _>_ next _d_ disable
  691. _v_ verify setup _f_ check _s_ select
  692. ^^ ^^ ^^
  693. "
  694. ("q" nil)
  695. ("<" flycheck-previous-error :color red)
  696. (">" flycheck-next-error :color red)
  697. ("?" flycheck-describe-checker)
  698. ("d" flycheck-disable-checker)
  699. ("f" flycheck-buffer)
  700. ("m" flycheck-manual)
  701. ("s" flycheck-select-checker)
  702. ("v" flycheck-verify-setup)
  703. )
  704. #+end_src
  705. * Treemacs
  706. A file manager comparable to neotree.
  707. [[https://github.com/Alexander-Miller/treemacs][Github]]
  708. It has some requirements, which gets used here anyway:
  709. - ace-window
  710. - hydra
  711. - projectile
  712. - python
  713. I copied the configuration example from the github site.
  714. No idea what this executable-find is about.
  715. TODO check it out!
  716. #+begin_src emacs-lisp
  717. (use-package treemacs
  718. :ensure t
  719. :defer t
  720. :config
  721. (setq treemacs-change-root-without-asking nil
  722. treemacs-collapse-dirs (if (executable-find "python") 3 0)
  723. treemacs-file-event-delay 5000
  724. treemacs-follow-after-init t
  725. treemacs-follow-recenter-distance 0.1
  726. treemacs-goto-tag-strategy 'refetch-index
  727. treemacs-indentation 2
  728. treemacs-indentation-string " "
  729. treemacs-is-never-other-window nil
  730. treemacs-never-persist nil
  731. treemacs-no-png-images nil
  732. treemacs-recenter-after-file-follow nil
  733. treemacs-recenter-after-tag-follow nil
  734. treemacs-show-hidden-files t
  735. treemacs-silent-filewatch nil
  736. treemacs-silent-refresh nil
  737. treemacs-sorting 'alphabetic-desc
  738. treemacs-tag-follow-cleanup t
  739. treemacs-tag-follow-delay 1.5
  740. treemacs-width 35)
  741. (treemacs-follow-mode t)
  742. (treemacs-filewatch-mode t)
  743. (pcase (cons (not (null (executable-find "git")))
  744. (not (null (executable-find "python3"))))
  745. (`(t . t)
  746. (treemacs-git-mode 'extended))
  747. (`(t . _)
  748. (treemacs-git-mode 'simple)))
  749. :bind
  750. (:map global-map
  751. ([f8] . treemacs-toggle))
  752. )
  753. #+end_src
  754. Treemacs-projectile is useful for uhh.. TODO explain!
  755. #+begin_src emacs-lisp
  756. (use-package treemacs-projectile
  757. :ensure t
  758. :defer t
  759. :config
  760. (setq treemacs-header-function #'treemacs-projectile-create-header)
  761. )
  762. #+end_src
  763. TODO
  764. Hydrastuff or keybindings for functions:
  765. - treemacs-projectile
  766. - treemacs-projectile-toggle
  767. - treemacs-toggle
  768. - treemacs-bookmark
  769. - treemacs-find-file
  770. - treemacs-find-tag
  771. * Window Handling
  772. Some tools to easen the navigation, creation and deletion of windows
  773. ** Ace-Window
  774. #+begin_src emacs-lisp
  775. (use-package ace-window
  776. :ensure t
  777. :init
  778. (global-set-key (kbd "C-x o") 'ace-window)
  779. )
  780. #+end_src
  781. ** Windmove
  782. Windmove easens the navigation between windows.
  783. Here we are setting the default keybindings (shift+arrow)
  784. CURRENTLY NOT WORKING, defaults are blocked.
  785. Also not sure if necessary when using ace-window.
  786. #+begin_src emacs-lisp
  787. (use-package windmove
  788. :ensure t
  789. :config
  790. (windmove-default-keybindings)
  791. )
  792. #+end_src
  793. * Quality of Life