Skip to content

Commit

Permalink
Added t and T commands.
Browse files Browse the repository at this point in the history
Added support for "global(1)" tags.
  • Loading branch information
gwsw committed Dec 12, 2001
1 parent 6f99b55 commit fce490b
Show file tree
Hide file tree
Showing 10 changed files with 638 additions and 53 deletions.
3 changes: 3 additions & 0 deletions NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* -X no longer disables keypad initialization.
New option --no-keypad disables keypad initialization.

* New commands t and T to step through multiple tag matches.
Added support for "global(1)" tags.

* New prompt style set by option -Pw defines the message printed
while waiting for data in the F command.

Expand Down
2 changes: 2 additions & 0 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#define A_F_FOREVER 50
#define A_GOPOS 51
#define A_REMOVE_FILE 52
#define A_NEXT_TAG 53
#define A_PREV_TAG 54

#define A_INVALID 100
#define A_NOACTION 101
Expand Down
47 changes: 47 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ exec_mca()
if (secure)
break;
edit_list(cbuf);
/* If tag structure is loaded then clean it up. */
cleantags();
break;
#endif
#if SHELL_ESCAPE
Expand Down Expand Up @@ -842,6 +844,7 @@ commands()
PARG parg;
IFILE old_ifile;
IFILE new_ifile;
char *tagfile;

search_type = SRCH_FORW;
wscroll = (sc_height + 1) / 2;
Expand Down Expand Up @@ -1359,6 +1362,11 @@ commands()
/*
* Examine next file.
*/
if (ntags())
{
error("No next file", NULL_PARG);
break;
}
if (number <= 0)
number = 1;
if (edit_next(number))
Expand All @@ -1375,6 +1383,11 @@ commands()
/*
* Examine previous file.
*/
if (ntags())
{
error("No previous file", NULL_PARG);
break;
}
if (number <= 0)
number = 1;
if (edit_prev(number))
Expand All @@ -1384,6 +1397,40 @@ commands()
}
break;

case A_NEXT_TAG:
if (number <= 0)
number = 1;
tagfile = nexttag(number);
if (tagfile == NULL)
{
error("No next tag", NULL_PARG);
break;
}
if (edit(tagfile) == 0)
{
POSITION pos = tagsearch();
if (pos != NULL_POSITION)
jump_loc(pos, jump_sline);
}
break;

case A_PREV_TAG:
if (number <= 0)
number = 1;
tagfile = prevtag(number);
if (tagfile == NULL)
{
error("No previous tag", NULL_PARG);
break;
}
if (edit(tagfile) == 0)
{
POSITION pos = tagsearch();
if (pos != NULL_POSITION)
jump_loc(pos, jump_sline);
}
break;

