Zap Documentation      Latest release     
ZapRedraw      Contact      Download     

Previous | Contents | Index | Next

Chapter 4: Selections

A common need when editing files is to perform an operation on a particular section of the file. For instance you might want to reformat it to a different line length, or move one section so it comes before another. In Zap, as in many editors, you do this by selecting a continuous section of the file; there are then a set of commands that you can perform on that section to do the jobs you need.

4.1 Making a selection

There are several ways to make a selection in Zap. The most obvious is to use the mouse, which we'll cover first.

If there is no selection, then dragging Select will select a new region, and clicking/dragging Adjust will select between the clicked point and the cursor. If there is already a selection, then dragging Select will start a new selection; clicking/dragging Adjust will alter the old region. In either case, hold down the Control key to leave the cursor unaffected by the selection.

Alternatively, there are a variety of methods for selecting via the keyboard, which can be quicker in some cases because you don't have to move from keyboard to mouse and back again repeatedly. To select via the keyboard, either hold down Escape while moving the cursor via the cursor keys (releasing Escape ends the selection), or type cSpace to start the selection, move the cursor to the end, and type cSpace again.

A third method is to use multiple clicks; double clicking selects a word, triple clicking a line, quadruple clicking a paragraph, and quintuple clicking the entire file. For more information about using the mouse in Zap, see chapter 5.

You can select the entire text using cT, and clear the selection by using cZ.

4.2 Copying, pasting, cutting, yanking and moving

