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.

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