nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 4ddf1940046738f25686d0abc3ff6d151c06ee06
parent 036c5f9c1f8321ae327dd43863f8b5cd0a29e91f
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Sun, 20 Mar 2016 14:34:46 +0000

Always asking whether it's okay when the name of the file was changed.
This fixes Savannah bug #46894.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5753 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

Diffstat:
MChangeLog | 2++
Msrc/files.c | 36++++++++++++++++++++++++------------
2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -6,6 +6,8 @@ that is: treat the deletion of words like pressing Backspace/Delete. * src/search.c (get_history_completion, find_history): Cycle through the items from newest to oldest. This fixes Savannah bug #47205. + * src/files.c (do_writeout): When the name of the file was changed, + always ask whether this is okay. This fixes Savannah bug #46894. 2016-03-19 Benno Schulenberg <bensberg@justemail.net> * src/search.c (search_init): Always remember the last typed string, diff --git a/src/files.c b/src/files.c @@ -2276,6 +2276,8 @@ int do_writeout(bool exiting) #ifndef DISABLE_EXTRA static bool did_credits = FALSE; #endif + bool maychange = FALSE; + /* Whether it's okay to save the file under a different name. */ bool result = FALSE; if (exiting && openfile->filename[0] != '\0' && ISSET(TEMP_FILE)) { @@ -2452,19 +2454,29 @@ int do_writeout(bool exiting) if (ISSET(RESTRICTED)) continue; - if (name_exists) { - i = do_yesno_prompt(FALSE, - _("File exists; OVERWRITE? ")); - if (i == 0 || i == -1) - continue; - } else + if (!maychange) { #ifndef NANO_TINY - if (exiting || !openfile->mark_set) -#endif - { - i = do_yesno_prompt(FALSE, - _("Save file under DIFFERENT NAME? ")); - if (i == 0 || i == -1) + if (exiting || !openfile->mark_set) +#endif + { + i = do_yesno_prompt(FALSE, + _("Save file under DIFFERENT NAME? ")); + if (i < 1) + continue; + maychange = TRUE; + } + } + + if (name_exists) { + char *question = _("File \"%s\" exists; OVERWRITE? "); + char *message = charalloc(strlen(question) + + strlen(answer) + 1); + sprintf(message, question, answer); + + i = do_yesno_prompt(FALSE, message); + free(message); + + if (i < 1) continue; } }