Navigating

Another powerfull feature of Devparrot is how you can address position into a buffer.

Addressing positions is almost a necessity as it is used by a lot of commands.

This can be used to :

The global way of addressing a position is to start from a particular position or range and add a number of modifiers to get the position/range we want.

Well known positions

The well known positions are:

Well known ranges

The well known ranges are:

The 'selection' always exists. If there is no text selected, the selection range is a range of zero length starting and ending at 'insert' position.

Position to position modifiers

There is a number of modifiers that can be applied to a index that return a new index:

i+1c   # The position on char after the insert position
i-3l   # The position 3 lines before the insert position
start+5l+4c  # The 4th char of the 6th line (1+5)
i~ws+2c      # The second char of the word under the insert cursor

Position to range modifiers

There is a number of modifiers that can be applied to a index that return a new range:

c:word # The word under the mouse cursor
c/i    # The position of the first i char after the mouse cursor
end?foo  # The last occurence of 'foo' in the buffer

Range to index modifiers

There is a number of modifiers that can be applied to a range that return a new index:

10.0  # The begginning of the 10th line
10.first # The begginning of the 10th line
10.last  # The end of the 10th line (just befor the \n)
sel.-3  # The positon 3 char before the end of the selection.

Range to range modifiers

There is a number of modifiers that can be applied to a range that return a new range:

10+1l # The 11th line
4+3c  # A range starting from the 4.3 index to 5.3 index
5/bar # The first occurence of bar in the 5th line (equ to '5.first/bar'

Combining indices into range

It is also possible to combine to indeces with ':' to create a range starting from the first index and going upto the second one.

i:c # A range starting from the insert index and going to the mouse cursor
i:i+10c # A range 10 chars long starting from insert

Default values

If you don't provide a base, Devparrot will take one for you.

The default base is 'insert'. So:

+1c # is equivalent to i+1c

If you are combining indices to create range. The default base for the second index is the first index. So:

i:+1l # is equivalent to i:i+1l
10.5~ws:~we # is equivalent to 10.5~ws:10.5~ws~we (and also to 10.5:word

Specifying the document

By default, a index or a range corresponding to the current buffer. But you can specify to which document the document correspond.

This is done by preceding the range by '<document>@'

foo@i # the insert position in the buffer foo
bar@i+5c:word # the word range around the 5 chars after the insert position of the bar buffer.

Where to use it

Short answer : with command and macro.

You can use it with the goto command:

goto +10l     # go 10 lines down
goto 10       # go to line 10 (10.0)
goto foo@50.5 # go to the 50.5 char of foo document (must be open before)
goto foo@all/functionName # go to the first occurence of "functionName" if document foo

You can use it with copy/cut/paste commands:

copy sel # Copy the selected text to the clipboard (yes, what is launch when you copy your text with shortcut)
paste sel # Copy the clipboard's content in place of the selected text (or insert it, if there is no selection)
paste foo@10 # Copy the clipboard's content in place of the 10th line of foo document
paste foo@10.0 # Copy the clipboard's content at the beginning of the 10th line of foo document

Or with search/replace commands:

search foo 10.0:+5l # search foo occurences between the 10th line on the 14th (beginnig of the 15th)
replace foo bar sel # replace all occurences of foo by bar in the selected range.

The range macro return the text corresponding to the range given at argument:

replace %range(i:word) foo i:line # replace the current word by foo in the current line

With the section command.

shell ls | section foo@sel # replace the selection of the foo document by the output of the ls shell command.
section sel | shell myfilter.sh | section sel # launch myfilter.sh script, send it the current selection as standard input and replace the selection by the standard output.