Commit 8c705b5d authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

Moving an updated position-history item to the end of the list,

so that it won't be dropped any time soon.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5582 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 30 additions and 17 deletions
+30 -17
2016-01-24 Benno Schulenberg <bensberg@justemail.net>
* src/files.c (update_poshistory): Move an updated item to the end
of the list, so that it won't be dropped any time soon. The problem
was pointed out by David Niklas.
2016-01-22 Benno Schulenberg <bensberg@justemail.net> 2016-01-22 Benno Schulenberg <bensberg@justemail.net>
* src/utils.c (get_homedir): Don't use $HOME when we're root, because * src/utils.c (get_homedir): Don't use $HOME when we're root, because
some sudos don't filter it out of the environment (which can lead to some sudos don't filter it out of the environment (which can lead to
......
...@@ -3183,33 +3183,41 @@ void save_poshistory(void) ...@@ -3183,33 +3183,41 @@ void save_poshistory(void)
* and a column. If no entry is found, add a new one at the end. */ * and a column. If no entry is found, add a new one at the end. */
void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos) void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos)
{ {
poshiststruct *posptr, *posprev = NULL; poshiststruct *posptr, *theone, *posprev = NULL;
char *fullpath = get_full_path(filename); char *fullpath = get_full_path(filename);
if (fullpath == NULL) if (fullpath == NULL)
return; return;
/* Look for a matching filename in the list. */
for (posptr = position_history; posptr != NULL; posptr = posptr->next) { for (posptr = position_history; posptr != NULL; posptr = posptr->next) {
if (!strcmp(posptr->filename, fullpath)) { if (!strcmp(posptr->filename, fullpath))
posptr->lineno = lineno; break;
posptr->xno = xpos;
free(fullpath);
return;
}
posprev = posptr; posprev = posptr;
} }
/* Didn't find it, make a new node yo! */ theone = posptr;
posptr = (poshiststruct *)nmalloc(sizeof(poshiststruct));
posptr->filename = mallocstrcpy(NULL, fullpath);
posptr->lineno = lineno;
posptr->xno = xpos;
posptr->next = NULL;
/* If we didn't find it, make a new node; otherwise, if we're
* not at the end, move the matching one to the end. */
if (theone == NULL) {
theone = (poshiststruct *)nmalloc(sizeof(poshiststruct));
theone->filename = mallocstrcpy(NULL, fullpath);
if (position_history == NULL) if (position_history == NULL)
position_history = posptr; position_history = theone;
else else
posprev->next = posptr; posprev->next = theone;
} else if (posptr->next != NULL) {
posprev->next = posptr->next;
while (posptr->next != NULL)
posptr = posptr->next;
posptr->next = theone;
}
/* Store the last cursor position. */
theone->lineno = lineno;
theone->xno = xpos;
theone->next = NULL;
free(fullpath); free(fullpath);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment