forked from FG42/FG42
1
0
Fork 0

Add corfu as the main completion framework

This commit is contained in:
Sameer Rahmani 2024-04-30 10:58:18 +01:00
parent a9b7a40473
commit a163cdc33e
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
7 changed files with 136 additions and 91 deletions

View File

@ -58,20 +58,6 @@
}; };
fg42 = app.drv; 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 { run-test-wm = pkgs.writeShellApplication {
name = "run-test-wm"; name = "run-test-wm";
@ -103,6 +89,7 @@
type = "app"; type = "app";
program = "${test-x}/bin/test-x"; program = "${test-x}/bin/test-x";
}; };
apps.default = { apps.default = {
type = "app"; type = "app";
program = "${fg42}/bin/fg42"; program = "${fg42}/bin/fg42";

View File

@ -1,71 +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: 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)
(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

View File

@ -22,30 +22,45 @@
{ lib, config, pkgs, makeFG42Drv, ... }: { lib, config, pkgs, makeFG42Drv, ... }:
with lib; with lib;
let let
cfg = config.fg42.auto-complete; cfg = config.fg42.completion;
deps = deps =
(with pkgs.emacsPackages; [ (with pkgs.emacsPackages;
optionals (cfg.backend == "corfu") [
corfu
cape
] ++ optionals (cfg.backend == "company") [
company company
company-box company-box
]); ]);
drv = makeFG42Drv { drv = makeFG42Drv {
pname = "autocomplete"; pname = "completion";
version = config.fg42.version; version = config.fg42.version;
buildInputs = deps; buildInputs = deps;
src = ./.; src = ./.;
}; };
backendDesc = ''
The backend to use for the completion. (default corfu)
'';
in 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 { config = mkIf cfg.enable {
fg42.elispPackages = [ drv ] ++ deps; fg42.elispPackages = [ drv ] ++ deps;
fg42.requires = [ drv.pname ]; fg42.requires = [ drv.pname ];
fg42.vars = [ fg42.vars = [
(defVar "auto-complete" cfg.enable "Auto completion for FG42.") (defVar "completion" cfg.enable "Completion for FG42.")
(defVar "completion-backend" cfg.backend backendDesc)
]; ];
}; };
} }

View File

@ -0,0 +1,92 @@
;;; 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)
(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

View File

@ -28,7 +28,7 @@ let
./minibuffer-vertico ./minibuffer-vertico
./graphics ./graphics
./noether ./noether
./autocomplete ./completion
./language-server ./language-server
./nix ./nix
./c-family ./c-family

View File

@ -242,6 +242,12 @@ contextual information."
(setq tooltip-use-echo-area t) (setq tooltip-use-echo-area t)
(setq x-gtk-use-system-tooltips nil) (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 ;; Global configurations
(tool-bar-mode -1) (tool-bar-mode -1)
(tooltip-mode nil) (tooltip-mode nil)

View File

@ -37,6 +37,22 @@
`,default))) `,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) (defmacro with-config (name &rest body)
"Run the BODY only if the config NAME is set to t." "Run the BODY only if the config NAME is set to t."
(declare (indent defun)) (declare (indent defun))