fixing c++ and eglot systems

This commit is contained in:
Chris Cochrun 2022-12-05 10:45:12 -06:00
parent 81012a9d4a
commit 6c20cda022
2 changed files with 62 additions and 4 deletions

View file

@ -2002,7 +2002,36 @@ I'm gonna try this to speed up emacs and make it nicer
*** C++ *** C++
In c++ I just want to make sure lsp is called when enter c++-mode In c++ I just want to make sure lsp is called when enter c++-mode
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(add-hook 'c++-mode-hook 'eglot) (defun astyle-this-buffer ()
"Use astyle command to auto format c/c++ code."
(interactive "r")
(let* ((original-point (point))) ;; save original point before processing, thanks to @Scony
(progn
(if (executable-find "astyle")
(shell-command-on-region
(point-min) (point-max)
(concat
"astyle"
" --style=" cc-mode-code-style
" --indent=spaces=" (number-to-string c-basic-offset)
" --pad-oper"
" --pad-header"
" --break-blocks"
" --delete-empty-lines"
" --align-pointer=type"
" --align-reference=name")
(current-buffer) t
(get-buffer-create "*Astyle Errors*") t)
(message "Cannot find binary \"astyle\", please install first."))
(goto-char original-point)))) ;; restore original point
(defun astyle-before-save ()
"Auto styling before saving."
(interactive)
(when (member major-mode '(cc-mode c++-mode c-mode))
(astyle-this-buffer)))
(add-hook 'c-mode-common-hook (lambda () (add-hook 'before-save-hook 'astyle-before-save)))
#+END_SRC #+END_SRC
*** Web *** Web
@ -2094,7 +2123,7 @@ Let's give eglot a try.
(use-package eglot (use-package eglot
:commands eglot :commands eglot
:hook :hook
(c++-mode . eglot)) (c++-mode . eglot-ensure))
#+end_src #+end_src
#+begin_src emacs-lisp #+begin_src emacs-lisp

33
init.el
View file

@ -1374,7 +1374,36 @@ targets."
) )
(use-package tree-sitter-langs) (use-package tree-sitter-langs)
(add-hook 'c++-mode-hook 'eglot) (defun astyle-this-buffer ()
"Use astyle command to auto format c/c++ code."
(interactive "r")
(let* ((original-point (point))) ;; save original point before processing, thanks to @Scony
(progn
(if (executable-find "astyle")
(shell-command-on-region
(point-min) (point-max)
(concat
"astyle"
" --style=" cc-mode-code-style
" --indent=spaces=" (number-to-string c-basic-offset)
" --pad-oper"
" --pad-header"
" --break-blocks"
" --delete-empty-lines"
" --align-pointer=type"
" --align-reference=name")
(current-buffer) t
(get-buffer-create "*Astyle Errors*") t)
(message "Cannot find binary \"astyle\", please install first."))
(goto-char original-point)))) ;; restore original point
(defun astyle-before-save ()
"Auto styling before saving."
(interactive)
(when (member major-mode '(cc-mode c++-mode c-mode))
(astyle-this-buffer)))
(add-hook 'c-mode-common-hook (lambda () (add-hook 'before-save-hook 'astyle-before-save)))
(use-package web-mode (use-package web-mode
:config :config
@ -1408,7 +1437,7 @@ targets."
(use-package eglot (use-package eglot
:commands eglot :commands eglot
:hook :hook
(c++-mode . eglot)) (c++-mode . eglot-ensure))
(use-package consult-eglot) (use-package consult-eglot)