Sun Studio 12: C User's Guide

8.2.9 Command-Line Syntax for Editors

cscope invokes the vi editor by default. You can override the default setting by assigning your preferred editor to the EDITOR environment variable and exporting EDITOR, as described in 8.2.1 Step 1: Set Up the Environment. However, cscope expects the editor it uses to have a command-line syntax of the form:

% editor +linenum filename

as does vi. If the editor you want to use does not have this command-line syntax, you must write an interface between cscope and the editor.

Suppose you want to use ed. Because ed does not allow specification of a line number on the command-line, you cannot use it to view or edit files with cscope unless you write a shell script that contains the following line:

/usr/bin/ed $2

Let’s name the shell script myedit. Now set the value of EDITOR to your shell script and export EDITOR:

In a Bourne shell, type:

$ EDITOR=myedit; export EDITOR

In a C shell, type:

% setenv EDITOR myedit

When cscope invokes the editor for the list item you have specified, say, line 17 in main.c, it invokes your shell script with the command-line:

% myedit +17 main.c

myedit then discards the line number ($1) and calls ed correctly with the file name ($2). Of course, you are not moved automatically to line 17 of the file and must execute the appropriate ed commands to display and edit the line.