Skip to content

Commit

Permalink
Add --save-marks option.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 29, 2018
1 parent c6a8071 commit 128c1df
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 46 deletions.
4 changes: 3 additions & 1 deletion NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

* Add --wheel-lines option.

* Add --nohistdups option.
* Add --no-histdups option.

* Add --save-marks option.

* Support PCRE2 regular expression library.

Expand Down
13 changes: 13 additions & 0 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
extern int sc_width;
extern int utf_mode;
extern int no_hist_dups;
extern int marks_modified;

static char cmdbuf[CMDBUF_SIZE]; /* Buffer for holding a multi-char command */
static int cmd_col; /* Current column of the cursor */
Expand Down Expand Up @@ -52,6 +53,7 @@ public char closequote = '"';
#define HISTFILE_FIRST_LINE ".less-history-file:"
#define HISTFILE_SEARCH_SECTION ".search"
#define HISTFILE_SHELL_SECTION ".shell"
#define HISTFILE_MARK_SECTION ".mark"

/*
* A mlist structure represents a command history.
Expand Down Expand Up @@ -1479,6 +1481,9 @@ read_cmdhist2(action, uparam, skip_search, skip_shell)
ml = NULL;
skip = NULL;
#endif
} else if (strcmp(line, HISTFILE_MARK_SECTION) == 0)
{
ml = NULL;
} else if (*line == '"')
{
if (ml != NULL)
Expand All @@ -1488,6 +1493,9 @@ read_cmdhist2(action, uparam, skip_search, skip_shell)
else
(*action)(uparam, ml, line+1);
}
} else if (*line == 'm')
{
restore_mark(line);
}
}
fclose(f);
Expand Down Expand Up @@ -1655,6 +1663,10 @@ histfile_modified()
#if SHELL_ESCAPE || PIPEC
if (mlist_shell.modified)
return 1;
#endif
#if CMD_HISTORY
if (marks_modified)
return 1;
#endif
return 0;
}
Expand Down Expand Up @@ -1698,6 +1710,7 @@ save_cmdhist()
ctx.fout = fout;
ctx.mlist = NULL;
read_cmdhist(copy_hist, &ctx, skip_search, skip_shell);
save_marks(fout, HISTFILE_MARK_SECTION);
fclose(fout);
#if MSDOS_COMPILER==WIN32C
/*
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ AC_TRY_COMPILE([], [int f(int a) { return a; }],

# Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([fsync popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod])
AC_CHECK_FUNCS([fsync popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod realpath])

# AC_CHECK_FUNCS may not work for inline functions, so test these separately.
AC_MSG_CHECKING(for memcpy)
Expand Down
15 changes: 15 additions & 0 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,21 @@ lglob(filename)
return (gfilename);
}

/*
* @@@
*/
public char *
lrealpath(path)
char *path;
{
#if HAVE_REALPATH
char rpath[PATH_MAX];
if (realpath(path, rpath) != NULL)
return (save(rpath));
#endif
return (save(path));
}

/*
* Return number of %s escapes in a string.
* Return a large number if there are any other % escapes besides %s.
Expand Down
27 changes: 24 additions & 3 deletions ifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ new_ifile(filename, prev)
p->h_hold = 0;
p->h_filestate = NULL;
link_ifile(p, prev);
/*
* {{ It's dodgy to call mark.c functions from here;
* there is potentially dangerous recursion.
* Probably need to revisit this design. }}
*/
mark_check_ifile(ext_ifile(p));
return (p);
}

Expand Down Expand Up @@ -204,11 +210,26 @@ find_ifile(filename)
char *filename;
{
struct ifile *p;
char *rfilename = lrealpath(filename);

for (p = anchor.h_next; p != &anchor; p = p->h_next)
if (strcmp(filename, p->h_filename) == 0)
return (p);
return (NULL);
{
if (strcmp(filename, p->h_filename) == 0 ||
strcmp(rfilename, p->h_filename) == 0)
{
/*
* If given name is shorter than the name we were
* previously using for this file, adopt shorter name.
*/
if (strlen(filename) < strlen(p->h_filename))
strcpy(p->h_filename, filename);
break;
}
}
free(rfilename);
if (p == &anchor)
p = NULL;
return (p);
}

/*
Expand Down
11 changes: 2 additions & 9 deletions less.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,6 @@ struct scrpos
int ln;
};

/*
* A mark is an ifile (input file) plus a position within the file.
*/
struct mark
{
IFILE m_ifile;
struct scrpos m_scrpos;
};

typedef union parg
{
char *p_string;
Expand Down Expand Up @@ -544,6 +535,8 @@ struct hilite_tree;
void postoa LESSPARAMS ((POSITION, char*));
void linenumtoa LESSPARAMS ((LINENUM, char*));
void inttoa LESSPARAMS ((int, char*));
int lstrtoi LESSPARAMS ((char*, char**));
POSITION lstrtopos LESSPARAMS ((char*, char**));
#if MSDOS_COMPILER==WIN32C
int pclose LESSPARAMS ((FILE*));
#endif
16 changes: 10 additions & 6 deletions less.hlp.VER
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,20 @@
Don't display tildes after end of file.
-# [_N] .... --shift=[_N]
Horizontal scroll amount (0 = one half screen width)
--no-keypad
Don't send termcap keypad init/deinit strings.
--follow-name
The F command changes files if the input file is renamed.
--use-backslash
Subsequent options use backslash as escape char.
--mouse
Enable mouse input.
--no-keypad
Don't send termcap keypad init/deinit strings.
--no-histdups
Remove duplicates from command history.
--rscroll=C
Set the character used to mark truncated lines.
--nohistdups
Remove duplicates from command history.
--save-marks
Retain marks across invocations of less.
--use-backslash
Subsequent options use backslash as escape char.


---------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ Disables sending the keypad initialization and deinitialization strings
to the terminal.
This is sometimes useful if the keypad strings make the numeric
keypad behave in an undesirable manner.
.IP "\-\-nohistdups"
.IP "\-\-no-histdups"
This option changes the behavior so that if a search string or
file name is typed in, and the same string is already in the history list,
the existing copy is removed from the history list before the new one is added.
Expand All @@ -968,6 +968,9 @@ This option changes the character used to mark truncated lines.
It may begin with a two-character attribute indicator like LESSBINFMT does.
If there is no attribute indicator, standout is used.
If set to "-", truncated lines are not marked.
.IP "\-\-save-marks"
Save marks in the history file, so marks are retained
across different invocations of \fIless\fP.
.IP "\-\-use-backslash"
This option changes the interpretations of options which follow this one.
After the \-\-use-backslash option, any backslash in an option string is
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ main(argc, argv)
* Command line arguments override environment arguments.
*/
is_tty = isatty(1);
init_mark();
init_cmds();
get_term();
expand_cmd_tables();
Expand Down Expand Up @@ -226,7 +227,6 @@ main(argc, argv)

if (missing_cap && !know_dumb)
error("WARNING: terminal is not fully functional", NULL_PARG);
init_mark();
open_getchr();
raw_mode(1);
init_signals(1);
Expand Down
Loading

0 comments on commit 128c1df

Please sign in to comment.