Add support for the C family

This commit is contained in:
Sameer Rahmani 2024-04-18 21:35:40 +01:00
parent 09a545edc1
commit b8e23dcb61
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
9 changed files with 176 additions and 18 deletions

View File

@ -0,0 +1,52 @@
# Fg42 - Emacs Editor for advance users
#
# Copyright (c) 2010-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# 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, version 2.
#
# 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/>.
# This is the home manager module that exposes FG42. It differs
# from FG42 modules that are structurally the same but used in
# different context
# A list of default FG42 modules to build FG42 with.
{ lib, config, pkgs, makeFG42Drv, ... }:
with lib;
let
cfg = config.fg42.c-family;
deps =
(with pkgs.emacsPackages; [
eldoc-cmake
ninja-mode
]);
drv = makeFG42Drv {
pname = "c-family";
version = config.fg42.version;
buildInputs = deps;
src = ./.;
};
in
{
options.fg42.c-family.enable = mkAndEnableOption "c-family";
config = mkIf cfg.enable {
fg42.elispPackages = [ drv ] ++ deps;
fg42.paths = (with pkgs;[
cmake-language-server
]);
fg42.requires = [ drv.pname ];
};
}

View File

@ -0,0 +1,93 @@
;;; 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: 4.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."
:mode ("\\(?:CMakeLists\\.txt\\|\\.cmake\\)\\'" . cmake-ts-mode)
:hook ((cmake-ts-mode . fg42/autocomplete)
(cmake-ts-mode . fg42/ensure-lang-server)))
(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 " "))))
;;;###autoload
(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")
(fg42/ensure-lang-server)
(when (and (boundp 'eglot-managed-p) (eglot-managed-p))
(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 . fg42/autocomplete)
(c++-ts-mode . fg42/c-ts-mode-setup)
(c++-ts-mode . flyspell-prog-mode))
(provide 'fg42/c-family)
;;; c-family.el ends here

View File

@ -31,6 +31,7 @@ let
./autocomplete
./language-server
./nix
./c-family
];
pkgsModule = { config, ... }: {

View File

@ -31,6 +31,7 @@ let
projectile-ripgrep
pkg-info
expand-region
direnv
helpful
envrc
pinentry
@ -71,6 +72,7 @@ in
fg42.paths = (with pkgs;[
ripgrep
dicts
direnv
]);
fg42.font = {

View File

@ -198,9 +198,16 @@ contextual information."
"It is a rainbow parentheses like mode which highlights delimiters such as
parentheses, brackets or braces according to their depth."
;; Enable rainbow-delimiters for programming
:commands rainbow-delimiters-mode
:hook (prog-mode-hook . rainbow-delimiters-mode))
(use! direnv
"Direnv integration for FG42."
:config
(direnv-mode))
(defun fg42/setup-editor ()
"Setup the overall functionality of FG42."

View File

@ -35,5 +35,10 @@ let
in
{
imports = [
../language-server
];
fg42.elispPackages = [ drv ] ++ deps;
fg42.requires = [ drv.pname ];
}

View File

@ -29,11 +29,15 @@
"Evaluation Result OverlayS for Emacs Lisp."
:commands eros-mode)
(use! paredit
"Minor mode for editing parentheses."
:commands enable-paredit-mode)
(use! elisp-mode
"Elisp mode."
:hook
((emacs-lisp-mode . rainbow-delimiters-mode)
(emacs-lisp-mode . paredit-mode)
(emacs-lisp-mode . enable-paredit-mode)
;; (emacs-lisp-mode . company-mode)
(emacs-lisp-mode . eros-mode)))

View File

@ -34,10 +34,13 @@ shipped with Emacs."
(use! eldoc-box
"View eldoc stuff in a frame."
:commands eldoc-box-hover-mode)
:commands eldoc-box-hover-mode
:hook (eldoc-mode . eldoc-box-hover-mode))
(use! markdown-mode
"Renders markdown in Emacs.")
"Renders markdown in Emacs."
:init (setq markdown-command "multimarkdown"))
;;;###autoload
@ -53,6 +56,7 @@ or via `use!' `:hook'."
(interactive)
;; TODO: Configure LSP here as an alternative here by looking at
;; the configs in `fg42/config'
(add-hook 'eglot-managed-mode-hook #'eldoc-box-hover-mode t)
(eglot-ensure))

View File

@ -24,6 +24,10 @@ with lib;
let
cfg = config.fg42;
deps = (with pkgs.emacsPackages; [
treesit-grammars.with-all-grammars
]);
drv = makeFG42Drv {
pname = "unit";
version = config.fg42.version;
@ -179,7 +183,7 @@ in
config = {
fg42.version = import ../../version.nix { };
fg42.elispPackages = [ drv ];
fg42.elispPackages = [ drv ] ++ deps;
fg42.theme = lib.mkDefault "base16-eighties";
fg42.theme-package-name = lib.mkDefault "base16-theme";
@ -192,20 +196,6 @@ in
'')
];
# Extract the package pname's to pass to elisp to `require` them in the init
# file, while compiling.
# fg42.requires = map nix2elispName config.fg42.elispPackages;
# fg42.docstrings = (with builtins;
# let
# desc = opt:
# if hasAttr "description" opt
# then opt.description
# else "";
# in
# lib.concatMapAttrs
# (k: v: { ${k} = desc v; })
# options.fg42);
};
}