add Mike Frysinger's patch (with minor modifications) to allow

displaying other characters, specified in the rcfile, for the first
characters of tabs and spaces


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1782 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-05-29 16:25:30 +00:00
parent c833d9e80f
commit 483ea32c75
10 changed files with 111 additions and 18 deletions

View File

@ -96,6 +96,11 @@ CVS code -
- Since KEEP_CUTBUFFER is only used in cut.c, make it a static - Since KEEP_CUTBUFFER is only used in cut.c, make it a static
variable in cut.c instead of a flag, and unset it in other variable in cut.c instead of a flag, and unset it in other
files via the new function cutbuffer_reset(). (DLR) files via the new function cutbuffer_reset(). (DLR)
- Add the ability to change the characters used to display the
beginning characters of tabs and spaces via the rcfile entry
"whitespace". This is disabled if nanorc support is disabled
or if we're in tiny mode. (Mike Frysinger; minor changes and
adaptations by DLR)
- files.c: - files.c:
add_open_file() add_open_file()
- Rearrange the NANO_SMALL #ifdef so that the code to set the - Rearrange the NANO_SMALL #ifdef so that the code to set the
@ -246,6 +251,11 @@ CVS code -
- Convert to properly handle strings generated by - Convert to properly handle strings generated by
display_string() that have been used in the search prompt display_string() that have been used in the search prompt
since 1.3.0. (David Benbennick) since 1.3.0. (David Benbennick)
- Use display_string() directly to display the text that we
didn't find instead of relying on statusbar() to do it
indirectly, since the latter won't display its text with the
user-specified whitespace characters and the former will.
(DLR)
- utils.c: - utils.c:
is_blank_char() is_blank_char()
- New function used as an isblank() equivalent, since isblank() - New function used as an isblank() equivalent, since isblank()
@ -362,6 +372,8 @@ CVS code -
- Document the smart home key option. (DLR) - Document the smart home key option. (DLR)
- nanorc.5: - nanorc.5:
- Document the smart home key option. (DLR) - Document the smart home key option. (DLR)
- Document the whitespace option. (DLR, adapted from
documentation by Mike Frysinger)
- nano.texi: - nano.texi:
- Fix toggle inaccuracies: Meta-L now toggles line wrapping, and - Fix toggle inaccuracies: Meta-L now toggles line wrapping, and
Meta-< and Meta-> aren't toggles. (DLR) Meta-< and Meta-> aren't toggles. (DLR)
@ -375,6 +387,8 @@ CVS code -
- Add missing mouse entry, and update the nanorc sample regexes - Add missing mouse entry, and update the nanorc sample regexes
to account for the backupdir and mouse options. (DLR) to account for the backupdir and mouse options. (DLR)
- Add smarthome description. (DLR) - Add smarthome description. (DLR)
- Document the whitespace option. (DLR, adapted from
documentation by Mike Frysinger)
- README.CVS: - README.CVS:
- Increase the minimum required autoconf version to 2.54, and - Increase the minimum required autoconf version to 2.54, and
change the recommended automake version 1.7 to the minimum change the recommended automake version 1.7 to the minimum

View File

@ -135,6 +135,10 @@ Save automatically on exit, don't prompt.
\fBset/unset view\fP \fBset/unset view\fP
Disallow file modification. Disallow file modification.
.TP .TP
\fBset whitespace "\fIstring\fP"\fP
Set the two characters used to display the first characters of tabs and
spaces. They cannot be control characters.
.TP
.B syntax "\fIstr\fP" ["\fIfileregex\fP" ... ] .B syntax "\fIstr\fP" ["\fIfileregex\fP" ... ]
Defines a syntax named \fIstr\fP which can be activated via the \fB-Y\fP Defines a syntax named \fIstr\fP which can be activated via the \fB-Y\fP
flag, or will be automatically activated if the current filename matches flag, or will be automatically activated if the current filename matches

View File

@ -106,6 +106,10 @@
## Disallow file modification, why would you want this in an rc file? ;) ## Disallow file modification, why would you want this in an rc file? ;)
# set view # set view
## The two characters used to display the first characters of tabs and
## spaces. ASCII 187 and ASCII 183 seem to be good values for these.
# set whitespace " "
## Color setup ## Color setup
## Format: ## Format:
## syntax "short description" ["filename regex" ...] ## syntax "short description" ["filename regex" ...]
@ -215,7 +219,7 @@
## highlight possible errors and parameters ## highlight possible errors and parameters
#color brightwhite "^ *(set|unset|syntax|color).*$" #color brightwhite "^ *(set|unset|syntax|color).*$"
## set, unset and syntax ## set, unset and syntax
#color cyan "^ *(set|unset) +(autoindent|backup|backupdir|const|cut|fill|historylog|mouse|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|rebinddelete|regexp|smarthome|smooth|speller|suspend|tabsize|tempfile|view)" #color cyan "^ *(set|unset) +(autoindent|backup|backupdir|const|cut|fill|historylog|mouse|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|rebinddelete|regexp|smarthome|smooth|speller|suspend|tabsize|tempfile|view|whitespace)"
#color green "^ *(set|unset|syntax)\>" #color green "^ *(set|unset|syntax)\>"
## colors ## colors
#color yellow "^ *color +(bright)?(white|black|red|blue|green|yellow|magenta|cyan)(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" #color yellow "^ *color +(bright)?(white|black|red|blue|green|yellow|magenta|cyan)(,(white|black|red|blue|green|yellow|magenta|cyan))?\>"

