diff options
| author | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2025-06-20 20:31:32 +0300 |
|---|---|---|
| committer | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2025-06-30 21:57:29 +0300 |
| commit | 812d78be497ec305c716cef90b4bbc83ba12f63e (patch) | |
| tree | 2f309b7e307287e85803697de9575562993a1cc5 /scm | |
| parent | e647ca924d892d365ec51b98571032716c0743f1 (diff) | |
mu-scm: add options, some tweaks
Add the (options) procedure + docs.
Some internal tweaks / clean-ups.
Diffstat (limited to 'scm')
| -rw-r--r-- | scm/mu-scm-store.cc | 8 | ||||
| -rw-r--r-- | scm/mu-scm-test.scm | 10 | ||||
| -rw-r--r-- | scm/mu-scm.cc | 25 | ||||
| -rw-r--r-- | scm/mu-scm.scm | 41 | ||||
| -rw-r--r-- | scm/mu-scm.texi | 14 |
5 files changed, 69 insertions, 29 deletions
diff --git a/scm/mu-scm-store.cc b/scm/mu-scm-store.cc index f11ef83..cd43a8d 100644 --- a/scm/mu-scm-store.cc +++ b/scm/mu-scm-store.cc @@ -142,13 +142,13 @@ Mu::Scm::init_store(const Store& store) return; store_type = scm_make_foreign_object_type( - scm_from_utf8_symbol("store"), - scm_list_1 (scm_from_utf8_symbol("data")), - {}); // no finalizer + make_symbol("store"), + scm_list_1(make_symbol("data")), + {});// no finalizer default_store = scm_make_foreign_object_1( store_type, const_cast<Store*>(&store)); - scm_c_define("default-store-object", default_store); + scm_c_define("%default-store-object", default_store); init_subrs(); diff --git a/scm/mu-scm-test.scm b/scm/mu-scm-test.scm index d6c9325..6438efb 100644 --- a/scm/mu-scm-test.scm +++ b/scm/mu-scm-test.scm @@ -53,6 +53,15 @@ (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) (test-begin "test-helpers") (test-equal 1750077792 (iso-date->time-t "2025-06-16T12:43:12")) @@ -70,6 +79,7 @@ (test-basic) (test-basic-mfind) (test-mfind) + (test-misc) (test-helpers) (test-end "mu-scm-tests") diff --git a/scm/mu-scm.cc b/scm/mu-scm.cc index 374716c..9595b6e 100644 --- a/scm/mu-scm.cc +++ b/scm/mu-scm.cc @@ -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 */ static void -init_config (const Options& opts) +init_options(const Options& opts) { - scm_c_define("options", - alist_add( - SCM_EOL, - make_symbol("mu-home"), opts.muhome, - make_symbol("verbose"), opts.verbose, - make_symbol("debug"), opts.debug, - make_symbol("quiet"), opts.quiet)); + SCM scm_opts = alist_add(SCM_EOL, + make_symbol("verbose"), opts.verbose, + make_symbol("debug"), opts.debug, + 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 init_module_mu(void* _data) { - init_config(config->options); + init_options(config->options); init_store(config->store); } @@ -83,7 +87,6 @@ static std::string mu_scm_path; static std::string mu_scm_shell_path; } - static Result<void> prepare_run(const Mu::Scm::Config& conf) { diff --git a/scm/mu-scm.scm b/scm/mu-scm.scm index 44350da..3861ffa 100644 --- a/scm/mu-scm.scm +++ b/scm/mu-scm.scm @@ -24,7 +24,6 @@ #:export ( ;; classes <store> - *default-store* mfind mcount @@ -69,6 +68,9 @@ cc bcc + ;; misc + options + ;; helpers iso-date->time-t time-t->iso-date)) @@ -289,12 +291,12 @@ not found." ;; 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 ;; open. ;; ;; 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. ;; 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 <store> #:store-object store-object)) -(define *default-store* - ;; default-store-object is defined in mu-scm-store.cc - (make-store default-store-object)) +(define %default-store + ;; %default-store-object is defined in mu-scm-store.cc + (make-store %default-store-object)) (define* (mfind query #:key - (store *default-store*) + (store %default-store) (related? #f) (skip-dups? #f) (sort-field 'date) (reverse? #f) (max-results #f)) - "Find messages matching some query. The query is mandatory, -the other (keyword) arguments are optional. + "Find messages matching some query. +The query is mandatory, the other (keyword) arguments are optional. (mfind QUERY - #:store *default-store*. Leave at default. + #:store %default-store. Leave at default. #:related? include related messages? Default: false #:skip-dups? skip duplicates? Default: false #:sort-field? field to sort by, a symbol. Default: date @@ -335,25 +337,36 @@ the other (keyword) arguments are optional. (define* (mcount #:key - (store *default-store*)) + (store %default-store)) "Get the number of messages." (store-mcount (store-object store))) (define* (cfind pattern #:key - (store *default-store*) + (store %default-store) (personal? #f) (after #f) (max-results #f)) - "Find contacts matching some regex pattern, similar to 'mu-cfind(1). + "Find contacts matching some regex pattern, similar to mu-cfind(1). + The pattern is mandatory; the other (keyword) arguments are optional. (cfind PATTERN - #:store *default-store*. Leave at default. + #:store %default-store. Leave at default. #:personal? only include 'personal' contacts. Default: all #:after only include contacts last seen time_t: Default all #:max-results max. number of matches. Default: false (unlimited))." (store-cfind (store-object store) pattern personal? after max-results)) +;;; Misc + +(define (options) + "Get an alist with the general options this instance of \"mu\" started with. +These are based on the command-line arguments, environment etc., see +the mu-scm(1) manpage for details. + +The alist maps symbols to values; a value of #f indicates that the value +is at its default." + %options) ;;; Helpers diff --git a/scm/mu-scm.texi b/scm/mu-scm.texi index 07fccbd..a9b0297 100644 --- a/scm/mu-scm.texi +++ b/scm/mu-scm.texi @@ -261,6 +261,7 @@ I.e., the information from @code{mu cfind} @menu * Store:: the database of all information * Message:: inspecting individual messages +* Miscellaneous:: other functions * Helpers:: some helper functions @end menu @@ -599,6 +600,19 @@ For example: @c billion-dollar startup on it), but it can be useful for development and @c debugging. +@node Miscellaneous +@section Miscellaneous + +@deffn {Scheme Procedure} options +@end deffn + +This yields an association-list (alist) of general options passed to @command{mu +scm}. Values at @t{#f} indicate that the value is at its default. +@lisp + (options) +=> ((mu-home . #f) (quiet . #f) (debug . #f) (verbose . #f)) +@end lisp + @node Helpers @section Helpers |
