Skip to content

Commit

Permalink
optional load compiler libraries on activate to speed up Emacs start
Browse files Browse the repository at this point in the history
  • Loading branch information
plandes committed Dec 4, 2023
1 parent 5bec5ed commit 47c5667
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
18 changes: 12 additions & 6 deletions flex-compile-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@
(require 'dash)
(require 'flex-compile-manage)

(config-manage-declare-functions
cider-repl-return cider-connect
nrepl-dict-get nrepl-sync-request:eval
cider-current-connection cider-current-session cider-current-ns
cider-load-file cider-last-sexp cider-quit cider-jack-in)
(declare-function cider-repl-return "cider")
(declare-function cider-connect "cider")
(declare-function cider-current-connection "cider")
(declare-function cider-current-session "cider")
(declare-function cider-current-ns "cider")
(declare-function cider-load-file "cider")
(declare-function cider-last-sexp "cider")
(declare-function cider-quit "cider")
(declare-function cider-jack-in "cider")
(declare-function nrepl-dict-get "nrepl-dict")
(declare-function nrepl-sync-request:eval "nrepl-client")

(config-manage-declare-variables
cider-repl-display-in-current-window)
Expand Down Expand Up @@ -132,7 +138,7 @@ This also sets `cider-repl-display-in-current-window' to nil"
"Send the contents of FILE to the Cider REPL buffer of THIS compiler."
(ignore this)
(save-excursion
(apply #'set-buffer (list (find-file-noselect file)))
(set-buffer (list (find-file-noselect file)))
(cider-load-file file)))

(cl-defmethod flex-compiler-eval-initial-at-point
Expand Down
4 changes: 3 additions & 1 deletion flex-compile-ess.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

(require 'flex-compile-manage)

(config-manage-declare-functions ess-eval-region R)
(declare-function R "ess")
(declare-function ess-eval-region "ess")

(defclass ess-flex-compiler (repl-flex-compiler)
()
Expand All @@ -55,6 +56,7 @@ This is a REPL based compiler to evaluate R code with
(cl-defmethod flex-compiler-load-libraries ((this ess-flex-compiler))
"Load library `ess-site' for THIS compielr."
(ignore this)
(require 'ess)
(require 'ess-site))

(cl-defmethod flex-compiler-repl-start ((this ess-flex-compiler))
Expand Down
16 changes: 14 additions & 2 deletions flex-compile-manage.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
(require 'flex-compile-single-buffer)
(require 'flex-compile-repl)

;;; compiler shared configuration
(defcustom flex-compile-manage-load-libraries-entry 'activate
"When to load the compiler's libraries.
This invokes a method that `require's all the libraries needed for the compiler
to run."
:type '(choice (const :tag "When the compiler is activated" activate)
(const :tag "When the compiler is accessed" assert-ready))
:group 'flex-compile)

;;; compiler manager/orchestration
(defclass flex-compile-manager (config-manager config-persistable)
()
Expand Down Expand Up @@ -128,13 +138,16 @@ THIS is the object instance."
CRITERIA, see the `config-manager’ method ‘config-manager-activate’."
(let ((compiler (cl-call-next-method this criteria)))
(message "Active compiler is now %s" (config-entry-name compiler))
(when (eq flex-compile-manage-load-libraries-entry 'activate)
(flex-compiler-load-libraries compiler))
compiler))

(cl-defmethod flex-compile-manager-assert-ready ((this flex-compile-manager))
"Make sure the active/selected compiler is ready and libraries loaded.
THIS is the object instance."
(let ((active (flex-compile-manager-active this)))
(flex-compiler-load-libraries active)))
(when (eq flex-compile-manage-load-libraries-entry 'assert-ready)
(flex-compiler-load-libraries active))))

(cl-defmethod config-manager-remove-entry ((this flex-compile-manager) entry)
"Disallow ENTRY deletion since it is nonsensical for this implementation.
Expand All @@ -153,7 +166,6 @@ THIS is the object instance."
funcall
(flex-compile-manager-register this)))))


;; library configuration
(defvar flex-compile-manage-inst
(flex-compile-manager :object-name "compiler")
Expand Down
2 changes: 0 additions & 2 deletions flex-compile-org-export.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

(require 'flex-compile-manage)



(config-manage-declare-functions
org-open-file
org-twbs-export-to-html)
Expand Down
19 changes: 9 additions & 10 deletions flex-compile-python.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@
;;; Code:

(require 'subr-x)
(require 'python)
(require 'flex-compile-manage)
(require 'flex-compile-repl)

(config-manage-declare-functions
python-nav-backward-statement
python-nav-forward-statement
python-shell-calculate-command
python-shell-completion-native-setup
python-shell-parse-command
python-shell-send-buffer
python-shell-send-string
run-python)
(declare-function python-nav-backward-statement "python")
(declare-function python-nav-forward-statement "python")
(declare-function python-shell-calculate-command "python")
(declare-function python-shell-completion-native-setup "python")
(declare-function python-shell-parse-command "python")
(declare-function python-shell-send-buffer "python")
(declare-function python-shell-send-string "python")
(declare-function run-python "python")

(config-manage-declare-variables
python-shell-completion-native-enable)

Expand Down

0 comments on commit 47c5667

Please sign in to comment.