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.

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