;;; 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) (require 'fg42/config) (require 'cl-lib)) ;; Language Servers and friends (use! eglot "Eglot is a minimalistic yet powerful LSP replacement shipped with Emacs." :commands eglot-ensure) (use! eldoc-box "View eldoc stuff in a frame." :commands eldoc-box-hover-mode :hook (eldoc-mode . eldoc-box-hover-mode)) (use! markdown-mode "Renders markdown in Emacs." :init (setq markdown-command "multimarkdown")) ;;;###autoload (cl-defgeneric fg42/setup-lang-server-for (mode) "Setup a language server for the given MODE. Other Nix modules can specialize this function to alter the default behaviour. For example for C++: \(cl-defmethod fg42/setup-lang-server-for ((mode (eql c-ts-mode))) ;; Do whatever you want here ) The default implementation sets up Eglot." (eglot-ensure)) ;;;###autoload (defun fg42/ensure-lang-server () "Setup the appropriate language server for the current buffer. This function is supposed to be run using a hook. For example: \(add-hook 'foo-mode-hook #'fg42/enruse-lang-server) 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) (fg42/setup-lang-server-for major-mode)) ;;;###autoload (cl-defgeneric fg42/format-buffer-for (mode) "Format the current buffer that managed by major MODE. By default if the buffer is managed by `eglot' it will use `eglot-format-buffer' to format the buffer. Other Nix modules can specialize this function to alter the default behaviour. For example for C++: \(cl-defmethod fg42/format-buffer-for ((mode (eql c-ts-mode))) ;; Do whatever you want here ) The default implementation sets up Eglot." (when(and (functionp 'eglot-managed-p) (eglot-managed-p)) (eglot-format-buffer))) ;;;###autoload (defun fg42/lang-server-format () "Format the current buffer using the current language server. This function is supposed to be run as a hook handler." (interactive) (fg42/format-buffer-for major-mode)) ;; Setup the language server and the formatter ;; On emacs startup (add-hook 'emacs-startup-hook (lambda () (add-hook 'prog-mode-hook #'fg42/ensure-lang-server) (add-hook 'before-save-hook #'fg42/lang-server-format))) (provide 'fg42/language-server) ;;; language-server.el ends here