Zap implements both the Edit style copy/move of selections, and the Emacs style paste/yank. Both of these will work happily across different windows, files and even from one mode to another (although if you copy a selection in, say, Code mode into Text mode you won't get the disassembled text but rather the binary data - see section 7.4 for a solution to this).

The Edit method: to move a selection to the cursor position press cV. To copy the selection to the cursor position press cC.

The Emacs method: to move a selection, cut it with cX and then paste it with cY (the undo buffer must be turned on for this to work - see section 3.5.1). To copy a selection, grab it with cE (this is called keeping) and paste it with cY. Press scY to cycle through the previously cut selections (this is called yanking).

Note that the DELTOEND (cK) and DELLINE (F10) commands also produce data which can be pasted by cY.

Another way to copy text is via the Copy key - see section 3.3 for more information.

4.2.1 The global clipboard

One very useful (but sadly little-known) feature common to several RISC OS applications is the global clipboard. Put simply, this is a way of using cut and paste,as described above, across different applications. Unlike Zap's 'yank ring' which allows yanking, as described above, the global clipboard can only contain one object at a time.

The way it works in Zap is that when you copy or cut anything to Zap's clipboard (the 'local' clipboard), it also gets put into the global clipboard too, so that other applications can use it. When someone else puts something into the global clipboard, Zap will use that in preference to its own local clipboard when pasting using cY (the PASTE command).

If there is something on the global clipboard and you want to use Zap's local clipboard instead, you can use the LOCALPASTE command (cEscape will bring up a minibuffer to type the command into - see chapter 11). If Zap has put something on the global clipboard which you don't want available to other applications any more, you can use the Disown clipboard option which is on the Misc->Clipboard submenu (the command is CLEARGC).

4.3 Saving the selection

If you have a selection, you can save it by pressing sF3 to bring up the save selection dialogue box. This works in exactly the same way as the normal save box (except that it only saves the selection); you can drag the file icon to a Filer window, or another application as you'd expect.

Another way to quickly save the selection is to Shift drag it with Select. This will save the selection with the filename 'Selection', but is really useful for quickly saving things into other applications. You can even Shift drag the selection into a Zap editing window - it will be copied to the point that you drag it to.

4.4 Processing the selection

There are a number of actions you can perform on an entire selection; here we will just cover the most important ones. These are all available from the Selection->Process submenu.

A related topic here is block editing, which allows you to make alterations on one line in the selection which are mirrored on all the others - see section 6.6.

4.4.1 Indent

Indent simply indents the selection by whatever you type into the indent submenu. In other words, it adds text at the beginning of each line of the selection depending on what the parameter is.

If you type in a number to the indent submenu, it will indent the selection by that number of spaces; otherwise it will indent it with whatever you type in. For instance, you might put the string > in the indent submenu to 'quote' the selection in the manner of an email reply.

Indent is also available by pressing cJ.

4.4.2 Outdent

Outdent simply un-indents the selection depending on whatever is in the indent submenu. If the indent parameter is currently a number, it will remove that many characters from the beginning of each line. If the indent parameter is some text, it will remove the same number of characters as are in the parameter (so two if the parameter is > , three if it is > > and so on).

4.4.3 GNU filters

This is a menu containing various GNU filter programs you can apply to the selection. Darren Salt has ported a range of GNU text filters to RISC OS; these are available from ftp://zap.tartarus.org/pub/ds/GNU/.

See section 4.4.10 for more information on general filtering within Zap.

4.4.4 Sort

This simply sorts the lines of the selection into alphabetical order. See section 4.4.11 for more details.

4.4.5 Format

This simply formats the selection to 77 characters, with a first-line indent for each paragraph. See section 4.4.12 for more details.

4.4.6 Swap case

This simply swaps the case of all the characters in the selection. It recognises the full ISO Latin 1 character set, so accented characters will have their cases swapped too.

4.4.7 Upper case

This does the same as swap case, but leaves all characters in upper case.

4.4.8 Lower case

This does the same as swap case, but leaves all characters in lower case.

4.4.9 Bracket ()

This simply places the selection in brackets.

4.4.10 Filters

Zap provides a way of filtering the selection (or the entire file, for that matter - see the documentation that comes with ZapText) through an external program. What actually happens is that the selection is fed through the filter program, and the output replaces the selection in the file. Several useful filters are supplied with Zap, and we introduce some of them here. For more information, see the files in !Zap.Code.Filters.Docs.

The menu options call these filters using the default options (assuming the filter has options); if you want to use different options you'll need to call the command yourself. The Zap command being used here is FILTERSEL, and the filters supplied with Zap are kept in a special place which you access by prefixing their names with ZF:. For instance FILTERSEL ZF:Sort -descending -case will give a case sensitive, descending ASCII sort. For more information, see chapter 11 and the documentation supplied both with ZapText and the filters.

A number of useful filters are supplied with Zap, and are described below. You can use the Selection->Process->Filter... menu option to enter their names: eg, for filter ZF:sort, you would type ZF:sort at the minibuffer that pops up.

4.4.11 Filter ZF:sort

The sort filter sorts in straight ASCII order. The option on the menu (Selection->Process->Sort) does an ascending case insensitive sort - if you call the filter yourself you can change those options, as well as making it skip leading spaces and tabs on each line.

4.4.12 Filter ZF:format

The format filter is a simple text formatter. A paragraph is recognised by either starting with a space, or ending with two line feeds. Tab characters are treated as spaces. This filter has a fair number of options, and it's probably easier to read the documentation that comes with it than to describe only part of it here. You'll almost certainly want to call it directly yourself to be able to take advantage of all the features, but it is also on the menu as Selection->Process->Filter.

Note that Zap has an internal command, FORMATTEXT (cF6), which does not work in the same way. For information on that, see section 6.3, which explains Zap's various internal formatting and wrapping modes.

4.4.13 Filter ZF:untab

The untab filter simply replaces each tab character in a file with an equivalent number of spaces. It is different to the UNTABIFY command, which leaves tabs inside quotes ("") alone in program source modes such as C, Java and so on.

4.5 "Sending" the selection

Zap can send the selection straight to the keyboard buffer. You can start this through the Selection->Send menu option. Zap sends the selection a character at a time; you can abort at any time by pressing Escape.

The menu option will strip out control characters; if you need to send them too you'll need to use the SENDSEL command directly.

Only one selection at a time may be in the process of being sent.


The next section in the manual is chapter 5, which gives a complete description of how the mouse is used in Zap.

Alternatively, you might like to move on to chapter 6, which covers tabbing, wrapping and formatting, and other advanced editing issues.

Previous | Contents | Index | Next


© Copyright Zap Developers 1992-2004. All Rights Reserved.