Commit 6f143c81 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add the ability to convert (non-verbatim input) typed tabs to spaces

using the -E/--tabstospaces command line options, the "tabstospaces"
rcfile option, and the toggle Meta-E; also, change the short command
line option for --backupdir from -E to -C


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2682 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 77 additions and 17 deletions
+77 -17
...@@ -86,6 +86,15 @@ CVS code - ...@@ -86,6 +86,15 @@ CVS code -
still work the same way with them. This also fixes still work the same way with them. This also fixes
compilation on Mac OS X 10.4.1, which doesn't seem to define a compilation on Mac OS X 10.4.1, which doesn't seem to define a
wint_t type. (DLR, problem found by Emily Jackson) wint_t type. (DLR, problem found by Emily Jackson)
- Add the ability to convert typed tabs to spaces using
the -E/--tabstospaces command line options, the "tabstospaces"
rcfile option, and the toggle Meta-E. Note that this doesn't
affect tabs entered using verbatim input, and that it's
disabled when NANO_SMALL is defined. Also, change the short
command line option for --backupdir from -E to -C. Changes to
toggle_init(), help_init(), usage(), do_tab(), main(),
nanorc.sample, nano.1, nanorc.5, and nano.texi. (DLR,
suggested by many people)
- chars.c: - chars.c:
make_mbstring() make_mbstring()
- Change erroneous ENABLE_EXTRA #ifdef to NANO_EXTRA to fix a - Change erroneous ENABLE_EXTRA #ifdef to NANO_EXTRA to fix a
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
.\" Public License for copying conditions. There is NO warranty. .\" Public License for copying conditions. There is NO warranty.
.\" .\"
.\" $Id$ .\" $Id$
.TH NANO 1 "version 1.3.8" "June 3, 2005" .TH NANO 1 "version 1.3.8" "June 15, 2005"
.\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
.\" .\"
...@@ -50,10 +50,13 @@ line. ...@@ -50,10 +50,13 @@ line.
When saving a file, back up the previous version of it to the current When saving a file, back up the previous version of it to the current
filename suffixed with a ~. filename suffixed with a ~.
.TP .TP
.B \-E \fIdir\fP (\-\-backupdir=\fIdir\fP) .B \-C \fIdir\fP (\-\-backupdir=\fIdir\fP)
Set the directory where \fBnano\fP puts unique backup files if file Set the directory where \fBnano\fP puts unique backup files if file
backups are enabled. backups are enabled.
.TP .TP
.B \-E (\-\-tabstospaces)
Convert typed tabs to spaces.
.TP
.B \-F (\-\-multibuffer) .B \-F (\-\-multibuffer)
Enable multiple file buffers, if available. Enable multiple file buffers, if available.
.TP .TP
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
.\" Public License for copying conditions. There is NO warranty. .\" Public License for copying conditions. There is NO warranty.
.\" .\"
.\" $Id$ .\" $Id$
.TH NANORC 5 "version 1.3.8" "June 8, 2005" .TH NANORC 5 "version 1.3.8" "June 15, 2005"
.\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.SH NAME .SH NAME
...@@ -143,6 +143,9 @@ Allow nano to be suspended. ...@@ -143,6 +143,9 @@ Allow nano to be suspended.
Use a tab size of \fIn\fP columns instead of the default (8); must be Use a tab size of \fIn\fP columns instead of the default (8); must be
greater than 0. greater than 0.
.TP .TP
\fBset/unset tabstospaces\fP
Convert typed tabs to spaces.
.TP
\fBset/unset tempfile\fP \fBset/unset tempfile\fP
Save automatically on exit, don't prompt. Save automatically on exit, don't prompt.
.TP .TP
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
## Use cut to end of line by default. ## Use cut to end of line by default.
# set cut # set cut
## Convert typed tabs to spaces.
# set tabstospaces
## Set the line length for wrapping text and justifying paragraphs. ## Set the line length for wrapping text and justifying paragraphs.
## If fill is negative, the line length will be the screen width less ## If fill is negative, the line length will be the screen width less
## this number. ## this number.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
@smallbook @smallbook
@set EDITION 0.1 @set EDITION 0.1
@set VERSION 1.3.8 @set VERSION 1.3.8
@set UPDATED 03 Jun 2005 @set UPDATED 15 Jun 2005
@dircategory Editors @dircategory Editors
@direntry @direntry
...@@ -124,10 +124,13 @@ line. ...@@ -124,10 +124,13 @@ line.
When saving a file, back up the previous version of it to the current When saving a file, back up the previous version of it to the current
filename suffixed with a ~. filename suffixed with a ~.
@item -E, --backupdir=[dir] @item -C, --backupdir=[dir]
Set the directory where @code{nano} puts unique backup files if file Set the directory where @code{nano} puts unique backup files if file
backups are enabled. backups are enabled.
@item -E, --tabstospaces
Convert typed tabs to spaces.
@item -F, --multibuffer @item -F, --multibuffer
Enable multiple file buffers, if available. Enable multiple file buffers, if available.
......
...@@ -1151,6 +1151,8 @@ void toggle_init(void) ...@@ -1151,6 +1151,8 @@ void toggle_init(void)
#endif #endif
toggle_init_one(TOGGLE_MORESPACE_KEY, toggle_init_one(TOGGLE_MORESPACE_KEY,
N_("Use of more space for editing"), MORE_SPACE); N_("Use of more space for editing"), MORE_SPACE);
toggle_init_one(TOGGLE_TABSTOSPACES_KEY,
N_("Conversion of typed tabs to spaces"), TABS_TO_SPACES);
} }
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
......
...@@ -519,15 +519,20 @@ void help_init(void) ...@@ -519,15 +519,20 @@ void help_init(void)
} }
/* If the primary meta key sequence is the first entry, /* If the primary meta key sequence is the first entry,
* don't put parentheses around it. */ * don't put parentheses around it. */
if (entries == 1 && s->metaval == NANO_ALT_SPACE) { if (entries == 1) {
/* Yucky sentinel values we can't handle a better
* way. */
if (s->metaval == NANO_ALT_SPACE) {
char *space_ptr = display_string(_("Space"), 0, 5, char *space_ptr = display_string(_("Space"), 0, 5,
FALSE); FALSE);
ptr += sprintf(ptr, "M-%s", space_ptr); ptr += sprintf(ptr, "M-%s", space_ptr);
free(space_ptr); free(space_ptr);
}
} else } else
ptr += sprintf(ptr, entries == 1 ? "M-%c" : "(M-%c)", /* Normal values. */
ptr += sprintf(ptr, (entries == 1) ? "M-%c" : "(M-%c)",
toupper(s->metaval)); toupper(s->metaval));
*(ptr++) = '\t'; *(ptr++) = '\t';
} }
...@@ -1024,8 +1029,10 @@ void usage(void) ...@@ -1024,8 +1029,10 @@ void usage(void)
#ifndef NANO_SMALL #ifndef NANO_SMALL
print1opt("-A", "--smarthome", N_("Enable smart home key")); print1opt("-A", "--smarthome", N_("Enable smart home key"));
print1opt("-B", "--backup", N_("Save backups of existing files")); print1opt("-B", "--backup", N_("Save backups of existing files"));
print1opt(_("-E [dir]"), _("--backupdir=[dir]"), print1opt(_("-C [dir]"), _("--backupdir=[dir]"),
N_("Directory for saving unique backup files")); N_("Directory for saving unique backup files"));
print1opt("-E", "--tabstospaces",
N_("Convert typed tabs to spaces"));
#endif #endif
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
print1opt("-F", "--multibuffer", N_("Enable multiple file buffers")); print1opt("-F", "--multibuffer", N_("Enable multiple file buffers"));
...@@ -1381,7 +1388,28 @@ void do_delete(void) ...@@ -1381,7 +1388,28 @@ void do_delete(void)
void do_tab(void) void do_tab(void)
{ {
#ifndef NANO_SMALL
if (ISSET(TABS_TO_SPACES)) {
char *output;
size_t output_len = 0, new_pww = placewewant;
do {
new_pww++;
output_len++;
} while (new_pww % tabsize != 0);
output = charalloc(output_len + 1);
charset(output, ' ', output_len);
output[output_len] = '\0';
do_output(output, output_len, TRUE);
} else {
#endif
do_output("\t", 1, TRUE); do_output("\t", 1, TRUE);
#ifndef NANO_SMALL
}
#endif
} }
/* Someone hits Return *gasp!* */ /* Someone hits Return *gasp!* */
...@@ -4122,7 +4150,8 @@ int main(int argc, char **argv) ...@@ -4122,7 +4150,8 @@ int main(int argc, char **argv)
#ifndef NANO_SMALL #ifndef NANO_SMALL
{"smarthome", 0, NULL, 'A'}, {"smarthome", 0, NULL, 'A'},
{"backup", 0, NULL, 'B'}, {"backup", 0, NULL, 'B'},
{"backupdir", 1, NULL, 'E'}, {"backupdir", 1, NULL, 'C'},
{"tabstospaces", 0, NULL, 'E'},
{"noconvert", 0, NULL, 'N'}, {"noconvert", 0, NULL, 'N'},
{"smooth", 0, NULL, 'S'}, {"smooth", 0, NULL, 'S'},
{"restricted", 0, NULL, 'Z'}, {"restricted", 0, NULL, 'Z'},
...@@ -4169,11 +4198,11 @@ int main(int argc, char **argv) ...@@ -4169,11 +4198,11 @@ int main(int argc, char **argv)
while ((optchr = while ((optchr =
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
getopt_long(argc, argv, getopt_long(argc, argv,
"h?ABDE:FHINOQ:ST:VY:Zabcdefgijklmo:pr:s:tvwxz", "h?ABC:EFHINOQ:ST:VY:Zabcdefgijklmo:pr:s:tvwxz",
long_options, NULL) long_options, NULL)
#else #else
getopt(argc, argv, getopt(argc, argv,
"h?ABDE:FHINOQ:ST:VY:Zabcdefgijklmo:pr:s:tvwxz") "h?ABC:EFHINOQ:ST:VY:Zabcdefgijklmo:pr:s:tvwxz")
#endif #endif
) != -1) { ) != -1) {
...@@ -4193,9 +4222,12 @@ int main(int argc, char **argv) ...@@ -4193,9 +4222,12 @@ int main(int argc, char **argv)
case 'B': case 'B':
SET(BACKUP_FILE); SET(BACKUP_FILE);
break; break;
case 'E': case 'C':
backup_dir = mallocstrcpy(backup_dir, optarg); backup_dir = mallocstrcpy(backup_dir, optarg);
break; break;
case 'E':
SET(TABS_TO_SPACES);
break;
#endif #endif
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
case 'F': case 'F':
......
...@@ -303,7 +303,8 @@ typedef struct syntaxtype { ...@@ -303,7 +303,8 @@ typedef struct syntaxtype {
#define SMART_HOME (1<<26) #define SMART_HOME (1<<26)
#define WHITESPACE_DISPLAY (1<<27) #define WHITESPACE_DISPLAY (1<<27)
#define MORE_SPACE (1<<28) #define MORE_SPACE (1<<28)
#define NO_UTF8 (1<<29) #define TABS_TO_SPACES (1<<29)
#define NO_UTF8 (1<<30)
/* Control key sequences. Changing these would be very, very bad. */ /* Control key sequences. Changing these would be very, very bad. */
#define NANO_CONTROL_SPACE 0 #define NANO_CONTROL_SPACE 0
...@@ -489,6 +490,7 @@ typedef struct syntaxtype { ...@@ -489,6 +490,7 @@ typedef struct syntaxtype {
#define TOGGLE_SMARTHOME_KEY NANO_ALT_H #define TOGGLE_SMARTHOME_KEY NANO_ALT_H
#define TOGGLE_WHITESPACE_KEY NANO_ALT_P #define TOGGLE_WHITESPACE_KEY NANO_ALT_P
#define TOGGLE_MORESPACE_KEY NANO_ALT_O #define TOGGLE_MORESPACE_KEY NANO_ALT_O
#define TOGGLE_TABSTOSPACES_KEY NANO_ALT_E
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
#define MAIN_VISIBLE 12 #define MAIN_VISIBLE 12
......
...@@ -88,6 +88,9 @@ const static rcoption rcopts[] = { ...@@ -88,6 +88,9 @@ const static rcoption rcopts[] = {
#endif #endif
{"suspend", SUSPEND}, {"suspend", SUSPEND},
{"tabsize", 0}, {"tabsize", 0},
#ifndef NANO_SMALL
{"tabstospaces", TABS_TO_SPACES},
#endif
{"tempfile", TEMP_FILE}, {"tempfile", TEMP_FILE},
{"view", VIEW_MODE}, {"view", VIEW_MODE},
#ifndef NANO_SMALL #ifndef NANO_SMALL
......
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