Setup a basic eglot,company configuration for cpp

This commit is contained in:
Sameer Rahmani 2024-03-23 22:37:54 +00:00
parent 8f2944e0e4
commit 86699f34fb
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
18 changed files with 167 additions and 123 deletions

56
lisp/fg42/autocomplete.el Normal file
View File

@ -0,0 +1,56 @@
;;; 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))
(use! company
"Company is a modular text completion framework for GNU Emacs."
:commands global-company-mode
:bind (:map company-active-map
("M-n" . company-select-next)
("M-p" . company-select-previous)
("TAB" . company-complete-common-or-cycle)
("M-d" . company-show-doc-buffer))
:init
;; Use Company for completion
(setq company-show-numbers t)
(setq company-idle-delay 0)
(setq company-tooltip-limit 20)
(setq company-echo-delay 0)
(setq company-tooltip-align-annotations t)
(setq company-dabbrev-downcase nil)
:config
(bind-key [remap completion-at-point] #'company-complete company-mode-map))
(use! company-box
"A company front-end with icons."
:after company
:hook (company-mode . company-box-mode))
(provide 'fg42/autocomplete)
;;; autocomplete.el ends here

View File

@ -120,7 +120,9 @@
pkg-info pkg-info
envrc envrc
vertico vertico
orderless) orderless
eglot
)
(provide 'fg42/deps) (provide 'fg42/deps)
;;; deps.el ends here ;;; deps.el ends here

View File

@ -21,21 +21,27 @@
;; ;;
;;; Commentary: ;;; Commentary:
;;; Code: ;;; Code:
(require 'server)
(eval-when-compile (eval-when-compile
(require 'fpkg)) (require 'fpkg)
;; Language support
)
(require 'server)
(require 'fg42/modeline) (require 'fg42/modeline)
(require 'fg42/autocomplete)
(require 'fg42/langs/cpp)
;; (require 'fg42/utils) ;; (require 'fg42/utils)
;; (require 'fg42/modeline) ;; (require 'fg42/modeline)
;; (require 'fg42/cubes/modeline) ;; (require 'fg42/cubes/modeline)
;; (require 'fg42/themes) ;; (require 'fg42/themes)
;; (require 'fg42/project) ;; (require 'fg42/project)
(defvar fg42/font '("Fira Mono" 12)
"Font name and size to be used with FG42. (Default (\"Fira Mono\" 12).")
(defvar fg42/font '("Fira Mono" 12)) (defvar fg42/snippet-dir nil
"Where to find user's snippets.")
(defun fg42/setup-font () (defun fg42/setup-font ()
@ -48,6 +54,7 @@
(set-face-attribute 'default t :font name))) (set-face-attribute 'default t :font name)))
(defun fg42/setup-editor () (defun fg42/setup-editor ()
"Setup the overall functionality of FG42." "Setup the overall functionality of FG42."
(use! origami (use! origami
@ -107,12 +114,21 @@ contextual information."
:init :init
(setq epa-pinentry-mode 'loopback)) (setq epa-pinentry-mode 'loopback))
(use! imenu
"The Imenu facility offers a way to find the major definitions in a file by name."
:bind (("M-i" . imenu)))
(use! imenu-list (use! imenu-list
"his Emacs minor-mode creates an automatically updated buffer "his Emacs minor-mode creates an automatically updated buffer
called `Ilist' that is populated with the current buffer's imenu entries. called `Ilist' that is populated with the current buffer's imenu entries.
The `Ilist' buffer is typically shown as a sidebar (Emacs vertically splits the window)." The `Ilist' buffer is typically shown as a sidebar (Emacs vertically splits the window)."
:bind (("C-'" . imenu-list-smart-toggle))) :bind (("C-'" . imenu-list-smart-toggle)))
(use! display-line-numbers
"The builtin replacement of linum. It's is pretty fast."
:config
(global-display-line-numbers-mode 1))
(use! emojify (use! emojify
"Adds support for emojis to `FG42'" "Adds support for emojis to `FG42'"
:hook (emacs-startup . global-emojify-mode)) :hook (emacs-startup . global-emojify-mode))
@ -154,6 +170,7 @@ data. The typical example of this would be Lisp or Scheme source code."
"This cube controls the different aspect of buffer navigation" "This cube controls the different aspect of buffer navigation"
:bind ("C-<tab>" . ace-window)) :bind ("C-<tab>" . ace-window))
;; Minibuffer related stuff
(use! vertico (use! vertico
"Vertico provides a performant and minimalistic vertical completion UI "Vertico provides a performant and minimalistic vertical completion UI
based on the default completion system. The focus of Vertico is to provide based on the default completion system. The focus of Vertico is to provide
@ -190,6 +207,35 @@ match all of the components in any order."
Emacs." Emacs."
:if (display-graphic-p)) :if (display-graphic-p))
(use! yasnippet
"ASnippet is a template system for Emacs. "
:config
(let* ((snippet-home
(expand-file-name
"snippets"
(file-name-directory (locate-library "yasnippet-snippets"))))
(local-snippet (expand-file-name "snippets" fg42-home))
(user-snippets (or fg42/snippet-dir local-snippet)))
(setq yas-snippet-dirs `(,user-snippets ,local-snippet ,snippet-home))
(yas-global-mode 1)))
(use! yasnippet-snippets
"Yasnippet's snippets."
:after yasnippet)
;; Language Servers and friends
(use! eglot
"Eglot is a minimalistic yet powerful LSP replacement
shipped with Emacs."
:commands eglot
:autoload eglot-ensure)
(use! flycheck
"Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs."
:config (global-flycheck-mode))
;; In the following section we're setting some default behavior of FG42. ;; In the following section we're setting some default behavior of FG42.
;; Most of these configuration are opiniated and I think most of people ;; Most of these configuration are opiniated and I think most of people
;; shared the same opinion or don't care at all. ;; shared the same opinion or don't care at all.
@ -218,16 +264,24 @@ Emacs."
;; Support opening new minibuffers from inside existing minibuffers. ;; Support opening new minibuffers from inside existing minibuffers.
(setq enable-recursive-minibuffers t) (setq enable-recursive-minibuffers t)
(setq tooltip-use-echo-area t)
(setq x-gtk-use-system-tooltips nil)
;; Global configurations ;; Global configurations
(tool-bar-mode -1) (tool-bar-mode -1)
(tooltip-mode nil)
(menu-bar-mode -1) (menu-bar-mode -1)
(when (display-graphic-p) (when (display-graphic-p)
;; Smoother scrolling
(pixel-scroll-precision-mode)
(scroll-bar-mode -1)) (scroll-bar-mode -1))
(column-number-mode t) (column-number-mode t)
(show-paren-mode t) (show-paren-mode t)
(electric-pair-mode 1) (electric-pair-mode 1)
(global-company-mode)
;; Rectangular select ;; Rectangular select
(cua-selection-mode t) (cua-selection-mode t)

View File

@ -1,30 +0,0 @@
;;; Flags --- Flags library of FG42 -*- 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:
(require 'fg42/flags)
(provide 'lang-servers)
;;; lang-servers.el ends here

View File

@ -1,63 +0,0 @@
;;; 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:
(require 'fpkg)
(require 'fg42/utils)
(require 'fg42/language-servers)
;; (use! cmake-ts-mode)
(use! eldoc-cmake
: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")
(use! c++-ts-mode
"C++ setup. We're using treesitter version of c++ mode."
:mode ("\\.h\\'" . c++-ts-mode)
:mode ("\\.hpp\\'" . c++-ts-mode)
:mode ("\\.cpp\\'" . c++-ts-mode)
:hook ((c++-ts-mode-hook . fg42/ls-run)
(c++-ts-mode-hook . fg42/cpp-autocomplete))
)
(add-hook 'c++-ts-mode-hook (setq-local company-backends
'((company-dabbrev company-ispell :separate)
company-files))
(lambda ()
(require 'company-capf)
(require 'company-box)
(setq company-backends
'((company-capf
company-keywords)))))
(provide 'fg42/langs/cpp)
;;; cpp.el ends here

View File

@ -1 +0,0 @@
lxsameer@majin.3221106:1710087423

View File

@ -21,12 +21,27 @@
;; ;;
;;; Commentary: ;;; Commentary:
;;; Code: ;;; Code:
(require 'fpkg) (eval-when-compile
(require 'fg42/utils) (require 'fpkg))
(require 'fg42/language-servers)
(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"
"--malloc-trim"
)
"Arguments to pass to clangd.")
(use! cmake-ts-mode
"Enable cmake-ts-mode instead of the non-TS version.")
;; (use! cmake-ts-mode)
(use! eldoc-cmake (use! eldoc-cmake
"ElDoc and cmake integration"
:hook (cmake-ts-mode . eldoc-cmake-enable)) :hook (cmake-ts-mode . eldoc-cmake-enable))
@ -35,29 +50,36 @@
https://github.com/ninja-build/ninja/blob/master/misc/ninja-mode.el") https://github.com/ninja-build/ninja/blob/master/misc/ninja-mode.el")
(use! c++-ts-mode (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)))
(use! c-ts-mode
"C++ setup. We're using treesitter version of c++ mode." "C++ setup. We're using treesitter version of c++ mode."
:mode ("\\.h\\'" . c++-ts-mode) :init
:mode ("\\.hpp\\'" . c++-ts-mode) ;; Remap the standard C/C++ modes
:mode ("\\.cpp\\'" . c++-ts-mode) (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-hook . fg42/ls-run) :config
(c++-ts-mode-hook . fg42/cpp-autocomplete)) ;; Set the default lang server for C/C++ to clangd
) (with-eval-after-load 'eglot
(add-to-list
'eglot-server-programs
`(c-mode c++-mode c-ts-mode c++-ts-mode . ("clangd" ,@fg42/clangd-args))))
:hook
(c++-ts-mode . eglot-ensure)
(c++-ts-mode . company-mode)
(c++-ts-mode . fg42/c-ts-mode-setup)
(c++-ts-mode . flyspell-prog-mode))
(add-hook 'c++-ts-mode-hook (setq-local company-backends
'((company-dabbrev company-ispell :separate)
company-files))
(lambda ()
(require 'company-capf)
(require 'company-box)
(setq company-backends
'((company-capf
company-keywords)))))
(provide 'fg42/langs/cpp) (provide 'fg42/langs/cpp)
;;; cpp.el ends here ;;; cpp.el ends here

View File

@ -40,6 +40,7 @@
vazir-fonts, vazir-fonts,
fira-code, fira-code,
nerdfonts, nerdfonts,
noto-fonts,
gcc, gcc,
ltex-ls, ltex-ls,
bash, bash,
@ -108,8 +109,10 @@ in stdenv.mkDerivation (final: rec{
LISPDIR=$out/share/fg42/ LISPDIR=$out/share/fg42/
mkdir -p $out/bin mkdir -p $out/bin
install -d $LISPDIR install -d $LISPDIR
cp -rv ${src}/lisp/ $LISPDIR cp -rv ${src}/lisp/ $LISPDIR
cp -rv ${src}/share $out/ cp -rv ${src}/share $out/
cp -rv ${src}/snippets $LISPDIR/snippets
runHook preBuild runHook preBuild
@ -172,6 +175,7 @@ in stdenv.mkDerivation (final: rec{
${vazir-fonts} ${vazir-fonts}
${fira-code} ${fira-code}
${nerdfonts} ${nerdfonts}
${noto-fonts}
${lib.strings.concatLines paths} ${lib.strings.concatLines paths}
EOF EOF