Skip to content

Commit

Permalink
Make location and optional keyword parmeter for exordium-require
Browse files Browse the repository at this point in the history
  • Loading branch information
pkryger committed Dec 8, 2024
1 parent a3ede08 commit b3f56f9
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 78 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ Modules can be individually commented out if needed:
;; Themes
;; Note: use "export TERM=xterm-256color" for emacs -nw
(setq custom-theme-directory exordium-themes-dir)
(exordium-require 'init-progress-bar nil)
(exordium-require 'init-progress-bar)
(when exordium-nw
(set-face-background 'highlight nil))
Expand Down
6 changes: 3 additions & 3 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ after it's been byte compiled."
;; Themes
;; Note: use "export TERM=xterm-256color" for emacs -nw
(setq custom-theme-directory exordium-themes-dir)
(exordium-require 'init-progress-bar nil)
(exordium-require 'init-progress-bar)

(when exordium-nw
(set-face-background 'highlight nil))
Expand Down Expand Up @@ -454,8 +454,8 @@ after it's been byte compiled."
(exordium-require 'init-gdb)

;; RTags
(exordium-require 'init-rtags nil
:functions (rtags-auto-complete))
(exordium-require 'init-rtags
:functions (rtags-auto-complete))
(when (and (eq exordium-complete-mode :auto-complete)
exordium-rtags-auto-complete)
(rtags-auto-complete))
Expand Down
2 changes: 1 addition & 1 deletion modules/init-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
:config
(exec-path-from-shell-initialize)))

(exordium-require 'clojure "extensions")
(exordium-require 'clojure :location "extensions")

;;; Hippie expand - don't try to complete with file names
(setq hippie-expand-try-functions-list
Expand Down
55 changes: 32 additions & 23 deletions modules/init-require.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
;; and `defvars' forms, should the compiler not infer them from the loaded
;; module. For example, the folllowing expression:
;;
;; (exordium-require 'init-foo "foo-dir"
;; (exordium-require 'init-foo
;; :location "foo-dir"
;; :functions (foo-simple (foo-args . (arg1 arg2)))
;; :defines (foo-var))
;;
Expand Down Expand Up @@ -187,32 +188,37 @@ for `exordium-require', which see."
(load file nomessage))))

;;;###autoload
(defmacro exordium-require (feature &optional location &rest declarations)
"If FEATURE is not already loaded, load it from Exordium LOCATION.
Like `require', but concatenate LOCATION, that is relative in
Exordium project, with printname of FEATURE as FILE passed to
`load' (which see). Default LOCATION is \"modules\".
(defmacro exordium-require (feature &rest options)
"If FEATURE is not already loaded, load it from Exordium modules directory.
OPTIONS is a plist, with up to three properties: `:location',
`:functions', and `:defines'.
To suppress compiler warnings use DECLARATIONS which is a plist
with two properties: `:functions' and `:defines'. The `:functions'
is a list where each element either is a function FN or is a
cons (FN ARGLIST) that are passed to `declare-function' (which
see). Note that `declare-function' forms has FILE argument set
to nil. The `:defines' is a list where each element is a SYMBOL
that is passed to `defvar' (which see).
Like `require', but concatenate :location, that is relative in
Exordium project, with printname of FEATURE as a FILE argument passed to
`load' (which see). Default :location is \"modules\".
To suppress compiler warnings use `:functions' and `:defines'
keywords in OPTIONS argument. The `:functions' is a list where
each element either is a function FN or is a cons (FN ARGLIST)
that are passed to `declare-function' (which see). Note that
`declare-function' forms has FILE argument set to nil. The
`:defines' is a list where each element is a SYMBOL that is
passed to `defvar' (which see).
Please see Commentary in init-require.el for more details."
(declare (debug t) (indent 2))
(declare (debug t) (indent 1))
(when-let* (((if (and (consp feature) (eq #'quote (car feature))
(consp (cdr feature)) (symbolp (cadr feature))
(not (keywordp (cadr feature)))
(not (cddr feature)))
;; 'symbol is a (cons #'quote (cons symbol nil))
t (error "Wrong type argument: symbolp, %S" feature)))
;; 'symbol is a (cons #'quote (cons symbol nil))
t (error "Wrong type argument: symbolp, %S" feature)))

((if (or (stringp location) (and (symbolp location) (not location)))
;; "string" is a string, nil is a symbol
t (error "Wrong type argument: stringp or nil, %S" location)))
((let ((location (plist-get options :location)))
(if (or (and (stringp location) (< 0 (length location)))
(and (symbolp location) (not location)))
;; "string" is a string, nil is a symbol
t (error "Wrong type argument: stringp or nil, %S" location))))
(declare-forms
(or (append
(mapcar (lambda (fn)
Expand All @@ -232,13 +238,13 @@ Please see Commentary in init-require.el for more details."
(error
"Wrong type argument: symbolp or (and (consp) (symbolp car)), %S"
fn))))
(plist-get declarations :functions))
(plist-get options :functions))
(mapcar (lambda (var)
(if (and (symbolp var) (not (memq var '(nil t quote)))
(not (string-prefix-p ":" (symbol-name var))))
`(defvar ,var)
(error "Wrong type argument: symbolp, %S" var)))
(plist-get declarations :defines)))
(plist-get options :defines)))
t)))
(append
`(progn
Expand All @@ -265,7 +271,9 @@ Please see Commentary in init-require.el for more details."
(with-demoted-errors
,(format "(exordium-require) Cannot load %s: %%S" feature)
(unless (featurep ,feature)
(exordium--require-load ,feature ,location t))))
(exordium--require-load ,feature
,(plist-get options :location)
t))))
,@(when (listp declare-forms)
declare-forms))
,@(when (bound-and-true-p use-package-compute-statistics)
Expand All @@ -284,7 +292,8 @@ Please see Commentary in init-require.el for more details."
"Recursive `exordium-require' for feature `%s', require-nesting-list: %s"
,feature exordium--require-nesting-list)
(push ,feature exordium--require-nesting-list)
(exordium--require-load ,feature ,location)
(exordium--require-load ,feature
,(plist-get options :location))
(if (featurep ,feature)
,feature
(if-let* ((file (caar load-history)))
Expand Down
59 changes: 21 additions & 38 deletions modules/init-require.t.el
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ Recursion is in order: FORM, (car FORM), (cdr FORM)."
;; delay `exordium-require' macro expansion to test execution
(ignore-errors (unload-feature 'init-require.t-dummy))
(should (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy "modules"))))
(eval '(exordium-require 'init-require.t-dummy
:location "modules"))))
(should (featurep 'init-require.t-dummy)))

(ert-deftest exordium-require-with-location-and-declarations ()
Expand All @@ -116,7 +117,7 @@ Recursion is in order: FORM, (car FORM), (cdr FORM)."
(eq 'init-require.t-dummy
(eval '(exordium-require
'init-require.t-dummy
"modules"
:location "modules"
:functions (require.t-dummy-1
(require.t-dummy-2 . (arg1 arg2)))
:defines (require.t-dummy-3)))))
Expand All @@ -142,7 +143,8 @@ Recursion is in order: FORM, (car FORM), (cdr FORM)."
(ignore-errors (unload-feature 'init-require.t-dummy))
(let* ((debug-on-error nil))
(should-not (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy "themes")))))
(eval '(exordium-require 'init-require.t-dummy
:location "themes")))))
(should-not (featurep 'init-require.t-dummy)))

(ert-deftest exordium-require-signals-error-with-non-existing-location-while-debug ()
Expand All @@ -168,126 +170,107 @@ Recursion is in order: FORM, (car FORM), (cdr FORM)."
init-require.t-dummy)))))

(ert-deftest exordium-require-signals-error-with-wrong-location-type ()
(should-error (eval '(exordium-require 'init-require.t-dummy t)))
(should-error (eval '(exordium-require 'init-require.t-dummy 42)))
(should-error (eval '(exordium-require 'init-require.t-dummy ? )))
(should-error (eval '(exordium-require 'init-require.t-dummy 'modules)))
(should-error (eval '(exordium-require 'init-require.t-dummy :modules)))
(should-error (eval '(exordium-require 'init-require.t-dummy modules)))
(should-error (eval '(exordium-require
'init-require.t-dummy
(if t "modules" "themes")))))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location "")))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location t)))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location 42)))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location ? )))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location 'modules)))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location :modules)))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location modules)))
(should-error (eval '(exordium-require 'init-require.t-dummy
:location (if t "modules" "themes")))))


(ert-deftest exordium-require-signals-error-with-wrong-defines-type ()
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines (nil))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines (t))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines (42))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines ("var"))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines ('var))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines (:var))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines ((if t 'var 'var))))))

(ert-deftest exordium-require-signals-error-with-wrong-functions-type ()
;; invalid function without args
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (nil))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (t))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (42))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ("fn"))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ('fn))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (:fn))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((nil . (arg))))))
;; invalid function with valid arg
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((t . (arg))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((42 . (arg))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (("fn" . (arg))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (('fn . (arg))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((:fn . (arg))))))
;; valid function with invalid arg
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((fn . (nil))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((fn . (t))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((fn . (42))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((fn . ("arg"))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((fn . ('arg))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((fn . (:arg))))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ((fn . '(arg)))))))

(provide 'init-require.t)
Expand Down
2 changes: 1 addition & 1 deletion themes/atom-one-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-atom-one "themes" define-atom-one-theme)
(exordium-require 'color-theme-atom-one :location "themes")

(define-atom-one-theme)

Expand Down
2 changes: 1 addition & 1 deletion themes/github-modern-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-github-modern "themes" define-github-modern-theme)
(exordium-require 'color-theme-github-modern :location "themes")

(define-github-modern-theme)

Expand Down
2 changes: 1 addition & 1 deletion themes/material-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-material "themes" define-material-theme)
(exordium-require 'color-theme-material :location "themes")

(define-material-theme)

Expand Down
2 changes: 1 addition & 1 deletion themes/monokai-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-monokai "themes" define-monokai-theme)
(exordium-require 'color-theme-monokai :location "themes")

(define-monokai-theme)

Expand Down
2 changes: 1 addition & 1 deletion themes/solarized-dark-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-solarized "themes")
(exordium-require 'color-theme-solarized :location "themes")

(define-solarized-theme dark)

Expand Down
2 changes: 1 addition & 1 deletion themes/solarized-light-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-solarized "themes")
(exordium-require 'color-theme-solarized :location "themes")

(define-solarized-theme light)

Expand Down
2 changes: 1 addition & 1 deletion themes/tomorrow-day-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-tomorrow "themes")
(exordium-require 'color-theme-tomorrow :location "themes")

(define-tomorrow-theme day)

Expand Down
2 changes: 1 addition & 1 deletion themes/tomorrow-night-blue-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-tomorrow "themes")
(exordium-require 'color-theme-tomorrow :location "themes")

(define-tomorrow-theme night-blue)

Expand Down
2 changes: 1 addition & 1 deletion themes/tomorrow-night-bright-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))

(exordium-require 'color-theme-tomorrow "themes")
(exordium-require 'color-theme-tomorrow :location "themes")

(define-tomorrow-theme night-bright)

Expand Down
Loading

0 comments on commit b3f56f9

Please sign in to comment.