dk.salza.liq.slider

The slider is a basic construction resembling the most
fundamental actions of a text edtior.

The slider is immutable, so every slider function in this
namespace will take a slider as input together with some
parameters and evaluate to a new slider.

By having the slider as first parameter a series of actions
can be performed by using the threading operator "->",
like:

(->
  sl
  (end-of-line)
  (forward-char 3))

Some of the basic operations are:

* Moving cursor
* Inserting and removing content
* Setting marks and moving cursor to marks
* Marking regions

The sliderutil contains more slider related functions,
which are more complex and usually composed of the basic
functions in this file.

after

(after sl)
Returns a slider with content after cursor.

backward-visual-column

(backward-visual-column sl columns column)
Moves the point backward one line, where
the lines are wrapped. The parameter columns is
how many chars are allowed on one line. The parameter
column is the current selected column.
The visual result of this function is the cursor will
be located on the same column on the previous line, nomatter
if the line was wrapped or not.

backward-word

(backward-word sl)

before

(before sl)
Returns a slider with content before cursor.

beginning

(beginning sl)
Moves the point (cursor) to the beginning of the slider.

beginning-of-line

(beginning-of-line sl)
Moves the point to the beginning
of the current line.

beginning?

(beginning? sl)
True if and only if the point is at the
beginning of the slider.

clear

(clear sl)
Erases everything in the slider,
content and marks.

clear-marks

(clear-marks sl)
Removes all marks.

create

(create text)(create)
Creates a new slider with given text as text.
The point will be placed at the beginning.

A slider basically consists of two lists:

before: A list of characters (strings) before the point,
        where the first element is the character just before the point.
after:  A list of characters (strings) after the point,
        where the first element is the character just after the point.

So moving the point is more or less to take characters from one
of the lists and put into the other.

This text: abc|def

will look like this:

    before = (c b a), after = (d e f).

Moving the curser to the right will result in:

    before = (d c b a), after = (e f).

delete

(delete sl amount)
Deletes amount of characters to the left of
the cursor. So delete 3 of
aaabbb|ccc wil result in
aaa|ccc.

delete-line

(delete-line sl)
Deletes the current line.
The point will be placed at the beginning
of the next line.

delete-region

(delete-region sl markname)
Deletes the region between the given
mark and the point. If the mark does
not exist, nothing is deleted.

dirty?

(dirty? sl)

end

(end sl)
Moves the point to the end of the slider.

end-of-line

(end-of-line sl)
Moves the point to the end of the line. Right before the
next line break.

end-of-word

(end-of-word sl)

end?

(end? sl)
True if and only if the point is at the
end of the slider.

find-next

(find-next sl search)
Moves the point to the next search match
from the current point position.

find-next-regex

(find-next-regex sl regex)
Find next regex match. If no match
found ahead, position will be at end.

find-prev

(find-prev sl search)
Moves the point to the previous search match
from the current point position.

find-prev-regex

(find-prev-regex sl regex)
Find previous regex match. If no match
found ahead, position will be at beginning.

forward-line

(forward-line sl columns)(forward-line sl)

forward-visual-column

(forward-visual-column sl columns column)
Moves the point forward one line, where
the lines are wrapped. The parameter columns is
how many chars are allowed on one line. The parameter
column is the current selected column.
The visual result of this function is the cursor will
be located on the same column on the next line, nomatter
if the line was wrapped or not.

forward-word

(forward-word sl)

forward-word2

(forward-word2 sl)
Moves the point to beginning of next word or end-of-buffer

get-after-list

(get-after-list sl)

get-char

(get-char sl)
Returns the first character after the point.
If point is at the end of the slider, nil will
be returned.

get-content

(get-content sl)
The full content of the slider as text.

get-context

(get-context sl)
Calculates a context object like
a filepath, url, checkbox, code
collapse and returns the type and
the matched string.
Output like {:type :file :value /tmp/tmp.txt}

get-linenumber

(get-linenumber sl)
Return the linenumber of the point.
It will always be equal to one more
than the number of newline characters
in ::before.

get-mark

(get-mark sl name)
The position of the mark
with the given name.

get-meta

(get-meta sl key)
Get a meta value from a char.
If the value does not exist, nil will be
returned.

get-point

(get-point sl)
Returns the point. If at the beginning of the
slider the result is 0. If at the end of the
slider the result is the number of characters.

get-region

(get-region sl markname)
Returns the content between the mark
with the given name and the point.
If there is no mark with the given name
nil is returned.

get-region-as-slider

(get-region-as-slider sl markname)

