mu-scm: add options, some tweaks
Add the (options) procedure + docs. Some internal tweaks / clean-ups.
This commit is contained in:
@ -23,6 +23,10 @@ It can either open a shell ("REPL") or run scripts.
|
|||||||
|
|
||||||
Using *mu scm*, you can script *mu*.
|
Using *mu scm*, you can script *mu*.
|
||||||
|
|
||||||
|
* SCM OPTIONS
|
||||||
|
|
||||||
|
#+include: "muhome.inc" :minlevel 2
|
||||||
|
|
||||||
#+include: "common-options.inc" :minlevel 1
|
#+include: "common-options.inc" :minlevel 1
|
||||||
|
|
||||||
#+include: "exit-code.inc" :minlevel 1
|
#+include: "exit-code.inc" :minlevel 1
|
||||||
|
|||||||
@ -674,7 +674,7 @@ AssocPairs<SubCommand, CommandInfo, Options::SubCommandNum> SubCommandInfos= {{
|
|||||||
"remove", "Remove message from file-system and database", sub_remove }
|
"remove", "Remove message from file-system and database", sub_remove }
|
||||||
},
|
},
|
||||||
{ SubCommand::Scm,
|
{ SubCommand::Scm,
|
||||||
{Category::None,
|
{Category::NeedsReadOnlyStore,
|
||||||
"scm", "Start Guile/Scheme shell",sub_scm}
|
"scm", "Start Guile/Scheme shell",sub_scm}
|
||||||
},
|
},
|
||||||
{ SubCommand::Script,
|
{ SubCommand::Script,
|
||||||
|
|||||||
@ -142,13 +142,13 @@ Mu::Scm::init_store(const Store& store)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
store_type = scm_make_foreign_object_type(
|
store_type = scm_make_foreign_object_type(
|
||||||
scm_from_utf8_symbol("store"),
|
make_symbol("store"),
|
||||||
scm_list_1 (scm_from_utf8_symbol("data")),
|
scm_list_1(make_symbol("data")),
|
||||||
{});// no finalizer
|
{});// no finalizer
|
||||||
|
|
||||||
default_store = scm_make_foreign_object_1(
|
default_store = scm_make_foreign_object_1(
|
||||||
store_type, const_cast<Store*>(&store));
|
store_type, const_cast<Store*>(&store));
|
||||||
scm_c_define("default-store-object", default_store);
|
scm_c_define("%default-store-object", default_store);
|
||||||
|
|
||||||
init_subrs();
|
init_subrs();
|
||||||
|
|
||||||
|
|||||||
@ -53,6 +53,15 @@
|
|||||||
|
|
||||||
(test-end "test-mfind"))
|
(test-end "test-mfind"))
|
||||||
|
|
||||||
|
|
||||||
|
(define (test-misc)
|
||||||
|
(let ((opts (options)))
|
||||||
|
(test-assert (>= (length opts) 4))
|
||||||
|
(test-equal (assoc-ref opts 'quiet) #f)
|
||||||
|
(test-equal (assoc-ref opts 'debug) #f)
|
||||||
|
(test-equal (assoc-ref opts 'verbose) #f)
|
||||||
|
(test-equal (assoc-ref opts 'muhome) #f)))
|
||||||
|
|
||||||
(define (test-helpers)
|
(define (test-helpers)
|
||||||
(test-begin "test-helpers")
|
(test-begin "test-helpers")
|
||||||
(test-equal 1750077792 (iso-date->time-t "2025-06-16T12:43:12"))
|
(test-equal 1750077792 (iso-date->time-t "2025-06-16T12:43:12"))
|
||||||
@ -70,6 +79,7 @@
|
|||||||
(test-basic)
|
(test-basic)
|
||||||
(test-basic-mfind)
|
(test-basic-mfind)
|
||||||
(test-mfind)
|
(test-mfind)
|
||||||
|
(test-misc)
|
||||||
(test-helpers)
|
(test-helpers)
|
||||||
|
|
||||||
(test-end "mu-scm-tests")
|
(test-end "mu-scm-tests")
|
||||||
|
|||||||
@ -37,26 +37,30 @@ static SCM mu_mod; // The mu module
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a plist for the relevant configuration items
|
* Create a plist for the relevant option items
|
||||||
*
|
*
|
||||||
* @param opts
|
* @param opts
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
init_config (const Options& opts)
|
init_options(const Options& opts)
|
||||||
{
|
{
|
||||||
scm_c_define("options",
|
SCM scm_opts = alist_add(SCM_EOL,
|
||||||
alist_add(
|
|
||||||
SCM_EOL,
|
|
||||||
make_symbol("mu-home"), opts.muhome,
|
|
||||||
make_symbol("verbose"), opts.verbose,
|
make_symbol("verbose"), opts.verbose,
|
||||||
make_symbol("debug"), opts.debug,
|
make_symbol("debug"), opts.debug,
|
||||||
make_symbol("quiet"), opts.quiet));
|
make_symbol("quiet"), opts.quiet);
|
||||||
|
|
||||||
|
if (opts.muhome.empty())
|
||||||
|
scm_opts = alist_add(scm_opts, make_symbol("mu-home"), SCM_BOOL_F);
|
||||||
|
else
|
||||||
|
scm_opts = alist_add(scm_opts, make_symbol("mu-home"), opts.muhome);
|
||||||
|
|
||||||
|
scm_c_define("%options", scm_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_module_mu(void* _data)
|
init_module_mu(void* _data)
|
||||||
{
|
{
|
||||||
init_config(config->options);
|
init_options(config->options);
|
||||||
init_store(config->store);
|
init_store(config->store);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +87,6 @@ static std::string mu_scm_path;
|
|||||||
static std::string mu_scm_shell_path;
|
static std::string mu_scm_shell_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Result<void>
|
static Result<void>
|
||||||
prepare_run(const Mu::Scm::Config& conf)
|
prepare_run(const Mu::Scm::Config& conf)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -24,7 +24,6 @@
|
|||||||
#:export (
|
#:export (
|
||||||
;; classes
|
;; classes
|
||||||
<store>
|
<store>
|
||||||
*default-store*
|
|
||||||
|
|
||||||
mfind
|
mfind
|
||||||
mcount
|
mcount
|
||||||
@ -69,6 +68,9 @@
|
|||||||
cc
|
cc
|
||||||
bcc
|
bcc
|
||||||
|
|
||||||
|
;; misc
|
||||||
|
options
|
||||||
|
|
||||||
;; helpers
|
;; helpers
|
||||||
iso-date->time-t
|
iso-date->time-t
|
||||||
time-t->iso-date))
|
time-t->iso-date))
|
||||||
@ -289,12 +291,12 @@ not found."
|
|||||||
|
|
||||||
;; Store
|
;; Store
|
||||||
;;
|
;;
|
||||||
;; Note: we have a *default-store*, which is the store we opened during
|
;; Note: we have a %default-store, which is the store we opened during
|
||||||
;; startup; for now that's the only store supported, but we keep things
|
;; startup; for now that's the only store supported, but we keep things
|
||||||
;; open.
|
;; open.
|
||||||
;;
|
;;
|
||||||
;; Since it's the default store, we'd like to call the methods without
|
;; Since it's the default store, we'd like to call the methods without
|
||||||
;; explicitly using *default-store*; with GOOPS, we cannot pass a default for
|
;; explicitly using %default-store; with GOOPS, we cannot pass a default for
|
||||||
;; that, nor can we use keyword arguments (I think?). So use define* for that.
|
;; that, nor can we use keyword arguments (I think?). So use define* for that.
|
||||||
|
|
||||||
;; the 'store-object' is a foreign object wrapping a const Store*.
|
;; the 'store-object' is a foreign object wrapping a const Store*.
|
||||||
@ -306,23 +308,23 @@ not found."
|
|||||||
"Make a store from some STORE-OBJECT."
|
"Make a store from some STORE-OBJECT."
|
||||||
(make <store> #:store-object store-object))
|
(make <store> #:store-object store-object))
|
||||||
|
|
||||||
(define *default-store*
|
(define %default-store
|
||||||
;; default-store-object is defined in mu-scm-store.cc
|
;; %default-store-object is defined in mu-scm-store.cc
|
||||||
(make-store default-store-object))
|
(make-store %default-store-object))
|
||||||
|
|
||||||
(define* (mfind query
|
(define* (mfind query
|
||||||
#:key
|
#:key
|
||||||
(store *default-store*)
|
(store %default-store)
|
||||||
(related? #f)
|
(related? #f)
|
||||||
(skip-dups? #f)
|
(skip-dups? #f)
|
||||||
(sort-field 'date)
|
(sort-field 'date)
|
||||||
(reverse? #f)
|
(reverse? #f)
|
||||||
(max-results #f))
|
(max-results #f))
|
||||||
"Find messages matching some query. The query is mandatory,
|
"Find messages matching some query.
|
||||||
the other (keyword) arguments are optional.
|
|
||||||
|
|
||||||
|
The query is mandatory, the other (keyword) arguments are optional. | ||||||