From 107ed151e900cce76747d8c1135c874aff63050f Mon Sep 17 00:00:00 2001 From: Justin Burkett Date: Mon, 23 Sep 2019 10:37:08 -0400 Subject: [PATCH] Fix loading of evil-collection-X from subdirs Create autoloads for each of the setup functions in evil-collection. Add evil-collection-require, which is a version of require that knows where the evil-collection files live. Use evil-collection-require to fix header in evil-collection-woman. Update readme to reflect the fact that it's no longer necessary to load the evil-collection-X file to run evil-collection-X-setup --- evil-collection.el | 34 ++++++++++++++++++++++++---- modes/woman/evil-collection-woman.el | 2 +- readme.org | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/evil-collection.el b/evil-collection.el index fe7bf53..219d819 100644 --- a/evil-collection.el +++ b/evil-collection.el @@ -110,7 +110,7 @@ through removing their entry from `evil-collection-mode-list'." :type 'boolean :group 'evil-collection) -(defcustom evil-collection-mode-list +(defvar evil-collection--supported-modes `(2048-game ag alchemist @@ -240,6 +240,19 @@ through removing their entry from `evil-collection-mode-list'." xref youtube-dl (ztree ztree-diff)) + "List of modes supported by evil-collection. Elements are +either target mode symbols or lists which `car' is the mode +symbol and `cdr' the packages to register.") + +(dolist (mode evil-collection--supported-modes) + (let ((ec-mode-name (if (listp mode) (car mode) mode))) + (autoload + (intern (format "evil-collection-%s-setup" ec-mode-name)) + (expand-file-name + (format "modes/%s/evil-collection-%s" ec-mode-name ec-mode-name) + evil-collection-base-dir)))) + +(defcustom evil-collection-mode-list evil-collection--supported-modes "The list of modes which will be evilified by `evil-collection-init'. Elements are either target mode symbols or lists which `car' is the mode symbol and `cdr' the packages to register. @@ -498,6 +511,20 @@ should consist of key swaps (e.g. \"a\" \"b\" is equivalent to \"a\" \"b\" \"b\" collect replacement and collect key)) `(evil-collection-translate-key ,states ,keymaps ,@args)) +;;;###autoload +(defun evil-collection-require (mode &optional noerror) + "Require the evil-collection-MODE file, but do not activate it. + +MODE should be a symbol. This requires the evil-collection-MODE +feature without needing to manipulate `load-path'. NOERROR is +forwarded to `require'." + (let* ((mode-name (symbol-name mode)) + (feature (intern (format "evil-collection-%s" mode-name))) + (file (expand-file-name + (format "modes/%s/evil-collection-%s" mode-name mode-name) + evil-collection-base-dir))) + (require feature file noerror))) + ;;;###autoload (defun evil-collection-init (&optional modes) "Register the Evil bindings for all modes in `evil-collection-mode-list'. @@ -506,7 +533,6 @@ Alternatively, you may register select bindings manually, for instance: (with-eval-after-load 'calendar - (require 'evil-collection-calendar) (evil-collection-calendar-setup)) If MODES is specified (as either one mode or a list of modes), use those modes @@ -523,9 +549,7 @@ instead of the modes in `evil-collection-mode-list'." reqs (cdr mode))) (dolist (req reqs) (with-eval-after-load req - (load (expand-file-name (format "modes/%s/evil-collection-%s" m m) - evil-collection-base-dir) - nil t) + (evil-collection-require m) (funcall (intern (concat "evil-collection-" (symbol-name m) "-setup"))) (let ((mode-keymaps diff --git a/modes/woman/evil-collection-woman.el b/modes/woman/evil-collection-woman.el index 8759292..5cdccd2 100644 --- a/modes/woman/evil-collection-woman.el +++ b/modes/woman/evil-collection-woman.el @@ -28,7 +28,7 @@ ;;; Code: (require 'evil-collection) -(require 'evil-collection-man) ; WoMan's keymap inherits from Man. +(evil-collection-require 'man) (require 'woman) (defconst evil-collection-woman-maps '(woman-mode-map)) diff --git a/readme.org b/readme.org index 83ad5f8..2d683c6 100644 --- a/readme.org +++ b/readme.org @@ -41,7 +41,7 @@ more. or mode-by-mode, for instance: - : (with-eval-after-load 'calendar (require 'evil-collection-calendar) (evil-collection-calendar-setup)) + : (with-eval-after-load 'calendar (evil-collection-calendar-setup)) or by providing an argument to ~evil-collection-init~: