-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Yi editor incremental reader
--   
--   Yi editor incremental reader
@package yi-ireader
@version 0.17.1


-- | This module defines a list type and operations on it; it further
--   provides functions which write in and out the list. The goal is to
--   make it easy for the user to store a large number of text buffers and
--   cycle among them, making edits as she goes. The idea is inspired by
--   "incremental reading", see
--   <a>http://en.wikipedia.org/wiki/Incremental_reading</a>.
module Yi.IReader

-- | TODO: Why <a>ByteString</a>?
type Article = ByteString
newtype ArticleDB
ADB :: Seq Article -> ArticleDB
[unADB] :: ArticleDB -> Seq Article

-- | Take an <a>ArticleDB</a>, and return the first <a>Article</a> and an
--   ArticleDB - *without* that article.
split :: ArticleDB -> (Article, ArticleDB)

-- | Get the first article in the list. We use the list to express relative
--   priority; the first is the most, the last least. We then just cycle
--   through - every article gets equal time.
getLatestArticle :: ArticleDB -> Article

-- | We remove the old first article, and we stick it on the end of the
--   list using the presumably modified version.
removeSetLast :: ArticleDB -> Article -> ArticleDB
shift :: Int -> ArticleDB -> ArticleDB

-- | Insert a new article with top priority (that is, at the front of the
--   list).
insertArticle :: ArticleDB -> Article -> ArticleDB

-- | Serialize given <a>ArticleDB</a> out.
writeDB :: ArticleDB -> YiM ()

-- | Read in database from <a>getArticleDbFilename</a> and then parse it
--   into an <a>ArticleDB</a>.
readDB :: YiM ArticleDB

-- | Returns the database as it exists on the disk, and the current Yi
--   buffer contents. Note that the Default typeclass gives us an empty
--   Seq. So first we try the buffer state in the hope we can avoid a very
--   expensive read from disk, and if we find nothing (that is, if we get
--   an empty Seq), only then do we call <a>readDB</a>.
oldDbNewArticle :: YiM (ArticleDB, Article)

-- | Given an <a>ArticleDB</a>, dump the scheduled article into the buffer
--   (replacing previous contents).
setDisplayedArticle :: ArticleDB -> YiM ()

-- | Go to next one. This ignores the buffer, but it doesn't remove
--   anything from the database. However, the ordering does change.
nextArticle :: YiM ()

-- | Delete current article (the article as in the database), and go to
--   next one.
deleteAndNextArticle :: YiM ()

-- | The main action. We fetch the old database, we fetch the modified
--   article from the buffer, then we call the function
--   <tt>updateSetLast</tt> which removes the first article and pushes our
--   modified article to the end of the list.
saveAndNextArticle :: Int -> YiM ()

-- | Assume the buffer is an entirely new article just imported this
--   second, and save it. We don't want to use <tt>updateSetLast</tt> since
--   that will erase an article.
saveAsNewArticle :: YiM ()
instance Data.Binary.Class.Binary Yi.IReader.ArticleDB
instance Data.Default.Class.Default Yi.IReader.ArticleDB
instance Yi.Types.YiVariable Yi.IReader.ArticleDB


-- | A simple text mode; it does very little besides define a comment
--   syntax. We have it as a separate mode so users can bind the commands
--   to this mode specifically.
module Yi.Mode.IReader
abstract :: Mode syntax
ireaderMode :: Mode syntax
ireadMode :: YiM ()
