包含在尋找其他文件熱門支援資源 | 以 PDF 格式下載這本書 (2592 KB)
Chapter 3 Text EditorThe Text Editor is an interactive ASCII text editor. It allows you to create new files and modify existing files. This chapter describes how to use the Text Editor. You do not need to know any special editing commands because the editing commands are available from the base window. The editing functions provided in this DeskSet application are also available in the text editing panes of the Console and the Command Tool, and in the View and Compose windows of the Mail Tool. To open the Text Editor window, choose Workspace->Programs->Text Editor. Text Editor IconThe Text Editor icon shows you as much as it can of the beginning of the file name. When the file has been edited and you have not saved the changes, the file name is preceded by a right-angle bracket (>). When there is no file or when you have created a new file but have not saved it, the icon displays the words NO FILE. "Text Editor Icons " shows an example of three Text Editor icons. The one on the left contains a file named example. The one in the middle contains a file named example that has been edited but not saved. The one on the right contains either no file at all or a file that has never been saved. Text Editor IconsText Editor Base WindowThe Text Editor base window, shown in Figure 3-1, has a control area and a text pane that you use to compose and edit your text message. The header of the Text Editor window displays the name of the file you are editing (or the word NONE when you have not assigned a name to the file), and shows you the directory where the file is located. When you have made editing changes, the word "edited" is displayed in parentheses following the file name. Use the text pane to compose and edit your text. To begin, click SELECT in the text pane and begin typing. For information on adding, modifying, or deleting text, see the section "Working with Text" in Chapter 1, Introduction to the Solaris User Environment. To copy and move text, use the Cut/Copy/Paste functions from the Edit menu or from the keyboard. Note - Solaris supports SPARC, x86, and PowerPC-based machines. Command functions and their corresponding keyboard equivalents may differ on each machine. For a full table of these equivalents, see Chapter 1, Introduction to the Solaris User Environment. Figure 3-1 Text Editor Base Window
Text Editor MenusThe control area of the Text Editor has File, View, Edit, and Find buttons. These menu buttons are included as menu items in the Text pane pop-up menu. Text Pane Pop-Up MenuYou display the Text Pane pop-up menu by moving the pointer anywhere onto the Text pane and pressing MENU. (The Text Pane pop-up menu is also provided in the text editing panes of the Console, Command Tool, and Mail Tool applications.) The commands for each of the items in Text Pane pop-up menu operate in the same way as the controls in the Text Editor window, described in the following sections. An additional item on the Text Pane pop-up menu, called Extras, is also described later in this chapter. File MenuThe File menu contains items that you can use to open, save, save as, include and empty the document for your text files. For complete information on opening and saving files, refer to "Opening, Saving, Including and Attaching Files" in Chapter 1, Introduction to the Solaris User Environment. Include FileUse the include file to include an existing file into a new text file.
Include your file in the same manner you would open or save a file. For detailed information on choosing a file to open or save, refer to Chapter 1, Introduction to the Solaris User Environment. Empty DocumentUse the Empty Document item of the File menu to clear the contents of the text pane. If you have made editing changes and have not saved them, a Notice is displayed asking you to confirm or cancel the operation. View MenuUse the View menu item to control the position of the cursor and the way the line wrap is used. Select Line at NumberUse the Select Line at Number item to display the Text: Line Number window, shown in Figure 3-2. Type the number of the line that you want selected, and click SELECT on the Select Line at Number button. The text on the specified line is selected, and the insert point is moved to the end of the selected text. Figure 3-2 Text: Line Number Pop-up Window
What Line Number?Use the What Line Number? item of the View menu to locate the line number where the selected text begins. The line number is displayed in a Notice. When there is no current selection in the Text Editor window, the Notice displays an error message instead of a line number. Show Caret at TopUse the Show Caret at Top item of the View menu to scroll the document so the line currently containing the caret is the third line from the top of the text pane. Change Line WrapThe Change Line Wrap submenu provides three choices for line wrapping: word, character, and clip lines. The text shown in Figure 3-3 is wrapped at a character, so words are broken at the end of lines. Figure 3-3 Lines Wrapped at a Character
The most commonly used wrapping method is to wrap at the end of words. The text shown in Figure 3-4 is wrapped at the end of words. Figure 3-4 Lines Wrapped at a Word
If you choose Clip Lines, the beginning of each line that ends with a Return is displayed. In Figure 3-5 each line represents a paragraph because there are no carriage returns embedded in the lines. Only carriage returns are at the end of each paragraph. That is, Figure 3-5 Clipped Lines
Edit MenuThe Edit menu provides standard editing functions, as follows:
Find MenuThe Find menu items help you to search for specific text strings, special characters, and delimiters to find a text string and replace it with another. Text: Find and ReplaceUse Find and Replace to find specific text and replace it through the Text: Find and Replace window. If you have a current selection, it is automatically displayed in the Find text field, as shown in the example in Figure 3-6. Figure 3-6 Text: Find and Replace Pop-up Window
To find a text string and select it, type the text in the Find field and click SELECT on the Find button. Click SELECT on the Find button again to find and select the next occurrence of the text string. To replace the current selection with a text string, type the text in the Replace field and click SELECT on the Replace button. You can use the Replace button together with the Find button to find a string and then replace it with another, or separately to replace highlighted text. You can replace a string with nothing by leaving the Replace text field blank. If you want to find a text string that contains tabs or carriage returns, select the text containing tabs or carriage returns in the text pane before you display the Text: Find and Replace window. You cannot type carriage returns or tabs directly in the Find or Replace text fields. The buttons at the bottom of the Find and Replace window combine the find and replace operations, allowing you to quickly do any of these combinations:
You can specify whether you want the find and replace operations to apply to all of the text, or to restrict the operation to the text between the insert point and the end of the document. Use the abbreviated menu button at the lower right corner of the window to select either All Text or To End. The current setting is listed to the right of the abbreviated menu button, as shown in Figure 3-6. Find SelectionUse Find Selection on the Find menu to search the file for another occurrence of the text string that is highlighted as the current selection. You can search forward or backward from the insert point by choosing Forward or Backward from the Find Selection submenu. Find Marked TextUse Find Marked Text on the Find menu to highlight text between a matched set of delimiters provided as options in the Text: Find Marked Text window, shown in Figure 3-7. Figure 3-7 Text: Find Marked Text Pop-up Window
You can search and highlight text for any of the matched delimiters provided as choices in the Text:Find Marked Text pop-up window. Click SELECT on one of the sets of delimiters, and then click SELECT on the Find Pair button. Use the Backward or Forward choice to direct the search either backward or forward from the current insertion point. If you have nested delimiters, such as matched parentheses in a program's code, you can use the Expand choice to select text outward from the current insertion point to the next outer pair of specified delimiters. To surround the selected text with the selected delimiters, click SELECT on the Insert Pair button. To delete a matched pair of delimiters from the selected text, click SELECT on the Remove Pair button. Replace FieldThe Text Editor pane recognizes any text between the characters |> and <| as a text field. You can search forward through the text from the insert point to find and select each field using the Replace |>field<| item of the Find menu. The Replace |>field<| submenu provides three options: Expand, Next, and Previous:
Extras MenuThere is an additional item on the Text Pane pop-up menu, called Extras, that is not a button in the Control area (as File, View, Edit, and Find are). This menu contains some useful filters to format the selected text. You can customize the Extras menu and define your own set of filters available from the Extras menu. See "Customizing Your Text Editor" for information about how to define your own set of filters. This section describes the default Extras menu. FormatChoose Format to reformat selected long lines of text into physical lines of no more than 72 characters. This is useful, for example, when reading mail with lines longer than the width of the window. Formatting text before printing is also useful to make sure the lines will not be truncated by the printer. Format uses the UNIX fmt command. It does not split words between lines, and it preserves blank lines and the spacing between words. Note - Format (and fmt) work only on lines of no more than 1024 characters. CapitalizeUse Capitalize on the Extras menu to capitalize selected text.
Shift LinesChoose the Shift Lines item to insert or remove a Tab character at the beginning of each line in the selected text. Use the Shift Lines submenu to specify whether to shift right or left. Shift right inserts a Tab character, and shift left removes a Tab character. Pretty-print CThis item uses the UNIX indent command to format C program listings. It formats the selection according to standard specifications, or to the specifications of the .indent.pro file if you have one. Insert BracketsYou can use the Insert Brackets item to quickly insert any of the following type of brackets around the selected text, depending on which item you choose from the Insert Brackets submenu: ( ), [ ], { }, or " ". Remove BracketsChoose the Remove Brackets item to remove any of the following types of brackets around the selected text, depending on what item you choose from the Remove Brackets submenu: ( ), [ ], { }, or " ". Creating a New FileTo create a new file with Text Editor:
Working with an Existing FileYou can open (load) any standard ASCII text file into the Text Editor and then modify the current file, or change the name of the file to create a new file, which leaves the original file intact. To load a file from your file system into Text Editor:
Saving the Existing FileYou can now edit the existing file and either save your changes in that file, or save it as a new file. To modify the file, see the section, "Editing Files". To save the changes to the existing file, do the following: Choose File -> Save from the Text Editor control area. The file is automatically saved. Because UNIX does not allow two documents with the same name in one directory, when you make a copy of a document in the same directory the original file is automatically saved to a backup file and renamed with a % suffix. For instance, a file named messages would automatically be renamed messages%. The next save overwrites the existing backup file rather than creating a second backup. Figure 3-8 shows the two files displayed as icons in File Manager. Figure 3-8 Edited File and Backup File with a % Suffix
Note - If you do not want to retain the original, delete the file with the % suffix by pressing SELECT on the icon in File Manager and dragging it to the Wastebasket. Saving the Modified File as a New FileTo keep the original file intact and create a new file with the modifications, do the following:
Editing FilesUsing Text Editor, you can add and delete text from a file, copy text from one location to be pasted in another, and search for text strings in a file. Adding and Deleting TextYou can add new text to a file by placing the insert point anywhere in the file (click SELECT in the desired location) and typing the new text there. Likewise, you can delete characters by placing the text caret at the end of the character string you want to delete, and backspacing over those characters. Another way to delete a character string is to cut it. This places the text string in a system clipboard, and if you want you can paste it elsewhere. To cut and paste a text string, do the following:
Copying and Moving TextTo copy a section of text, you highlight the line of text using SELECT and ADJUST, as follows:
Tips on Cutting and Pasting
Printing Text Editor FilesBefore printing a Text Editor file, you may need to choose Format from the Extras menu to reformat selected long lines of text into physical lines of no more than 72 characters. A line of text is defined as ending with a carriage return. The Text Editor wraps a long line into several displayed lines, so what looks like several lines on your screen may actually just be one long line. You print Text Editor files by dragging and dropping the file onto the Print Tool application. To drag the entire Text Editor file, press SELECT on the text glyph inside the drag and drop target, drag the pointer to the Print Tool icon or drag and drop target, and release SELECT. The drag and drop target is the small shaded box in the upper right corner of the Text Editor or the upper left corner of the Print Tool. You can also print Text Editor files the same way you print any file with the File Manager. Save your Text Editor file using one of the methods described in the section "File Menu". Then select the file in the File Manager, and drag and drop it onto the Print Tool or choose Print File from the File Manager's File menu. See "Printing Files" for more information about printing files from the File Manager. Splitting PanesThe Text Editor pane can be split into two or more panes so that you can view and edit different parts of the document at the same time. The document itself is not split, so any editing changes you make in one view are reflected in other views as well. To split the Text Editor pane:
Drag and Drop FeatureDrag and drop is a method of moving files or selected text into and out of the Text Editor using only your mouse. Refer to Chapter 1, Introduction to the Solaris User Environment, for an overview of the drag and drop feature. To load a file (overwriting any existing text), you can drag and drop a text file onto the Text Editor drag and drop target or icon. To insert text within a Text Editor file, you can drag and drop a file or selected text to the spot in the text pane where you want the text inserted. You can drag and drop either selected text or the entire Text Editor file to any location in the DeskSet environment that accepts ASCII text. The following sections describe two different ways to drag and drop from the Text Editor application. Dragging Selected Text from the Text EditorTo drag a copy of selected text from the Text Editor:
Dragging Complete Text Editor FilesText Editor files can be dragged and dropped onto any place in the DeskSet environment that accepts ASCII files. This operation is always done as a copy. To drag a complete Text Editor file:
Customizing Your Text EditorThere are two files used by the Text Editor that you can modify to customize the Extras submenu of the Text Pane pop-up menu and to specify function key mappings. This section describes these two files. The .text_extras_menu FileYou can customize the Extras menu to include your own commands by modifying the file .text_extras_menu. By default (and depending on how your system is configured), the Text Editor uses the information found in the file /usr/openwin/lib/locale/<locale>xview/.text_extras_menu. <locale> is a subdirectory that contains locale specific text files. The default is "C", but may vary depending on the country locale. You can create your own copy of this file and tell the Text Editor to use it instead of the default in either of the following two ways:
The standard Extras menu file is /usr/openwin/lib/locale/C/xview/.text_extras_menu and is shown in Figure 3-13. It will give you ideas about how to implement your own extras menu file. Once you've created a custom file and indicated where to find it using one of the previous methods, you can make changes to the file and see them immediately implemented in the Extras menu. These changes also affect other text panes in DeskSet applications, such as the Mail Tool Compose window. Figure 3-13 Extras Menu File in /usr/lib/.text_extras_menu
The name of each Extras menu item is surrounded by double quotation marks. Each submenu begins with a MENU statement and ends with an END statement. To include a backslash (\) character in the .text_extras_menu file--as in the troff inline font specifications \fB and \fP--you need to use four backslash characters; for example:
Alternatively, you can use quotes in place of one pair of brackets; for example:
The .textswrc FileYou can associate filters (programs or routines) with unused function keys by modifying your own copy of the file .textswrc. When a text selection has been made and a function key pressed, the selected text is piped through the filter assigned to that key. The output is then piped back into the text at the caret, replacing the text that was selected. If you want to specify your own set of bindings of filter keys to function keys, you must copy the file /usr/lib/.textswrc to a file called .textswrc in your home directory. The Text Editor reads the file .textswrc from your home directory, if the file exists. Format of the .textswrc FileList the sample file /usr/lib/.textswrc to see an example of filters used with a right-handed keyboard. You can copy this file into your home directory, then modify it by adding filter bindings to unused function keys. Here is the basic format of each .textswrc file entry:
command-line A function is assigned to one of the function keys by including a statement like the following in your .textswrc file:
This example shows how to include C language comment markers around a piece of text. You could enter this example into your .textswrc file, and save the file. Then, to use this added function, start up a new Text Editor application. Changes to your .textswrc file are only effective when you bring up a new Text Editor. Then select the text and press the key. The text will be replaced with a copy of itself surrounded with "/*" and "*/". Note the C-like syntax of comments in the .textswrc file. When defining a filter in the .textswrc file, remember that the filter must appear in a directory accessible by your search path. If the command is not found, or if there is some other failure in the invocation of the filter, no change occurs in the document. |
||||