Scrap Primitives

Summary
Scrap Primitives
Macros
copyCopy marked area to scrap.
cutCut marked area to scrap.
delete_blockDeleted selected region.
drop_anchorStart marking a selection.
end_anchorSet the end of the anchor.
get_regionRetrieve marked region content.
inq_mark_sizeRetrieve size of marked region.
inq_markedDetermine the current marked region.
inq_marked_sizeSize the marked region.
inq_scrapObtain the scrap buffer identifier.
markToggle the anchor status.
pasteInsert scrap buffer at cursor location.
raise_anchorRaise the last dropped mark.
redoRedo an undo operation.
set_scrap_infoSet the scrap buffer details.
transferBuffer to buffer transfer.
write_blockWrite selected region.

Macros

copy

int copy([int append = FALSE],
[int keep = FALSE])

Copy marked area to scrap.

Description

The copy() primitive copies the content of the currently marked region to the scrap buffer, and releases the marked region on completion.

Parameters

appendOptional integer, if non-zero the copied region shall be appended to the scrap instead of replacing the scrap content.
keepOptional integer, if non-zero the marked region is retained otherwise the anchor is released.

Returns

The copy() primitive returns 1 on success, otherwise 0 on error.

Portability

n/a

See Also

cut, delete_block, inq_scrap, paste, transfer

cut

int cut([int append = FALSE],
[int syscopy = FALSE])

Cut marked area to scrap.

Description

The cut() primitive moves the content of the currently marked region to the scrap buffer, and releases the marked region on completion.

Parameters

appendOptional integer, if non-zero the copied region shall be appended to the scrap instead of replacing the scrap content.
keepOptional integer, if non-zero the marked region is retained otherwise the anchor is released.

Returns

The cut() primitive returns 1 on success, otherwise 0 on error.

Portability

n/a

See Also

paste, delete_block, inq_scrap, paste, transfer

delete_block

int delete_block()

Deleted selected region.

Description

The delete_block() primitive deleted the current marked block, leaving the cursor position on the last line of the marked region.

The characters included in the mark depend on the its type, and once deleted the mark is removed.

On completion the following is echoed on the command prompt.

Block deleted.

In the event of no active region the following is echoed.

No marked block.

Parameters

none

Returns

The delete_block() primitive returns one if the block was delete, otherwise zero.

See Also

cut, copy, delete_char

drop_anchor

int drop_anchor([int type = MK_NORMAL])

Start marking a selection.

Description

The drop_anchor() primitive starts marking a block of the specified type at the current position in the current buffer.

Marked regions are highlighted to stand out on the screen either in a different colour or in reverse video dependent on the available display capacities.

The following are the available region types.

Value
Constant
Description
1
MK_NORMAL
A normal mark.
2
MK_COLUMN
A column mark.
3
MK_LINE
A line mark.
4
MK_NONINC
A non-inclusive mark.
MK_NORMALA normal mark is a region which encompasses from the place where the anchor was dropped up to and including the current cursor position.
MK_COLUMNA column mark allows a rectangular section of the buffer to be marked, highlighting the inclusive columns between the left and right boundaries.
MK_LINEA line mark selects entire lines, and allows for easy movement of text from one part of a buffer to another.
MK_NONINCA non-inclusive mark, like a normal, is a region which encompasses from the place where the anchor was dropped up to and but does not include the current cursor position.

Regions are nestable, in that a drop_anchor may be issued without an intervening raise_anchor.  Each mark is pushed into a LIFO (last-in, first-out) stack, allowing multiple marks to exist simultaneously; each mark must however be eventually raised.  The most recent mark shall be the one displayed by the buffer.

The current active marked region can queried using inq_marked.

The marked region can be cleared by calling raise_anchor or performing a high level copy or cut buffer operations plus a numebr of the lower level functions, for example delete_block.

Parameters

typeOptional anchor type to be dropped, otherwise if omitted a MK_NORMAL anchor shall be created.

Returns

The drop_anchor returns 1 if successful, otherwise 0 on error.

Portability

n/a

See Also

mark, raise_anchor

end_anchor

int end_anchor([int line],
[int column])

Set the end of the anchor.

Description

The end_anchor() primitive sets the end of the current marked region without the need to move the cursor.

Parameters

lineOptional new line, if omitted the line shall be unchanged.
columnOptional new column, if omitted the column shall be unchanged.

Returns

The end_anchor returns 1 if successful, otherwise 0 on error.

Portability

n/a

See Also

mark, drop_anchor

get_region

int get_region([int bufnum])

Retrieve marked region content.

Description

The get_region() primitive is similar to copy yet is copies the content of the current marked region and returns the result as a string.

Parameters

bufnumOptional window identifier, if omitted the current buffer is referenced.

Returns

The get_region() primitive returns the content of the current marked region as a string, otherwise an empty string.

Portability

n/a

See Also

cut, paste, copy, inq_marked

inq_mark_size

int inq_mark_size()

Retrieve size of marked region.

Description

The inq_mark_size() primitive determines the number of characters what are in the currently marked region; this represents the the length of a string which would be necessary to hold its content, see get_region.

Parameters

none

Returns

The inq_mark_size() primitive returns the number of characters in the currently marked region, otherwise 0 if there is no current region.

Portability

A GriefEdit extension.

See Also

mark, drop_anchor, inq_marked

inq_marked

int inq_marked([int &start_line],
[int &start_col],
 [int &end_line],
[int &end_col])

Determine the current marked region.

Description

The inq_marked() primitive retrieves the current mark type and the associated coordinates of the marked area.

Region Types

Value
Constant
Description
0
MK_NONE
No mark is set
1
MK_NORMAL
Normal mark
2
MK_COLUMN
Column mark
3
MK_LINE
Line mark
4
MK_NONINC
Non-inclusive

Parameters

start_lineIf specified the integer parameter is set to the line number at the top of the marked region.
start_colIf specified the integer parameter is set to the column number at the beginning of the marked region.
end_lineIf specified the integer parameter is set to the line number marking the bottom of the marked region.
end_colIf specified the integer parameter is set to the column number at the end of the marked region.

Returns

The inq_marked() primitive returns the current region type, otherwise 0 if no mark is active.

Portability

n/a

See Also

mark

inq_marked_size

int inq_marked_size()

Size the marked region.

Description

The inq_marked_size() primitive is reserved for future compatibility.

The inq_marked_size() primitive determines the number of characters contained within the current marked region.

Parameters

Returns

Returns the character count within the marked region.

Portability

Function is currently a no-op, returning -1.

See Also

inq_marked

inq_scrap

int inq_scrap([int &last],
[int &type])

Obtain the scrap buffer identifier.

Description

The inq_scrap() primitive retrieves the buffer identifier of the current scrap buffer.

Parameters

lastNot used; provided for BRIEF compatibility.  If false the last newline in the scrap is not considered part of the scrap, otherwise true it is considered part of the scrap.
typeOptional integer variable reference, if stated shall be populated with the buffers mark type.

Returns

The inq_scrap() primitive returns the scrap buffer identifier.

Portability

n/a

See Also

copy, cut, paste, set_scrap_info

mark

int mark([int type = MK_NORMAL])

Toggle the anchor status.

Description

The mark() primitive toggles the status of the marked region.  If the anchor is currently dropped it shall be raised, and if raised it shall be dropped.

To be independent of the current state macros should generally utilise drop_anchor and raise_anchor, with mark reserved for keyboard bindings.

Parameters

typeOptional anchor type to be dropped, if omitted a MK_NORMAL (1) mark shall be dropped.
Value
Constant
Description
1
MK_NORMAL
A normal mark.
2
MK_COLUMN
A column mark.
3
MK_LINE
A line mark.
4
MK_NONINC
A non-inclusive mark.

Returns

The mark returns 1 if successful, otherwise 0 on error.

Portability

Unlike BRIEF the anchor status is always toggled.

BRIEF logic was equivalent to the following.  If type was stated and an anchor of a different type current exists, the anchor is converted.

if (! inq_marked() || type) {
drop_anchor(type);
} else {
raise_anchor();
}

See Also

inq_marked, raise_anchor, drop_anchor

paste

int paste([int syspaste = FALSE])

Insert scrap buffer at cursor location.

Description

The paste() primitive insert the contents of the scrap buffer at the current cursor location.

The buffer is pasted according to the type of the mark which created it:

  • Normal or non-exclusive mark, the scrape is inserted before the current position.
  • Line mark, the scrape is inserted before the current line.

Parameters

syspasteOptional boolean flag, is specified and is non-zero, then the text contents of the operating system buffer shall (e.g. clipboard under WIN32) shall be inserted into the current buffer where the cursor is located, if the feature is supported/available.

Returns

The paste() primitive returns 1 on success, otherwise 0 on failure.

Portability

n/a

See Also

cut, copy, inq_scrap, set_scrap_info

raise_anchor

int raise_anchor()

Raise the last dropped mark.

Description

The raise_anchor() primitive raises the last anchor mark that was dropped.

If no mark is dropped, this primitive has no effect.

Parameters

none

Returns

The raise_anchor returns 1 if successful, otherwise 0 on error.

Portability

n/a

See Also

mark, drop_anchor

redo

void redo()

Redo an undo operation.

Description

The redo() primitive redoes the last undone operation.

Parameters

none

Returns

nothing

Portability

n/a

See Also

undo

set_scrap_info

void set_scrap_info(  [int last],
[int type],
[int bufnum])

Set the scrap buffer details.

Description

The set_scrap_info() primitive specifies the mark type and newline handling to be applied against the scrap buffer.

