Emacs: Replace (unless slow-computer […] with :unless slow-computer.

This commit is contained in:
tastytea 2020-12-08 13:17:06 +01:00
parent c8b6a6bc90
commit d15eefdf5d
5 changed files with 255 additions and 260 deletions

View File

@ -1,6 +1,6 @@
;;; c++.el --- C++ settings. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-12-07T16:21:12+0100>
;; Time-stamp: <2020-12-08T13:10:22+0100>
;;; Commentary:
@ -10,40 +10,39 @@
(require 'basics/global-variables)
(require 'programming/common)
(unless slow-computer
(when (and (executable-find "clang-tidy")
;; clang-tidy is built into clangd >= 9.
(< (my/clangd-version) 9.0))
(use-package flycheck-clang-tidy
:after (flycheck projectile lsp-ui)
:defines (lsp-mode)
:functions (flycheck-clang-tidy-setup)
:config (progn
(defun my/clang-tidy-off ()
"Disable c/c++-clang-tidy."
(when (or (eq major-mode 'c++-mode)
(eq major-mode 'c-mode))
(add-to-list 'flycheck-disabled-checkers
'c/c++-clang-tidy)))
(defun my/clang-tidy-on ()
"Enable c/c++-clang-tidy."
(when (or (eq major-mode 'c++-mode)
(eq major-mode 'c-mode))
(setq-local flycheck-disabled-checkers
(remove 'c/c++-clang-tidy
flycheck-disabled-checkers))))
(defun my/flycheck-clang-tidy-setup ()
(flycheck-clang-tidy-setup)
;; Run clang-tidy after the lsp-ui checker.
(when lsp-mode
(unless (equal (flycheck-get-next-checker-for-buffer
'lsp-ui) 'c/c++-clang-tidy)
(flycheck-add-next-checker
'lsp-ui '(warning . c/c++-clang-tidy))))))
:hook ((flycheck-mode . my/flycheck-clang-tidy-setup)
(first-change . my/clang-tidy-off) ; Disable when file is modified.
(before-save . my/clang-tidy-on)))) ; Enable if file is saved.
) ; unless slow-computer.
(when (and (executable-find "clang-tidy")
;; clang-tidy is built into clangd >= 9.
(< (my/clangd-version) 9.0))
(use-package flycheck-clang-tidy
:unless slow-computer
:after (flycheck projectile lsp-ui)
:defines (lsp-mode)
:functions (flycheck-clang-tidy-setup)
:config (progn
(defun my/clang-tidy-off ()
"Disable c/c++-clang-tidy."
(when (or (eq major-mode 'c++-mode)
(eq major-mode 'c-mode))
(add-to-list 'flycheck-disabled-checkers
'c/c++-clang-tidy)))
(defun my/clang-tidy-on ()
"Enable c/c++-clang-tidy."
(when (or (eq major-mode 'c++-mode)
(eq major-mode 'c-mode))
(setq-local flycheck-disabled-checkers
(remove 'c/c++-clang-tidy
flycheck-disabled-checkers))))
(defun my/flycheck-clang-tidy-setup ()
(flycheck-clang-tidy-setup)
;; Run clang-tidy after the lsp-ui checker.
(when lsp-mode
(unless (equal (flycheck-get-next-checker-for-buffer
'lsp-ui) 'c/c++-clang-tidy)
(flycheck-add-next-checker
'lsp-ui '(warning . c/c++-clang-tidy))))))
:hook ((flycheck-mode . my/flycheck-clang-tidy-setup)
(first-change . my/clang-tidy-off) ; Disable when file is modified.
(before-save . my/clang-tidy-on)))) ; Enable if file is saved.
;; Highlight Doxygen comments.
(use-package highlight-doxygen

View File

@ -1,6 +1,6 @@
;;; common.el --- Common programming settings. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-12-08T12:50:22+0100>
;; Time-stamp: <2020-12-08T13:08:13+0100>
;;; Commentary:
@ -45,43 +45,42 @@
:hook (prog-mode . turn-on-eldoc-mode))
;; Syntax checking with many plugins.
(unless slow-computer
(use-package flycheck
:demand t
:functions (flycheck-add-mode)
:diminish flycheck-mode
:custom ((flycheck-cppcheck-checks '("style" "warning" "information"))
(flycheck-emacs-lisp-load-path 'inherit) ; Use load-path of Emacs.
(flycheck-idle-change-delay 2.0))
:config (progn
(global-flycheck-mode)
(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)))
) ; unless slow-computer.
(use-package flycheck
:unless slow-computer
:demand t
:functions (flycheck-add-mode)
:diminish flycheck-mode
:custom ((flycheck-cppcheck-checks '("style" "warning" "information"))
(flycheck-emacs-lisp-load-path 'inherit) ; Use load-path of Emacs.
(flycheck-idle-change-delay 2.0))
:config (progn
(global-flycheck-mode)
(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)))
;; Autocompletion mode with many plugins.
(unless slow-computer
(use-package company
:diminish company-mode
: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))
(use-package company
:unless slow-computer
:diminish company-mode
: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))
;; Documentation popups for completions.
(use-package company-quickhelp
:after (company)
:config (company-quickhelp-mode))
) ; unless slow-computer.
;; Sorting and filtering for company.
(use-package company-prescient
@ -89,80 +88,79 @@
:hook (after-init . company-prescient-mode))
;; Automatic project management.
(unless slow-computer
(use-package projectile
:demand t
:after (treemacs ivy window-purpose)
:functions (f-directory?
treemacs-collapse-other-projects
treemacs-toggle-node
my/projectile-kill-buffers
purpose-set-window-purpose-dedicated-p)
:diminish projectile-mode
:init (progn
(defun my/projectile-enable-caching? (&rest args)
"Turn on caching for certain projects.
(use-package projectile
:unless slow-computer
:demand t
:after (treemacs ivy window-purpose)
:functions (f-directory?
treemacs-collapse-other-projects
treemacs-toggle-node
my/projectile-kill-buffers
purpose-set-window-purpose-dedicated-p)
:diminish projectile-mode
:init (progn
(defun my/projectile-enable-caching? (&rest args)
"Turn on caching for certain projects.
Ignores ARGS."
(if (string= (projectile-project-name) ".emacs.d")
(progn
(message "Turning on caching for \"%s\"."
(projectile-project-name))
(setq-local projectile-enable-caching t))
(kill-local-variable 'projectile-enable-caching)))
(advice-add 'projectile-find-file
:before #'my/projectile-enable-caching?)
(advice-add 'counsel-projectile-find-file
:before #'my/projectile-enable-caching?)
(if (string= (projectile-project-name) ".emacs.d")
(progn
(message "Turning on caching for \"%s\"."
(projectile-project-name))
(setq-local projectile-enable-caching t))
(kill-local-variable 'projectile-enable-caching)))
(advice-add 'projectile-find-file
:before #'my/projectile-enable-caching?)
(advice-add 'counsel-projectile-find-file
:before #'my/projectile-enable-caching?)
(defun my/switch-project ()
"Find file in project, add project to `treemacs' and
(defun my/switch-project ()
"Find file in project, add project to `treemacs' and
collapse other projects."
; Enable caching maybe before listing files.
(my/projectile-enable-caching?)
; Enable caching maybe before listing files.
(my/projectile-enable-caching?)
(if (member 'counsel-projectile-mode minor-mode-list)
(counsel-projectile-find-file)
(projectile-find-file))
(when (>= (frame-width) 120)
(treemacs-add-and-display-current-project)
(treemacs-collapse-other-projects)
(other-window 1)))
(if (member 'counsel-projectile-mode minor-mode-list)
(counsel-projectile-find-file)
(projectile-find-file))
(when (>= (frame-width) 120)
(treemacs-add-and-display-current-project)
(treemacs-collapse-other-projects)
(other-window 1)))
(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 \
(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 \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DWITH_TESTS=YES ..")
(projectile-completion-system 'ivy)
(projectile-indexing-method 'hybrid) ; Allow filtering.
(projectile-globally-ignored-file-suffixes '("~")))
:config (progn
(setq projectile-project-compilation-cmd
(concat "cmake --build . -- -j"
(substring
(shell-command-to-string "nproc --ignore=1") 0 -1)
" && 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))))
) ; unless slow-computer.
(projectile-completion-system 'ivy)
(projectile-indexing-method 'hybrid) ; Allow filtering.
(projectile-globally-ignored-file-suffixes '("~")))
:config (progn
(setq projectile-project-compilation-cmd
(concat "cmake --build . -- -j"
(substring
(shell-command-to-string "nproc --ignore=1") 0 -1)
" && 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))))
;; Highlight TODO, FIXME, NOTE and so on.
(use-package hl-todo

View File

@ -1,6 +1,6 @@
;;; git.el --- magit and stuff. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-12-03T21:40:09+0100>
;; Time-stamp: <2020-12-08T13:15:20+0100>
;;; Commentary:
@ -16,35 +16,35 @@
(setq-local fill-column 72))
:hook (git-commit-mode . my/set-git-commit-fill-column))
(unless slow-computer
(use-package magit
:after (keychain-environment)
:custom (magit-diff-refine-hunk 'all) ; Show word-granularity differences.
:bind (("C-x g" . nil) ; Disable default.
("C-c g" . magit-status)
("C-c M-g" . magit-dispatch)
(:map magit-hunk-section-map
("RET" . magit-diff-visit-worktree-file-other-window)))
:hook ((after-save . magit-after-save-refresh-status)
(magit-mode . keychain-refresh-environment)))
(use-package magit
:unless slow-computer
:after (keychain-environment)
:custom (magit-diff-refine-hunk 'all) ; Show word-granularity differences.
:bind (("C-x g" . nil) ; Disable default.
("C-c g" . magit-status)
("C-c M-g" . magit-dispatch)
(:map magit-hunk-section-map
("RET" . magit-diff-visit-worktree-file-other-window)))
:hook ((after-save . magit-after-save-refresh-status)
(magit-mode . keychain-refresh-environment)))
;; Use libgit rather than git.
(use-package magit-libgit)
;; Use libgit rather than git.
(use-package magit-libgit
:after (magit))
;; Show TODOs in magit-status.
(use-package magit-todos
:after magit
:init (put 'magit-todos-depth 'safe-local-variable #'integerp)
:hook (magit-mode . magit-todos-mode))
;; Show TODOs in magit-status.
(use-package magit-todos
:after (magit)
:init (put 'magit-todos-depth 'safe-local-variable #'integerp)
:hook (magit-mode . magit-todos-mode))
;; Work with Git forges from Magit.
(use-package forge
:after magit
:config (add-to-list 'forge-alist
'("schlomp.space" "schlomp.space/api/v1"
"schlomp.space" forge-gitea-repository))
:hook (prog-mode . forge-bug-reference-setup))
) ; unless slow-computer.
;; Work with Git forges from Magit.
(use-package forge
:after (magit)
:config (add-to-list 'forge-alist
'("schlomp.space" "schlomp.space/api/v1"
"schlomp.space" forge-gitea-repository))
:hook (prog-mode . forge-bug-reference-setup))
(provide 'programming/git)
;;; git.el ends here

View File

@ -1,6 +1,6 @@
;;; lsp.el --- Language Server Protocol. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-12-07T15:03:32+0100>
;; Time-stamp: <2020-12-08T13:13:22+0100>
;;; Commentary:
@ -10,73 +10,72 @@
(require 'basics/global-variables)
(require 'programming/common)
(unless slow-computer
;; Client for Language Server Protocol servers.
(use-package lsp-mode
:if (executable-find "clangd")
:defines (lsp-clients-clangd-args)
:diminish lsp-mode
:custom ((lsp-prefer-flymake nil) ; Disable flymake.
(lsp-auto-guess-root t) ; Don't ask for project root.
(lsp-eldoc-render-all t)
(lsp-restart 'auto-restart)
(lsp-enable-semantic-highlighting t) ; Needs clangd 11(?).
(lsp-semantic-tokens-apply-modifiers t)
(lsp-prefer-capf t)
(lsp-keymap-prefix "C-c l")
(lsp-keep-workspace-alive nil))
:custom-face
;; Semantic highlighting. TODO: Check later if better options are available.
(lsp-face-semhl-variable ((t (:inherit font-lock-variable-name-face
:italic t))))
(lsp-face-semhl-parameter ((t (:inherit font-lock-variable-name-face
:italic t :underline t))))
(lsp-face-semhl-member ((t (:inherit default :weight semibold))))
(lsp-face-semhl-enum ((t (:inherit font-lock-type-face))))
:config (progn
(setq lsp-clients-clangd-args '("--compile-commands-dir=build"))
;; Add “-clang-tidy” to clangd args if the version supports it.
(when (>= (my/clangd-version) 9.0)
(add-to-list 'lsp-clients-clangd-args "--clang-tidy" t))
;; Mark lsp-clients-clangd-args as safe to override.
(put 'lsp-clients-clangd-args 'safe-local-variable #'consp))
:bind ("C-c C-f" . lsp-execute-code-action)
:hook ((c++-mode . lsp)
(c-mode . lsp)
(python-mode . lsp)
(nxml-mode . lsp)
(lsp-mode . lsp-enable-which-key-integration)))
;; Client for Language Server Protocol servers.
(use-package lsp-mode
:if (and (executable-find "clangd") (not slow-computer))
:defines (lsp-clients-clangd-args)
:diminish lsp-mode
:custom ((lsp-prefer-flymake nil) ; Disable flymake.
(lsp-auto-guess-root t) ; Don't ask for project root.
(lsp-eldoc-render-all t)
(lsp-restart 'auto-restart)
(lsp-enable-semantic-highlighting t) ; Needs clangd 11(?).
(lsp-semantic-tokens-apply-modifiers t)
(lsp-prefer-capf t)
(lsp-keymap-prefix "C-c l")
(lsp-keep-workspace-alive nil))
:custom-face
;; Semantic highlighting. TODO: Check later if better options are available.
(lsp-face-semhl-variable ((t (:inherit font-lock-variable-name-face
:italic t))))
(lsp-face-semhl-parameter ((t (:inherit font-lock-variable-name-face
:italic t :underline t))))
(lsp-face-semhl-member ((t (:inherit default :weight semibold))))
(lsp-face-semhl-enum ((t (:inherit font-lock-type-face))))
:config (progn
(setq lsp-clients-clangd-args '("--compile-commands-dir=build"))
;; Add “-clang-tidy” to clangd args if the version supports it.
(when (>= (my/clangd-version) 9.0)
(add-to-list 'lsp-clients-clangd-args "--clang-tidy" t))
;; Mark lsp-clients-clangd-args as safe to override.
(put 'lsp-clients-clangd-args 'safe-local-variable #'consp))
:bind ("C-c C-f" . lsp-execute-code-action)
:hook ((c++-mode . lsp)
(c-mode . lsp)
(python-mode . lsp)
(nxml-mode . lsp)
(lsp-mode . lsp-enable-which-key-integration)))
;; Eye-candy and flycheck support for lsp-mode.
(use-package lsp-ui
:after (lsp-mode flycheck whitespace)
:functions (my/whitespace-mode-on my/whitespace-mode-off)
: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.
:config (defun my/lsp-ws-toggle ()
"Works around the dots-in-wrong-color bug."
(if lsp-ui-peek-mode
(my/whitespace-mode-off)
(my/whitespace-mode-on)))
:bind (:map lsp-ui-mode-map
("M-." . lsp-ui-peek-find-definitions)
("C-M-." . lsp-ui-peek-find-references)
("C-M-," . lsp-ui-peek-find-implementation))
:hook ((lsp-mode . lsp-ui-mode)
(lsp-ui-peek-mode . my/lsp-ws-toggle)))
;; Eye-candy and flycheck support for lsp-mode.
(use-package lsp-ui
:after (lsp-mode flycheck whitespace)
:functions (my/whitespace-mode-on my/whitespace-mode-off)
: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.
:config (defun my/lsp-ws-toggle ()
"Works around the dots-in-wrong-color bug."
(if lsp-ui-peek-mode
(my/whitespace-mode-off)
(my/whitespace-mode-on)))
:bind (:map lsp-ui-mode-map
("M-." . lsp-ui-peek-find-definitions)
("C-M-." . lsp-ui-peek-find-references)
("C-M-," . lsp-ui-peek-find-implementation))
:hook ((lsp-mode . lsp-ui-mode)
(lsp-ui-peek-mode . my/lsp-ws-toggle)))
;; ivy interface to lsp-mode.
(use-package lsp-ivy
:demand t
:after (lsp-mode ivy))
;; ivy interface to lsp-mode.
(use-package lsp-ivy
:demand t
:after (lsp-mode ivy))
;; Integration between lsp-mode and treemacs.
(use-package lsp-treemacs
:after (treemacs lsp-ui)
:bind (:map lsp-ui-mode-map
("<f7>" . lsp-treemacs-errors-list)))
) ; unless slow-computer.
;; Integration between lsp-mode and treemacs.
(use-package lsp-treemacs
:after (treemacs lsp-ui)
:bind (:map lsp-ui-mode-map
("<f7>" . lsp-treemacs-errors-list)))
)
(provide 'programming/lsp)
;;; lsp.el ends here

View File

@ -1,6 +1,6 @@
;;; common.el --- Common settings for text files. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-12-07T16:03:09+0100>
;; Time-stamp: <2020-12-08T13:16:30+0100>
;;; Commentary:
@ -105,39 +105,38 @@
(ispell-hunspell-add-multi-dic "de_DE,de_AT,de_CH")))
;; Interactive spell checking.
(unless slow-computer
(use-package flyspell
:if (or (executable-find "aspell")
(executable-find "hunspell")
(executable-find "ispell"))
:diminish flyspell-mode
:custom ((flyspell-default-dictionary "en_US"))
:config (progn
(defun my/toggle-flyspell ()
"Toggle flyspell-mode and run flyspell-buffer after activating."
(interactive)
(if (bound-and-true-p flyspell-mode)
(flyspell-mode 0)
(flyspell-mode)
(flyspell-buffer)))
(use-package flyspell
:if (and (not slow-computer)
(or (executable-find "aspell")
(executable-find "hunspell")
(executable-find "ispell")))
:diminish flyspell-mode
:custom ((flyspell-default-dictionary "en_US"))
:config (progn
(defun my/toggle-flyspell ()
"Toggle flyspell-mode and run flyspell-buffer after activating."
(interactive)
(if (bound-and-true-p flyspell-mode)
(flyspell-mode 0)
(flyspell-mode)
(flyspell-buffer)))
(defun my/flyspell-german ()
"Set dictionary to german."
(interactive)
(ispell-change-dictionary "de_DE")))
:bind (("<f8>" . my/toggle-flyspell)
(:map flyspell-mode-map
("C-;" . nil) ; iedit needs C-;.
("C-M-i" . nil))) ; imenu-anywhere needs it.
:hook ((prog-mode . flyspell-prog-mode) ; Spellcheck comments.
(text-mode . flyspell-mode) ; Spellcheck text documents ↓.
(LaTeX-mode . my/flyspell-german)
(LaTeX-mode . flyspell-mode)
(adoc-mode . flyspell-mode)
(markdown-mode . flyspell-mode)
(git-commit-mode . flyspell-mode))
:mode ("COMMIT_EDITMSG\\'" . flyspell-mode))
) ; unless slow-computer.
(defun my/flyspell-german ()
"Set dictionary to german."
(interactive)
(ispell-change-dictionary "de_DE")))
:bind (("<f8>" . my/toggle-flyspell)
(:map flyspell-mode-map
("C-;" . nil) ; iedit needs C-;.
("C-M-i" . nil))) ; imenu-anywhere needs it.
:hook ((prog-mode . flyspell-prog-mode) ; Spellcheck comments.
(text-mode . flyspell-mode) ; Spellcheck text documents ↓.
(LaTeX-mode . my/flyspell-german)
(LaTeX-mode . flyspell-mode)
(adoc-mode . flyspell-mode)
(markdown-mode . flyspell-mode)
(git-commit-mode . flyspell-mode))
:mode ("COMMIT_EDITMSG\\'" . flyspell-mode))
;; The string Time-stamp: <> in the first 8 lines of the file will be updated
;; with the current timestamp.