case A_INDEX_FILE:
/*
* Examine a particular file.
Expand Down
2 changes: 2 additions & 0 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ static unsigned char cmdtable[] =
CONTROL('X'),CONTROL('V'),0, A_EXAMINE,
':','n',0, A_NEXT_FILE,
':','p',0, A_PREV_FILE,
't',0, A_NEXT_TAG,
'T',0, A_PREV_TAG,
':','x',0, A_INDEX_FILE,
':','d',0, A_REMOVE_FILE,
'-',0, A_OPT_TOGGLE,
Expand Down
2 changes: 2 additions & 0 deletions less.hlp.VER
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
g < ESC-< * Go to first line in file (or line _N).
G > ESC-> * Go to last line in file (or line _N).
p % * Go to beginning of file (or _N percent into file).
t * Go to the (_N-th) next tag.
T * Go to the (_N-th) previous tag.
{ ( [ * Find close bracket } ) ].
} ) ] * Find open bracket { ( [.
ESC-^F _<_c_1_> _<_c_2_> * Find close bracket _<_c_2_>.
Expand Down
12 changes: 9 additions & 3 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ Examine the first file in the command line list.
If a number N is specified, the N-th file in the list is examined.
.IP ":d"
Remove the current file from the list of files.
.IP "t"
Go to the next tag, if there were more than one matches for the current tag.
See the \-t option for more details about tags.
.IP "T"
Go to the previous tag, if there were more than one matches for the current tag.
.IP "= or ^G or :f"
Prints some information about the file being viewed,
including its name
Expand Down Expand Up @@ -692,10 +697,11 @@ on the next line.
.IP "-t\fItag\fP or --tag=\fItag\fP"
The -t option, followed immediately by a TAG,
will edit the file containing that tag.
For this to work, there must be a file called "tags" in the
current directory, which was previously built by the
For this to work, tag information must be available;
for example, there may be a file in the current directory called "tags",
which was previously built by
.I ctags
(1) command.
(1) or an equivalent command.
This option may also be specified from within
.I less
(using the \- command) as a way of examining a new file.
Expand Down
3 changes: 2 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public char * editproto;
#endif

#if TAGS
extern char * tags;
extern char * tagoption;
extern int jump_sline;
#endif
Expand Down Expand Up @@ -217,7 +218,7 @@ main(argc, argv)
* Select the first file to examine.
*/
#if TAGS
if (tagoption != NULL)
if (tagoption != NULL || strcmp(tags, "-") == 0)
{
/*
* A -t option was given.
Expand Down
31 changes: 23 additions & 8 deletions prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ extern char *editproto;
* These strings are expanded by pr_expand().
*/
static constant char s_proto[] =
"?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\\: %x..%t";
"?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\\: %x..%t";
static constant char m_proto[] =
"?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t";
"?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t";
static constant char M_proto[] =
"?f%f .?n?m(file %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t";
"?f%f .?n?m(%T %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t";
static constant char e_proto[] =
"?f%f .?m(file %i of %m) .?ltlines %lt-%lb?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t";
"?f%f .?m(%T %i of %m) .?ltlines %lt-%lb?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t";
static constant char h_proto[] =
"HELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done";
static constant char w_proto[] =
Expand Down Expand Up @@ -199,9 +199,9 @@ cond(c, where)
case 'D': /* Same as L */
return (linenums && ch_length() != NULL_POSITION);
case 'm': /* More than one file? */
return (nifile() > 1);
return (ntags() ? (ntags() > 1) : (nifile() > 1));
case 'n': /* First prompt in a new file? */
return (new_file);
return (ntags() ? 1 : new_file);
case 'p': /* Percent into file (bytes) known? */
return (curr_byte(where) != NULL_POSITION &&
ch_length() > 0);
Expand All @@ -213,6 +213,8 @@ cond(c, where)
case 'B':
return (ch_length() != NULL_POSITION);
case 'x': /* Is there a "next" file? */
if (ntags())
return (0);
return (next_ifile(curr_ifile) != NULL_IFILE);
}
return (0);
Expand Down Expand Up @@ -285,7 +287,10 @@ protochar(c, where, iseditproto)
free(s);
break;
case 'i': /* Index into list of files */
ap_int(get_index(curr_ifile));
if (ntags())
ap_int(curr_tag());
else
ap_int(get_index(curr_ifile));
break;
case 'l': /* Current line number */
n = currline(where);
Expand All @@ -303,7 +308,11 @@ protochar(c, where, iseditproto)
ap_int(n-1);
break;
case 'm': /* Number of files */
ap_int(nifile());
n = ntags();
if (n)
ap_int(n);
else
ap_int(nifile());
break;
case 'p': /* Percent into file (bytes) */
pos = curr_byte(where);
Expand Down Expand Up @@ -334,6 +343,12 @@ protochar(c, where, iseditproto)
while (mp > message && mp[-1] == ' ')
mp--;
break;
case 'T': /* Type of list */
if (ntags())
ap_str("tag");
else
ap_str("file");
break;
case 'x': /* Name of next file */
h = next_ifile(curr_ifile);
if (h != NULL_IFILE)
Expand Down
Loading

0 comments on commit fce490b

Please sign in to comment.