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.

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