From: David Lawrence Ramsey Date: Sat, 29 May 2004 16:25:30 +0000 (+0000) Subject: add Mike Frysinger's patch (with minor modifications) to allow X-Git-Tag: v1.3.3~37 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=483ea32c75a651ef8232a36c1590d59db3de0047;p=nano.git 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 --- diff --git a/ChangeLog b/ChangeLog index be2e9789..cfb47012 100644 --- a/ChangeLog +++ b/ChangeLog @@ -96,6 +96,11 @@ CVS code - - 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 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: add_open_file() - 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 display_string() that have been used in the search prompt 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: is_blank_char() - New function used as an isblank() equivalent, since isblank() @@ -362,6 +372,8 @@ CVS code - - Document the smart home key option. (DLR) - nanorc.5: - Document the smart home key option. (DLR) + - Document the whitespace option. (DLR, adapted from + documentation by Mike Frysinger) - nano.texi: - Fix toggle inaccuracies: Meta-L now toggles line wrapping, and Meta-< and Meta-> aren't toggles. (DLR) @@ -375,6 +387,8 @@ CVS code - - Add missing mouse entry, and update the nanorc sample regexes to account for the backupdir and mouse options. (DLR) - Add smarthome description. (DLR) + - Document the whitespace option. (DLR, adapted from + documentation by Mike Frysinger) - README.CVS: - Increase the minimum required autoconf version to 2.54, and change the recommended automake version 1.7 to the minimum diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index f79c80a3..69a2e015 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -135,6 +135,10 @@ Save automatically on exit, don't prompt. \fBset/unset view\fP Disallow file modification. .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" ... ] 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 diff --git a/doc/nanorc.sample b/doc/nanorc.sample index ee0074db..f7a79608 100644 --- a/doc/nanorc.sample +++ b/doc/nanorc.sample @@ -106,6 +106,10 @@ ## Disallow file modification, why would you want this in an rc file? ;) # 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 ## Format: ## syntax "short description" ["filename regex" ...] @@ -215,7 +219,7 @@ ## highlight possible errors and parameters #color brightwhite "^ *(set|unset|syntax|color).*$" ## 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)\>" ## colors #color yellow "^ *color +(bright)?(white|black|red|blue|green|yellow|magenta|cyan)(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" diff --git a/src/global.c b/src/global.c index 48e997fa..465a65c7 100644 --- a/src/global.c +++ b/src/global.c @@ -73,6 +73,11 @@ char *quotestr = NULL; /* Quote string. The default value is #ifndef NANO_SMALL 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 int resetstatuspos; /* Hack for resetting the status bar @@ -238,11 +243,14 @@ void toggle_init(void) #ifndef DISABLE_WRAPPING char *toggle_wrap_msg; #endif +#ifdef ENABLE_COLOR + char *toggle_syntax_msg; +#endif #ifdef ENABLE_MULTIBUFFER char *toggle_multibuffer_msg; #endif -#ifdef ENABLE_COLOR - char *toggle_syntax_msg; +#ifdef ENABLE_NANORC + char *toggle_whitespace_msg; #endif /* There is no need to reinitialize the toggles. They can't @@ -273,6 +281,9 @@ void toggle_init(void) #ifdef ENABLE_MULTIBUFFER toggle_multibuffer_msg = _("Multiple file buffers"); #endif +#ifdef ENABLE_NANORC + toggle_whitespace_msg = _("Whitespace display"); +#endif toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP); #ifdef ENABLE_MULTIBUFFER @@ -309,6 +320,9 @@ void toggle_init(void) #ifdef ENABLE_COLOR toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX); #endif +#ifdef ENABLE_NANORC + toggle_init_one(TOGGLE_WHITESPACE_KEY, toggle_whitespace_msg, WHITESPACE_DISPLAY); +#endif } #ifdef DEBUG diff --git a/src/nano.c b/src/nano.c index 5eb13e7f..62bc1307 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2959,6 +2959,11 @@ void do_toggle(const toggle *which) case TOGGLE_SYNTAX_KEY: edit_refresh(); break; +#endif +#ifdef ENABLE_NANORC + case TOGGLE_WHITESPACE_KEY: + edit_refresh(); + break; #endif } @@ -3408,6 +3413,11 @@ int main(int argc, char *argv[]) } #endif +#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) + if (whitespace == NULL) + whitespace = mallocstrcpy(NULL, " "); +#endif + if (tabsize == -1) tabsize = 8; diff --git a/src/nano.h b/src/nano.h index 5574a5ca..1a724aa8 100644 --- a/src/nano.h +++ b/src/nano.h @@ -282,6 +282,7 @@ typedef struct historyheadtype { #define HISTORYLOG (1<<27) #define RESTRICTED (1<<28) #define SMART_HOME (1<<29) +#define WHITESPACE_DISPLAY (1<<30) /* Control key sequences, changing these would be very very bad. */ #define NANO_CONTROL_SPACE 0 @@ -451,6 +452,7 @@ typedef struct historyheadtype { #define TOGGLE_BACKUP_KEY NANO_ALT_B #define TOGGLE_SYNTAX_KEY NANO_ALT_Y #define TOGGLE_SMARTHOME_KEY NANO_ALT_H +#define TOGGLE_WHITESPACE_KEY NANO_ALT_P #endif /* !NANO_SMALL */ #define MAIN_VISIBLE 12 diff --git a/src/proto.h b/src/proto.h index e54bfc40..f4cf99bc 100644 --- a/src/proto.h +++ b/src/proto.h @@ -52,6 +52,9 @@ extern char *quotestr; #ifndef NANO_SMALL extern char *backup_dir; +#ifdef ENABLE_NANORC +extern char *whitespace; +#endif #endif extern WINDOW *topwin, *edit, *bottomwin; diff --git a/src/rcfile.c b/src/rcfile.c index 0a8ff976..b30c62a8 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -90,6 +90,9 @@ const static rcoption rcopts[] = { {"tabsize", 0}, {"tempfile", TEMP_OPT}, {"view", VIEW_MODE}, +#ifndef NANO_SMALL + {"whitespace", 0}, +#endif {NULL, 0} }; @@ -148,12 +151,13 @@ char *parse_next_word(char *ptr) return ptr; } -/* The keywords operatingdir, backupdir, fill, tabsize, speller, and - * quotestr take an argument when set. Among these, operatingdir, - * backupdir, speller, and quotestr have to allow tabs and spaces in the - * argument. Thus, if the next word starts with a ", we say it ends - * with the last " of the line. Otherwise, the word is interpreted as - * usual. That is so the arguments can contain "s too. */ +/* The keywords operatingdir, backupdir, fill, tabsize, speller, + * quotestr, and whitespace take an argument when set. Among these, + * operatingdir, backupdir, speller, quotestr, and whitespace have to + * allow tabs and spaces in the argument. Thus, if the next word starts + * with a ", we say it ends with the last " of the line. Otherwise, the + * word is interpreted as usual. That is so the arguments can contain + * "s too. */ char *parse_argument(char *ptr) { const char *ptr_bak = ptr; @@ -545,6 +549,7 @@ void parse_rcfile(FILE *rcstream) #endif #ifndef NANO_SMALL || !strcasecmp(rcopts[i].name, "backupdir") + || !strcasecmp(rcopts[i].name, "whitespace") #endif #ifndef DISABLE_SPELLER || !strcasecmp(rcopts[i].name, "speller") @@ -592,6 +597,18 @@ void parse_rcfile(FILE *rcstream) if (!strcasecmp(rcopts[i].name, "backupdir")) backup_dir = mallocstrcpy(NULL, option); 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 #ifndef DISABLE_SPELLER if (!strcasecmp(rcopts[i].name, "speller")) diff --git a/src/search.c b/src/search.c index adf0b55d..4a7c1ef3 100644 --- a/src/search.c +++ b/src/search.c @@ -71,11 +71,18 @@ void regexp_cleanup(void) void not_found_msg(const char *str) { - int numchars = actual_x(str, COLS / 2); - + char *disp; + int numchars; + 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) diff --git a/src/winio.c b/src/winio.c index ca2d6ad6..601b6301 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1435,11 +1435,15 @@ char *display_string(const char *buf, size_t start_col, size_t len) index = 0; for (; index < alloc_len; buf++) { - if (*buf == '\t') - do { + if (*buf == '\t') { + converted[index++] = +#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) + ISSET(WHITESPACE_DISPLAY) ? whitespace[0] : +#endif + ' '; + while ((column + index) % tabsize) converted[index++] = ' '; - } while ((column + index) % tabsize); - else if (is_cntrl_char(*buf)) { + } else if (is_cntrl_char(*buf)) { converted[index++] = '^'; if (*buf == '\n') /* 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++] = '?'; else 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; } assert(len <= alloc_len + column - start_col); @@ -1996,10 +2006,18 @@ void statusbar(const char *msg, ...) char *bar; char *foo; 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); vsnprintf(bar, COLS - 3, msg, ap); va_end(ap); foo = display_string(bar, 0, COLS - 4); +#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) + if (old_whitespace) + SET(WHITESPACE_DISPLAY); +#endif free(bar); foo_len = strlen(foo); start_x = (COLS - foo_len - 4) / 2;