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.

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