diff --git a/nix/modules/c-family/default.nix b/nix/modules/c-family/default.nix new file mode 100644 index 0000000..2ec4338 --- /dev/null +++ b/nix/modules/c-family/default.nix @@ -0,0 +1,52 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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 . + +# 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 ]; + }; +} diff --git a/nix/modules/c-family/lisp/fg42/c-family.el b/nix/modules/c-family/lisp/fg42/c-family.el new file mode 100644 index 0000000..4708ab0 --- /dev/null +++ b/nix/modules/c-family/lisp/fg42/c-family.el @@ -0,0 +1,93 @@ +;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*- +;; +;; Copyright (c) 2010-2024 Sameer Rahmani & Contributors +;; +;; Author: Sameer Rahmani +;; 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 . +;; +;;; 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 diff --git a/nix/modules/default.nix b/nix/modules/default.nix index f602fb0..b539d3e 100644 --- a/nix/modules/default.nix +++ b/nix/modules/default.nix @@ -31,6 +31,7 @@ let ./autocomplete ./language-server ./nix + ./c-family ]; pkgsModule = { config, ... }: { diff --git a/nix/modules/editor/default.nix b/nix/modules/editor/default.nix index 89d0742..3510a56 100644 --- a/nix/modules/editor/default.nix +++ b/nix/modules/editor/default.nix @@ -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 = { diff --git a/nix/modules/editor/lisp/fg42/editor.el b/nix/modules/editor/lisp/fg42/editor.el index e5ee083..d736fef 100644 --- a/nix/modules/editor/lisp/fg42/editor.el +++ b/nix/modules/editor/lisp/fg42/editor.el @@ -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." diff --git a/nix/modules/elisp/default.nix b/nix/modules/elisp/default.nix index 7e7840f..31045e3 100644 --- a/nix/modules/elisp/default.nix +++ b/nix/modules/elisp/default.nix @@ -35,5 +35,10 @@ let in { + imports = [ + ../language-server + ]; + fg42.elispPackages = [ drv ] ++ deps; + fg42.requires = [ drv.pname ]; } diff --git a/nix/modules/elisp/lisp/fg42/elisp.el b/nix/modules/elisp/lisp/fg42/elisp.el index 63d3a05..13e0cfc 100644 --- a/nix/modules/elisp/lisp/fg42/elisp.el +++ b/nix/modules/elisp/lisp/fg42/elisp.el @@ -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))) diff --git a/nix/modules/language-server/lisp/fg42/language-server.el b/nix/modules/language-server/lisp/fg42/language-server.el index 10fc95e..f65d234 100644 --- a/nix/modules/language-server/lisp/fg42/language-server.el +++ b/nix/modules/language-server/lisp/fg42/language-server.el @@ -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)) diff --git a/nix/modules/unit/default.nix b/nix/modules/unit/default.nix index de8be24..b01cd93 100644 --- a/nix/modules/unit/default.nix +++ b/nix/modules/unit/default.nix @@ -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); }; }