Emacs: Refactor programming/common.el.

This commit is contained in:
tastytea 2020-03-09 15:36:23 +01:00
parent b788e7d8f0
commit 5421bbd971
1 changed files with 112 additions and 188 deletions

View File

@ -1,6 +1,6 @@
;;; common.el --- Common programming settings. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-03-09T15:18:43+0100>
;; Time-stamp: <2020-03-09T15:35:25+0100>
;;; Commentary:
@ -12,36 +12,26 @@
:ensure nil
:defines (compilation-mode-map)
:custom (compilation-scroll-output 'first-error)
:config
(setq-default indent-tabs-mode nil ; Set default indentation.
tab-width 4)
(electric-pair-mode t) ; Auto-type closing brackets.
:config (progn
(setq-default indent-tabs-mode nil ; Set default indentation.
tab-width 4)
(electric-pair-mode t)) ; Auto-type closing brackets.
:bind (("C-:" . ff-find-other-file) ; Switch between header and source.
(:map compilation-mode-map
("<f5>" . compilation-previous-error)
("<f6>" . compilation-next-error)
))
)
("<f6>" . compilation-next-error))))
;; Guess indentation and if spaces or tabs are to be used.
(use-package dtrt-indent
:after (editorconfig)
:diminish dtrt-indent-mode
:hook
(dtrt-indent-mode . editorconfig-apply)
(prog-mode . dtrt-indent-mode)
)
:hook ((dtrt-indent-mode . editorconfig-apply)
(prog-mode . dtrt-indent-mode)))
;; Online documentation mode.
(use-package eldoc
:diminish eldoc-mode
:hook
(prog-mode . turn-on-eldoc-mode)
)
:hook (prog-mode . turn-on-eldoc-mode))
;; Syntax checking with many plugins.
(unless slow-computer
@ -49,24 +39,18 @@
:defer nil
: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.
: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
(:map flycheck-mode-map
("<f5>" . flycheck-previous-error)
("<f6>" . flycheck-next-error)
("<f7>" . flycheck-list-errors)
)
)
: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)))
) ; unless slow-computer.
;; Autocompletion mode with many plugins.
@ -87,112 +71,89 @@
;; Fuzzy autocompletion for company.
(use-package company-flx
:after company
:config
(company-flx-mode +1)
)
:config (company-flx-mode +1))
(use-package company-statistics
:after company
:hook
(after-init . company-statistics-mode)
)
:hook (after-init . company-statistics-mode))
;; Documentation popups for completions.
(use-package company-quickhelp
:config
(company-quickhelp-mode)
)
:config (company-quickhelp-mode))
) ; unless slow-computer.
;; Automatic project management.
(unless slow-computer
(use-package projectile
:after (treemacs ivy)
:after (treemacs ivy window-purpose)
:functions (f-directory?
treemacs-collapse-other-projects
treemacs-toggle-node
my/projectile-kill-buffers)
my/projectile-kill-buffers
purpose-set-window-purpose-dedicated-p)
:diminish projectile-mode
: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)))
: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)))
(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."
(if (member 'counsel-projectile-mode minor-mode-list)
(counsel-projectile-find-file)
(projectile-find-file))
(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))
(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)
: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)
;; 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)
)
)
(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))))
) ; 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)
)
: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)
)
: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)
)
:bind (("<home>" . mwim-beginning-of-line-or-code)
("<end>" . mwim-end-of-line-or-code)))
;; Needs to be here in order to diminish it.
(use-package hideshow
@ -201,110 +162,73 @@ collapse other projects."
;; Fold code.
(use-package fold-dwim
:after (hideshow)
:bind
("C-c f" . fold-dwim-toggle)
:hook
(prog-mode . hs-minor-mode)
)
:bind ("C-c f" . fold-dwim-toggle)
: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)
)
:custom-face (hl-indent-face
((t (:inherit hl-indent-face ; Reversed whitespace.
:background "gray18"
:foreground "#1c1e1f"))))
:hook (prog-mode . hl-indent-mode))
;; Tries to find points of interest in buffer and jumps to them.
(use-package imenu
:custom
(imenu-auto-rescan t)
:bind
("M-i" . imenu)
)
:custom (imenu-auto-rescan t)
:bind ("M-i" . imenu))
;; Tries to find points of interest in all open buffers and jumps to them.
(use-package imenu-anywhere
:after (imenu ivy)
:bind
("C-M-i" . ivy-imenu-anywhere)
)
:bind ("C-M-i" . ivy-imenu-anywhere))
;; 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.
)
:custom (dumb-jump-selector 'ivy)
:bind ("M-." . dumb-jump-go)) ; Will be overwritten by more intelligent modes.
;; Support .editorconfig files.
(use-package editorconfig
:diminish editorconfig-mode
:config
(editorconfig-mode 1)
)
:config (editorconfig-mode 1))
(use-package smerge-mode
:defines (smerge-mode-map)
:bind
(:map smerge-mode-map
("<f5>" . smerge-prev)
("<f6>" . smerge-next)
("<f7>" . smerge-resolve)
)
)
:bind (:map smerge-mode-map
("<f5>" . smerge-prev)
("<f6>" . smerge-next)
("<f7>" . smerge-resolve)))
(use-package copyright
:config
(defun my/maybe-copyright-update ()
"Update existing copyright notice to indicate the current
:config (defun my/maybe-copyright-update ()
"Update existing copyright notice to indicate the current
year if mode is derived from prog-mode."
(if (derived-mode-p 'prog-mode)
(copyright-update)))
:hook
(before-save . my/maybe-copyright-update)
)
(if (derived-mode-p 'prog-mode)
(copyright-update)))
:hook (before-save . my/maybe-copyright-update))
;; Highlights parentheses, brackets or braces according to their depth.
(use-package rainbow-delimiters
:custom
(rainbow-delimiters-max-face-count 2)
: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"))))
:hook
(prog-mode . rainbow-delimiters-mode)
)
:custom (rainbow-delimiters-max-face-count 2)
: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")))))
:hook (prog-mode . rainbow-delimiters-mode))
(use-package rainbow-mode
:diminish rainbow-mode
:hook
(prog-mode . rainbow-mode)
)
:hook (prog-mode . rainbow-mode))
(provide 'programming/common)
;;; common.el ends here