2024-03-21 19:37:50 +00:00
|
|
|
;;; 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
|
2024-04-05 21:04:36 +01:00
|
|
|
;; Version: 4.0.0
|
2024-03-21 19:37:50 +00:00
|
|
|
;;
|
|
|
|
;; 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:
|
2024-03-23 22:37:54 +00:00
|
|
|
(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"
|
2024-03-24 21:56:25 +00:00
|
|
|
"--completion-style=detailed")
|
2024-03-23 22:37:54 +00:00
|
|
|
"Arguments to pass to clangd.")
|
|
|
|
|
|
|
|
(use! cmake-ts-mode
|
|
|
|
"Enable cmake-ts-mode instead of the non-TS version.")
|
2024-03-21 19:37:50 +00:00
|
|
|
|
|
|
|
(use! eldoc-cmake
|
2024-03-23 22:37:54 +00:00
|
|
|
"ElDoc and cmake integration"
|
2024-03-21 19:37:50 +00:00
|
|
|
: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")
|
|
|
|
|
|
|
|
|
2024-03-24 21:56:25 +00:00
|
|
|
(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 " "))))
|
|
|
|
|
|
|
|
|
2024-03-23 22:37:54 +00:00
|
|
|
(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
|
2024-03-24 21:56:25 +00:00
|
|
|
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)))
|
2024-03-21 19:37:50 +00:00
|
|
|
|
|
|
|
|
2024-03-23 22:37:54 +00:00
|
|
|
(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))
|
2024-03-21 19:37:50 +00:00
|
|
|
|
2024-03-23 22:37:54 +00:00
|
|
|
:hook
|
|
|
|
(c++-ts-mode . company-mode)
|
|
|
|
(c++-ts-mode . fg42/c-ts-mode-setup)
|
|
|
|
(c++-ts-mode . flyspell-prog-mode))
|
2024-03-21 19:37:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
(provide 'fg42/langs/cpp)
|
|
|
|
;;; cpp.el ends here
|