View File

@ -73,6 +73,11 @@ char *quotestr = NULL; /* Quote string. The default value is
#ifndef NANO_SMALL #ifndef NANO_SMALL
char *backup_dir = NULL; /* Backup directory. */ char *backup_dir = NULL; /* Backup directory. */
#ifdef ENABLE_NANORC
char *whitespace = NULL; /* Characters used when displaying
the first characters of tabs and
spaces. */
#endif
#endif #endif
int resetstatuspos; /* Hack for resetting the status bar int resetstatuspos; /* Hack for resetting the status bar
@ -238,11 +243,14 @@ void toggle_init(void)
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
char *toggle_wrap_msg; char *toggle_wrap_msg;
#endif #endif
#ifdef ENABLE_COLOR
char *toggle_syntax_msg;
#endif
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
char *toggle_multibuffer_msg; char *toggle_multibuffer_msg;
#endif #endif
#ifdef ENABLE_COLOR #ifdef ENABLE_NANORC
char *toggle_syntax_msg; char *toggle_whitespace_msg;
#endif #endif
/* There is no need to reinitialize the toggles. They can't /* There is no need to reinitialize the toggles. They can't
@ -273,6 +281,9 @@ void toggle_init(void)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
toggle_multibuffer_msg = _("Multiple file buffers"); toggle_multibuffer_msg = _("Multiple file buffers");
#endif #endif
#ifdef ENABLE_NANORC
toggle_whitespace_msg = _("Whitespace display");
#endif
toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP); toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
@ -309,6 +320,9 @@ void toggle_init(void)
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX); toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX);
#endif #endif
#ifdef ENABLE_NANORC
toggle_init_one(TOGGLE_WHITESPACE_KEY, toggle_whitespace_msg, WHITESPACE_DISPLAY);
#endif
} }
#ifdef DEBUG #ifdef DEBUG

View File

@ -2959,6 +2959,11 @@ void do_toggle(const toggle *which)
case TOGGLE_SYNTAX_KEY: case TOGGLE_SYNTAX_KEY:
edit_refresh(); edit_refresh();
break; break;
#endif
#ifdef ENABLE_NANORC
case TOGGLE_WHITESPACE_KEY:
edit_refresh();
break;
#endif #endif
} }
@ -3408,6 +3413,11 @@ int main(int argc, char *argv[])
} }
#endif #endif
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
if (whitespace == NULL)
whitespace = mallocstrcpy(NULL, " ");
#endif
if (tabsize == -1) if (tabsize == -1)
tabsize = 8; tabsize = 8;

View File

@ -282,6 +282,7 @@ typedef struct historyheadtype {
#define HISTORYLOG (1<<27) #define HISTORYLOG (1<<27)
#define RESTRICTED (1<<28) #define RESTRICTED (1<<28)
#define SMART_HOME (1<<29) #define SMART_HOME (1<<29)
#define WHITESPACE_DISPLAY (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
@ -451,6 +452,7 @@ typedef struct historyheadtype {
#define TOGGLE_BACKUP_KEY NANO_ALT_B #define TOGGLE_BACKUP_KEY NANO_ALT_B
#define TOGGLE_SYNTAX_KEY NANO_ALT_Y #define TOGGLE_SYNTAX_KEY NANO_ALT_Y
#define TOGGLE_SMARTHOME_KEY NANO_ALT_H #define TOGGLE_SMARTHOME_KEY NANO_ALT_H
#define TOGGLE_WHITESPACE_KEY NANO_ALT_P
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
#define MAIN_VISIBLE 12 #define MAIN_VISIBLE 12

View File

@ -52,6 +52,9 @@ extern char *quotestr;
#ifndef NANO_SMALL #ifndef NANO_SMALL
extern char *backup_dir; extern char *backup_dir;
#ifdef ENABLE_NANORC
extern char *whitespace;
#endif
#endif #endif
extern WINDOW *topwin, *edit, *bottomwin; extern WINDOW *topwin, *edit, *bottomwin;

View File

@ -90,6 +90,9 @@ const static rcoption rcopts[] = {
{"tabsize", 0}, {"tabsize", 0},
{"tempfile", TEMP_OPT}, {"tempfile", TEMP_OPT},
{"view", VIEW_MODE}, {"view", VIEW_MODE},
#ifndef NANO_SMALL
{"whitespace", 0},
#endif
{NULL, 0} {NULL, 0}
}; };
@ -148,12 +151,13 @@ char *parse_next_word(char *ptr)
return ptr; return ptr;
} }
/* The keywords operatingdir, backupdir, fill, tabsize, speller, and /* The keywords operatingdir, backupdir, fill, tabsize, speller,
* quotestr take an argument when set. Among these, operatingdir, * quotestr, and whitespace take an argument when set. Among these,
* backupdir, speller, and quotestr have to allow tabs and spaces in the * operatingdir, backupdir, speller, quotestr, and whitespace have to
* argument. Thus, if the next word starts with a ", we say it ends * allow tabs and spaces in the argument. Thus, if the next word starts
* with the last " of the line. Otherwise, the word is interpreted as * with a ", we say it ends with the last " of the line. Otherwise, the
* usual. That is so the arguments can contain "s too. */ * word is interpreted as usual. That is so the arguments can contain
* "s too. */
char *parse_argument(char *ptr) char *parse_argument(char *ptr)
{ {
const char *ptr_bak = ptr; const char *ptr_bak = ptr;
@ -545,6 +549,7 @@ void parse_rcfile(FILE *rcstream)
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
|| !strcasecmp(rcopts[i].name, "backupdir") || !strcasecmp(rcopts[i].name, "backupdir")
|| !strcasecmp(rcopts[i].name, "whitespace")
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
|| !strcasecmp(rcopts[i].name, "speller") || !strcasecmp(rcopts[i].name, "speller")
@ -592,6 +597,18 @@ void parse_rcfile(FILE *rcstream)
if (!strcasecmp(rcopts[i].name, "backupdir")) if (!strcasecmp(rcopts[i].name, "backupdir"))
backup_dir = mallocstrcpy(NULL, option); backup_dir = mallocstrcpy(NULL, option);
else else
if (!strcasecmp(rcopts[i].name, "whitespace")) {
size_t ws_len;
whitespace = mallocstrcpy(NULL, option);
ws_len = strlen(whitespace);
if (ws_len != 2 || (ws_len == 2 && (is_cntrl_char(whitespace[0]) || is_cntrl_char(whitespace[1])))) {
rcfile_error(_("Two non-control characters required"));
free(whitespace);
whitespace = NULL;
} else
SET(WHITESPACE_DISPLAY);
} else
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
if (!strcasecmp(rcopts[i].name, "speller")) if (!strcasecmp(rcopts[i].name, "speller"))

View File

@ -71,11 +71,18 @@ void regexp_cleanup(void)
void not_found_msg(const char *str) void not_found_msg(const char *str)
{ {
int numchars = actual_x(str, COLS / 2); char *disp;
int numchars;
assert(str != NULL); assert(str != NULL);
statusbar(_("\"%.*s%s\" not found"), numchars, str,
str[numchars] == '\0' ? "" : "..."); disp = display_string(str, 0, (COLS / 2) + 1);
numchars = strnlen(disp, COLS / 2);
statusbar(_("\"%.*s%s\" not found"), numchars, disp,
disp[numchars] == '\0' ? "" : "...");
free(disp);
} }
void search_abort(void) void search_abort(void)

View File

@ -1435,11 +1435,15 @@ char *display_string(const char *buf, size_t start_col, size_t len)
index = 0; index = 0;
for (; index < alloc_len; buf++) { for (; index < alloc_len; buf++) {
if (*buf == '\t') if (*buf == '\t') {
do { converted[index++] =
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
ISSET(WHITESPACE_DISPLAY) ? whitespace[0] :
#endif
' ';
while ((column + index) % tabsize)
converted[index++] = ' '; converted[index++] = ' ';
} while ((column + index) % tabsize); } else if (is_cntrl_char(*buf)) {
else if (is_cntrl_char(*buf)) {
converted[index++] = '^'; converted[index++] = '^';
if (*buf == '\n') if (*buf == '\n')
/* Treat newlines embedded in a line as encoded nulls; /* Treat newlines embedded in a line as encoded nulls;
@ -1450,7 +1454,13 @@ char *display_string(const char *buf, size_t start_col, size_t len)
converted[index++] = '?'; converted[index++] = '?';
else else
converted[index++] = *buf + 64; converted[index++] = *buf + 64;
} else } else if (*buf == ' ')
converted[index++] =
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
ISSET(WHITESPACE_DISPLAY) ? whitespace[1] :
#endif
' ';
else
converted[index++] = *buf; converted[index++] = *buf;
} }
assert(len <= alloc_len + column - start_col); assert(len <= alloc_len + column - start_col);
@ -1996,10 +2006,18 @@ void statusbar(const char *msg, ...)
char *bar; char *bar;
char *foo; char *foo;
size_t start_x = 0, foo_len; size_t start_x = 0, foo_len;
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
int old_whitespace = ISSET(WHITESPACE_DISPLAY);
UNSET(WHITESPACE_DISPLAY);
#endif
bar = charalloc(COLS - 3); bar = charalloc(COLS - 3);
vsnprintf(bar, COLS - 3, msg, ap); vsnprintf(bar, COLS - 3, msg, ap);
va_end(ap); va_end(ap);
foo = display_string(bar, 0, COLS - 4); foo = display_string(bar, 0, COLS - 4);
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
if (old_whitespace)
SET(WHITESPACE_DISPLAY);
#endif
free(bar); free(bar);
foo_len = strlen(foo); foo_len = strlen(foo);
start_x = (COLS - foo_len - 4) / 2; start_x = (COLS - foo_len - 4) / 2;