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.

1096 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
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. a sane default configuration for navigation, manipulation etc. is still necessary
  11. - Spaceline / Powerline or similar
  12. I want a pretty status bar!
  13. - Markdown mode
  14. There might be more than one package for this.
  15. - Git gutter:
  16. Do some configuration to make it useful (see given source link in the [[*Git][Section]] of gutter)
  17. Maybe only enable it for modes where it is likely I use git?
  18. - Some webmode stuff
  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. Highlight parens etc. for improved readability
  497. #+begin_src emacs-lisp
  498. (use-package rainbow-delimiters
  499. :ensure t
  500. :config
  501. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  502. )
  503. #+end_src
  504. ** Smartparens
  505. Smartparens is a beast on its own, so it's worth having a dedicated section for it
  506. #+begin_src emacs-lisp
  507. (use-package smartparens
  508. :ensure t
  509. :diminish smartparens-mode
  510. :config
  511. (add-hook 'prog-mode-hook 'smartparens-mode)
  512. )
  513. #+end_src
  514. ** Git
  515. [[https://magit.vc/manual/magit/index.html][Link]]
  516. I want to do git stuff here, not in a separate terminal window
  517. Little crashcourse in magit:
  518. - magit-init to init a git project
  519. - magit-status (C-x g) to call the status window
  520. in status buffer:
  521. - s stage files
  522. - u unstage files
  523. - U unstage all files
  524. - a apply changed to staging
  525. - c c commit (type commit message, then C-c C-c to commit)
  526. - b b switch to another branch
  527. - P u git push
  528. - F u git pull
  529. #+begin_src emacs-lisp
  530. (use-package magit
  531. :ensure t
  532. :init
  533. ;; set git-path in work environment
  534. (if (string-equal user-login-name "POH")
  535. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  536. )
  537. :defer t
  538. :bind (("C-x g" . magit-status))
  539. )
  540. #+end_src
  541. Display line changes in gutter based on git history. Enable it everywhere
  542. [[https://github.com/syohex/emacs-git-gutter][Source]]
  543. #+begin_src emacs-lisp
  544. (use-package git-gutter
  545. :ensure t
  546. :config
  547. (global-git-gutter-mode t)
  548. :diminish git-gutter-mode
  549. )
  550. #+end_src
  551. Time machine lets me step through the history of a file as recorded in git.
  552. [[https://github.com/pidu/git-timemachine][Source]]
  553. #+begin_src emacs-lisp
  554. (use-package git-timemachine
  555. :ensure t
  556. )
  557. #+end_src
  558. ** Company Mode
  559. Complete Anything!
  560. Activate company and make it react nearly instantly
  561. #+begin_src emacs-lisp
  562. (use-package company
  563. :ensure t
  564. :config
  565. (setq-default company-minimum-prefix-length 1
  566. company-tooltip-align-annotation t
  567. company-tooltop-flip-when-above t
  568. company-show-numbers t
  569. company-idle-delay 0.1)
  570. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  571. ;; (define-key company-active-map (kbd "RET") nil)
  572. (company-tng-configure-default)
  573. )
  574. #+end_src
  575. *** Company backend hooks
  576. Backend configuration for python-mode
  577. Common backends are:
  578. - company-files: files & directory
  579. - company-keywords: keywords
  580. - company-capf: ??
  581. - company-abbrev: ??
  582. - company-dabbrev: dynamic abbreviations
  583. - company-ispell: ??
  584. #+begin_src emacs-lisp
  585. (defun company/python-mode-hook()
  586. (set (make-local-variable 'company-backends)
  587. '((company-jedi company-dabbrev company-yasnippet) company-capf company-files))
  588. ;; '((company-jedi company-dabbrev) company-capf company-files))
  589. (company-mode t)
  590. )
  591. #+end_src
  592. (defun add-pcomplete-to-capf ()
  593. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  594. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  595. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  596. Backend for Orgmode
  597. #+begin_src emacs-lisp
  598. (defun company/org-mode-hook()
  599. (set (make-local-variable 'company-backends)
  600. '(company-capf company-files))
  601. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  602. (company-mode t)
  603. )
  604. #+end_src
  605. Backend configuration for lisp-mode
  606. #+begin_src emacs-lisp
  607. (defun company/elisp-mode-hook()
  608. (set (make-local-variable 'company-backends)
  609. '((company-elisp company-dabbrev) company-capf company-files))
  610. (company-mode t)
  611. )
  612. #+end_src
  613. *** Misc Company packages
  614. Addon to sort suggestions by usage
  615. #+begin_src emacs-lisp
  616. (use-package company-statistics
  617. :ensure t
  618. :after company
  619. :config
  620. (company-statistics-mode 1)
  621. )
  622. #+end_src
  623. Get a popup with documentation of the completion candidate.
  624. For the popups the package pos-tip.el is used and automatically installed.
  625. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  626. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  627. #+begin_src emacs-lisp
  628. (use-package company-quickhelp
  629. :ensure t
  630. :after company
  631. :config
  632. (company-quickhelp-mode 1)
  633. )
  634. #+end_src
  635. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  636. ** Projectile
  637. Brings search functions on project level
  638. #+begin_src emacs-lisp
  639. (use-package projectile
  640. :ensure t
  641. :defer t
  642. :bind
  643. (("C-c p p" . projectile-switch-project)
  644. ("C-c p s s" . projectile-ag))
  645. :init
  646. (setq-default
  647. projectile-cache-file (expand-file-name ".projectile-cache" user-emacs-directory)
  648. projectile-known-projects-file (expand-file-name
  649. ".projectile-bookmarks" user-emacs-directory))
  650. :config
  651. (projectile-mode t)
  652. (setq-default
  653. projectile-completion-system 'ivy
  654. projectile-enable-caching t
  655. projectile-mode-line '(:eval (projectile-project-name)))
  656. )
  657. #+end_src
  658. ** Yasnippet
  659. Snippets!
  660. TODO: yas-minor-mode? what's that?
  661. #+begin_src emacs-lisp
  662. (use-package yasnippet
  663. :ensure t
  664. :init
  665. (yas-global-mode)
  666. :mode ("\\.yasnippet" . snippet-mode)
  667. :config
  668. (setq yas-snippet-dirs (concat user-emacs-directory "snippets"))
  669. )
  670. #+end_src
  671. ** Lisp
  672. #+begin_src emacs-lisp
  673. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  674. #+end_src
  675. ** Python
  676. Systemwide following packages need to be installed:
  677. - venv
  678. The virtual environments need to have following modules installed:
  679. - jedi
  680. - epc
  681. - pylint
  682. #+begin_src emacs-lisp
  683. (use-package flycheck
  684. :ensure t
  685. :init
  686. (add-hook 'after-init-hook #'global-flycheck-mode)
  687. (add-hook 'python-mode-hook (lambda ()
  688. (semantic-mode 1)
  689. (flycheck-select-checker 'python-pylint)))
  690. )
  691. #+end_src
  692. Automatically start python-mode when opening a .py-file.
  693. Not sure if python.el is better than python-mode.el.
  694. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  695. 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]].
  696. Also limit the completion backends to those which make sense in Python.
  697. #+begin_src emacs-lisp
  698. (use-package python
  699. :mode ("\\.py\\'" . python-mode)
  700. :interpreter ("python" . python-mode)
  701. :init
  702. (add-hook 'python-mode-hook 'company/python-mode-hook)
  703. :config
  704. (setq python-shell-completion-native-enable nil)
  705. )
  706. #+end_src
  707. Jedi is a backend for python autocompletion and needs to be installed on the server:
  708. - pip install jedi
  709. Code checks need to be installed, too:
  710. - pip install flake8
  711. #+begin_src emacs-lisp
  712. (use-package company-jedi
  713. :defer t
  714. ;; :after company
  715. :ensure t
  716. :config
  717. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  718. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  719. (add-hook 'python-mode-hook 'jedi:setup)
  720. (setq jedi:complete-on-dot t)
  721. (setq jedi:use-shortcuts t)
  722. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  723. )
  724. #+end_src
  725. A wrapper to handle virtual environments.
  726. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  727. TODO: automatically start an inferior python process or switch to it if already created
  728. #+begin_src emacs-lisp
  729. (use-package pyvenv
  730. :ensure t
  731. :init
  732. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  733. :config
  734. (pyvenv-mode t)
  735. (defun my/post-activate-hook()
  736. (setq jedi:environment-root pyvenv-virtual-env)
  737. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  738. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  739. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  740. ;; default traceback, other option M-x jedi:toggle-log-traceback
  741. ;; traceback is in jedi:pop-to-epc-buffer
  742. (jedi:setup)
  743. (company/python-mode-hook)
  744. (setq jedi:server-args '("--log-traceback")))
  745. ;; (add-to-list 'company-backends 'company-jedi)
  746. ;; (add-to-list 'company-backends 'company-anaconda)
  747. ;; (lambda ()
  748. ;; (set (make-local-variable 'company-backends)
  749. ;; '((company-jedi company-dabbrev) company-capf company-files)))
  750. ;; (setq flycheck-checker 'python-pylint))
  751. ;; (flycheck-select-checker 'python-pylint))
  752. ;; (setq flycheck-checker 'python-flake8)
  753. (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook)
  754. )
  755. #+end_src
  756. I want Emacs to automatically start the proper virtual environment.
  757. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  758. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  759. Depends on pyvenv
  760. #+begin_src emacs-lisp
  761. (use-package auto-virtualenv
  762. :ensure t
  763. ;; :after pyvenv
  764. ;; :defer t
  765. :init
  766. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  767. ;; activate on changing buffers
  768. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  769. ;; activate on focus in
  770. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  771. )
  772. #+end_src
  773. Anaconda test
  774. begin_src emacs-lisp
  775. (use-package anaconda-mode
  776. :ensure t
  777. :defer t
  778. :init
  779. (add-hook 'python-mode-hook 'anaconda-mode)
  780. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  781. :config
  782. (setq anaconda-eldoc-mode 1)
  783. )
  784. end_src
  785. begin_src emacs-lisp
  786. (use-package company-anaconda
  787. :ensure t
  788. :defer t
  789. :init
  790. (defun my/company-anaconda-hook()
  791. (add-to-list 'company-backends 'company-anaconda))
  792. (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  793. )
  794. end_src
  795. * Hydra
  796. Hydra allows grouping of commands
  797. #+begin_src emacs-lisp
  798. (use-package hydra
  799. :ensure t
  800. :bind
  801. ("C-c f" . hydra-flycheck/body)
  802. :config
  803. (setq-default hydra-default-hint nil)
  804. )
  805. #+end_src
  806. ** Hydra Flycheck
  807. Flycheck is necessary, obviously
  808. #+begin_src emacs-lisp
  809. (defhydra hydra-flycheck (:color blue)
  810. "
  811. ^
  812. ^Flycheck^ ^Errors^ ^Checker^
  813. ^────────^──────────^──────^────────────^───────^───────────
  814. _q_ quit _<_ previous _?_ describe
  815. _m_ manual _>_ next _d_ disable
  816. _v_ verify setup _f_ check _s_ select
  817. ^^ ^^ ^^
  818. "
  819. ("q" nil)
  820. ("<" flycheck-previous-error :color red)
  821. (">" flycheck-next-error :color red)
  822. ("?" flycheck-describe-checker)
  823. ("d" flycheck-disable-checker)
  824. ("f" flycheck-buffer)
  825. ("m" flycheck-manual)
  826. ("s" flycheck-select-checker)
  827. ("v" flycheck-verify-setup)
  828. )
  829. #+end_src
  830. * Treemacs
  831. A file manager comparable to neotree.
  832. [[https://github.com/Alexander-Miller/treemacs][Github]]
  833. It has some requirements, which gets used here anyway:
  834. - ace-window
  835. - hydra
  836. - projectile
  837. - python
  838. I copied the configuration example from the github site.
  839. No idea what this executable-find is about.
  840. TODO check it out!
  841. #+begin_src emacs-lisp
  842. (use-package treemacs
  843. :ensure t
  844. :defer t
  845. :config
  846. (setq treemacs-change-root-without-asking nil
  847. treemacs-collapse-dirs (if (executable-find "python") 3 0)
  848. treemacs-file-event-delay 5000
  849. treemacs-follow-after-init t
  850. treemacs-follow-recenter-distance 0.1
  851. treemacs-goto-tag-strategy 'refetch-index
  852. treemacs-indentation 2
  853. treemacs-indentation-string " "
  854. treemacs-is-never-other-window nil
  855. treemacs-never-persist nil
  856. treemacs-no-png-images nil
  857. treemacs-recenter-after-file-follow nil
  858. treemacs-recenter-after-tag-follow nil
  859. treemacs-show-hidden-files t
  860. treemacs-silent-filewatch nil
  861. treemacs-silent-refresh nil
  862. treemacs-sorting 'alphabetic-desc
  863. treemacs-tag-follow-cleanup t
  864. treemacs-tag-follow-delay 1.5
  865. treemacs-width 35)
  866. (treemacs-follow-mode t)
  867. (treemacs-filewatch-mode t)
  868. (pcase (cons (not (null (executable-find "git")))
  869. (not (null (executable-find "python3"))))
  870. (`(t . t)
  871. (treemacs-git-mode 'extended))
  872. (`(t . _)
  873. (treemacs-git-mode 'simple)))
  874. :bind
  875. (:map global-map
  876. ([f8] . treemacs-toggle))
  877. )
  878. #+end_src
  879. Treemacs-projectile is useful for uhh.. TODO explain!
  880. #+begin_src emacs-lisp
  881. (use-package treemacs-projectile
  882. :ensure t
  883. :defer t
  884. :config
  885. (setq treemacs-header-function #'treemacs-projectile-create-header)
  886. )
  887. #+end_src
  888. TODO
  889. Hydrastuff or keybindings for functions:
  890. - treemacs-projectile
  891. - treemacs-projectile-toggle
  892. - treemacs-toggle
  893. - treemacs-bookmark
  894. - treemacs-find-file
  895. - treemacs-find-tag
  896. * Window Handling
  897. Some tools to easen the navigation, creation and deletion of windows
  898. ** Ace-Window
  899. #+begin_src emacs-lisp
  900. (use-package ace-window
  901. :ensure t
  902. :init
  903. (global-set-key (kbd "C-x o") 'ace-window)
  904. )
  905. #+end_src
  906. ** Windmove
  907. Windmove easens the navigation between windows.
  908. Here we are setting the default keybindings (shift+arrow)
  909. CURRENTLY NOT WORKING, defaults are blocked.
  910. Also not sure if necessary when using ace-window.
  911. #+begin_src emacs-lisp
  912. (use-package windmove
  913. :ensure t
  914. :config
  915. (windmove-default-keybindings)
  916. )
  917. #+end_src
  918. * Quality of Life