FG42/lisp/fg42/langs/cpp.el

92 lines
3.0 KiB
EmacsLisp

;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2024 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://devheroes.codes/FG42/FG42
;; Version: 3.0.0
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;; Code:
(eval-when-compile
(require 'fpkg))
(defvar fg42/clangd-args
(list
(format "-j=%s" (- (num-processors) 2))
"--clang-tidy"
"--header-insertion=iwyu"
"--pch-storage=memory"
"--background-index"
"--cross-file-rename"
"--completion-style=detailed")
"Arguments to pass to clangd.")
(use! cmake-ts-mode
"Enable cmake-ts-mode instead of the non-TS version.")
(use! eldoc-cmake
"ElDoc and cmake integration"
:hook (cmake-ts-mode . eldoc-cmake-enable))
(use! ninja-mode
"This cube enables Ninja integration with FG42. For more info checkout:
https://github.com/ninja-build/ninja/blob/master/misc/ninja-mode.el")
(defun fg42/c_cpp_ls (_)
"Return the proper lang server fo C/C++.
By default it will return `clangd' or `ccls' depends on what you have
installed. If you set `CPP_LS' env variable, then the value of that
var will be used instead. You can use `add-advice' to change the
return value of this function as well."
(let ((ls (getenv "CPP_LS")))
(if (null ls)
(eglot-alternatives `(("clangd" ,@fg42/clangd-args) ("ccls")))
(split-string ls " "))))
(defun fg42/c-ts-mode-setup ()
"A hook handler to setup cpp related configurations."
(message "[FG42][C/C++]: Make sure to setup clangd to fit your needs. For more info: https://clangd.llvm.org/config")
(setq-local company-backends
'((company-capf :with company-yasnippet) :separate
(company-keywords company-dabbrev company-ispell) :separate
company-files))
;; We set eglot's autoload command to `eglot-ensure'
(eglot-ensure)
(add-to-list 'eglot-server-programs
`(c++-ts-mode . ,#'fg42/c_cpp_ls)))
(use! c-ts-mode
"C++ setup. We're using treesitter version of c++ mode."
:init
;; Remap the standard C/C++ modes
(add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode))
(add-to-list 'major-mode-remap-alist '(c++-mode . c++-ts-mode))
(add-to-list 'major-mode-remap-alist '(c-or-c++-mode . c-or-c++-ts-mode))
:hook
(c++-ts-mode . company-mode)
(c++-ts-mode . fg42/c-ts-mode-setup)
(c++-ts-mode . flyspell-prog-mode))
(provide 'fg42/langs/cpp)
;;; cpp.el ends here