2019-10-14 17:38:14 +02:00
|
|
|
;;; common.el --- Common programming settings. -*- lexical-binding: t; -*-
|
|
|
|
|
2020-01-24 23:17:35 +01:00
|
|
|
;; Time-stamp: <2020-01-24T23:17:24+0100>
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'basics/global-variables)
|
|
|
|
|
|
|
|
(use-package emacs
|
|
|
|
:ensure nil
|
|
|
|
|
2019-11-09 18:56:17 +01:00
|
|
|
:custom
|
|
|
|
(compilation-scroll-output 'first-error)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:config
|
|
|
|
(setq-default indent-tabs-mode nil ; Set default indentation.
|
|
|
|
tab-width 4)
|
|
|
|
(electric-pair-mode t) ; Auto-type closing brackets.
|
|
|
|
)
|
|
|
|
|
2019-12-29 04:36:42 +01:00
|
|
|
;; Guess indentation and if spaces or tabs are to be used.
|
2019-10-14 17:38:14 +02:00
|
|
|
(use-package dtrt-indent
|
2020-01-07 07:26:14 +01:00
|
|
|
:after (editorconfig)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:hook
|
2020-01-07 07:26:14 +01:00
|
|
|
(dtrt-indent-mode . editorconfig-apply)
|
2019-10-14 17:38:14 +02:00
|
|
|
(prog-mode . dtrt-indent-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Online documentation mode.
|
|
|
|
(use-package eldoc
|
|
|
|
:hook
|
|
|
|
(prog-mode . turn-on-eldoc-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Syntax checking with many plugins.
|
|
|
|
(unless slow-computer
|
|
|
|
(use-package flycheck
|
|
|
|
:defer nil
|
|
|
|
:functions (flycheck-add-mode)
|
|
|
|
|
|
|
|
:custom
|
|
|
|
(flycheck-cppcheck-checks '("style" "warning" "information"))
|
|
|
|
(flycheck-emacs-lisp-load-path 'inherit) ; Use load-path of Emacs.
|
|
|
|
|
|
|
|
:config
|
|
|
|
(global-flycheck-mode)
|
|
|
|
;; (setq flycheck-check-syntax-automatically '(save new-line mode-change))
|
|
|
|
(flycheck-add-mode 'html-tidy 'web-mode)
|
|
|
|
(flycheck-add-mode 'css-csslint 'web-mode)
|
|
|
|
|
|
|
|
:bind
|
2019-12-26 07:24:33 +01:00
|
|
|
(:map flycheck-mode-map
|
|
|
|
("<f5>" . flycheck-previous-error)
|
|
|
|
("<f6>" . flycheck-next-error)
|
|
|
|
("<f7>" . flycheck-list-errors)
|
|
|
|
)
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Autocompletion mode with many plugins.
|
|
|
|
(unless slow-computer
|
|
|
|
(use-package company
|
|
|
|
:custom
|
|
|
|
;; Show suggestions after entering one character.
|
|
|
|
(company-minimum-prefix-length 1)
|
|
|
|
;; Wrap around at end/beginning of list.
|
|
|
|
(company-selection-wrap-around t)
|
|
|
|
;; Align annotation to the right border.
|
|
|
|
(company-tooltip-align-annotations t)
|
|
|
|
|
|
|
|
:bind
|
|
|
|
(:map company-active-map
|
|
|
|
("<return>" . nil) ; Disable completion on return.
|
|
|
|
("RET" . nil) ; https://emacs.stackexchange.com/a/13290
|
2019-12-23 03:52:07 +01:00
|
|
|
("<tab>" . company-complete-selection) ; Make tab work in lists (GUI).
|
|
|
|
("TAB" . company-complete-selection) ; Same in terminals.
|
|
|
|
)
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
:hook
|
|
|
|
(after-init . global-company-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Fuzzy autocompletion for company.
|
|
|
|
(use-package company-flx
|
|
|
|
:after company
|
|
|
|
|
|
|
|
:config
|
|
|
|
(company-flx-mode +1)
|
|
|
|
)
|
|
|
|
|
|
|
|
(use-package company-statistics
|
|
|
|
:after company
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(after-init . company-statistics-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Documentation popups for completions.
|
|
|
|
(use-package company-quickhelp
|
|
|
|
:config
|
|
|
|
|
|
|
|
(company-quickhelp-mode)
|
|
|
|
)
|
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Automatic project management.
|
|
|
|
(unless slow-computer
|
|
|
|
(use-package projectile
|
2019-11-09 18:55:55 +01:00
|
|
|
:after (treemacs ivy)
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
:init
|
|
|
|
(defvar my/cmake-compile-command ; cmake command for compiling with 1
|
|
|
|
(concat "cmake --build . -- -j" ; core less than available.
|
|
|
|
(substring (shell-command-to-string "nproc --ignore=1") 0 -1)))
|
|
|
|
|
2019-11-09 18:55:55 +01:00
|
|
|
(defun my/switch-project ()
|
|
|
|
"Add project to treemacs."
|
|
|
|
(treemacs-add-and-display-current-project)
|
2019-11-09 19:30:10 +01:00
|
|
|
(treemacs-collapse-other-projects)
|
|
|
|
(treemacs-toggle-node))
|
2019-11-09 18:55:55 +01:00
|
|
|
|
|
|
|
(defun my/projectile-kill-buffers ()
|
|
|
|
"Kill project buffers and remove project from treemacs."
|
|
|
|
(interactive)
|
|
|
|
(projectile-kill-buffers)
|
|
|
|
(let ((current-prefix-arg (projectile-project-name)))
|
|
|
|
(treemacs-remove-project-from-workspace)))
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:custom
|
|
|
|
(projectile-project-compilation-dir "build")
|
2019-11-09 18:55:55 +01:00
|
|
|
(projectile-switch-project-action 'my/switch-project)
|
2019-10-14 17:38:14 +02:00
|
|
|
(projectile-project-configure-cmd
|
|
|
|
"cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
|
|
|
-GUnix\\ Makefiles ..")
|
|
|
|
(projectile-completion-system 'ivy)
|
|
|
|
|
|
|
|
:config
|
|
|
|
(setq projectile-project-compilation-cmd
|
|
|
|
(concat my/cmake-compile-command " && cd tests && ctest -Q"))
|
|
|
|
(projectile-mode +1)
|
|
|
|
|
|
|
|
;; Mark variables as safe. This prevents prompts when using .dir-locals.el.
|
|
|
|
(put 'projectile-project-compilation-cmd 'safe-local-variable #'stringp)
|
|
|
|
(put 'projectile-project-configure-cmd 'safe-local-variable #'stringp)
|
|
|
|
|
2020-01-15 23:15:10 +01:00
|
|
|
;; Auto-search for projects.
|
|
|
|
(if (f-directory? "~/Projekte")
|
|
|
|
(setq projectile-project-search-path '("~/Projekte")))
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:bind
|
|
|
|
("C-c p" . 'projectile-command-map)
|
2019-11-28 10:09:13 +01:00
|
|
|
;; (:map projectile-command-map
|
|
|
|
;; ("k" . 'my/projectile-kill-buffers))
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Highlight TODO, FIXME, NOTE and so on.
|
|
|
|
(use-package hl-todo
|
|
|
|
:bind
|
|
|
|
(:map hl-todo-mode-map
|
|
|
|
("C-c t" . hl-todo-occur))
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(prog-mode . hl-todo-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Better commenting.
|
|
|
|
(use-package smart-comment
|
|
|
|
:bind
|
|
|
|
("C-x c" . smart-comment)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Toggle betweeen beginning/end of line and beginning/end of code.
|
|
|
|
(use-package mwim
|
|
|
|
:bind
|
|
|
|
("<home>" . mwim-beginning-of-line-or-code)
|
|
|
|
("<end>" . mwim-end-of-line-or-code)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Fold code.
|
|
|
|
(use-package fold-dwim
|
|
|
|
:bind
|
2019-12-26 21:30:46 +01:00
|
|
|
("C-c f" . fold-dwim-toggle)
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
:hook
|
|
|
|
(prog-mode . hs-minor-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Highlight indentation.
|
|
|
|
(use-package hl-indent
|
|
|
|
:custom-face
|
|
|
|
(hl-indent-face ((t (:inherit hl-indent-face ; Reversed whitespace.
|
|
|
|
:background "gray18"
|
|
|
|
:foreground "#1c1e1f"
|
|
|
|
))))
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(prog-mode . hl-indent-mode)
|
|
|
|
)
|
|
|
|
|
2019-11-09 21:55:09 +01:00
|
|
|
;; Tries to find points of interest in buffer and jumps to them.
|
|
|
|
(use-package imenu
|
|
|
|
:custom
|
|
|
|
(imenu-auto-rescan t)
|
|
|
|
|
|
|
|
:bind
|
|
|
|
("M-i" . imenu)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Tries to find points of interest in all open buffers and jumps to them.
|
2019-10-14 17:38:14 +02:00
|
|
|
(use-package imenu-anywhere
|
2019-11-09 21:55:09 +01:00
|
|
|
:after (imenu ivy)
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
:bind
|
2019-11-09 21:55:09 +01:00
|
|
|
("C-M-i" . ivy-imenu-anywhere)
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
;; Jump to definition using grep.
|
|
|
|
(use-package dumb-jump
|
|
|
|
:after (ivy)
|
|
|
|
|
|
|
|
:custom
|
|
|
|
(dumb-jump-selector 'ivy)
|
|
|
|
|
|
|
|
:bind
|
|
|
|
("M-." . dumb-jump-go) ; Will be overwritten by more intelligent modes.
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Support .editorconfig files.
|
|
|
|
(use-package editorconfig
|
|
|
|
:config
|
|
|
|
(editorconfig-mode 1)
|
|
|
|
)
|
|
|
|
|
|
|
|
(use-package smerge
|
|
|
|
:ensure nil ; Builtin.
|
|
|
|
|
2019-12-26 07:24:33 +01:00
|
|
|
:defines (smerge-mode-map)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:bind
|
2019-12-26 07:24:33 +01:00
|
|
|
(:map smerge-mode-map
|
|
|
|
("<f5>" . smerge-prev)
|
|
|
|
("<f6>" . smerge-next)
|
|
|
|
("<f7>" . smerge-resolve)
|
|
|
|
)
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
;; Git integration.
|
|
|
|
(use-package git-commit
|
|
|
|
:pin melpa
|
2020-01-24 23:17:35 +01:00
|
|
|
:after (window-purpose)
|
|
|
|
:defer nil
|
|
|
|
|
|
|
|
:config
|
|
|
|
(defun my/split-vertically-if-dedicated ()
|
|
|
|
"Split buffers vertically if focused buffer is dedicated to a purpose."
|
|
|
|
(when (purpose-window-purpose-dedicated-p)
|
|
|
|
;; (setq-local split-width-threshold nil)
|
|
|
|
(setq-local split-height-threshold 40)
|
|
|
|
))
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(git-commit-setup . my/split-vertically-if-dedicated)
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
2020-01-24 23:17:35 +01:00
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
(unless slow-computer
|
2019-12-01 07:12:30 +01:00
|
|
|
;; magit from melpa needs transient from melpa.
|
|
|
|
(use-package transient
|
|
|
|
:pin melpa)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
(use-package magit
|
|
|
|
:pin melpa
|
|
|
|
|
|
|
|
:custom
|
|
|
|
(magit-diff-refine-hunk 'all) ; Show word-granularity differences.
|
|
|
|
|
|
|
|
:bind
|
|
|
|
("C-x g" . magit-status)
|
|
|
|
("C-x M-g" . magit-dispatch)
|
2019-12-01 07:13:44 +01:00
|
|
|
|
|
|
|
:hook
|
|
|
|
(after-save . magit-after-save-refresh-status)
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
|
|
|
|
2019-12-01 07:14:13 +01:00
|
|
|
;; Use libgit rather than git.
|
|
|
|
(use-package magit-libgit
|
|
|
|
:pin melpa
|
|
|
|
)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
;; Show TODOs in magit-status.
|
|
|
|
(use-package magit-todos
|
2019-11-20 04:52:28 +01:00
|
|
|
:after magit
|
|
|
|
|
2019-12-31 12:58:12 +01:00
|
|
|
:config
|
|
|
|
;; Mark variables as safe. This prevents prompts when using .dir-locals.el.
|
|
|
|
(put 'magit-todos-depth 'safe-local-variable #'integerp)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:hook
|
|
|
|
(magit-mode . magit-todos-mode)
|
|
|
|
)
|
2019-11-20 04:52:28 +01:00
|
|
|
|
|
|
|
;; Work with Git forges from Magit.
|
|
|
|
(use-package forge
|
|
|
|
:pin melpa ; <https://github.com/magit/forge/issues/8>
|
|
|
|
|
|
|
|
:after magit
|
|
|
|
|
|
|
|
:config
|
|
|
|
(add-to-list 'forge-alist '("schlomp.space" "schlomp.space/api/v1"
|
|
|
|
"schlomp.space" forge-gitea-repository))
|
|
|
|
)
|
2019-10-14 17:38:14 +02:00
|
|
|
) ; unless slow-computer.
|
|
|
|
|
2020-01-20 19:28:01 +01:00
|
|
|
(unless slow-computer
|
|
|
|
;; Client for Language Server Protocol servers.
|
|
|
|
(use-package lsp-mode
|
|
|
|
:if (executable-find "clangd")
|
|
|
|
:after (whitespace)
|
|
|
|
|
|
|
|
:custom
|
|
|
|
(lsp-prefer-flymake nil) ; Disable flymake.
|
|
|
|
(lsp-auto-guess-root t) ; Don't ask for project root.
|
|
|
|
(lsp-clients-clangd-args '("-compile-commands-dir=build"))
|
|
|
|
(lsp-eldoc-render-all t) ; Display all eldoc information.
|
|
|
|
|
|
|
|
:config
|
|
|
|
(defun my/lsp-ws-toggle ()
|
|
|
|
(if lsp-ui-peek-mode
|
|
|
|
(my/whitespace-mode-off)
|
|
|
|
(my/whitespace-mode-on)))
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(c++-mode . lsp)
|
|
|
|
(c-mode . lsp)
|
|
|
|
(lsp-ui-peek-mode . my/lsp-ws-toggle) ; Dots in wrong color.
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Eye-candy and flycheck support for lsp-mode.
|
|
|
|
(use-package lsp-ui
|
|
|
|
:after (lsp-mode flycheck)
|
|
|
|
|
|
|
|
:custom
|
|
|
|
(lsp-ui-sideline-enable nil) ; Do not insert doc into buffer.
|
|
|
|
(lsp-ui-doc-include-signature t) ; Include signature in doc popup.
|
|
|
|
(lsp-ui-doc-enable nil) ; Disable doc popup.
|
|
|
|
|
|
|
|
:bind
|
|
|
|
(:map lsp-ui-mode-map
|
|
|
|
("M-." . lsp-ui-peek-find-definitions)
|
|
|
|
("C-M-." . lsp-ui-peek-find-references)
|
2020-01-24 22:16:55 +01:00
|
|
|
("C-M-," . lsp-ui-peek-find-implementation)
|
2020-01-20 19:28:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(lsp-mode . lsp-ui-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Completions with lsp-mode.
|
|
|
|
(use-package company-lsp
|
|
|
|
:after (lsp-mode company)
|
|
|
|
|
|
|
|
:config
|
|
|
|
(push 'company-lsp company-backends)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; ivy interface to lsp-mode.
|
|
|
|
(use-package lsp-ivy
|
|
|
|
:after (lsp-mode ivy)
|
|
|
|
)
|
2020-01-20 20:25:29 +01:00
|
|
|
|
|
|
|
;; Integration between lsp-mode and treemacs.
|
|
|
|
(use-package lsp-treemacs
|
2020-01-21 03:35:41 +01:00
|
|
|
:after (treemacs lsp-ui)
|
2020-01-20 20:25:29 +01:00
|
|
|
|
|
|
|
:bind
|
|
|
|
(:map lsp-ui-mode-map
|
|
|
|
("<f7>" . lsp-treemacs-errors-list) ; Use treemacs for error list.
|
|
|
|
("M-i" . lsp-treemacs-symbols) ; Display symbols using treemacs.
|
|
|
|
)
|
|
|
|
)
|
2020-01-20 19:28:01 +01:00
|
|
|
) ; unless slow-computer.
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
(provide 'programming/common)
|
|
|
|
;;; common.el ends here
|