get-visible-content

(get-visible-content sl)
This is not really in use yet, since there
is not yet a hide lines functionality.

get-visual-column

(get-visual-column sl columns)

hidden?

(hidden? sl)
Checks if current position is a hidden
region.

hide-region

(hide-region sl markname)
Hides/collapses the given region:
The content between the cursor and the
given mark

highlight-sexp-at-point

(highlight-sexp-at-point sl)
Setting marks hl0 and hl1 on parenthesis matching the
current s-expression for a view to use to highlight the
the boundries of the s-expression.

insert

(insert sl text)
Insert text at the point. The point will be
moved to the end of the inserted text.

insert-newline

(insert-newline sl)
Special function to insert newline without too
much overhead.

insert-slider

(insert-slider sl1 sl2)
Insert second slider into first.
Point is moved to match second slider.
Marks are lost

insert-space

(insert-space sl)
Special funcon to insert a space without too
much overhead.

insert-subslider

(insert-subslider sl subsl)

is-newline?

(is-newline? c)
Check if \n or {:char \n}

left

(left sl)(left sl amount)
Moves the point to the left the given amount of times.
So moving one character left is achieved with
(left sl 1).

left-until

(left-until sl pred)
Moves the cursor backward, until for the current char:
(pred char) is true.
The cursor will be places just before the
character. The function only mathces single characters, not
character sequences!
If there is no match, the cursor will move all the way to the
beginning of the slider.
Example (cursor = ^):
  aaacde^aacf   -- left-until c -->   aa^cdeaacf.

look-ahead

(look-ahead sl amount)
Returns char after the cursor given amount forward.
If amount = 0 the char right after the cursor will be
returned.
If there is no result, nil is returned.

look-behind

(look-behind sl amount)
Returns char behind the cursor given amount back.
If amount = 1 the char right behind the cursor will be
returned.
If there is no result, nil is returned.

mark-paren-end

(mark-paren-end sl name)
Marks the paren-end of the
current s-exp. In this case:
aa (aa (aa|aa(aa))
The last paren will be selected.

mark-paren-start

(mark-paren-start sl name)
Marks the paren-start of the
current s-exp. In this case:
aaa (aaa (aa)  a|aa
The first paren start is selected.

pad-right

(pad-right sl columns)
Pad to the right with spaces

point-to-mark

(point-to-mark sl name)
Moves the point to the mark
with the given name.
If the mark does not exist nothing
is changed.

remove-mark

(remove-mark sl name)
Removes the mark with the given name.

right

(right sl)(right sl amount)
Moves the point to the right (forward) the given amount of times.

right-until

(right-until sl pred)
Moves the cursor forward, until for the current char:
(pred char) is true.
The cursor will be placed just before the
character. The function only matches single characters, not
character sequences!
If there is no match, the cursor will move all the way to the
end of the slider.
Example (cursor = ^):
  aaacde^aacf   -- right-until c -->   aacdeaa^cf.

select-sexp-at-point

(select-sexp-at-point sl)
Selects the smallest valid s-expression containing
the point (cursor position). The function take into
account that the parenthesis should be balanced.

set-dirty

(set-dirty sl dirty)(set-dirty sl)

set-mark

(set-mark sl name)
Sets a named mark at the point.
When inserting or deleting text strectly left to
the mark, the mark will be moved
accordingly.

set-meta

(set-meta sl key val)
Set a meta value on the current char.
If char is a string it will be converted to a map.

set-point

(set-point sl newpoint)
Moves point the the given location.
Not further than beginning of the slider
and the end of the slider.

sexp-at-point

(sexp-at-point sl)
Returns the sexp at the current point. If there is no
s-expression nil will be returned.

slide-marks

(slide-marks marks point amount)
This function will move marks strictly after
point with the given amount.
Marks at point will not be moved.
When text is inserted, marks should be
moved accordingly.

slider

slider?

(slider? sl)
Returns true if the input has shape/properties
like a slider.

string-ahead

(string-ahead sl amount)
Returns next amount of chars as string.

swap-line-down

(swap-line-down sl)

swap-line-up

(swap-line-up sl)

take-lines

(take-lines sl rows columns)
Generate list of lines with
at most columns chars. When exeeding
end empty lines will be provided.

unhide

(unhide sl)
If current position contains hidden/collapsed
content it will be expanded.

update-top-of-window

(update-top-of-window sl rows columns tow)
Returns slider where cursor marks has been set
and point moved to top of window.

wrap

(wrap sl columns)
Wrap all lines. Cursor will be at end.