From a163cdc33eddd82f474c245ce1b81c8baef05a99 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Tue, 30 Apr 2024 10:58:18 +0100 Subject: [PATCH] Add corfu as the main completion framework --- flake.nix | 15 +-- .../autocomplete/lisp/fg42/autocomplete.el | 71 -------------- .../{autocomplete => completion}/default.nix | 25 ++++- .../completion/lisp/fg42/completion.el | 92 +++++++++++++++++++ nix/modules/default.nix | 2 +- nix/modules/editor/lisp/fg42/editor.el | 6 ++ nix/modules/unit/lisp/fg42/config.el | 16 ++++ 7 files changed, 136 insertions(+), 91 deletions(-) delete mode 100644 nix/modules/autocomplete/lisp/fg42/autocomplete.el rename nix/modules/{autocomplete => completion}/default.nix (67%) create mode 100644 nix/modules/completion/lisp/fg42/completion.el diff --git a/flake.nix b/flake.nix index 268e33d..bf1d69e 100644 --- a/flake.nix +++ b/flake.nix @@ -58,20 +58,6 @@ }; fg42 = app.drv; - # fg42-wm = pkgs.callPackage ./nix/fg42 - # { - # inherit nixpkgs; - # modules = [ - # ./nix/modules/editor - # ./nix/modules/elisp - # ./nix/modules/graphics - # ./nix/modules/noether - # ./nix/modules/wm - # ]; - # extraPackages = { - # noether = inputs.noether.outputs.packages.${system}.default; - # }; - # }.drv; run-test-wm = pkgs.writeShellApplication { name = "run-test-wm"; @@ -103,6 +89,7 @@ type = "app"; program = "${test-x}/bin/test-x"; }; + apps.default = { type = "app"; program = "${fg42}/bin/fg42"; diff --git a/nix/modules/autocomplete/lisp/fg42/autocomplete.el b/nix/modules/autocomplete/lisp/fg42/autocomplete.el deleted file mode 100644 index 2a8de4f..0000000 --- a/nix/modules/autocomplete/lisp/fg42/autocomplete.el +++ /dev/null @@ -1,71 +0,0 @@ -;;; 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)) - - -(use! company - "Company is a modular text completion framework for GNU Emacs." - :hook (emacs-startup . 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 - (setq-default company-backends - '(company-capf (company-keywords :separate) company-files)) - (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)) - - -;;;###autoload -(defun fg42/autocomplete () - "Initialize FG42's auto complete. -This function is meant to be used with hooks." - ;; Why? because if we end up with more auto completion alternatives - ;; to company mode, then we can setup them here rather than walking - ;; around fixing downstream modules. - (interactive) - (company-mode t)) - - -(provide 'fg42/autocomplete) -;;; autocomplete.el ends here diff --git a/nix/modules/autocomplete/default.nix b/nix/modules/completion/default.nix similarity index 67% rename from nix/modules/autocomplete/default.nix rename to nix/modules/completion/default.nix index 4148d9f..45c8d11 100644 --- a/nix/modules/autocomplete/default.nix +++ b/nix/modules/completion/default.nix @@ -22,30 +22,45 @@ { lib, config, pkgs, makeFG42Drv, ... }: with lib; let - cfg = config.fg42.auto-complete; + cfg = config.fg42.completion; deps = - (with pkgs.emacsPackages; [ + (with pkgs.emacsPackages; + optionals (cfg.backend == "corfu") [ + corfu + cape + ] ++ optionals (cfg.backend == "company") [ company company-box ]); drv = makeFG42Drv { - pname = "autocomplete"; + pname = "completion"; version = config.fg42.version; buildInputs = deps; src = ./.; }; + backendDesc = '' + The backend to use for the completion. (default corfu) + ''; in { - options.fg42.auto-complete.enable = mkAndEnableOption "auto-complete"; + options.fg42.completion = { + enable = mkAndEnableOption "completion"; + backend = mkOption { + type = types.str; + default = "corfu"; + description = backendDesc; + }; + }; config = mkIf cfg.enable { fg42.elispPackages = [ drv ] ++ deps; fg42.requires = [ drv.pname ]; fg42.vars = [ - (defVar "auto-complete" cfg.enable "Auto completion for FG42.") + (defVar "completion" cfg.enable "Completion for FG42.") + (defVar "completion-backend" cfg.backend backendDesc) ]; }; } diff --git a/nix/modules/completion/lisp/fg42/completion.el b/nix/modules/completion/lisp/fg42/completion.el new file mode 100644 index 0000000..ecda93a --- /dev/null +++ b/nix/modules/completion/lisp/fg42/completion.el @@ -0,0 +1,92 @@ +;;; 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)) + +(fg42/config-when "completion-backend" "company" + (use! company + "Company is a modular text completion framework for GNU Emacs." + :hook (emacs-startup . 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 + (setq-default company-backends + '(company-capf (company-keywords :separate) company-files)) + (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))) + + +(fg42/config-when "completion-backend" "corfu" + (use! corfu + "Corfu enhances in-buffer completion with a small completion popup. +The current candidates are shown in a popup below or above the point. The candidates +can be selected by moving up and down. Corfu is the minimalistic in-buffer completion +counterpart of the Vertico minibuffer UI." + :custom + (corfu-cycle t) ;; Enable cycling for `corfu-next/previous' + (corfu-auto t) ;; Enable auto completion + (corfu-separator ?\s) ;; Orderless field separator + (corfu-quit-at-boundary nil) ;; Never quit at completion boundary + ;; (corfu-quit-no-match nil) ;; Never quit, even if there is no match + (corfu-preview-current nil) ;; Disable current candidate preview + (corfu-preselect 'prompt) ;; Preselect the prompt + (corfu-on-exact-match nil) ;; Configure handling of exact matches + (corfu-scroll-margin 5) ;; Use scroll margin + :hook (emacs-startup . global-corfu-mode))) + + +;;;###autoload +(defun fg42/setup-completion () + "Initialize FG42's completion system. +This function is meant to be used with hooks." + ;; Why? because if we end up with more auto completion alternatives + ;; to corfu or company mode, then we can setup them here rather than walking + ;; around fixing downstream modules. + (interactive) + + (fg42/config-when "completion-backend" "company" + (company-mode t))) + + +(provide 'fg42/completion) +;;; completion.el ends here diff --git a/nix/modules/default.nix b/nix/modules/default.nix index 36e30e9..2efb381 100644 --- a/nix/modules/default.nix +++ b/nix/modules/default.nix @@ -28,7 +28,7 @@ let ./minibuffer-vertico ./graphics ./noether - ./autocomplete + ./completion ./language-server ./nix ./c-family diff --git a/nix/modules/editor/lisp/fg42/editor.el b/nix/modules/editor/lisp/fg42/editor.el index 72377fb..fc8ba5c 100644 --- a/nix/modules/editor/lisp/fg42/editor.el +++ b/nix/modules/editor/lisp/fg42/editor.el @@ -242,6 +242,12 @@ contextual information." (setq tooltip-use-echo-area t) (setq x-gtk-use-system-tooltips nil) + ;; Emacs 30 and newer: Disable Ispell completion function. + (setq text-mode-ispell-word-completion nil) + ;; Enable indentation+completion using the TAB key. + ;; `completion-at-point' is often bound to M-TAB. + (setq tab-always-indent 'complete) + ;; Global configurations (tool-bar-mode -1) (tooltip-mode nil) diff --git a/nix/modules/unit/lisp/fg42/config.el b/nix/modules/unit/lisp/fg42/config.el index 594f607..3883545 100644 --- a/nix/modules/unit/lisp/fg42/config.el +++ b/nix/modules/unit/lisp/fg42/config.el @@ -37,6 +37,22 @@ `,default))) +(defmacro fg42/config= (key value) + "Check whether config name KEY has the VALUE or not." + `(string= (fg42/config-get-or ,key) ,value)) + + +(defmacro fg42/config-when (key value &rest body) + "Run the BODY only if config KEY has the VALUE." + (declare (indent defun)) + (message ">> %s %s %s" key value (string= (fg42/config-get-or key) value)) + (if (fg42/config= key value) + `(progn + ,@body) + `(progn + (message "nooooo")))) + + (defmacro with-config (name &rest body) "Run the BODY only if the config NAME is set to t." (declare (indent defun))