2011-02-18 Chris Allegretta <chrisa@asty.org>

* New saved cursor position history option.  Command line option -P or --poslog, rc file
          entry "poslog".  Search history changes to ~/.nano/search_history, cursor position log
          is ~/.nano/filepos_history.  Added checks to move the legacy .nano_history file to the new
          location.  Several new functions to files.c: load_poshistory(), save_poshistory(),
          check_poshistory(), update_poshistory(), and reworking of histfilename().  New FAQ entry
          4.15 discussing the change and offering an interoperability workaround.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4530 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2011-02-18 07:30:57 +00:00
parent 9bfda9196b
commit 8e2a930714
8 changed files with 79 additions and 21 deletions

View File

@ -1,3 +1,11 @@
2011-02-18 Chris Allegretta <chrisa@asty.org>
* New saved cursor position history option. Command line option -P or --poslog, rc file
entry "poslog". Search history changes to ~/.nano/search_history, cursor position log
is ~/.nano/filepos_history. Added checks to move the legacy .nano_history file to the new
location. Several new functions to files.c: load_poshistory(), save_poshistory(),
check_poshistory(), update_poshistory(), and reworking of histfilename(). New FAQ entry
4.15 discussing the change and offering an interoperability workaround.
2011-02-12 Chris Allegretta <chrisa@asty.org>
* Initial libmagic implementation, adapted from Eitan Adler <eitanadlerlist@gmail.com>.
New nanorc entry "magic" to enable this functionality, nanorc file and man page updates.

View File

@ -46,7 +46,8 @@
<a href="#4.11">4.11. How do I make nano my default editor (in Pine, mutt, etc.)?</a><br>
<a href="#4.12">4.12. I've compiled nano with color support, but I don't see any color when I run it!</a><br>
<a href="#4.13">4.13. How do I select text for or paste text from the clipboard in an X terminal when I'm running nano in one and nano's mouse support is turned on?</a><br>
<a href="#4.14">4.14. When I paste text into a document, each line gets indented further than the last. Why does nano do this, and how can I avoid it?</a></p></blockquote>
<a href="#4.14">4.14. When I paste text into a document, each line gets indented further than the last. Why does nano do this, and how can I avoid it?</a><br>
<a href="#4.15">4.15. On startup I get a message that says "Detected a legacy nano history file". Now other nano versionc can't find my search history!</a></p></blockquote>
<h2><a href="#5">5. Internationalization</a></h2>
<blockquote><p><a href="#5.1">5.1. There's no translation for my language!</a><br>
<a href="#5.2">5.2. I don't like the translation for &lt;x&gt; in my language. How can I fix it?</a><br>
@ -222,6 +223,11 @@
<blockquote><p>Try holding down the Shift key and selecting or pasting the text as you normally would.</p></blockquote>
<h2><a name="4.14"></a>4.14. When I paste text into a document, each line gets indented further than the last. Why does nano do this, and how can I avoid it?</h2>
<blockquote><p>You have the autoindent feature turned on. Hit Meta-I to turn it off, paste your text, and then hit Meta-I again to turn it back on.</p></blockquote>
<h2><a name="4.15"></a>4.15. On startup I get a message that says "Detected a legacy nano history file". Now other nano versionc can't find my search history!</h2>
<blockquote><p>In nano 2.3.0, cursor position history was introduced, and both files now reside under a .nano directory in your home. Nano was trying to move this file into the new location so it could continue to use it. This means that if you try and use an earlier version of nano, it will be unable to see your previous search history. To fix this, run the following commands:<br>
mv ~/.nano/search_history ~/.nano_history<br>
ln -sf ~/.nano_history ~/.nano/search_history<br>
</p></blockquote>
<hr width="100%">
<h1><a name="5"></a>5. Internationalization</h1>
<h2><a name="5.1"></a>5.1. There's no translation for my language!</h2>

View File

@ -180,6 +180,9 @@ won't work properly with this option enabled.
.B set/unset regexp
Do extended regular expression searches by default.
.TP
.B set/unset poslog
Save the cursor position of files between editing sessions.
.TP
.B set/unset smarthome
Make the Home key smarter. When Home is pressed anywhere but at the
very beginning of non-whitespace characters on a line, the cursor will

View File

@ -4,7 +4,7 @@ syntax "nanorc" "\.?nanorc$"
## Possible errors and parameters
icolor brightwhite "^[[:space:]]*((un)?set|include|syntax|i?color).*$"
## Keywords
icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|autoindent|backup|backupdir|backwards|boldtext|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quickblank|quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|softwrap|speller|suspend|suspendenable|tabsize|tabstospaces|tempfile|undo|view|whitespace|wordbounds)\>"
icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|autoindent|backup|backupdir|backwards|boldtext|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|poslog|preserve|punct)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quickblank|quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|softwrap|speller|suspend|suspendenable|tabsize|tabstospaces|tempfile|undo|view|whitespace|wordbounds)\>"
icolor green "^[[:space:]]*(set|unset|include|syntax|header|magic)\>"
## Colors
icolor yellow "^[[:space:]]*i?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>"

View File

