yi-0.12.4: The Haskell-Scriptable Editor

Safe HaskellNone
  • TemplateHaskell
  • OverloadedStrings
  • NondecreasingIndentation
  • LambdaCase



The top level editor state, and operations on it. This is inside an internal module for easy re-export with Yi.Types bits.



data Editor Source

The Editor state




bufferStack :: !(NonEmpty BufferRef)

Stack of all the buffers. Invariant: first buffer is the current one.

buffers :: !(Map BufferRef FBuffer)
refSupply :: !Int

Supply for buffer, window and tab ids.

tabs_ :: !(PointedList Tab)

current tab contains the visible windows pointed list.

dynamic :: !DynamicState

dynamic components

statusLines :: !Statuses
maxStatusHeight :: !Int
killring :: !Killring
currentRegex :: !(Maybe SearchExp)

currently highlighted regex (also most recent regex for use in vim bindings)

searchDirection :: !Direction
pendingEvents :: ![Event]

Processed events that didn't yield any action yet.

onCloseActions :: !(Map BufferRef (EditorM ()))

Actions to be run when the buffer is closed; should be scrapped.

class (Monad m, MonadState Editor m) => MonadEditor m where Source

Minimal complete definition


acceptedInputsOtherWindow :: EditorM () Source

Shows the current key bindings in a new window

bufferSet :: Editor -> [FBuffer] Source

Return the buffers we have, in no particular order

closeBufferAndWindowE :: EditorM () Source

Close current buffer and window, unless it's the last one.

closeBufferE :: Text -> EditorM () Source

Close a buffer. Note: close the current buffer if the empty string is given

closeOtherE :: EditorM () Source

Make the current window the only window on the screen

clrStatus :: EditorM () Source

Clear the status line

commonNamePrefix :: Editor -> [FilePath] Source

Return a prefix that can be removed from all buffer paths while keeping them unique.

currentBuffer :: Editor -> BufferRef Source

Return the current buffer

deleteBuffer :: MonadEditor m => BufferRef -> m () Source

Delete a buffer (and release resources associated with it).

deleteTabE :: EditorM () Source

Deletes the current tab. If there is only one tab open then error out. When the last tab is focused, move focus to the left, otherwise move focus to the right.

emptyEditor :: Editor Source

The initial state

findBufferWith :: BufferRef -> Editor -> FBuffer Source

Find buffer with this key

findBufferWithName :: Text -> Editor -> [BufferRef] Source

Find buffers with this name

focusWindowE :: WindowRef -> EditorM () Source

bring the editor focus the window with the given key.

Fails if no window with the given key is found.

getBufferWithName :: MonadEditor m => Text -> m BufferRef Source

Find buffer with given name. Fail if not found.

getEditorDyn :: (MonadEditor m, YiVariable a, Default a, Functor m) => m a Source

Dynamically-extensible state components.

These hooks are used by keymaps to store values that result from Actions (i.e. that restult from IO), as opposed to the pure values they generate themselves, and can be stored internally.

The dynamic field is a type-indexed map.

Retrieve a value from the extensible state

getRegE :: EditorM YiString Source

Return the contents of the yank register

layoutManagerNextVariantE :: EditorM () Source

Next variant of the current layout manager, as given by nextVariant

layoutManagerPreviousVariantE :: EditorM () Source

Previous variant of the current layout manager, as given by previousVariant

layoutManagersNextE :: EditorM () Source

Cycle to the next layout manager, or the first one if the current one is nonstandard.

layoutManagersPreviousE :: EditorM () Source

Cycle to the previous layout manager, or the first one if the current one is nonstandard.

moveTabE :: Maybe Int -> EditorM () Source

Moves the focused tab to the given index, or to the end if the index is not specified.

moveWinNextE :: EditorM () Source

Swap focused window with the next one

moveWinPrevE :: EditorM () Source

Swap focused window with the previous one

newBufferE Source


:: BufferId

buffer name

-> YiString

buffer contents

-> EditorM BufferRef 

Like fnewE, create a new buffer filled with the String s, Switch the current window to this buffer. Doesn't associate any file with the buffer (unlike fnewE) and so is good for popup internal buffers (like scratch)

newEmptyBufferE :: BufferId -> EditorM BufferRef Source

Like newBufferE but defaults to empty contents.

newTabE :: EditorM () Source

Creates a new tab containing a window that views the current buffer.

newTempBufferE :: EditorM BufferRef Source

Creates an in-memory buffer with a unique name.

newWindowE :: Bool -> BufferRef -> EditorM Window Source

Create a new window onto the given buffer.

nextTabE :: EditorM () Source

Moves to the next tab in the round robin set of tabs

nextWinE :: EditorM () Source

Rotate focus to the next window

prevWinE :: EditorM () Source

Rotate focus to the previous window

previousTabE :: EditorM () Source

Moves to the previous tab in the round robin set of tabs

printMsg :: MonadEditor m => Text -> m () Source

Prints a message with defaultStyle.

printMsgs :: MonadEditor m => [Text] -> m () Source

Prints a all given messages with defaultStyle.

pushWinToFirstE :: EditorM () Source

Moves the focused window to the first window, and moves all other windows down the stack.

putEditorDyn :: (MonadEditor m, YiVariable a, Functor m) => a -> m () Source

Insert a value into the extensible state, keyed by its type

setDividerPosE :: DividerRef -> DividerPosition -> EditorM () Source

Sets the given divider position on the current tab

setRegE :: YiString -> EditorM () Source

Put string into yank register

setStatus :: MonadEditor m => Status -> m () Source

Set the "background" status line

shiftOtherWindow :: MonadEditor m => m () Source

Switch focus to some other window. If none is available, create one.

splitE :: EditorM () Source

Split the current window, opening a second window onto current buffer. TODO: unfold newWindowE here?

stringToNewBuffer Source


:: MonadEditor m 
=> BufferId

The buffer indentifier

-> YiString

The contents with which to populate the buffer

-> m BufferRef 

Create and fill a new buffer, using contents of string. | Does not focus the window, or make it the current window. | Call newWindowE or switchToBufferE to take care of that.

swapWinWithFirstE :: EditorM () Source

Swaps the focused window with the first window. Useful for layouts such as HPairOneStack, for which the first window is the largest.

switchToBufferE :: BufferRef -> EditorM () Source

Attach the specified buffer to the current window

switchToBufferWithNameE :: Text -> EditorM () Source

Switch to the buffer specified as parameter. If the buffer name is empty, switch to the next buffer.

tryCloseE :: EditorM () Source

Close the current window. If there is only one tab open and the tab contains only one window then do nothing.

windowsOnBufferE :: BufferRef -> EditorM [Window] Source

Return the windows that are currently open on the buffer whose key is given

withCurrentBuffer :: MonadEditor m => BufferM a -> m a Source

Perform action with current window's buffer

withGivenBuffer :: MonadEditor m => BufferRef -> BufferM a -> m a Source

Perform action with any given buffer, using the last window that was used for that buffer.

withGivenBufferAndWindow :: MonadEditor m => Window -> BufferRef -> BufferM a -> m a Source

Perform action with any given buffer

withOtherWindow :: MonadEditor m => m a -> m a Source

Execute the argument in the context of an other window. Create one if necessary. The current window is re-focused after the argument has completed.