Parameters

lastNot used; provided for BRIEF compatibility.  If false the last newline in the scrap is not considered part of the scrap, otherwise true it is considered part of the scrap.
typeOptional integer value, specifies the mark-type to be applied to the scrap buffer.
bufnumOptional integer buffer identifier, if stated changes the current scrap buffer to the specified buffer.  The resulting buffer shall be marked with the buffer flag BF_SCRAPBUF.

Returns

The set_scrap_info() primitive returns 0 on success, otherwise -1 on error, for example in invalid buffer.

Portability

n/a

See Also

copy, cut, paste, inq_scrap

transfer

int transfer(int bufnum,
 int sline,
 [int scolumn],
int eline,
 [int ecolumn])

Buffer to buffer transfer.

Description

The transfer() primitive moves the specified region from the buffer bufnum into the current buffer.

All characters in the source buffer between the start and end positions inclusive are included in the block.

The primitive has two forms determined by the number of coordinates arguments being either four or two, as followings:

  • start line/column sline, scol and end line/column eline and ecol.
  • start line sline and end line eline.

Unlike the original BRIEF implementation, this version is more forgiving and is provided for compatibility; it is usually far easier to use the region macros.

Parameters

bufnumBuffer identifier of the source.
slineStarting line.
scolumnStarting column.
elineEnding line.
ecolumnEnding column.

Returns

The transfer() primitive returns non-zero on success, otherwise zero or less on error.

Portability

The short form of transfer is an extension yet less error prone and more convenient interface.

See Also

copy, cut, paste

write_block

int write_block([string filename],
 [int append = FALSE],
[int keep = FALSE],
 [int pause = TRUE])

Write selected region.

Description

The write_block() primitive writes out the currently marked region to the file filename.  If filename is not specified, then it is prompted for as follows

Write marked area as:

The characters included in the mark depend on the its type, and once written the mark is removed unless keep is specified.

Writing out a marked region does not affect the backup flag or the undo information flag; see undo and set_backup.

On completion the following is echoed on the command prompt.

Write successful.

In the event of no active region the following is echoed.

No marked block.

File Name

Several special leading characters within the stated filename act as modifiers on the output mode of the file.

’|’data is written to a pipe instead of a file.  The string content after the | is passed as an argument to popen().
’>’, ‘>>’data shall be appended to the specified file following the >; same effect as stated append.

Parameters

filenameOptional string value containing the path of the destination filename.  If omitted the user shall be prompted.
appendOptional boolean value, if true the block is appended to the end of the file; otherwise the file content is replaced.
keepOptional boolean value, if true the marked region is retainined, otherwise on completion the region is cleared.
pauseOptional boolean value control pipe completion handling.  During pipe operations the command may destroy the screen.  If omitted or is non-zero then the user is prompted to hit <Enter> before continuing.

Returns

The write_block() primitive returns one on success, otherwise zero on error.

Portability

The filename and append options are GriefEdit extensions to BRIEF.

See Also

delete_block, write_buffer, undo, set_backup

$Id: $

To send feedback on this topic email: grie.nosp@m.fedit@gmai.nosp@m.l.com

Copyright © Adam Young All Rights Reserved.

int copy([int append = FALSE],
[int keep = FALSE])
Copy marked area to scrap.
int cut([int append = FALSE],
[int syscopy = FALSE])
Cut marked area to scrap.
int delete_block()
Deleted selected region.
int drop_anchor([int type = MK_NORMAL])
Start marking a selection.
int end_anchor([int line],
[int column])
Set the end of the anchor.
int get_region([int bufnum])
Retrieve marked region content.
int inq_mark_size()
Retrieve size of marked region.
int inq_marked([int &start_line],
[int &start_col],
 [int &end_line],
[int &end_col])
Determine the current marked region.
int inq_marked_size()
Size the marked region.
int inq_scrap([int &last],
[int &type])
Obtain the scrap buffer identifier.
int mark([int type = MK_NORMAL])
Toggle the anchor status.
int paste([int syspaste = FALSE])
Insert scrap buffer at cursor location.
int raise_anchor()
Raise the last dropped mark.
void redo()
Redo an undo operation.
void set_scrap_info(  [int last],
[int type],
[int bufnum])
Set the scrap buffer details.
int transfer(int bufnum,
 int sline,
 [int scolumn],
int eline,
 [int ecolumn])
Buffer to buffer transfer.
int write_block([string filename],
 [int append = FALSE],
[int keep = FALSE],
 [int pause = TRUE])
Write selected region.
void delete_char([int num])
Delete character.
int undo([int move],
[int pastwrite = -1],
[int redo = FALSE])
Undo previous edit operations.
int set_backup(int mode,
 [int bufnum])
Set backup creation mode.
int write_buffer(  [string filename],
[int flags],
[string encoding])
Write to buffer content.