From 8e2a9307148a88515e78c91afd0ef1bd72ef66c2 Mon Sep 17 00:00:00 2001
From: Chris Allegretta
4.12. I've compiled nano with color support, but I don't see any color when I run it!
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?
- 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?
5.1. There's no translation for my language!
5.2. I don't like the translation for <x> in my language. How can I fix it?
@@ -222,6 +223,11 @@Try holding down the Shift key and selecting or pasting the text as you normally would.
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?
+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.
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!
+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:
+mv ~/.nano/search_history ~/.nano_history
+ln -sf ~/.nano_history ~/.nano/search_history
+
5. Internationalization
5.1. There's no translation for my language!
diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index 4a0fc0f0..e4c3ea2f 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -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 diff --git a/doc/syntax/nanorc.nanorc b/doc/syntax/nanorc.nanorc index 102fc028..bda5f4f4 100644 --- a/doc/syntax/nanorc.nanorc +++ b/doc/syntax/nanorc.nanorc @@ -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))?\>" diff --git a/src/files.c b/src/files.c index 30b1ba7d..f1df487c 100644 --- a/src/files.c +++ b/src/files.c @@ -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,7 +2915,44 @@ void save_poshistory(void) } } -/* Check the POS history to see if file matches +/* 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); diff --git a/src/nano.c b/src/nano.c index 6326e97c..c51b644c 100644 --- a/src/nano.c +++ b/src/nano.c @@ -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"), _("--quotestr= "), @@ -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'}, diff --git a/src/proto.h b/src/proto.h index 3af48420..9ce39d9c 100644 --- a/src/proto.h +++ b/src/proto.h @@ -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 diff --git a/src/rcfile.c b/src/rcfile.c index af68a64f..36f86301 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -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}, -- 2.39.5