From f9c24c716653e81771c1f97e9c3a082a7863138d Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 31 May 2025 12:41:37 +0300 Subject: [PATCH] mu: add 'scm' command Add the "scm" command, the way to get a Guile/Scheme shell. This is experimental but will replace the current guile support in guile/ at some point. --- meson.build | 9 +++++++++ meson_options.txt | 7 ++++++- mu/mu-cmd-info.cc | 16 ++++++++++++++-- mu/mu-cmd.cc | 19 ++++++++++++++++++- mu/mu-options.cc | 14 +++++++++++++- mu/mu-options.hh | 14 +++++++++++++- 6 files changed, 73 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index c47663d7..0a5cd583 100644 --- a/meson.build +++ b/meson.build @@ -306,6 +306,15 @@ if not get_option('guile').disabled() and guile_dep.found() subdir('guile') endif +# this must happen _after_ subdir('lib') +if not get_option('scm').disabled() and guile_dep.found() + config_h_data.set('BUILD_SCM', 1) + subdir('scm') +else + # dummy-dep. + mu_scm_dep = declare_dependency('', required:false) +endif + subdir('mu') # emacs -- needed for mu4e compilation diff --git a/meson_options.txt b/meson_options.txt index c0366bd8..35c74c96 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -35,7 +35,7 @@ option('lispdir', # -# guile +# guile & scm # option('guile', @@ -48,6 +48,11 @@ option('guile-extension-dir', type: 'string', description: 'custom install path for the guile extension module') +option('scm', + type : 'feature', + value: 'auto', + description: 'build the guile scripting support (requires guile-3.x)') + # # misc # diff --git a/mu/mu-cmd-info.cc b/mu/mu-cmd-info.cc index 257c9093..b52fef90 100644 --- a/mu/mu-cmd-info.cc +++ b/mu/mu-cmd-info.cc @@ -288,8 +288,20 @@ topic_mu(const Options& opts) "yes" #else "no" -#endif - , "GNU Guile 3.x scripting support?"}); +#endif /*BUILD_GUILE*/ + , "GNU Guile 3.x support (old)?"}); + + info.add_row({"scm-support", +#if BUILD_SCM + "yes" +#else + "no" +#endif /*BUILD_SCM*/ + , "GNU Guile 3.x support (new)?"}); + + + + info.add_row({"readline-support", #if HAVE_LIBREADLINE "yes" diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index bcdca985..d14c355f 100644 --- a/mu/mu-cmd.cc +++ b/mu/mu-cmd.cc @@ -35,6 +35,10 @@ #include "message/mu-message.hh" #include "message/mu-mime-object.hh" +#if BUILD_GUILE +#include "scm/mu-scm.hh" +#endif/*BUILD_GUILE*/ + #include "utils/mu-error.hh" #include "utils/mu-utils-file.hh" #include "utils/mu-utils.hh" @@ -43,7 +47,6 @@ using namespace Mu; - static Result cmd_fields(const Options& opts) { @@ -63,6 +66,17 @@ cmd_find(const Options& opts) return mu_cmd_find(*store, opts); } +static Result +cmd_scm(const Store& store, const Options& opts) +{ +#if !BUILD_SCM + return Err(Error::Code::InvalidArgument, + "scm/guile is not available in this build"); +#else + return Mu::Scm::run(Mu::Scm::Config{store, opts}); +#endif /*BUILD_SCM*/ +} + static void show_usage(void) @@ -133,6 +147,9 @@ Mu::mu_cmd_execute(const Options& opts) try { return cmd_find(opts); case Options::SubCommand::Info: return with_readonly_store(mu_cmd_info, opts); + case Options::SubCommand::Scm: + return with_readonly_store(cmd_scm, opts); + /* writable store */ diff --git a/mu/mu-options.cc b/mu/mu-options.cc index 2b969321..41876504 100644 --- a/mu/mu-options.cc +++ b/mu/mu-options.cc @@ -545,7 +545,15 @@ sub_server(CLI::App& sub, Options& opts) sub.add_flag("--allow-temp-file", opts.server.allow_temp_file, "Allow for the temp-file optimization") ->excludes("--commands"); +} +static void +sub_scm(CLI::App& sub, Options& opts) +{ + sub.add_option("script-path", opts.scm.script_path, "Path to script") + ->type_name(""); + sub.add_option("script-args", opts.scm.params, "Parameters for script") + ->type_name(""); } static void @@ -665,9 +673,13 @@ AssocPairs SubCommandInfos= {{ {Category::NeedsWritableStore, "remove", "Remove message from file-system and database", sub_remove } }, + { SubCommand::Scm, + {Category::None, + "scm", "Start Guile/Scheme shell",sub_scm} + }, { SubCommand::Script, // Note: SubCommand::Script is special; there's no literal - // "script" subcommand, there subcommands for all the scripts. + // "script" subcommand, there are subcommands for all the scripts. {Category::None, "script", "Invoke a script", {}} }, diff --git a/mu/mu-options.hh b/mu/mu-options.hh index bd5799a6..0b110c8e 100644 --- a/mu/mu-options.hh +++ b/mu/mu-options.hh @@ -40,6 +40,7 @@ struct Options { using SizeVec = std::vector; using OptTStamp = Option; using OptFieldId = Option; + using OptString = Option; using StringVec = std::vector; /* @@ -62,7 +63,7 @@ struct Options { enum struct SubCommand { Add, Cfind, Extract, Fields, Find, Help, Index,Info, Init, Mkdir, - Move, Remove, Script, Server, Verify, View, + Move, Remove, Scm, Script, Server, Verify, View, // __count__ }; @@ -80,6 +81,7 @@ struct Options { SubCommand::Mkdir, SubCommand::Move, SubCommand::Remove, + SubCommand::Scm, SubCommand::Script, SubCommand::Server, SubCommand::Verify, @@ -226,6 +228,16 @@ struct Options { StringVec files; /**< Files to remove */ } remove; + + /* + * Scm + */ + struct Scm { + OptString script_path; /**< Path to script (optional) */ + StringVec params; /**< Parameters for script (after "--") */ + } scm; + + /* * Scripts (i.e., finding scriot) */