Emacs: Moved git and lsp config to separate files.

This commit is contained in:
tastytea 2020-01-27 02:11:10 +01:00
parent e088c867d1
commit 8664fe9a90
4 changed files with 171 additions and 145 deletions

View File

@ -1,6 +1,6 @@
;;; common.el --- Common programming settings. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-01-26T20:35:54+0100>
;; Time-stamp: <2020-01-27T02:09:18+0100>
;;; Commentary:
@ -248,148 +248,5 @@
)
)
;; Git integration.
(use-package git-commit
:pin melpa
)
(unless slow-computer
;; magit from melpa needs transient from melpa.
(use-package transient
:pin melpa)
(use-package magit
:pin melpa
:custom
(magit-diff-refine-hunk 'all) ; Show word-granularity differences.
:config
(defun my/magit-display-buffer (buffer)
"Workaround to ensure that BUFFER is split vertically if necessary."
(if (and git-commit-mode
(with-current-buffer buffer
(derived-mode-p 'magit-diff-mode)))
(display-buffer buffer '((display-buffer-pop-up-window
display-buffer-use-some-window
display-buffer-below-selected)
(inhibit-same-window . t)))
(magit-display-buffer-traditional buffer)))
(setq magit-display-buffer-function #'my/magit-display-buffer)
:bind
("C-x g" . magit-status)
("C-x M-g" . magit-dispatch)
:hook
(after-save . magit-after-save-refresh-status)
)
;; Use libgit rather than git.
(use-package magit-libgit
:pin melpa
)
;; Show TODOs in magit-status.
(use-package magit-todos
:after magit
:config
;; Mark variables as safe. This prevents prompts when using .dir-locals.el.
(put 'magit-todos-depth 'safe-local-variable #'integerp)
:hook
(magit-mode . magit-todos-mode)
)
;; 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))
)
) ; unless slow-computer.
(unless slow-computer
;; Client for Language Server Protocol servers.
(use-package lsp-mode
:if (executable-find "clangd")
:after (whitespace)
:defines (lsp-clients-clangd-args)
:custom
(lsp-prefer-flymake nil) ; Disable flymake.
(lsp-auto-guess-root t) ; Don't ask for project root.
(lsp-eldoc-render-all t) ; Display all eldoc information.
:config
(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)
(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)
("C-M-," . lsp-ui-peek-find-implementation)
)
: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)
)
;; 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) ; Use treemacs for error list.
("M-i" . lsp-treemacs-symbols) ; Display symbols using treemacs.
)
)
) ; unless slow-computer.
(provide 'programming/common)
;;; common.el ends here

78
init.d/programming/git.el Normal file
View File

@ -0,0 +1,78 @@
;;; git.el --- magit and stuff. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-01-27T02:06:44+0100>
;;; Commentary:
;;; Code:
(require 'basics/global-variables)
;; Git integration.
(use-package git-commit
:pin melpa
)
(unless slow-computer
;; magit from melpa needs transient from melpa.
(use-package transient
:pin melpa)
(use-package magit
:pin melpa
:custom
(magit-diff-refine-hunk 'all) ; Show word-granularity differences.
:config
(defun my/magit-display-buffer (buffer)
"Workaround to ensure that BUFFER is split vertically if necessary."
(if (and git-commit-mode
(with-current-buffer buffer
(derived-mode-p 'magit-diff-mode)))
(display-buffer buffer '((display-buffer-pop-up-window
display-buffer-use-some-window
display-buffer-below-selected)
(inhibit-same-window . t)))
(magit-display-buffer-traditional buffer)))
(setq magit-display-buffer-function #'my/magit-display-buffer)
:bind
("C-x g" . magit-status)
("C-x M-g" . magit-dispatch)
:hook
(after-save . magit-after-save-refresh-status)
)
;; Use libgit rather than git.
(use-package magit-libgit
:pin melpa
)
;; Show TODOs in magit-status.
(use-package magit-todos
:after magit
:config
;; Mark variables as safe. This prevents prompts when using .dir-locals.el.
(put 'magit-todos-depth 'safe-local-variable #'integerp)
:hook
(magit-mode . magit-todos-mode)
)
;; 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))
)
) ; unless slow-computer.
(provide 'programming/git)
;;; git.el ends here

89
init.d/programming/lsp.el Normal file
View File

@ -0,0 +1,89 @@
;;; lsp.el --- Language Server Protocol. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-01-27T02:10:04+0100>
;;; Commentary:
;;; Code:
(require 'basics/global-variables)
(unless slow-computer
;; Client for Language Server Protocol servers.
(use-package lsp-mode
:if (executable-find "clangd")
:after (whitespace)
:defines (lsp-clients-clangd-args)
:custom
(lsp-prefer-flymake nil) ; Disable flymake.
(lsp-auto-guess-root t) ; Don't ask for project root.
(lsp-eldoc-render-all t) ; Display all eldoc information.
:config
(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)
(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)
("C-M-," . lsp-ui-peek-find-implementation)
)
: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)
)
;; 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) ; Use treemacs for error list.
("M-i" . lsp-treemacs-symbols) ; Display symbols using treemacs.
)
)
) ; unless slow-computer.
(provide 'programming/lsp)
;;; lsp.el ends here

View File

@ -1,6 +1,6 @@
;;; init.el --- tastytea's Emacs init file. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-01-01T03:37:43+0100>
;; Time-stamp: <2020-01-27T02:10:15+0100>
;;; Commentary:
;; Requires at least Emacs 26. Most of it will probably work with Emacs 24 and
@ -41,6 +41,8 @@
(require 'programming/common)
(require 'programming/c++)
(require 'programming/git)
(require 'programming/lsp)
(require 'programming/misc)
(require 'net/server)