@ -279,6 +279,10 @@ bool close_buffer(void)
if (openfile == openfile->next)
return FALSE;
#ifndef NANO_TINY
update_poshistory(openfile->filename, openfile->current->lineno, xplustabs()+1);
#endif /* NANO_TINY */
/* Switch to the next file buffer. */
switch_to_next_buffer_void();
@ -2880,8 +2884,8 @@ void save_history(void)
void save_poshistory(void)
{
char *poshist;
char *statusstr;
openfilestruct *ofptr = openfile;
char *statusstr = NULL;
poshiststruct *posptr;
poshist = poshistfilename();
@ -2896,18 +2900,14 @@ void save_poshistory(void)
* history file. */
chmod(poshist, S_IRUSR | S_IWUSR);
while (1) {
char *name = get_full_path(ofptr->filename);
statusstr = charalloc(strlen(name) + 2 * sizeof(ssize_t) + 4);
sprintf(statusstr, "%s %d %d\n", name, (int) ofptr->current->lineno,
(int) strnlenpt(openfile->current->data, openfile->current_x) + 1);
for (posptr = poshistory; posptr != NULL; posptr = posptr->next) {
statusstr = charalloc(strlen(posptr->filename) + 2 * sizeof(ssize_t) + 4);
sprintf(statusstr, "%s %d %d\n", posptr->filename, (int) posptr->lineno,
(int) posptr->xno);
if (fwrite(statusstr, sizeof(char), strlen(statusstr), hist) < strlen(statusstr))
history_error(N_("Error writing %s: %s"), poshist,
strerror(errno));
free(name);
if (ofptr->next == ofptr)
break;
ofptr = ofptr->next;
free(statusstr);
}
fclose(hist);
}
@ -2915,6 +2915,43 @@ void save_poshistory(void)
}
}
/* Update the POS history, given a filename line and column.
* If no entry is found, add a new entry on the end
*/
void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos)
{
poshiststruct *posptr, *posprev = NULL;
char *fullpath = get_full_path(filename);
if (fullpath == NULL)
return;
for (posptr = poshistory; posptr != NULL; posptr = posptr->next) {
if (!strcmp(posptr->filename, fullpath)) {
posptr->lineno = lineno;
posptr->xno = xpos;
return;
}
posprev = posptr;
}
/* Didn't find it, make a new node yo! */
posptr = nmalloc(sizeof(poshiststruct));
posptr->filename = mallocstrcpy(NULL, fullpath);
posptr->lineno = lineno;
posptr->xno = xpos;
posptr->next = NULL;
if (!poshistory)
poshistory = posptr;
else
posprev->next = posptr;
free(fullpath);
}
/* Check the POS history to see if file matches
* an existing entry. If so return 1 and set line and column
* to the right values Otherwise return 0
@ -2931,9 +2968,11 @@ int check_poshistory(const char *file, ssize_t *line, ssize_t *column)
if (!strcmp(posptr->filename, fullpath)) {
*line = posptr->lineno;
*column = posptr->xno;
free(fullpath);
return 1;
}
}
free(fullpath);
return 0;
}
@ -2943,7 +2982,6 @@ void load_poshistory(void)
{
char *nanohist = poshistfilename();
/* Assume do_rcfile() has reported a missing home directory. */
if (nanohist != NULL) {
FILE *hist = fopen(nanohist, "rb");
@ -2974,7 +3012,6 @@ void load_poshistory(void)
xptr = parse_next_word(lineptr);
lineno = atoi(lineptr);
xno = atoi(xptr);
fprintf(stderr, "Read data: file %s, line %d, xpos %d\n", line, lineno, xno);
if (poshistory == NULL) {
poshistory = nmalloc(sizeof(poshiststruct));
poshistory->filename = mallocstrcpy(NULL, line);
@ -2982,7 +3019,7 @@ void load_poshistory(void)
poshistory->xno = xno;
poshistory->next = NULL;
} else {
for (posptr = poshistory; posptr != NULL; posptr = posptr->next)
for (posptr = poshistory; posptr->next != NULL; posptr = posptr->next)
;
posptr->next = nmalloc(sizeof(poshiststruct));
posptr->next->filename = mallocstrcpy(NULL, line);

View File

@ -605,8 +605,10 @@ void finish(void)
#if !defined(NANO_TINY) && defined(ENABLE_NANORC)
if (!no_rcfiles && ISSET(HISTORYLOG))
save_history();
if (!no_rcfiles && ISSET(POS_HISTORY))
if (!no_rcfiles && ISSET(POS_HISTORY)) {
update_poshistory(openfile->filename, openfile->current->lineno, xplustabs()+1);
save_poshistory();
}
#endif
#ifdef DEBUG
@ -859,8 +861,8 @@ void usage(void)
#endif
print_opt("-O", "--morespace", N_("Use one more line for editing"));
#ifndef NANO_TINY
print_opt("-P", "--poshistory",
N_("Save and load history of cursor position"));
print_opt("-P", "--poslog",
N_("Log & read location of cursor position"));
#endif
#ifndef DISABLE_JUSTIFY
print_opt(_("-Q <str>"), _("--quotestr=<str>"),
@ -2098,7 +2100,7 @@ int main(int argc, char **argv)
{"tabstospaces", 0, NULL, 'E'},
{"historylog", 0, NULL, 'H'},
{"noconvert", 0, NULL, 'N'},
{"poshistory", 0, NULL, 'P'},
{"poslog", 0, NULL, 'P'},
{"smooth", 0, NULL, 'S'},
{"quickblank", 0, NULL, 'U'},
{"undo", 0, NULL, 'u'},

View File

@ -114,6 +114,7 @@ extern filestruct *replace_history;
extern filestruct *replaceage;
extern filestruct *replacebot;
extern poshiststruct *poshistory;
void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos);
#endif
#ifdef HAVE_REGEX_H

View File

@ -85,6 +85,7 @@ static const rcoption rcopts[] = {
{"historylog", HISTORYLOG},
{"matchbrackets", 0},
{"noconvert", NO_CONVERT},
{"poslog", POS_HISTORY},
{"quiet", QUIET},
{"quickblank", QUICK_BLANK},
{"smarthome", SMART_HOME},