2019-10-14 17:38:14 +02:00
|
|
|
;;; common.el --- Common programming settings. -*- lexical-binding: t; -*-
|
|
|
|
|
2020-05-24 22:17:02 +02:00
|
|
|
;; Time-stamp: <2020-05-24T22:16:49+0200>
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2020-03-18 15:00:17 +01:00
|
|
|
(require 'basics/package-management)
|
2019-10-14 17:38:14 +02:00
|
|
|
(require 'basics/global-variables)
|
|
|
|
|
|
|
|
(use-package emacs
|
2020-02-27 04:37:07 +01:00
|
|
|
:defines (compilation-mode-map)
|
|
|
|
:custom (compilation-scroll-output 'first-error)
|
2020-03-09 15:36:23 +01:00
|
|
|
:config (progn
|
|
|
|
(setq-default indent-tabs-mode nil ; Set default indentation.
|
|
|
|
tab-width 4)
|
2020-03-10 13:00:22 +01:00
|
|
|
(electric-pair-mode t) ; Auto-type closing brackets.
|
|
|
|
|
|
|
|
(defun my/clangd-version ()
|
|
|
|
"Returns the version of clangd as float."
|
|
|
|
(string-to-number
|
|
|
|
(nth 2 (split-string
|
|
|
|
(shell-command-to-string "clangd --version"))))))
|
2020-02-27 04:37:07 +01:00
|
|
|
:bind (("C-:" . ff-find-other-file) ; Switch between header and source.
|
|
|
|
(:map compilation-mode-map
|
|
|
|
("<f5>" . compilation-previous-error)
|
2020-03-09 15:36:23 +01:00
|
|
|
("<f6>" . compilation-next-error))))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
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)
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish dtrt-indent-mode
|
2020-03-09 15:36:23 +01:00
|
|
|
:hook ((dtrt-indent-mode . editorconfig-apply)
|
|
|
|
(prog-mode . dtrt-indent-mode)))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Online documentation mode.
|
|
|
|
(use-package eldoc
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish eldoc-mode
|
2020-03-09 15:36:23 +01:00
|
|
|
:hook (prog-mode . turn-on-eldoc-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Syntax checking with many plugins.
|
|
|
|
(unless slow-computer
|
|
|
|
(use-package flycheck
|
2020-05-24 22:17:02 +02:00
|
|
|
:demand t
|
2019-10-14 17:38:14 +02:00
|
|
|
:functions (flycheck-add-mode)
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish flycheck-mode
|
2020-03-09 15:36:23 +01:00
|
|
|
:custom ((flycheck-cppcheck-checks '("style" "warning" "information"))
|
|
|
|
(flycheck-emacs-lisp-load-path 'inherit)) ; Use load-path of Emacs.
|
|
|
|
:config (progn
|
|
|
|
(global-flycheck-mode)
|
|
|
|
(setq flycheck-check-syntax-automatically
|
|
|
|
(delq 'idle-change flycheck-check-syntax-automatically))
|
|
|
|
(flycheck-add-mode 'html-tidy 'web-mode)
|
|
|
|
(flycheck-add-mode 'css-csslint 'web-mode))
|
|
|
|
:bind (: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
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish company-mode
|
2020-03-09 15:18:51 +01:00
|
|
|
:custom ((company-minimum-prefix-length 1) ; Suggestions after 1 character.
|
|
|
|
(company-selection-wrap-around t)
|
|
|
|
(company-tooltip-align-annotations t) ; Align to the right border.
|
|
|
|
(company-idle-delay 0.5))
|
|
|
|
:bind (:map company-active-map
|
|
|
|
("<return>" . nil) ; Disable completion on return.
|
|
|
|
("RET" . nil) ; https://emacs.stackexchange.com/a/13290
|
|
|
|
("<tab>" . company-complete-selection) ; Make tab work in lists.
|
|
|
|
("TAB" . company-complete-selection)) ; Tab in terminals.
|
|
|
|
:hook (after-init . global-company-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Fuzzy autocompletion for company.
|
|
|
|
(use-package company-flx
|
|
|
|
:after company
|
2020-03-09 15:36:23 +01:00
|
|
|
:config (company-flx-mode +1))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
(use-package company-statistics
|
|
|
|
:after company
|
2020-03-09 15:36:23 +01:00
|
|
|
:hook (after-init . company-statistics-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Documentation popups for completions.
|
|
|
|
(use-package company-quickhelp
|
2020-03-09 15:36:23 +01:00
|
|
|
:config (company-quickhelp-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Automatic project management.
|
|
|
|
(unless slow-computer
|
|
|
|
(use-package projectile
|
2020-03-09 15:36:23 +01:00
|
|
|
:after (treemacs ivy window-purpose)
|
2020-02-03 15:13:18 +01:00
|
|
|
:functions (f-directory?
|
|
|
|
treemacs-collapse-other-projects
|
|
|
|
treemacs-toggle-node
|
2020-03-09 15:36:23 +01:00
|
|
|
my/projectile-kill-buffers
|
|
|
|
purpose-set-window-purpose-dedicated-p)
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish projectile-mode
|
2020-03-09 15:36:23 +01:00
|
|
|
:init (progn
|
|
|
|
(defvar my/cmake-compile-command ; cmake command for compiling with
|
|
|
|
(concat "cmake --build . -- -j" ; 1 core less than available.
|
|
|
|
(substring
|
|
|
|
(shell-command-to-string "nproc --ignore=1") 0 -1)))
|
|
|
|
|
|
|
|
(defun my/switch-project ()
|
|
|
|
"Find file in project, add project to `treemacs' and
|
2020-02-12 14:39:47 +01:00
|
|
|
collapse other projects."
|
2020-03-09 15:36:23 +01:00
|
|
|
(if (member 'counsel-projectile-mode minor-mode-list)
|
|
|
|
(counsel-projectile-find-file)
|
|
|
|
(projectile-find-file))
|
2020-03-27 14:01:30 +01:00
|
|
|
(when (>= (frame-width) 120)
|
2020-03-27 00:05:09 +01:00
|
|
|
(treemacs-add-and-display-current-project)
|
|
|
|
(treemacs-collapse-other-projects)
|
|
|
|
(other-window 1)))
|
2020-03-09 15:36:23 +01:00
|
|
|
|
|
|
|
(defun my/projectile-kill-buffers ()
|
|
|
|
"Kill project buffers and delete other windows."
|
|
|
|
(interactive)
|
|
|
|
(projectile-kill-buffers)
|
|
|
|
(delete-other-windows)
|
|
|
|
(purpose-set-window-purpose-dedicated-p nil nil)))
|
|
|
|
:custom ((projectile-project-compilation-dir "build")
|
|
|
|
(projectile-switch-project-action 'my/switch-project)
|
|
|
|
(projectile-project-configure-cmd
|
|
|
|
"cmake -GUnix\\ Makefiles -DCMAKE_BUILD_TYPE=Debug \
|
2020-02-02 13:50:50 +01:00
|
|
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DWITH_TESTS=YES ..")
|
2020-03-09 15:36:23 +01:00
|
|
|
(projectile-completion-system 'ivy))
|
|
|
|
:config (progn
|
|
|
|
(setq projectile-project-compilation-cmd
|
|
|
|
(concat my/cmake-compile-command
|
|
|
|
" && cd tests && ctest -Q"))
|
|
|
|
(projectile-mode +1)
|
|
|
|
;; Mark variables as safe. Prevents prompts with .dir-locals.el.
|
|
|
|
(put 'projectile-project-compilation-cmd
|
|
|
|
'safe-local-variable #'stringp)
|
|
|
|
(put 'projectile-project-configure-cmd
|
|
|
|
'safe-local-variable #'stringp)
|
|
|
|
;; Auto-search for projects.
|
|
|
|
(if (f-directory? "~/Projekte")
|
|
|
|
(setq projectile-project-search-path '("~/Projekte"))))
|
|
|
|
:bind (("C-c p" . 'projectile-command-map)
|
|
|
|
(:map projectile-command-map
|
|
|
|
("k" . 'my/projectile-kill-buffers))
|
|
|
|
(:map projectile-mode-map ; Only override in projectile-mode.
|
|
|
|
("C-x C-f" . 'projectile-find-file))))
|
2019-10-14 17:38:14 +02:00
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Highlight TODO, FIXME, NOTE and so on.
|
|
|
|
(use-package hl-todo
|
2020-03-09 15:36:23 +01:00
|
|
|
:bind (:map hl-todo-mode-map
|
|
|
|
("C-c t" . hl-todo-occur))
|
|
|
|
:hook (prog-mode . hl-todo-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Better commenting.
|
|
|
|
(use-package smart-comment
|
2020-03-27 17:11:14 +01:00
|
|
|
:bind ("C-c c" . smart-comment))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Toggle betweeen beginning/end of line and beginning/end of code.
|
|
|
|
(use-package mwim
|
2020-03-09 15:36:23 +01:00
|
|
|
:bind (("<home>" . mwim-beginning-of-line-or-code)
|
|
|
|
("<end>" . mwim-end-of-line-or-code)))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2020-02-11 17:48:50 +01:00
|
|
|
;; Needs to be here in order to diminish it.
|
|
|
|
(use-package hideshow
|
|
|
|
:diminish hs-minor-mode)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
;; Fold code.
|
|
|
|
(use-package fold-dwim
|
2020-02-11 17:48:50 +01:00
|
|
|
:after (hideshow)
|
2020-03-09 15:36:23 +01:00
|
|
|
:bind ("C-c f" . fold-dwim-toggle)
|
|
|
|
:hook (prog-mode . hs-minor-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Highlight indentation.
|
|
|
|
(use-package hl-indent
|
2020-04-17 03:51:57 +02:00
|
|
|
:after (doom-themes whitespace)
|
|
|
|
:config (progn
|
|
|
|
(set-face-background 'hl-indent-face ; Reverse whitespace-space.
|
|
|
|
(face-foreground 'whitespace-space))
|
|
|
|
(set-face-foreground 'hl-indent-face (face-background 'default)))
|
2020-03-09 15:36:23 +01:00
|
|
|
:hook (prog-mode . hl-indent-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2019-11-09 21:55:09 +01:00
|
|
|
;; Tries to find points of interest in buffer and jumps to them.
|
|
|
|
(use-package imenu
|
2020-03-09 15:36:23 +01:00
|
|
|
:custom (imenu-auto-rescan t)
|
|
|
|
:bind ("M-i" . imenu))
|
2019-11-09 21:55:09 +01:00
|
|
|
|
|
|
|
;; 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)
|
2020-03-09 15:36:23 +01:00
|
|
|
:bind ("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)
|
2020-03-09 15:36:23 +01:00
|
|
|
:custom (dumb-jump-selector 'ivy)
|
|
|
|
:bind ("M-." . dumb-jump-go)) ; Will be overwritten by more intelligent modes.
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Support .editorconfig files.
|
|
|
|
(use-package editorconfig
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish editorconfig-mode
|
2020-03-09 15:36:23 +01:00
|
|
|
:config (editorconfig-mode 1))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2020-01-27 02:39:22 +01:00
|
|
|
(use-package smerge-mode
|
2019-12-26 07:24:33 +01:00
|
|
|
:defines (smerge-mode-map)
|
2020-03-09 15:36:23 +01:00
|
|
|
:bind (:map smerge-mode-map
|
|
|
|
("<f5>" . smerge-prev)
|
|
|
|
("<f6>" . smerge-next)
|
|
|
|
("<f7>" . smerge-resolve)))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
2020-01-28 03:32:59 +01:00
|
|
|
(use-package copyright
|
2020-03-09 15:36:23 +01:00
|
|
|
:config (defun my/maybe-copyright-update ()
|
|
|
|
"Update existing copyright notice to indicate the current
|
2020-01-28 03:32:59 +01:00
|
|
|
year if mode is derived from prog-mode."
|
2020-03-09 15:36:23 +01:00
|
|
|
(if (derived-mode-p 'prog-mode)
|
|
|
|
(copyright-update)))
|
|
|
|
:hook (before-save . my/maybe-copyright-update))
|
2020-01-28 03:32:59 +01:00
|
|
|
|
2020-01-28 04:47:57 +01:00
|
|
|
;; Highlights parentheses, brackets or braces according to their depth.
|
|
|
|
(use-package rainbow-delimiters
|
2020-03-09 15:36:23 +01:00
|
|
|
:custom (rainbow-delimiters-max-face-count 2)
|
2020-03-10 10:29:02 +01:00
|
|
|
:custom-face (rainbow-delimiters-depth-1-face
|
|
|
|
((t (:inherit rainbow-delimiters-base-face
|
|
|
|
:foreground "LightPink"))))
|
|
|
|
(rainbow-delimiters-depth-2-face
|
|
|
|
((t (:inherit rainbow-delimiters-base-face
|
|
|
|
:foreground "LightGreen"))))
|
|
|
|
(rainbow-delimiters-depth-3-face
|
|
|
|
((t (:inherit rainbow-delimiters-base-face
|
|
|
|
:foreground "MediumPurple1"))))
|
|
|
|
(rainbow-delimiters-depth-4-face
|
|
|
|
((t (:inherit rainbow-delimiters-base-face
|
|
|
|
:foreground "LightSkyBlue"))))
|
2020-03-09 15:36:23 +01:00
|
|
|
:hook (prog-mode . rainbow-delimiters-mode))
|
2020-01-28 04:47:57 +01:00
|
|
|
|
2020-02-04 18:50:04 +01:00
|
|
|
(use-package rainbow-mode
|
2020-02-11 17:48:50 +01:00
|
|
|
:diminish rainbow-mode
|
2020-03-09 15:36:23 +01:00
|
|
|
:hook (prog-mode . rainbow-mode))
|
2020-02-04 18:50:04 +01:00
|
|
|
|
2020-04-20 21:27:46 +02:00
|
|
|
;; Make bug references clickable.
|
|
|
|
(use-package bug-reference
|
2020-05-13 02:46:17 +02:00
|
|
|
:straight nil ; Inbuilt.
|
2020-04-20 21:27:46 +02:00
|
|
|
:config (put 'bug-reference-url-format 'safe-local-variable #'stringp)
|
|
|
|
:hook (prog-mode . bug-reference-prog-mode))
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
(provide 'programming/common)
|
|
|
|
;;; common.el ends here
|