Skip to content

Commit

Permalink
feat(cape): helpers to make use of cape-super-capf
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jul 1, 2023
1 parent b84b2e0 commit ac587e0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 5 deletions.
25 changes: 20 additions & 5 deletions core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,26 @@ Unmount eCryptfs' private directory." t)

(register-definition-prefixes "me-backports-29" '("loaddefs-generate" "messages-buffer-name" "native-compile-prune-cache" "scratch-buffer" "setopt" "with-memoization"))


;;; Generated autoloads from ../modules/extras/me-cape-super-capf.el

(defvar +cape-global-capes '(tempel-complete :completion cape-dict) "\
A list of global capes to be available at all times.
The key :completion is used to specify where completion candidates should be
placed, otherwise they come first.")
(custom-autoload '+cape-global-capes "../modules/extras/me-cape-super-capf" t)
(defvar +cape-hosts '(eglot-completion-at-point lsp-completion-at-point elisp-completion-at-point tags-completion-at-point-function) "\
A prioritised list of host capfs to create a super cape onto from
`+cape-global-capes'.")
(custom-autoload '+cape-hosts "../modules/extras/me-cape-super-capf" t)
(autoload '+cape-load-capes "../modules/extras/me-cape-super-capf" "\
Load all capes specified in `+cape-global-capes'." t)
(autoload '+toggle-cape-auto-super-capf "../modules/extras/me-cape-super-capf" "\
Enable auto generating Cape's super Capf.
This depends on `+cape-hosts' and `+cape-global-capes'.
(fn &optional DISABLE)" t)


;;; Generated autoloads from me-core-ui.el

Expand Down Expand Up @@ -792,11 +812,6 @@ Register dictionaries for `LANGS` to spell-fu's multi-dict.

(register-definition-prefixes "me-splash" '("minemacs-splash"))


;;; Generated autoloads from ../modules/extras/me-super-cape.el

(register-definition-prefixes "../modules/extras/me-super-cape" '("+cape-"))


;;; Generated autoloads from me-vars.el

Expand Down
67 changes: 67 additions & 0 deletions modules/extras/me-cape-super-capf.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
;;; me-cape-super-capf.el --- Combine multiple capes -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 Abdelhak Bougouffa

;; Author: Abdelhak Bougouffa (concat "abougouffa" "@" "fedora" "project" "." "org")

;;; Commentary:
;; Make use of `cape''s super Capf functionality. Taken from:
;; https://git.sr.ht/~gagbo/doom-config/tree/master/item/modules/completion/corfu/config.el

;;; Code:

(defgroup minemacs-completion nil
"Completion related stuff."
:group 'minemacs)

;;;###autoload
(defcustom +cape-global-capes
'(tempel-complete :completion cape-dict)
"A list of global capes to be available at all times.
The key :completion is used to specify where completion candidates should be
placed, otherwise they come first."
:group 'minemacs-completion
:type '(repeat symbol))

;;;###autoload
(defcustom +cape-hosts
'(eglot-completion-at-point
lsp-completion-at-point
elisp-completion-at-point
tags-completion-at-point-function)
"A prioritised list of host capfs to create a super cape onto from
`+cape-global-capes'."
:group 'minemacs-completion
:type '(repeat symbol))

;;;###autoload
(defun +cape-load-capes ()
"Load all capes specified in `+cape-global-capes'."
(interactive)
(when-let ((host (cl-intersection +cape-hosts completion-at-point-functions)))
(setq-local
completion-at-point-functions
(cl-substitute
(apply
#'cape-super-capf
(cl-substitute
(car host)
:completion
(append (cl-pushnew :completion +cape-global-capes))))
(car host)
completion-at-point-functions))))

;;;###autoload
(defun +toggle-cape-auto-super-capf (&optional disable)
"Enable auto generating Cape's super Capf.
This depends on `+cape-hosts' and `+cape-global-capes'."
(interactive)
(let ((enabled (get '+cape-auto-super-capf 'enabled)))
(dolist (hook '(lsp-mode-hook eglot-managed-mode-hook change-major-mode-hook))
(apply (if (or enabled disable) #'remove-hook #'add-hook) (list hook #'+cape-load-capes))
(put '+cape-auto-super-capf 'enabled (not (or enabled disable))))))


(provide 'me-cape-super-capf)

;;; me-cape-super-capf.el ends here

0 comments on commit ac587e0

Please sign in to comment.