-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hello all. So recently I resolved to write, in some sort of Haskell
way, an 'incremental reading' utility. For details, see .
The summarized version is that an incremental reader is essentially an
editor* which has the user read a small portion of a number of
articles/books/papers (basically a bunch of text), and edit them.

I want to implement this in Yi as a mode. How would this work? Here's
my current idea:

(Let us assume I have previously inserted 5 articles into the
database). In my shell, I do '$yi'. Yi pops up. In Yi, I do 'M-x
iread'. A buffer pops up with a lengthy article in it. Perhaps it is a
scholarly essay on the mixing of genders in _Revolutionary Girl
Utena_. I read the first two paragraphs of article, and decide that
the introduction is devoid of any interesting material and I C-k all
10 lines. I decide that's enough for today, do a C-x s (updating the
database or file with the shortened version), and then I C-hit Esc.
That article is closed, and the second one opens. This one is an essay
by Karl Popper on his theory that Parmenides was the first to discover
that the Moon's light is reflected. I find it interesting, and I edit
a couple paragraphs down into question/answer pairs for review (eg.
'Popper believes what Pre-socratic philosopher founded the Eleatic
school?' 'Xenophanes'). I save, C-Esc, and begin on article #3... When
I finish article #5, then the whole iread mode exits and I'm left back
at *scratch* where I started.

OK, so now you have an idea of what I want the user/me to be able to
do. Here's the simple interface: for convenience, we store all the
articles in a single file, rather than have to deal with each article
being a file; the file is just a serialized list of strings which we
can 'read' back in as our list. Articles, once read & edited a little,
get sent to the back of the list. (It's possible to improve on this:
Strings aren't efficient, file I/O would be faster if we were
operating on a directory of files instead of a single file, we could
use a dlist instead of a list and so on; but this is very simple,
nigh-trivial.):

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREKAAYFAkktprQACgkQvpDo5Pfl1oIasACeNquucBxWcFgVrf16cDbN/GLk
mXIAoIjDtQuULyWtugLyTd/MB70yIVuN
=l9h/
-----END PGP SIGNATURE-----


> type Article = String
> type ArticleDB = [String] -- show/read already derived

> getLatestArticle :: ArticleDB -> Article
> getLatestArticle [] = ""
> getLatestArticle adb = head adb

> updateSetLast :: ArticleDB -> Article -> ArticleDB
> updateSetLast [] a = [a]
> updateSetLast (b:bs) a = bs ++ [a]

> insertNewArticle :: ArticleDB -> Article -> ArticleDB
> insertNewArticle adb a = a:adb

> deleteArticle :: ArticleDB -> Article -> ArticleDB
> deleteArticle = flip delete

> writeDB :: ArticleDB -> IO ()
> writeDB adb = join $ liftM (flip writeFile $ show adb) dbLocation

> readDB :: IO ArticleDB
> readDB = liftM readFile dbLocation >>= \ db -> (liftM read db)

> dbLocation :: IO FilePath
> dbLocation = getHomeDirectory >>= \ home -> return (home ++ ".yi/articles.db")

Where I bog down is actually turning this into a mode. I think what I
ultimately want looks a little like:

> imode = ireaderMode {
> modeKeymap = (choice [ctrlCh 'c' ?>> ctrl (char 'Esc') ?>>! saveAndNewArticle,
>                       metaCh 'Esc' ?>>! quitIreader ]
>                                      <||)
> }

> -- ??? -- saveAndNewArticle :: Yim ()
> saveAndNewArticle = do olddb <- readDB
                         newarticle <- turnIntoAString getBufferContents
                         newdb <- updateSetLast newarticle olddb
                         writeDB newdb
                         nextarticle <- getLatestArticle newdb
                         setBufferContents nextarticle
> quitIreader = undefined -- ???

Where I'm bogged down in saveAndNewArticle is that I have no
getBufferContents - there is a getBuffer, but that returns some sort
of BufferRef, and getBuffers returns EditorM [FBuffer], so...
Presumably I'd also need some way to convert from the fingerstrings or
whatever Yi is using to regular String.

Thoughts, everyone?

* either textual or an HTML editor; SuperMemo's
<https://secure.wikimedia.org/wikipedia/en/wiki/SuperMemo> incremental
reader is basically an editor which uses Internet Explorer to display
HTML documents. I don't terribly need HTML display capabilities, so
it's a text editor for me.

--
gwern

--~--~---------~--~----~------------~-------~--~----~
Yi development mailing list
yi-devel@googlegroups.com
http://groups.google.com/group/yi-devel
-~----------~----~----~----~------~----~------~--~---

Reply via email to