From a4740069c6f43f61ad333eaec6681f72977ba2d4 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 1 Jan 2021 00:00:34 +0000 Subject: [PATCH] Replace old C integration with lsp-mode config --- config.org | 74 +++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/config.org b/config.org index 96237eb..7f6cbd2 100644 --- a/config.org +++ b/config.org @@ -299,54 +299,42 @@ (setq-default indent-tabs-mode nil) #+end_src +*** Language Server Protocol + LSP seems to be the way forward in terms of IDE-like features in + Emacs; grab =lsp-mode= and enable =lsp-deferred=: + + #+begin_src emacs-lisp + (use-package lsp-mode + :init (setq lsp-keymap-prefix "C-c l") + :commands (lsp lsp-deferred)) + #+end_src + + =lsp-deferred= means that the LSP server will only be started once + a buffer is actually opened, which makes more sense to me. + + Also going to give =lsp-ui= a shot, which displays a bunch of + information from the language server in the buffer. It looks like + it could be a bit much but we'll see. + + #+begin_src emacs-lisp + (use-package lsp-ui :commands lsp-ui-mode) + #+end_src + + Finally, to enable Ido integration: + + #+begin_src emacs-lisp + (require 'lsp-ido) + #+end_src + ** C - For C, I like to indent with tabs and align with spaces: this - behaviour is provided by =smart-tabs-mode=. + For C there is =clangd= implementing LSP. Assuming that's installed + and on the =PATH=, we can just hook =lsp-mode= into the default + mode and there will be much rejoicing. #+begin_src emacs-lisp - (use-package smart-tabs-mode) - (smart-tabs-insinuate 'c) + (add-hook 'c-mode-hook #'lsp-deferred) #+end_src - I'll generally format my code in BSD style but I also use - =clang-format= a lot, so I have a keybinding to run that. - - #+begin_src emacs-lisp - (setq c-default-style "bsd") - (setq c-basic-offset 4) - - (use-package clang-format) - (add-hook 'c-mode-hook - (lambda () - (define-key c-mode-map (kbd "C-M-f") - 'clang-format-buffer))) - #+end_src - - Meson is my build system of choice for C, but I also use CMake a lot. - - #+begin_src emacs-lisp - (use-package meson-mode) - (use-package cmake-mode) - #+end_src - -*** Code Navigation - Using GNU Global for now, so hook =ggtags-mode= into =c-mode=: - - #+begin_src emacs-lisp - (use-package ggtags - :config - (add-hook 'c-mode-common-hook - (lambda () (ggtags-mode 1)))) - #+end_src - - And, of course, add some keybindings - - #+begin_src emacs-lisp - (define-key ggtags-mode-map (kbd "C-c g r") 'ggtags-find-reference) - (define-key ggtags-mode-map (kbd "C-c g d") 'ggtags-find-definition) - (define-key ggtags-mode-map (kbd "C-c g u") 'ggtags-update-tags) - #+end_src - ** Haskell My workflow with Haskell is very REPL-based, so I always want =interactive-haskell-mode= on.