yi-0.6.2.4: The Haskell-Scriptable Editor

Yi.Buffer.Indent

Synopsis

Documentation

tabB :: BufferM StringSource

Return either a t or the number of spaces specified by tabSize in the IndentSettings. Note that if you actually want to insert a tab character (for example when editing makefiles) then you should use: insertB '\t'.

indentSettingsB :: BufferM IndentSettingsSource

Retrieve the current indentation settings for the buffer.

autoIndentB :: IndentBehaviour -> BufferM ()Source

A specialisation of autoIndentHelperB. This is the most basic and the user is encouraged to specialise autoIndentHelperB on their own.

autoIndentHelperBSource

Arguments

:: BufferM [Int]

Action to fetch hints from previous lines

-> (String -> BufferM [Int])

Action to calculate hints from previous line

-> IndentBehaviour

Sets the indent behaviour, see Yi.Buffer.IndentBehaviour for a description

-> BufferM () 

This takes two arguments the first is a function to obtain indentation hints from lines above the current one. The second is a function to obtain a set of indentation hints from the previous line. Both of these are in the BufferM monad although the second seems like it is unnecessary. However we must take into account the length of tabs which come from the the tab settings and hence we must be in the BufferM monad.

To get the straightforward behaviour of the indents of all previous lines until one of them has zero indent call this with: autoIndentHelperB fetchPreviousIndentsB (fmap (: []) indentOfB) However commonly we wish to have something more interesting for the second argument, in particular we commonly wish to have the last opening bracket of the previous line as well as its indent.

cycleIndentsB :: IndentBehaviour -> [Int] -> BufferM ()Source

Cycles through the indentation hints. It does this without requiring to set/get any state. We just look at the current indentation of the current line and moving to the largest indent that is

fetchPreviousIndentsB :: BufferM [Int]Source

A function generally useful as the first argument to autoIndentHelperB. This searches the lines above the current line for the indentations of each line until we get to a line which has no indentation *and* is not empty. Indicating that we have reached the outer scope.

autoIndentWithKeywordsBSource

Arguments

:: [String]

Keywords to act as hints

-> [String]

Keywords to act as offset hints

-> IndentBehaviour 
-> BufferM () 

An application of autoIndentHelperB which adds more indentation hints using the given keywords. The offsets of the first set of keywords are used as hints. For the second set of keywords it is not the offsets of the keywords themselves but the offset of the first non-white characters after the keywords.

In addition to the keyword hints we also do the same as the default (autoIndentB) which is to use any non-closed opening brackets as hints.

lastOpenBracketHint :: String -> BufferM [Int]Source

Returns the position of the last opening bracket on the line which is not closed on the same line. Note that if we have unmatched parentheses such as ( ] then we may not get the correct answer, but in that case then arguably we don't really care if we get the correct answer (at least if we get it wrong the user may notice their error). We return a list here as it's a convenient way of returning no hint in the case of there being no non-closed bracket and normally such a hint will be part of a list of hints anyway. NOTE: this could be easily modified to return the indentations of *all* the non-closed opening brackets. But I think this is not what you generally want. TODO: we also do not care whether or not the bracket is within a string or escaped. If someone feels up to caring about that by all means please fix this.

keywordHints :: [String] -> String -> BufferM [Int]Source

Returns the offsets of all the given keywords within the given string. This is potentially useful as providing indentation hints.

keywordAfterHints :: [String] -> String -> BufferM [Int]Source

Returns the offsets of anything that isn't white space after a keyword on the given line. This is essentially then the same as keywordHints except that for each keyword on the input rather than return the offset at the start of the keyword we return the offset of the first non-white character after the keyword.

indentOfB :: String -> BufferM IntSource

Returns the indentation of a given string. Note that this depends on the current indentation settings.

spacingOfB :: String -> BufferM IntSource

Returns the length of a given string taking into account the white space and the indentation settings.

indentToB :: Int -> BufferM ()Source

Indents the current line to the given indentation level. In addition moves the point according to where it was on the line originally. If we were somewhere within the indentation (ie at the start of the line or on an empty line) then we want to just go to the end of the (new) indentation. However if we are currently pointing somewhere within the text of the line then we wish to remain pointing to the same character.

indentAsPreviousB :: BufferM ()Source

Indent as much as the previous line

newlineAndIndentB :: BufferM ()Source

Insert a newline at point and indent the new line as the previous one.

rePadString :: IndentSettings -> Int -> String -> StringSource

Set the padding of the string to newCount, filling in tabs if expandTabs is set in the buffers IndentSettings

indentString :: IndentSettings -> Int -> String -> StringSource

shifts right (or left if num is negative) num times, filling in tabs if expandTabs is set in the buffers IndentSettings

shiftIndentOfRegion :: Int -> Region -> BufferM ()Source

Increases the indentation on the region by the given amount of shiftWidth

indentOfCurrentPosB :: BufferM IntSource

Return the number of spaces at the beginning of the line, up to the point.