[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 1/3] files: require a toggle to write selection inst
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH 1/3] files: require a toggle to write selection instead of buffer to file |
Date: |
Sun, 25 Feb 2018 19:57:21 +0100 |
From: Brand Huntsman <address@hidden>
When the mark is on, nano will no longer automatically offer to write
out only the marked region when ^O is pressed. Instead, the user has
to actively choose to write out just the marked region by pressing M-S,
the "Selection" toggle.
Signed-off-by: Brand Huntsman <address@hidden>
---
src/files.c | 24 ++++++++++++++++--------
src/global.c | 11 +++++++++++
src/proto.h | 1 +
3 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/src/files.c b/src/files.c
index e6fe1fb6..56dc2b64 100644
--- a/src/files.c
+++ b/src/files.c
@@ -2026,6 +2026,7 @@ bool write_marked_file(const char *name, FILE *f_open,
bool tmp,
int do_writeout(bool exiting, bool withprompt)
{
bool result = FALSE;
+ bool only_the_region = FALSE;
kind_of_writing_type method = OVERWRITE;
char *given;
/* The filename we offer, or what the user typed so far. */
@@ -2038,11 +2039,7 @@ int do_writeout(bool exiting, bool withprompt)
/* Display newlines in filenames as ^J. */
as_an_at = FALSE;
- given = mallocstrcpy(NULL,
-#ifndef NANO_TINY
- (openfile->mark && !exiting) ? "" :
-#endif
- openfile->filename);
+ given = mallocstrcpy(NULL, openfile->filename);
while (TRUE) {
const char *msg;
@@ -2058,7 +2055,7 @@ int do_writeout(bool exiting, bool withprompt)
/* When the mark is on, offer to write the selection to disk,
but
* not when in restricted mode, because it would allow writing
to
* a file not specified on the command line. */
- if (openfile->mark && !exiting && !ISSET(RESTRICTED))
+ if (only_the_region)
/* TRANSLATORS: The next six strings are prompts. */
msg = (method == PREPEND) ? _("Prepend Selection to
File") :
(method == APPEND) ? _("Append
Selection to File") :
@@ -2132,6 +2129,17 @@ int do_writeout(bool exiting, bool withprompt)
} else if (func == append_void) {
method = (method == APPEND) ? OVERWRITE : APPEND;
continue;
+ } else if (func == flip_selection) {
+ if (only_the_region) {
+ given = mallocstrcpy(given, openfile->filename);
+ reinit_statusbar_x();
+ only_the_region = FALSE;
+ } else if (openfile->mark && !exiting &&
!ISSET(RESTRICTED)) {
+ given = mallocstrcpy(given, "");
+ only_the_region = TRUE;
+ } else
+ beep();
+ continue;
}
#endif /* !NANO_TINY */
if (func == do_help_void) {
@@ -2184,7 +2192,7 @@ int do_writeout(bool exiting, bool withprompt)
if (!maychange) {
#ifndef NANO_TINY
- if (exiting || !openfile->mark)
+ if (exiting || !only_the_region)
#endif
{
if (do_yesno_prompt(FALSE,
_("Save file under "
@@ -2252,7 +2260,7 @@ int do_writeout(bool exiting, bool withprompt)
* function is disabled, since it allows reading from or
* writing to files not specified on the command line. */
#ifndef NANO_TINY
- if (openfile->mark && !exiting && withprompt &&
!ISSET(RESTRICTED))
+ if (only_the_region && withprompt)
result = write_marked_file(answer, NULL, FALSE, method);
else
#endif
diff --git a/src/global.c b/src/global.c
index 6209d119..ff0dd236 100644
--- a/src/global.c
+++ b/src/global.c
@@ -303,6 +303,9 @@ void append_void(void)
void prepend_void(void)
{
}
+void flip_selection(void)
+{
+}
void backup_file_void(void)
{
}
@@ -654,6 +657,8 @@ void shortcut_init(void)
const char *mac_gist = N_("Toggle the use of Mac format");
const char *append_gist = N_("Toggle appending");
const char *prepend_gist = N_("Toggle prepending");
+ const char *flipselection_gist =
+ N_("Toggle between whole buffer and marked region");
const char *backup_gist = N_("Toggle backing up of the original file");
const char *execute_gist = N_("Execute external command");
#endif
@@ -1021,6 +1026,9 @@ void shortcut_init(void)
add_to_funcs(prepend_void, MWRITEFILE,
N_("Prepend"), WITHORSANS(prepend_gist), TOGETHER,
NOVIEW);
+ add_to_funcs(flip_selection, MWRITEFILE,
+ N_("Selection"), WITHORSANS(flipselection_gist),
TOGETHER, NOVIEW);
+
add_to_funcs(backup_file_void, MWRITEFILE,
N_("Backup File"), WITHORSANS(backup_gist), BLANKAFTER,
NOVIEW);
}
@@ -1328,6 +1336,7 @@ void shortcut_init(void)
if (!ISSET(RESTRICTED)) {
add_to_sclist(MWRITEFILE, "M-A", 0, append_void, 0);
add_to_sclist(MWRITEFILE, "M-P", 0, prepend_void, 0);
+ add_to_sclist(MWRITEFILE, "M-S", 0, flip_selection, 0);
add_to_sclist(MWRITEFILE, "M-B", 0, backup_file_void, 0);
add_to_sclist(MINSERTFILE|MEXTCMD, "^X", 0, flip_execute, 0);
}
@@ -1650,6 +1659,8 @@ sc *strtosc(const char *input)
s->func = append_void;
else if (!strcasecmp(input, "prepend"))
s->func = prepend_void;
+ else if (!strcasecmp(input, "flipselection"))
+ s->func = flip_selection;
else if (!strcasecmp(input, "backup"))
s->func = backup_file_void;
else if (!strcasecmp(input, "flipexecute"))
diff --git a/src/proto.h b/src/proto.h
index 26f7d6d8..8eeb3087 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -706,6 +706,7 @@ void dos_format_void(void);
void mac_format_void(void);
void append_void(void);
void prepend_void(void);
+void flip_selection(void);
void backup_file_void(void);
void flip_execute(void);
#endif
--
2.16.2
- [Nano-devel] [PATCH 1/3] files: require a toggle to write selection instead of buffer to file,
Benno Schulenberg <=