* cosmetics

This commit is contained in:
djcb
2011-11-27 16:21:49 +02:00
parent ebb3df2e2b
commit dce908cf93
2 changed files with 35 additions and 44 deletions

View File

@ -8,15 +8,14 @@
`guile'[1] is an interpreter/library for the Scheme programming language[2], `guile'[1] is an interpreter/library for the Scheme programming language[2],
specifically meant for extending other programs. It is, in fact, the specifically meant for extending other programs. It is, in fact, the
official GNU language for doing so. 'muile' requires guile 2.x to get the full official GNU language for doing so. 'muile' requires guile 2.x to get the full
support. support.
older versions will not support e.g. the 'mu-stats.scm' things Older versions may not support e.g. the 'mu-stats.scm' things discussed below.
discussed below.
The combination of mu + guile is called `muile', and allows you to write The combination of mu + guile is called `muile', and allows you to write
little Scheme-programs to query the mu-database, or inspect individual little Scheme-programs to query the mu-database, or inspect individual
messages. It is still in an experimental stage, but useful already. messages. It is still in an experimental stage, but useful already.
** How do I get it? ** How do I get it?
The git-version and the future 0.9.7 version of mu will automatically build The git-version and the future 0.9.7 version of mu will automatically build
@ -29,7 +28,7 @@ older versions will not support e.g. the 'mu-stats.scm' things
created, as well. created, as well.
** What can I do with it? ** What can I do with it?
Go to toys/muile and start muile. You'll end up with a guile-shell where you Go to toys/muile and start muile. You'll end up with a guile-shell where you
can type scheme [1], it looks something like this (for guile 2.x): can type scheme [1], it looks something like this (for guile 2.x):
@ -40,14 +39,14 @@ older versions will not support e.g. the 'mu-stats.scm' things
Now, let's load a message (of course, replace with a message on your system): Now, let's load a message (of course, replace with a message on your system):
,---- ,----
| scheme@(guile-user)> (define msg (mu:msg:make-from-file "/home/djcb/Maildir/cur/12131e7b20a2:2,S")) | scheme@(guile-user)> (define msg (mu:msg:make-from-file "/home/djcb/Maildir/cur/12131e7b20a2:2,S"))
`---- `----
This defines a variable 'msg', which holds some message on your file This defines a variable 'msg', which holds some message on your file
system. It's now easy to inspect this message: system. It's now easy to inspect this message:
,---- ,----
| scheme@(guile-user)> (define msg (mu:msg:make-from-file "/home/djcb/Maildir/cur/12131e7b20a2:2,S")) | scheme@(guile-user)> (define msg (mu:msg:make-from-file "/home/djcb/Maildir/cur/12131e7b20a2:2,S"))
`---- `----
Now, we can inspect this message a bit: Now, we can inspect this message a bit:
@ -57,17 +56,17 @@ older versions will not support e.g. the 'mu-stats.scm' things
| scheme@(guile-user)> (mu:msg:flags msg) | scheme@(guile-user)> (mu:msg:flags msg)
| $2 = (mu:attach mu:unread) | $2 = (mu:attach mu:unread)
`---- `----
and so on. Note, it's probably easiest to explore the various mu: methods and so on. Note, it's probably easiest to explore the various mu: methods
using autocompletion; to enable that make sure you have using autocompletion; to enable that make sure you have
,---- ,----
| (use-modules (ice-9 readline)) | (use-modules (ice-9 readline))
| (activate-readline) | (activate-readline)
`---- `----
in your ~/.guile configuration. in your ~/.guile configuration.
** does this tool have some parameters? ** does this tool have some parameters?
@ -79,7 +78,7 @@ older versions will not support e.g. the 'mu-stats.scm' things
example: example:
,---- ,----
| ./muile --msg=~/Maildir/inbox/cur/1311310172_1234:2,S | ./muile --msg=~/Maildir/inbox/cur/1311310172_1234:2,S
| [...] | [...]
| scheme@(guile-user)> mu:current-msg | scheme@(guile-user)> mu:current-msg
| $1 = #<msg /home/djcb/Maildir/inbox/cur/1311310172_1234:2,S> | $1 = #<msg /home/djcb/Maildir/inbox/cur/1311310172_1234:2,S>
@ -92,7 +91,7 @@ older versions will not support e.g. the 'mu-stats.scm' things
That's easy, too - it does require a little more scheme knowledge. For That's easy, too - it does require a little more scheme knowledge. For
searching messages there is the mu:store:for-each function, which takes two searching messages there is the mu:store:for-each function, which takes two
arguments; the first argument is a function that will be called for each arguments; the first argument is a function that will be called for each
message found. The optional second argument is the search expression (following message found. The optional second argument is the search expression (following
'mu find' syntax); if don't provide the argument, all messages match. 'mu find' syntax); if don't provide the argument, all messages match.
So how does this work in practice? Let's see I want to see the subject and So how does this work in practice? Let's see I want to see the subject and
@ -105,9 +104,9 @@ older versions will not support e.g. the 'mu-stats.scm' things
or slightly more readable: or slightly more readable:
,---- ,----
| (mu:store:for-each | (mu:store:for-each
| (lambda(msg) | (lambda(msg)
| (format #t "~s ~s\n" (mu:msg:from msg) (mu:msg:subject msg))) | (format #t "~s ~s\n" (mu:msg:from msg) (mu:msg:subject msg)))
| "milk") | "milk")
`---- `----
@ -116,7 +115,7 @@ older versions will not support e.g. the 'mu-stats.scm' things
Scheme-knowledge... but this time is good as any to learn this nice Scheme-knowledge... but this time is good as any to learn this nice
language. language.
** Can I do some statistics on my messages? ** Can I do some statistics on my messages?
Yes you can. In fact, it's pretty easy. If you load (in the muile/ directory) Yes you can. In fact, it's pretty easy. If you load (in the muile/ directory)
@ -134,9 +133,9 @@ older versions will not support e.g. the 'mu-stats.scm' things
| scheme@(guile-user)> (mu:stats:per-weekday) | scheme@(guile-user)> (mu:stats:per-weekday)
| $1 = ((0 . 2255) (1 . 2788) (2 . 2868) (3 . 2599) (4 . 2629) (5 . 2287) (6 . 1851)) | $1 = ((0 . 2255) (1 . 2788) (2 . 2868) (3 . 2599) (4 . 2629) (5 . 2287) (6 . 1851))
`---- `----
Note, Sunday=0, Monday=1 and so on. Apparently, I get/send most of e-mail on Note, Sunday=0, Monday=1 and so on. Apparently, I get/send most of e-mail on
Tuesdays, and least on Saturday. Tuesdays, and least on Saturday.
And note that mu:stats:per-weekdays takes an optional search expression And note that mu:stats:per-weekdays takes an optional search expression
argument, to limit the results to messages matching that, e.g., to only argument, to limit the results to messages matching that, e.g., to only
@ -151,18 +150,18 @@ older versions will not support e.g. the 'mu-stats.scm' things
I learnt that during 3-4am I sent/receive only about a third of what I sent I learnt that during 3-4am I sent/receive only about a third of what I sent
during 11-12pm. during 11-12pm.
** What about getting the top-10 people in the To:-field? ** What about getting the top-10 people in the To:-field?
Easy. Easy.
,---- ,----
| scheme@(guile-user)> (mu:stats:top-n-to) | scheme@(guile-user)> (mu:stats:top-n-to)
| $1 = ((("Abc" "myself@example.com") . 4465) (("Def" "somebodyelse@example.com") . 2114) | $1 = ((("Abc" "myself@example.com") . 4465) (("Def" "somebodyelse@example.com") . 2114)
| (and so on) | (and so on)
`---- `----
I've changed the names a bit to protect the innocent, but what the function I've changed the names a bit to protect the innocent, but what the function
does is return a list of pairs of does is return a list of pairs of
(<name> <email>) . <frequency> (<name> <email>) . <frequency>
@ -173,7 +172,7 @@ older versions will not support e.g. the 'mu-stats.scm' things
There are also the functions 'mu:stats:top-n-subject' and There are also the functions 'mu:stats:top-n-subject' and
'mu:stats:top-n-from' which do the same, mutatis mutandis, and it's quite 'mu:stats:top-n-from' which do the same, mutatis mutandis, and it's quite
easy to add your own (see the mu-stats.scm for examples) easy to add your own (see the mu-stats.scm for examples)
** What about showing the results in a table? ** What about showing the results in a table?
Even easier. Try: Even easier. Try:
@ -181,7 +180,7 @@ older versions will not support e.g. the 'mu-stats.scm' things
,---- ,----
| (mu:stats:table (mu:stats:top-n-to)) | (mu:stats:table (mu:stats:top-n-to))
`---- `----
or or
,---- ,----
@ -189,7 +188,7 @@ older versions will not support e.g. the 'mu-stats.scm' things
`---- `----
You can also export the table: You can also export the table:
,---- ,----
| (mu:stats:export (mu:stats:per-weekday)) | (mu:stats:export (mu:stats:per-weekday))
`---- `----
@ -198,17 +197,9 @@ older versions will not support e.g. the 'mu-stats.scm' things
in e.g. 'R' or 'gnuplot'. in e.g. 'R' or 'gnuplot'.
[1] http://www.gnu.org/s/guile/ [1] http://www.gnu.org/s/guile/
[2] http://en.wikipedia.org/wiki/Scheme_(programming_language) [2] http://en.wikipedia.org/wiki/Scheme_(programming_language)
# Local Variables: # Local Variables:
# mode: org; org-startup-folded: nil # mode: org; org-startup-folded: nil
# End: # End:

View File

@ -57,10 +57,10 @@ muile_config_new (int *argcp, char ***argvp)
if (opts->msgpath) if (opts->msgpath)
opts->msgpath = mu_util_dir_expand (opts->msgpath); opts->msgpath = mu_util_dir_expand (opts->msgpath);
g_option_context_free (octx); g_option_context_free (octx);
return opts; return opts;
} }
static void static void
@ -74,7 +74,7 @@ muile_config_destroy (MuileConfig *conf)
static void static void
usage (void) usage (void)
{ {
g_print ("usage: muile [--muhome=<dir>] [msgfile]\n"); g_print ("usage: muile [--muhome <dir>] [--msg <msgfile>]\n");
} }
@ -84,9 +84,9 @@ main (int argc, char *argv[])
MuileConfig *opts; MuileConfig *opts;
g_type_init (); g_type_init ();
#ifdef HAVE_PRE2_GUILE #ifdef HAVE_PRE2_GUILE
g_warning ("Note: muile will not function correctly unless you have a " g_warning ("Note: muile will not function properly unless you are using a"
"UTF-8 locale."); "UTF-8 locale.");
#endif /* HAVE_PRE2_GUILE */ #endif /* HAVE_PRE2_GUILE */
@ -95,7 +95,7 @@ main (int argc, char *argv[])
usage (); usage ();
goto error; goto error;
} }
if (!mu_runtime_init (opts->muhome /* NULL is okay */, if (!mu_runtime_init (opts->muhome /* NULL is okay */,
"muile")) { "muile")) {
usage (); usage ();
@ -103,23 +103,23 @@ main (int argc, char *argv[])
} }
mu_guile_init (); /* initialize mu guile modules */ mu_guile_init (); /* initialize mu guile modules */
if (opts->msgpath) { if (opts->msgpath) {
if (!(gboolean)scm_with_guile if (!(gboolean)scm_with_guile
((MuGuileFunc*)&mu_guile_msg_load_current, opts->msgpath)) ((MuGuileFunc*)&mu_guile_msg_load_current, opts->msgpath))
goto error; goto error;
} }
scm_shell (argc, argv); scm_shell (argc, argv);
mu_runtime_uninit (); mu_runtime_uninit ();
muile_config_destroy (opts); muile_config_destroy (opts);
return 0; return 0;
error: error:
muile_config_destroy (opts); muile_config_destroy (opts);
return 1; return 1;
} }