Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02df950240 | ||
|
|
a69a8ce3ca | ||
|
|
8a03d55c53 | ||
|
|
544351f3be | ||
|
|
96ebaf8ab4 | ||
|
|
6b7c661fb7 | ||
|
|
6823831c06 | ||
|
|
ec82530125 | ||
|
|
a45e1f89c0 | ||
|
|
c1cd813dcb | ||
|
|
c96e62e33a | ||
|
|
6283557d2f | ||
|
|
af90f03ac5 | ||
|
|
588022ab8c | ||
|
|
cf0820549b | ||
|
|
f54bc6c7d6 | ||
|
|
2cdff6c32c | ||
|
|
49d8b99e4f | ||
|
|
bb81932422 | ||
|
|
5efb6836a8 | ||
|
|
48fa14acc0 | ||
|
|
eb7181b35e | ||
|
|
8db42023bb | ||
|
|
018a8e12ca | ||
|
|
b4a5aedc6c | ||
|
|
d6ed174d09 | ||
|
|
78f92e044a | ||
|
|
f11931a0dd | ||
|
|
31a6931be9 | ||
|
|
debb288115 | ||
|
|
c75a3839da | ||
|
|
b6a32fbd5f | ||
|
|
09e4c86606 | ||
|
|
20eb422829 | ||
|
|
90c6b572d0 | ||
|
|
712b574fb7 | ||
|
|
fd023d6dcf | ||
|
|
9c16be32d7 | ||
|
|
c3cdb099da | ||
|
|
682a088fb8 | ||
|
|
8c25bd0e94 | ||
|
|
20e122ef41 | ||
|
|
0dcac9188f | ||
|
|
1c010d8ec9 | ||
|
|
b020937475 | ||
|
|
e3f46b066a | ||
|
|
df7fe1280d | ||
|
|
929770191e | ||
|
|
66d9d6c6d2 | ||
|
|
de816840cb | ||
|
|
74fcc3be79 | ||
|
|
b6909d3737 | ||
|
|
823d79b36c | ||
|
|
735757b0c1 | ||
|
|
09b919a68f | ||
|
|
2f718e11a7 | ||
|
|
77da54c6c6 | ||
|
|
6bf52dcc8d | ||
|
|
3d9e803aed | ||
|
|
ede64d7ea0 | ||
|
|
e8db390d6f | ||
|
|
0c1bf429e8 | ||
|
|
f6357a73f0 | ||
|
|
49ca7e5aa8 | ||
|
|
be9b1a1887 |
74
ChangeLog
74
ChangeLog
@@ -1,3 +1,77 @@
|
||||
Changes between v5.6.1 and v5.7:
|
||||
--------------------------------
|
||||
|
||||
Benno Schulenberg (62):
|
||||
build: drop the check for two functions that we don't use any more
|
||||
build: fix compilation for --enable-tiny plus --enable-multibuffer
|
||||
build: fix compilation when configured with --disable-multibuffer
|
||||
build: fix compilation when configured with --enable-tiny
|
||||
bump version numbers and add a news item for the 5.7 release
|
||||
chars: implement mblen() ourselves, for efficiency
|
||||
chars: implement mbtowc() ourselves, for more efficiency
|
||||
chars: work around a UTF-8 bug in glibc, to display invalid codes right
|
||||
chars: work around the wrong private-use-character widths on OpenBSD
|
||||
display: avoid determining twice from and until where to draw each row
|
||||
display: make the output of --constantshow less jittery
|
||||
editing: prevent the pointer for the top row from becoming dangling
|
||||
feedback: upon first switch to a buffer, show its error message (if any)
|
||||
files: always register the format, also when the file is unwritable
|
||||
files: create a new buffer earlier, so that error messages can be stored
|
||||
files: when Mac format has been detected, stay with it
|
||||
gnulib: pull in the fix for a build problem on older Debian
|
||||
gnulib: update to its current upstream state
|
||||
indicator: adjust the size to the number of visible lines, not chunks
|
||||
input: accept Unicode codes for non-characters as valid, since they are
|
||||
memory: do not allocate space for multidata when it's already allocated
|
||||
memory: fix an off-by-one error to free also the last line in a group
|
||||
memory: prevent a use-after-free when the user respects a lock file
|
||||
oops: that doesn't work -- you can't break out of two for loops at once
|
||||
options: retire the obsolete 'smooth', 'morespace', and 'nopauses'
|
||||
softwrap: avoid time-consuming computations, to burden large files less
|
||||
startup: do not crash when trying to open a device or directory
|
||||
startup: do not store an error message in the record of another buffer
|
||||
startup: save the compiled file-matching regexes, to avoid recompiling
|
||||
startup: show the helpful message only when ^G has not been rebound
|
||||
syntax: c: colorize also labels that contain digits, and uncolorize colon
|
||||
syntax: po: improve the coloring of format specifiers
|
||||
syntaxes: replace [[:space:]] with [[:blank:]] to exclude carriage return
|
||||
tweaks: adjust and improve one comment, and frob another
|
||||
tweaks: adjust two comments, and reshuffle two fragments
|
||||
tweaks: avoid a warning on newer compilers, by writing an extra byte
|
||||
tweaks: avoid calling extra_chunks_in() when not softwrapping
|
||||
tweaks: avoid converting a file name for more than will fit on screen
|
||||
tweaks: avoid parsing a multibyte character twice
|
||||
tweaks: condense three comments, drop another, and rewrap a line
|
||||
tweaks: drop unneeded braces and adjust indentation after previous change
|
||||
tweaks: elide a call of strlen() for every row
|
||||
tweaks: elide a function that is now basically just two lines
|
||||
tweaks: elide an unneeded resetting NULL call to wctomb()
|
||||
tweaks: elide a small function that is used just once
|
||||
tweaks: elide the pointless is_valid_unicode() function
|
||||
tweaks: elide two more instances of useless character copying
|
||||
tweaks: improve a couple of comments
|
||||
tweaks: morph a function into what it is actually used for
|
||||
tweaks: normalize the indentation after an earlier change
|
||||
tweaks: put the most likely condition first, for a quicker return
|
||||
tweaks: reduce the maximum character length from six bytes to four
|
||||
tweaks: remove a misplaced (and nested) #ifdef
|
||||
tweaks: rename a variable, away from an abbreviation
|
||||
tweaks: rename a variable, for contrast with another
|
||||
tweaks: reshuffle a comment, and put the main extension first
|
||||
tweaks: reshuffle a fragment of code, to prepare for the next change
|
||||
tweaks: reshuffle two conditions, to have the most unlikely one first
|
||||
tweaks: set the file format only when unset, so it doesn't need saving
|
||||
tweaks: shorten a comment and trim an #ifdef
|
||||
tweaks: simplify two fragments of code
|
||||
tweaks: simplify two fragments of code, eliding useless character copying
|
||||
|
||||
Hussam al-Homsi (1):
|
||||
syntax: c: make the highlighting of '#include <...>' more compliant
|
||||
|
||||
Mike Frysinger (1):
|
||||
syntax: tcl: support Expect scripts too
|
||||
|
||||
|
||||
Changes between v5.6 and v5.6.1:
|
||||
--------------------------------
|
||||
|
||||
|
||||
8
NEWS
8
NEWS
@@ -1,3 +1,11 @@
|
||||
2021.04.29 - GNU nano 5.7 "Toți ceilalți arau câmpurile"
|
||||
• The output of --constantshow (without --minibar) is more stable.
|
||||
• When opening multiple buffers and there is an error message, this
|
||||
message is shown again upon first switch to the relevant buffer.
|
||||
• The position and size of the indicator now follow actual lines,
|
||||
instead of visual lines when in softwrap mode, meaning that the
|
||||
size of the indicator can change when scrolling in softwrap mode.
|
||||
|
||||
2021.03.03 - GNU nano 5.6.1 "Geelgors"
|
||||
• Search matches are properly colorized in softwrap mode too.
|
||||
• Option 'highlightcolor' has been renamed to 'spotlightcolor'.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Generate configure & friends for GIT users.
|
||||
|
||||
gnulib_url="git://git.sv.gnu.org/gnulib.git"
|
||||
gnulib_hash="c9b44f214c7c798c7701c7a281584e262b263655"
|
||||
gnulib_hash="afeeb21058d15e5250fff9fbea2c1fec011c061a"
|
||||
|
||||
modules="
|
||||
futimens
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
|
||||
AC_INIT([GNU nano], [5.6.1], [nano-devel@gnu.org], [nano])
|
||||
AC_INIT([GNU nano], [5.7], [nano-devel@gnu.org], [nano])
|
||||
AC_CONFIG_SRCDIR([src/nano.c])
|
||||
AC_CANONICAL_HOST
|
||||
AM_INIT_AUTOMAKE([1.14])
|
||||
@@ -350,7 +350,7 @@ fi])
|
||||
dnl Checks for functions.
|
||||
|
||||
if test "x$enable_utf8" != xno; then
|
||||
AC_CHECK_FUNCS(iswalnum iswpunct mblen mbstowcs mbtowc wctomb)
|
||||
AC_CHECK_FUNCS(iswalpha iswalnum iswpunct mbstowcs wctomb)
|
||||
fi
|
||||
|
||||
dnl Checks for available flags.
|
||||
@@ -435,11 +435,10 @@ AC_SUBST(CURSES_LIB)
|
||||
|
||||
if test "x$enable_utf8" != xno && \
|
||||
test x$CURSES_LIB_WIDE = xyes && \
|
||||
test x$ac_cv_func_iswalpha = xyes && \
|
||||
test x$ac_cv_func_iswalnum = xyes && \
|
||||
test x$ac_cv_func_iswpunct = xyes && \
|
||||
test x$ac_cv_func_mblen = xyes && \
|
||||
test x$ac_cv_func_mbstowcs = xyes && \
|
||||
test x$ac_cv_func_mbtowc = xyes && \
|
||||
test x$ac_cv_func_wctomb = xyes; then
|
||||
AC_DEFINE(ENABLE_UTF8, 1, [Define this if your system has sufficient UTF-8 support.])
|
||||
else
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<h3><a name="1.3"></a>1.3. Why the name change from TIP?</h3>
|
||||
<blockquote><p>On January 10, 2000, TIP was officially renamed to nano because of a namespace conflict with another program called 'tip'. The original 'tip' program "establishes a full duplex terminal connection to a remote host", and was included with many older Unix systems (and newer ones like Solaris). The conflict was not noticed at first because there is no 'tip' utility included with most GNU/Linux distributions (where nano was developed).</p></blockquote>
|
||||
<h3><a name="1.4"></a>1.4. What is the current version of nano?</h3>
|
||||
<blockquote><p>The current version of nano <i>should</i> be <b>5.6.1</b>. Of course, you should always check the <a href="https://nano-editor.org/">nano homepage</a> to see what the latest and greatest version is.</p></blockquote>
|
||||
<blockquote><p>The current version of nano <i>should</i> be <b>5.7</b>. Of course, you should always check the <a href="https://nano-editor.org/">nano homepage</a> to see what the latest and greatest version is.</p></blockquote>
|
||||
<h3><a name="1.5"></a>1.5. I want to read the man page without having to download the program!</h3>
|
||||
<blockquote><p>Jeez, demanding, aren't we? Okay, look <a href="https://nano-editor.org/dist/latest/nano.1.html">here</a>.</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
.\" Documentation License along with this program. If not, see
|
||||
.\" <https://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.TH NANO 1 "version 5.6.1" "March 2021"
|
||||
.TH NANO 1 "version 5.7" "April 2021"
|
||||
|
||||
.SH NAME
|
||||
nano \- Nano's ANOther editor, inspired by Pico
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
@smallbook
|
||||
@set EDITION 0.5
|
||||
@set VERSION 5.6.1
|
||||
@set UPDATED March 2021
|
||||
@set VERSION 5.7
|
||||
@set UPDATED April 2021
|
||||
|
||||
@dircategory Editors
|
||||
@direntry
|
||||
@@ -23,7 +23,7 @@
|
||||
@titlepage
|
||||
@title GNU @command{nano}
|
||||
@subtitle a small and friendly text editor
|
||||
@subtitle version 5.6.1
|
||||
@subtitle version 5.7
|
||||
|
||||
@author Chris Allegretta
|
||||
@page
|
||||
@@ -63,7 +63,7 @@ e-mail: @email{chrisa@@asty.org}@*
|
||||
@node Top
|
||||
@top
|
||||
|
||||
This manual documents the GNU @command{nano} editor, version 5.6.1.
|
||||
This manual documents the GNU @command{nano} editor, version 5.7.
|
||||
|
||||
@menu
|
||||
* Introduction::
|
||||
@@ -946,10 +946,6 @@ The line plus column numbers and the character code are displayed only when
|
||||
@code{set constantshow} is used, and can be toggled on and off with @key{M-C}.
|
||||
The state flags are displayed only when @code{set stateflags} is used.
|
||||
|
||||
@item set morespace
|
||||
Deprecated option since it has become the default setting.
|
||||
When needed, use @code{unset emptyline} instead.
|
||||
|
||||
@item set mouse
|
||||
Enable mouse support, so that mouse clicks can be used to place the
|
||||
cursor, set the mark (with a double click), or execute shortcuts.
|
||||
@@ -967,9 +963,6 @@ Don't display the help lists at the bottom of the screen.
|
||||
Don't automatically add a newline when a text does not end with one.
|
||||
(This can cause you to save non-POSIX text files.)
|
||||
|
||||
@item set nopauses
|
||||
Obsolete option. Ignored.
|
||||
|
||||
@item set nowrap
|
||||
Deprecated option since it has become the default setting.
|
||||
When needed, use @code{unset breaklonglines} instead.
|
||||
@@ -1055,10 +1048,6 @@ jump to that beginning (either forwards or backwards). If the cursor is
|
||||
already at that position, it will jump to the true beginning of the
|
||||
line.
|
||||
|
||||
@item set smooth
|
||||
Deprecated option since it has become the default setting.
|
||||
When needed, use @code{unset jumpyscrolling} instead.
|
||||
|
||||
@item set softwrap
|
||||
Display lines that exceed the screen's width over multiple screen lines.
|
||||
(You can make this soft-wrapping occur at whitespace instead of rudely at
|
||||
|
||||
13
doc/nanorc.5
13
doc/nanorc.5
@@ -16,7 +16,7 @@
|
||||
.\" Documentation License along with this program. If not, see
|
||||
.\" <https://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.TH NANORC 5 "version 5.6.1" "March 2021"
|
||||
.TH NANORC 5 "version 5.7 "April 2021"
|
||||
|
||||
.SH NAME
|
||||
nanorc \- GNU nano's configuration file
|
||||
@@ -199,10 +199,6 @@ The line plus column numbers and the character code are displayed only when
|
||||
\fBset constantshow\fR is used, and can be toggled on and off with \fBM-C\fR.
|
||||
The state flags are displayed only when \fBset stateflags\fR is used.
|
||||
.TP
|
||||
.B set morespace
|
||||
Deprecated option since it has become the default setting.
|
||||
When needed, use \fBunset emptyline\fR instead.
|
||||
.TP
|
||||
.B set mouse
|
||||
Enable mouse support, if available for your system. When enabled, mouse
|
||||
clicks can be used to place the cursor, set the mark (with a double
|
||||
@@ -223,9 +219,6 @@ Don't display the two help lines at the bottom of the screen.
|
||||
Don't automatically add a newline when a text does not end with one.
|
||||
(This can cause you to save non-POSIX text files.)
|
||||
.TP
|
||||
.B set nopauses
|
||||
Obsolete option. Ignored.
|
||||
.TP
|
||||
.B set nowrap
|
||||
Deprecated option since it has become the default setting.
|
||||
When needed, use \fBunset breaklonglines\fR instead.
|
||||
@@ -309,10 +302,6 @@ jump to that beginning (either forwards or backwards). If the cursor is
|
||||
already at that position, it will jump to the true beginning of the
|
||||
line.
|
||||
.TP
|
||||
.B set smooth
|
||||
Deprecated option since it has become the default setting.
|
||||
When needed, use \fBunset jumpyscrolling\fR instead.
|
||||
.TP
|
||||
.B set softwrap
|
||||
Display lines that exceed the screen's width over multiple screen lines.
|
||||
(You can make this soft-wrapping occur at whitespace instead of rudely at
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
.\" Documentation License along with this program. If not, see
|
||||
.\" <https://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.TH RNANO 1 "version 5.6.1" "March 2021"
|
||||
.TH RNANO 1 "version 5.7" "April 2021"
|
||||
|
||||
.SH NAME
|
||||
rnano \- a restricted nano
|
||||
|
||||
705
po/nano.pot
705
po/nano.pot
File diff suppressed because it is too large
Load Diff
711
po/pt_BR.po
711
po/pt_BR.po
File diff suppressed because it is too large
Load Diff
709
po/zh_CN.po
709
po/zh_CN.po
File diff suppressed because it is too large
Load Diff
705
po/zh_TW.po
705
po/zh_TW.po
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION="5.6.1"
|
||||
VERSION="5.7"
|
||||
|
||||
./configure -C --enable-tiny && make && ./configure -C &&
|
||||
|
||||
|
||||
236
src/chars.c
236
src/chars.c
@@ -51,7 +51,7 @@ bool is_alpha_char(const char *c)
|
||||
#ifdef ENABLE_UTF8
|
||||
wchar_t wc;
|
||||
|
||||
if (mbtowc(&wc, c, MAXCHARLEN) < 0)
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswalpha(wc);
|
||||
@@ -67,7 +67,7 @@ bool is_alnum_char(const char *c)
|
||||
#ifdef ENABLE_UTF8
|
||||
wchar_t wc;
|
||||
|
||||
if (mbtowc(&wc, c, MAXCHARLEN) < 0)
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswalnum(wc);
|
||||
@@ -85,7 +85,7 @@ bool is_blank_char(const char *c)
|
||||
if ((signed char)*c >= 0)
|
||||
return (*c == ' ' || *c == '\t');
|
||||
|
||||
if (mbtowc(&wc, c, MAXCHARLEN) < 0)
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswblank(wc);
|
||||
@@ -112,7 +112,7 @@ bool is_punct_char(const char *c)
|
||||
#ifdef ENABLE_UTF8
|
||||
wchar_t wc;
|
||||
|
||||
if (mbtowc(&wc, c, MAXCHARLEN) < 0)
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswpunct(wc);
|
||||
@@ -176,62 +176,123 @@ char control_mbrep(const char *c, bool isdata)
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* Return the width in columns of the given (multibyte) character. */
|
||||
int mbwidth(const char *c)
|
||||
/* Convert the given multibyte sequence c to wide character wc, and return
|
||||
* the number of bytes in the sequence, or -1 for an invalid sequence. */
|
||||
int mbtowide(wchar_t *wc, const char *c)
|
||||
{
|
||||
/* Only characters beyond U+02FF can be other than one column wide. */
|
||||
if ((unsigned char)*c > 0xCB) {
|
||||
wchar_t wc;
|
||||
int width;
|
||||
if ((signed char)*c < 0 && use_utf8) {
|
||||
unsigned char v1 = (unsigned char)c[0];
|
||||
unsigned char v2 = (unsigned char)c[1] ^ 0x80;
|
||||
|
||||
if (mbtowc(&wc, c, MAXCHARLEN) < 0)
|
||||
return 1;
|
||||
if (v2 > 0x3F || v1 < 0xC2)
|
||||
return -1;
|
||||
|
||||
width = wcwidth(wc);
|
||||
if (v1 < 0xE0) {
|
||||
*wc = (((unsigned int)(v1 & 0x1F) << 6) | (unsigned int)v2);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (width < 0)
|
||||
return 1;
|
||||
unsigned char v3 = (unsigned char)c[2] ^ 0x80;
|
||||
|
||||
return width;
|
||||
} else
|
||||
return 1;
|
||||
if (v3 > 0x3F)
|
||||
return -1;
|
||||
|
||||
if (v1 < 0xF0) {
|
||||
if ((v1 > 0xE0 || v2 >= 0x20) && (v1 != 0xED || v2 < 0x20)) {
|
||||
*wc = (((unsigned int)(v1 & 0x0F) << 12) |
|
||||
((unsigned int)v2 << 6) | (unsigned int)v3);
|
||||
return 3;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char v4 = (unsigned char)c[3] ^ 0x80;
|
||||
|
||||
if (v4 > 0x3F || v1 > 0xF4)
|
||||
return -1;
|
||||
|
||||
if ((v1 > 0xF0 || v2 >= 0x10) && (v1 != 0xF4 || v2 < 0x10)) {
|
||||
*wc = (((unsigned int)(v1 & 0x07) << 18) | ((unsigned int)v2 << 12) |
|
||||
((unsigned int)v3 << 6) | (unsigned int)v4);
|
||||
return 4;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
*wc = (unsigned int)*c;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character occupies two cells. */
|
||||
bool is_doublewidth(const char *ch)
|
||||
{
|
||||
wchar_t wc;
|
||||
|
||||
/* Only from U+1100 can code points have double width. */
|
||||
if ((unsigned char)*ch < 0xE1 || !use_utf8)
|
||||
return FALSE;
|
||||
|
||||
if (mbtowide(&wc, ch) < 0)
|
||||
return FALSE;
|
||||
|
||||
return (wcwidth(wc) == 2);
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character occupies zero cells. */
|
||||
bool is_zerowidth(const char *ch)
|
||||
{
|
||||
return (use_utf8 && mbwidth(ch) == 0);
|
||||
}
|
||||
wchar_t wc;
|
||||
|
||||
/* Convert the given Unicode value to a multibyte character, if possible.
|
||||
* If the conversion succeeds, return the (dynamically allocated) multibyte
|
||||
* character and its length. Otherwise, return a length of zero. */
|
||||
char *make_mbchar(long code, int *length)
|
||||
{
|
||||
char *mb_char = nmalloc(MAXCHARLEN);
|
||||
/* Only from U+0300 can code points have zero width. */
|
||||
if ((unsigned char)*ch < 0xCC || !use_utf8)
|
||||
return FALSE;
|
||||
|
||||
*length = wctomb(mb_char, (wchar_t)code);
|
||||
if (mbtowide(&wc, ch) < 0)
|
||||
return FALSE;
|
||||
|
||||
/* Reject invalid Unicode characters. */
|
||||
if (*length < 0 || !is_valid_unicode((wchar_t)code)) {
|
||||
IGNORE_CALL_RESULT(wctomb(NULL, 0));
|
||||
*length = 0;
|
||||
}
|
||||
#if defined(__OpenBSD__)
|
||||
/* Work around an OpenBSD bug -- see https://sv.gnu.org/bugs/?60393. */
|
||||
if (wc >= 0xF0000)
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
return mb_char;
|
||||
return (wcwidth(wc) == 0);
|
||||
}
|
||||
#endif /* ENABLE_UTF8 */
|
||||
|
||||
/* Return the length (in bytes) of the character located at *pointer. */
|
||||
/* Return the number of bytes in the character that starts at *pointer. */
|
||||
int char_length(const char *pointer)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
/* If possibly a multibyte character, get its length; otherwise, it's 1. */
|
||||
if ((unsigned char)*pointer > 0xC1) {
|
||||
int length = mblen(pointer, MAXCHARLEN);
|
||||
if ((unsigned char)*pointer > 0xC1 && use_utf8) {
|
||||
unsigned char c1 = (unsigned char)pointer[0];
|
||||
unsigned char c2 = (unsigned char)pointer[1];
|
||||
|
||||
return (length < 0 ? 1 : length);
|
||||
} else
|
||||
if ((c2 ^ 0x80) > 0x3F)
|
||||
return 1;
|
||||
|
||||
if (c1 < 0xE0)
|
||||
return 2;
|
||||
|
||||
if (((unsigned char)pointer[2] ^ 0x80) > 0x3F)
|
||||
return 1;
|
||||
|
||||
if (c1 < 0xF0) {
|
||||
if ((c1 > 0xE0 || c2 >= 0xA0) && (c1 != 0xED || c2 < 0xA0))
|
||||
return 3;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (((unsigned char)pointer[3] ^ 0x80) > 0x3F)
|
||||
return 1;
|
||||
|
||||
if (c1 > 0xF4)
|
||||
return 1;
|
||||
|
||||
if ((c1 > 0xF0 || c2 >= 0x90) && (c1 != 0xF4 || c2 < 0x90))
|
||||
return 4;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
@@ -242,15 +303,7 @@ size_t mbstrlen(const char *pointer)
|
||||
size_t count = 0;
|
||||
|
||||
while (*pointer != '\0') {
|
||||
#ifdef ENABLE_UTF8
|
||||
if ((unsigned char)*pointer > 0xC1) {
|
||||
int length = mblen(pointer, MAXCHARLEN);
|
||||
|
||||
pointer += (length < 0 ? 1 : length);
|
||||
} else
|
||||
#endif
|
||||
pointer++;
|
||||
|
||||
pointer += char_length(pointer);
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -261,19 +314,7 @@ size_t mbstrlen(const char *pointer)
|
||||
* given string, and return a copy of this character in *thechar. */
|
||||
int collect_char(const char *string, char *thechar)
|
||||
{
|
||||
int charlen;
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* If this is a UTF-8 starter byte, get the number of bytes of the character. */
|
||||
if ((unsigned char)*string > 0xC1) {
|
||||
charlen = mblen(string, MAXCHARLEN);
|
||||
|
||||
/* When the multibyte sequence is invalid, only take the first byte. */
|
||||
if (charlen <= 0)
|
||||
charlen = 1;
|
||||
} else
|
||||
#endif
|
||||
charlen = 1;
|
||||
int charlen = char_length(string);
|
||||
|
||||
for (int i = 0; i < charlen; i++)
|
||||
thechar[i] = string[i];
|
||||
@@ -286,20 +327,29 @@ int collect_char(const char *string, char *thechar)
|
||||
int advance_over(const char *string, size_t *column)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if ((signed char)*string < 0) {
|
||||
int charlen = mblen(string, MAXCHARLEN);
|
||||
|
||||
if (charlen > 0) {
|
||||
if (is_cntrl_char(string))
|
||||
*column += 2;
|
||||
else
|
||||
*column += mbwidth(string);
|
||||
if ((signed char)*string < 0 && use_utf8) {
|
||||
/* A UTF-8 upper control code has two bytes and takes two columns. */
|
||||
if (((unsigned char)string[0] == 0xC2 && (signed char)string[1] < -96)) {
|
||||
*column += 2;
|
||||
return 2;
|
||||
} else {
|
||||
charlen = 1;
|
||||
*column += 1;
|
||||
}
|
||||
wchar_t wc;
|
||||
int charlen = mbtowide(&wc, string);
|
||||
|
||||
return charlen;
|
||||
if (charlen < 0) {
|
||||
*column += 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int width = wcwidth(wc);
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
*column += (width < 0 || wc >= 0xF0000) ? 1 : width;
|
||||
#else
|
||||
*column += (width < 0) ? 1 : width;
|
||||
#endif
|
||||
return charlen;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -308,12 +358,8 @@ int advance_over(const char *string, size_t *column)
|
||||
*column += tabsize - *column % tabsize;
|
||||
else
|
||||
*column += 2;
|
||||
} else if (*string == 0x7F)
|
||||
} else if (0x7E < (unsigned char)*string && (unsigned char)*string < 0xA0)
|
||||
*column += 2;
|
||||
#ifndef ENABLE_UTF8
|
||||
else if (0x7F < (unsigned char)*string && (unsigned char)*string < 0xA0)
|
||||
*column += 2;
|
||||
#endif
|
||||
else
|
||||
*column += 1;
|
||||
|
||||
@@ -396,8 +442,8 @@ int mbstrncasecmp(const char *s1, const char *s2, size_t n)
|
||||
continue;
|
||||
}
|
||||
|
||||
bool bad1 = (mbtowc(&wc1, s1, MAXCHARLEN) < 0);
|
||||
bool bad2 = (mbtowc(&wc2, s2, MAXCHARLEN) < 0);
|
||||
bool bad1 = (mbtowide(&wc1, s1) < 0);
|
||||
bool bad2 = (mbtowide(&wc2, s2) < 0);
|
||||
|
||||
if (bad1 || bad2) {
|
||||
if (*s1 != *s2)
|
||||
@@ -522,13 +568,13 @@ char *mbstrchr(const char *string, const char *chr)
|
||||
bool bad_s = FALSE, bad_c = FALSE;
|
||||
wchar_t ws, wc;
|
||||
|
||||
if (mbtowc(&wc, chr, MAXCHARLEN) < 0) {
|
||||
if (mbtowide(&wc, chr) < 0) {
|
||||
wc = (unsigned char)*chr;
|
||||
bad_c = TRUE;
|
||||
}
|
||||
|
||||
while (*string != '\0') {
|
||||
int symlen = mbtowc(&ws, string, MAXCHARLEN);
|
||||
int symlen = mbtowide(&ws, string);
|
||||
|
||||
if (symlen < 0) {
|
||||
ws = (unsigned char)*string;
|
||||
@@ -590,20 +636,13 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer)
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
#if defined(ENABLE_NANORC) && (!defined(NANO_TINY) || defined(ENABLE_JUSTIFY))
|
||||
/* Return TRUE if the given string contains at least one blank character,
|
||||
* and FALSE otherwise. */
|
||||
/* Return TRUE if the given string contains at least one blank character. */
|
||||
bool has_blank_char(const char *string)
|
||||
{
|
||||
char symbol[MAXCHARLEN];
|
||||
while (*string != '\0' && !is_blank_char(string))
|
||||
string += char_length(string);
|
||||
|
||||
while (*string != '\0') {
|
||||
string += collect_char(string, symbol);
|
||||
|
||||
if (is_blank_char(symbol))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return *string;
|
||||
}
|
||||
#endif /* ENABLE_NANORC && (!NANO_TINY || ENABLE_JUSTIFY) */
|
||||
|
||||
@@ -615,14 +654,3 @@ bool white_string(const char *string)
|
||||
|
||||
return !*string;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* Return TRUE if wc is valid Unicode, and FALSE otherwise. */
|
||||
bool is_valid_unicode(wchar_t wc)
|
||||
{
|
||||
return ((0 <= wc && wc <= 0xD7FF) ||
|
||||
(0xE000 <= wc && wc <= 0xFDCF) ||
|
||||
(0xFDF0 <= wc && wc <= 0xFFFD) ||
|
||||
(0xFFFF < wc && wc <= 0x10FFFF && (wc & 0xFFFF) <= 0xFFFD));
|
||||
}
|
||||
#endif
|
||||
|
||||
17
src/color.c
17
src/color.c
@@ -119,19 +119,9 @@ void prepare_palette(void)
|
||||
* the list starting at head. Return TRUE upon success. */
|
||||
bool found_in_list(regexlisttype *head, const char *shibboleth)
|
||||
{
|
||||
regexlisttype *item;
|
||||
regex_t rgx;
|
||||
|
||||
for (item = head; item != NULL; item = item->next) {
|
||||
regcomp(&rgx, item->full_regex, NANO_REG_EXTENDED | REG_NOSUB);
|
||||
|
||||
if (regexec(&rgx, shibboleth, 0, NULL, 0) == 0) {
|
||||
regfree(&rgx);
|
||||
for (regexlisttype *item = head; item != NULL; item = item->next)
|
||||
if (regexec(item->one_rgx, shibboleth, 0, NULL, 0) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
regfree(&rgx);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@@ -305,7 +295,8 @@ void precalc_multicolorinfo(void)
|
||||
|
||||
/* For each line, allocate cache space for the multiline-regex info. */
|
||||
for (line = openfile->filetop; line != NULL; line = line->next)
|
||||
line->multidata = nmalloc(openfile->syntax->nmultis * sizeof(short));
|
||||
if (!line->multidata)
|
||||
line->multidata = nmalloc(openfile->syntax->nmultis * sizeof(short));
|
||||
|
||||
for (ink = openfile->syntax->color; ink != NULL; ink = ink->next) {
|
||||
/* If this is not a multi-line regex, skip it. */
|
||||
|
||||
28
src/cut.c
28
src/cut.c
@@ -34,7 +34,7 @@ void do_deletion(undo_type action)
|
||||
int charlen = char_length(openfile->current->data + openfile->current_x);
|
||||
size_t line_len = strlen(openfile->current->data + openfile->current_x);
|
||||
#ifndef NANO_TINY
|
||||
size_t old_amount = openfile->current->extrarows;
|
||||
size_t old_amount = ISSET(SOFTWRAP) ? extra_chunks_in(openfile->current) : 0;
|
||||
|
||||
/* If the type of action changed or the cursor moved to a different
|
||||
* line, create a new undo item, otherwise update the existing item. */
|
||||
@@ -49,13 +49,9 @@ void do_deletion(undo_type action)
|
||||
&openfile->current->data[openfile->current_x + charlen],
|
||||
line_len - charlen + 1);
|
||||
#ifndef NANO_TINY
|
||||
/* When softwrapping, recompute the number of chunks in the line,
|
||||
* and schedule a refresh if the number changed. */
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
if (openfile->current->extrarows != old_amount)
|
||||
refresh_needed = TRUE;
|
||||
}
|
||||
/* When softwrapping, a changed number of chunks requires a refresh. */
|
||||
if (ISSET(SOFTWRAP) && extra_chunks_in(openfile->current) != old_amount)
|
||||
refresh_needed = TRUE;
|
||||
|
||||
/* Adjust the mark if it is after the cursor on the current line. */
|
||||
if (openfile->mark == openfile->current &&
|
||||
@@ -94,10 +90,6 @@ void do_deletion(undo_type action)
|
||||
|
||||
unlink_node(joining);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP))
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
#endif
|
||||
/* Two lines were joined, so do a renumbering and refresh the screen. */
|
||||
renumber_from(openfile->current);
|
||||
refresh_needed = TRUE;
|
||||
@@ -336,9 +328,6 @@ void extract_segment(linestruct *top, size_t top_x, linestruct *bot, size_t bot_
|
||||
#ifndef NANO_TINY
|
||||
openfile->current->has_anchor = was_anchored;
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
|
||||
if (post_marked || same_line)
|
||||
openfile->mark = openfile->current;
|
||||
if (post_marked)
|
||||
@@ -391,10 +380,6 @@ void ingraft_buffer(linestruct *topline)
|
||||
}
|
||||
|
||||
if (topline != botline) {
|
||||
#ifndef NANO_TINY
|
||||
/* First compute the softwrapped chunks for each line in the graft. */
|
||||
compute_the_extra_rows_per_line_from(topline);
|
||||
#endif
|
||||
/* When inserting at end-of-buffer, update the relevant pointer. */
|
||||
if (line->next == NULL)
|
||||
openfile->filebot = botline;
|
||||
@@ -427,11 +412,6 @@ void ingraft_buffer(linestruct *topline)
|
||||
openfile->mark_x += length - xpos;
|
||||
} else if (mark_follows)
|
||||
openfile->mark_x += extralen;
|
||||
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
line->extrarows = extra_chunks_in(line);
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
}
|
||||
#endif
|
||||
|
||||
delete_node(topline);
|
||||
|
||||
@@ -111,9 +111,9 @@
|
||||
#define REPLACING 1
|
||||
#define INREGION 2
|
||||
|
||||
/* In UTF-8 a character is at most six bytes long. */
|
||||
#ifdef ENABLE_UTF8
|
||||
#define MAXCHARLEN 6
|
||||
/* In UTF-8 a valid character is at most four bytes long. */
|
||||
#define MAXCHARLEN 4
|
||||
#else
|
||||
#define MAXCHARLEN 1
|
||||
#endif
|
||||
@@ -246,7 +246,7 @@
|
||||
|
||||
/* Enumeration types. */
|
||||
typedef enum {
|
||||
NIX_FILE, DOS_FILE, MAC_FILE
|
||||
UNSPECIFIED, NIX_FILE, DOS_FILE, MAC_FILE
|
||||
} format_type;
|
||||
|
||||
typedef enum {
|
||||
@@ -307,7 +307,6 @@ enum {
|
||||
CUT_FROM_CURSOR,
|
||||
BACKWARDS_SEARCH,
|
||||
MULTIBUFFER,
|
||||
SMOOTH_SCROLL,
|
||||
REBIND_DELETE,
|
||||
RAW_SEQUENCES,
|
||||
NO_CONVERT,
|
||||
@@ -319,7 +318,6 @@ enum {
|
||||
RESTRICTED,
|
||||
SMART_HOME,
|
||||
WHITESPACE_DISPLAY,
|
||||
MORE_SPACE,
|
||||
TABS_TO_SPACES,
|
||||
QUICK_BLANK,
|
||||
WORD_BOUNDS,
|
||||
@@ -333,7 +331,6 @@ enum {
|
||||
TRIM_BLANKS,
|
||||
SHOW_CURSOR,
|
||||
LINE_NUMBERS,
|
||||
NO_PAUSES,
|
||||
AT_BLANKS,
|
||||
AFTER_ENDS,
|
||||
LET_THEM_ZAP,
|
||||
@@ -369,8 +366,8 @@ typedef struct colortype {
|
||||
} colortype;
|
||||
|
||||
typedef struct regexlisttype {
|
||||
char *full_regex;
|
||||
/* A regex string to match things that imply a certain syntax. */
|
||||
regex_t *one_rgx;
|
||||
/* A regex to match things that imply a certain syntax. */
|
||||
struct regexlisttype *next;
|
||||
/* The next regex. */
|
||||
} regexlisttype;
|
||||
@@ -441,10 +438,6 @@ typedef struct linestruct {
|
||||
/* The text of this line. */
|
||||
ssize_t lineno;
|
||||
/* The number of this line. */
|
||||
#ifndef NANO_TINY
|
||||
ssize_t extrarows;
|
||||
/* The extra rows that this line occupies when softwrapping. */
|
||||
#endif
|
||||
struct linestruct *next;
|
||||
/* Next node. */
|
||||
struct linestruct *prev;
|
||||
@@ -567,6 +560,8 @@ typedef struct openfilestruct {
|
||||
/* The syntax that applies to this file, if any. */
|
||||
#endif
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
char *errormessage;
|
||||
/* The ALERT message (if any) that occurred when opening the file. */
|
||||
struct openfilestruct *next;
|
||||
/* The next open file, if any. */
|
||||
struct openfilestruct *prev;
|
||||
|
||||
113
src/files.c
113
src/files.c
@@ -83,7 +83,7 @@ void make_new_buffer(void)
|
||||
openfile->mark = NULL;
|
||||
openfile->softmark = FALSE;
|
||||
|
||||
openfile->fmt = NIX_FILE;
|
||||
openfile->fmt = UNSPECIFIED;
|
||||
|
||||
openfile->undotop = NULL;
|
||||
openfile->current_undo = NULL;
|
||||
@@ -93,6 +93,9 @@ void make_new_buffer(void)
|
||||
openfile->statinfo = NULL;
|
||||
openfile->lock_filename = NULL;
|
||||
#endif
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
openfile->errormessage = NULL;
|
||||
#endif
|
||||
#ifdef ENABLE_COLOR
|
||||
openfile->syntax = NULL;
|
||||
#endif
|
||||
@@ -200,7 +203,8 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie
|
||||
* some byte-order-checking numbers (bytes 1008-1022). */
|
||||
lockdata[0] = 0x62;
|
||||
lockdata[1] = 0x30;
|
||||
snprintf(&lockdata[2], 10, "nano %s", VERSION);
|
||||
/* It's fine to overwrite byte 12 with the \0 as it is 0x00 anyway. */
|
||||
snprintf(&lockdata[2], 11, "nano %s", VERSION);
|
||||
lockdata[24] = mypid % 256;
|
||||
lockdata[25] = (mypid / 256) % 256;
|
||||
lockdata[26] = (mypid / (256 * 256)) % 256;
|
||||
@@ -370,9 +374,6 @@ bool open_buffer(const char *filename, bool new_one)
|
||||
{
|
||||
char *realname;
|
||||
/* The filename after tilde expansion. */
|
||||
#ifndef NANO_TINY
|
||||
char *thelocksname = NULL;
|
||||
#endif
|
||||
struct stat fileinfo;
|
||||
int descriptor = 0;
|
||||
/* Code 0 means new file, -1 means failure, and else it's the fd. */
|
||||
@@ -417,23 +418,28 @@ bool open_buffer(const char *filename, bool new_one)
|
||||
|
||||
/* When loading into a new buffer, first check the file's path is valid,
|
||||
* and then (if requested and possible) create a lock file for it. */
|
||||
if (new_one && has_valid_path(realname)) {
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(LOCKING) && !ISSET(VIEW_MODE) && filename[0] != '\0') {
|
||||
thelocksname = do_lockfile(realname, TRUE);
|
||||
|
||||
/* When not overriding an existing lock, don't open a buffer. */
|
||||
if (thelocksname == SKIPTHISFILE) {
|
||||
free(realname);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (new_one)
|
||||
if (new_one) {
|
||||
make_new_buffer();
|
||||
|
||||
if (has_valid_path(realname)) {
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(LOCKING) && !ISSET(VIEW_MODE) && filename[0] != '\0') {
|
||||
char *thelocksname = do_lockfile(realname, TRUE);
|
||||
|
||||
/* When not overriding an existing lock, discard the buffer. */
|
||||
if (thelocksname == SKIPTHISFILE) {
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
close_buffer();
|
||||
#endif
|
||||
free(realname);
|
||||
return FALSE;
|
||||
} else
|
||||
openfile->lock_filename = thelocksname;
|
||||
}
|
||||
#endif /* NANO_TINY */
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have a filename and are not in NOREAD mode, open the file. */
|
||||
if (filename[0] != '\0' && !ISSET(NOREAD_MODE))
|
||||
descriptor = open_file(realname, new_one, &f);
|
||||
@@ -452,13 +458,9 @@ bool open_buffer(const char *filename, bool new_one)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* When we've loaded a file into a new buffer, set the filename
|
||||
* and put the cursor at the start of the buffer. */
|
||||
/* For a new buffer, store filename and put cursor at start of buffer. */
|
||||
if (descriptor >= 0 && new_one) {
|
||||
openfile->filename = mallocstrcpy(openfile->filename, realname);
|
||||
#ifndef NANO_TINY
|
||||
openfile->lock_filename = thelocksname;
|
||||
#endif
|
||||
openfile->current = openfile->filetop;
|
||||
openfile->current_x = 0;
|
||||
openfile->placewewant = 0;
|
||||
@@ -469,6 +471,7 @@ bool open_buffer(const char *filename, bool new_one)
|
||||
if (new_one)
|
||||
find_and_prime_applicable_syntax();
|
||||
#endif
|
||||
|
||||
free(realname);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -541,10 +544,8 @@ void redecorate_after_switch(void)
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* While in a different buffer, the effective width of the screen may
|
||||
* have changed, so make sure that the softwrapped chunks per line and
|
||||
* the starting column for the first row get corresponding values. */
|
||||
compute_the_extra_rows_per_line_from(openfile->filetop);
|
||||
/* While in a different buffer, the width of the screen may have changed,
|
||||
* so make sure that the starting column for the first row is fitting. */
|
||||
ensure_firstcolumn_is_aligned();
|
||||
#endif
|
||||
|
||||
@@ -557,6 +558,11 @@ void redecorate_after_switch(void)
|
||||
/* Prevent a possible Shift selection from getting cancelled. */
|
||||
shift_held = TRUE;
|
||||
|
||||
if (openfile->errormessage) {
|
||||
statusline(ALERT, openfile->errormessage);
|
||||
free(openfile->errormessage);
|
||||
openfile->errormessage = NULL;
|
||||
} else
|
||||
/* Indicate on the status bar where we switched to. */
|
||||
mention_name_and_linecount();
|
||||
}
|
||||
@@ -594,12 +600,16 @@ void close_buffer(void)
|
||||
/* Free the undo stack. */
|
||||
discard_until(NULL);
|
||||
#endif
|
||||
free(orphan->errormessage);
|
||||
|
||||
openfile = orphan->prev;
|
||||
if (openfile == orphan)
|
||||
openfile = NULL;
|
||||
|
||||
free(orphan);
|
||||
|
||||
/* When just one buffer remains open, show "Exit" in the help lines. */
|
||||
if (openfile == openfile->next)
|
||||
if (openfile && openfile == openfile->next)
|
||||
exitfunc->desc = exit_tag;
|
||||
}
|
||||
#endif /* ENABLE_MULTIBUFFER */
|
||||
@@ -645,11 +655,9 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
||||
bool writable = TRUE;
|
||||
/* Whether the file is writable (in case we care). */
|
||||
#ifndef NANO_TINY
|
||||
int format = 0;
|
||||
/* 0 = Unix, 1 = DOS, 2 = Mac. */
|
||||
#endif
|
||||
format_type format = NIX_FILE;
|
||||
/* The type of line ending the file uses: Unix, DOS, or Mac. */
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (undoable)
|
||||
add_undo(INSERT, NULL);
|
||||
|
||||
@@ -678,20 +686,20 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
||||
if (control_C_was_pressed)
|
||||
break;
|
||||
|
||||
/* When the byte before the current one is a CR and we're doing
|
||||
* format conversion, then strip this CR when it's before a LF
|
||||
* OR when the file is in Mac format. Also, when still on the
|
||||
* first line, set the format to either DOS (1) or Mac (2). */
|
||||
/* When the byte before the current one is a CR and automatic format
|
||||
* conversion has not been switched off, then strip this CR when it's
|
||||
* before a LF OR when the file is in Mac format. Also, when this is
|
||||
* the first line break, make a note of the format. */
|
||||
if (input == '\n') {
|
||||
#ifndef NANO_TINY
|
||||
if (len > 0 && buf[len - 1] == '\r' && !ISSET(NO_CONVERT)) {
|
||||
if (num_lines == 0)
|
||||
format = 1;
|
||||
format = DOS_FILE;
|
||||
len--;
|
||||
}
|
||||
} else if ((num_lines == 0 || format == 2) &&
|
||||
} else if ((num_lines == 0 || format == MAC_FILE) &&
|
||||
len > 0 && buf[len - 1] == '\r' && !ISSET(NO_CONVERT)) {
|
||||
format = 2;
|
||||
format = MAC_FILE;
|
||||
len--;
|
||||
#endif
|
||||
} else {
|
||||
@@ -758,7 +766,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
||||
if (fd > 0 && !undoable && !ISSET(VIEW_MODE))
|
||||
writable = (access(filename, W_OK) == 0);
|
||||
|
||||
/* If the file ended with newline, or it was entirely empty, make the
|
||||
/* If the file ended with a newline, or it was entirely empty, make the
|
||||
* last line blank. Otherwise, put the last read data in. */
|
||||
if (len == 0)
|
||||
bottomline->data = copy_of("");
|
||||
@@ -770,7 +778,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
||||
* strip this CR and indicate that an extra blank line is needed. */
|
||||
if (buf[len - 1] == '\r' && !ISSET(NO_CONVERT)) {
|
||||
if (num_lines == 0)
|
||||
format = 2;
|
||||
format = MAC_FILE;
|
||||
buf[--len] = '\0';
|
||||
mac_line_needs_newline = TRUE;
|
||||
}
|
||||
@@ -799,18 +807,15 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
||||
if (!writable)
|
||||
statusline(ALERT, _("File '%s' is unwritable"), filename);
|
||||
#ifndef NANO_TINY
|
||||
else if (format == 2) {
|
||||
else if (format == MAC_FILE)
|
||||
/* TRANSLATORS: Keep the next three messages at most 78 characters. */
|
||||
openfile->fmt = MAC_FILE;
|
||||
statusline(HUSH, P_("Read %zu line (Converted from Mac format)",
|
||||
"Read %zu lines (Converted from Mac format)",
|
||||
num_lines), num_lines);
|
||||
} else if (format == 1) {
|
||||
openfile->fmt = DOS_FILE;
|
||||
else if (format == DOS_FILE)
|
||||
statusline(HUSH, P_("Read %zu line (Converted from DOS format)",
|
||||
"Read %zu lines (Converted from DOS format)",
|
||||
num_lines), num_lines);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
statusline(HUSH, P_("Read %zu line", "Read %zu lines",
|
||||
@@ -830,6 +835,8 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
||||
|
||||
if (ISSET(MAKE_IT_UNIX))
|
||||
openfile->fmt = NIX_FILE;
|
||||
else if (openfile->fmt == UNSPECIFIED)
|
||||
openfile->fmt = format;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1109,9 +1116,6 @@ void do_insertfile(bool execute)
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
bool was_multibuffer = ISSET(MULTIBUFFER);
|
||||
#endif
|
||||
#ifndef NANO_TINY
|
||||
format_type was_fmt = openfile->fmt;
|
||||
#endif
|
||||
|
||||
/* Display newlines in filenames as ^J. */
|
||||
as_an_at = FALSE;
|
||||
@@ -1279,12 +1283,9 @@ void do_insertfile(bool execute)
|
||||
{
|
||||
/* If the file actually changed, mark it as modified. */
|
||||
if (openfile->current->lineno != was_current_lineno ||
|
||||
openfile->current_x != was_current_x)
|
||||
openfile->current_x != was_current_x)
|
||||
set_modified();
|
||||
#ifndef NANO_TINY
|
||||
/* Ensure that the buffer retains the format that it had. */
|
||||
openfile->fmt = was_fmt;
|
||||
#endif
|
||||
|
||||
refresh_needed = TRUE;
|
||||
}
|
||||
|
||||
|
||||
61
src/nano.c
61
src/nano.c
@@ -76,7 +76,6 @@ linestruct *make_new_node(linestruct *prevnode)
|
||||
#endif
|
||||
newnode->lineno = (prevnode) ? prevnode->lineno + 1 : 1;
|
||||
#ifndef NANO_TINY
|
||||
newnode->extrarows = -2; /* Bad value, to make it easier to find bugs. */
|
||||
newnode->has_anchor = FALSE;
|
||||
#endif
|
||||
|
||||
@@ -100,6 +99,9 @@ void splice_node(linestruct *afterthis, linestruct *newnode)
|
||||
/* Free the data structures in the given node. */
|
||||
void delete_node(linestruct *line)
|
||||
{
|
||||
/* If the first line on the screen gets deleted, step one back. */
|
||||
if (line == openfile->edittop)
|
||||
openfile->edittop = line->prev;
|
||||
#ifdef ENABLE_WRAPPING
|
||||
/* If the spill-over line for hard-wrapping is deleted... */
|
||||
if (line == openfile->spillage_line)
|
||||
@@ -152,7 +154,6 @@ linestruct *copy_node(const linestruct *src)
|
||||
#endif
|
||||
dst->lineno = src->lineno;
|
||||
#ifndef NANO_TINY
|
||||
dst->extrarows = src->extrarows;
|
||||
dst->has_anchor = FALSE;
|
||||
#endif
|
||||
|
||||
@@ -1006,14 +1007,6 @@ void handle_sigwinch(int signal)
|
||||
the_window_resized = TRUE;
|
||||
}
|
||||
|
||||
/* Compute and store how many extra rows each line needs when softwrapping. */
|
||||
void compute_the_extra_rows_per_line_from(linestruct *fromline)
|
||||
{
|
||||
if (ISSET(SOFTWRAP))
|
||||
for (linestruct *line = fromline; line != NULL; line = line->next)
|
||||
line->extrarows = extra_chunks_in(line);
|
||||
}
|
||||
|
||||
/* Reinitialize and redraw the screen completely. */
|
||||
void regenerate_screen(void)
|
||||
{
|
||||
@@ -1056,7 +1049,6 @@ void regenerate_screen(void)
|
||||
|
||||
/* If we have an open buffer, redraw the contents of the subwindows. */
|
||||
if (openfile) {
|
||||
compute_the_extra_rows_per_line_from(openfile->filetop);
|
||||
ensure_firstcolumn_is_aligned();
|
||||
draw_all_subwindows();
|
||||
}
|
||||
@@ -1082,9 +1074,7 @@ void do_toggle(int flag)
|
||||
break;
|
||||
#endif
|
||||
case SOFTWRAP:
|
||||
if (ISSET(SOFTWRAP))
|
||||
compute_the_extra_rows_per_line_from(openfile->filetop);
|
||||
else
|
||||
if (!ISSET(SOFTWRAP))
|
||||
openfile->firstcolumn = 0;
|
||||
refresh_needed = TRUE;
|
||||
break;
|
||||
@@ -1246,9 +1236,7 @@ void confirm_margin(void)
|
||||
editwincols = COLS - margin - thebar;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* Recompute the softwrapped chunks for each line in the buffer,
|
||||
* and ensure a proper starting column for the first screen row. */
|
||||
compute_the_extra_rows_per_line_from(openfile->filetop);
|
||||
/* Ensure a proper starting column for the first screen row. */
|
||||
ensure_firstcolumn_is_aligned();
|
||||
focusing = keep_focus;
|
||||
#endif
|
||||
@@ -1414,12 +1402,13 @@ void inject(char *burst, size_t count)
|
||||
linestruct *thisline = openfile->current;
|
||||
size_t datalen = strlen(thisline->data);
|
||||
#ifndef NANO_TINY
|
||||
size_t old_amount = openfile->current->extrarows;
|
||||
size_t original_row = 0;
|
||||
size_t old_amount = 0;
|
||||
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
if (openfile->current_y == editwinrows - 1)
|
||||
original_row = chunk_for(xplustabs(), thisline);
|
||||
old_amount = extra_chunks_in(thisline);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1483,14 +1472,11 @@ void inject(char *burst, size_t count)
|
||||
/* When softwrapping and the number of chunks in the current line changed,
|
||||
* or we were on the last row of the edit window and moved to a new chunk,
|
||||
* we need a full refresh. */
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
if (openfile->current->extrarows != old_amount ||
|
||||
if (ISSET(SOFTWRAP) && (extra_chunks_in(openfile->current) != old_amount ||
|
||||
(openfile->current_y == editwinrows - 1 &&
|
||||
chunk_for(xplustabs(), openfile->current) > original_row)) {
|
||||
refresh_needed = TRUE;
|
||||
focusing = FALSE;
|
||||
}
|
||||
chunk_for(xplustabs(), openfile->current) > original_row))) {
|
||||
refresh_needed = TRUE;
|
||||
focusing = FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1804,18 +1790,8 @@ int main(int argc, char **argv)
|
||||
textdomain(PACKAGE);
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_UTF8) && !defined(NANO_TINY)
|
||||
if (MB_CUR_MAX > MAXCHARLEN)
|
||||
fprintf(stderr, "Unexpected large character size: %i bytes"
|
||||
" -- please report a bug\n", (int)MB_CUR_MAX);
|
||||
#endif
|
||||
|
||||
/* Set sensible defaults, different from what Pico does. */
|
||||
/* Set a sensible default, different from what Pico does. */
|
||||
SET(NO_WRAP);
|
||||
SET(SMOOTH_SCROLL);
|
||||
|
||||
/* Give a small visual hint that nano has changed. */
|
||||
SET(MORE_SPACE);
|
||||
|
||||
/* If the executable's name starts with 'r', activate restricted mode. */
|
||||
if (*(tail(argv[0])) == 'r')
|
||||
@@ -2175,13 +2151,9 @@ int main(int argc, char **argv)
|
||||
memmove(alt_speller, alt_speller + 1, strlen(alt_speller));
|
||||
#endif
|
||||
|
||||
/* If an rcfile undid the default settings, copy it to the new flags. */
|
||||
/* If an rcfile undid the default setting, copy it to the new flag. */
|
||||
if (!ISSET(NO_WRAP))
|
||||
SET(BREAK_LONG_LINES);
|
||||
if (!ISSET(SMOOTH_SCROLL))
|
||||
SET(JUMPY_SCROLLING);
|
||||
if (!ISSET(MORE_SPACE))
|
||||
SET(EMPTY_LINE);
|
||||
|
||||
/* Simply OR the boolean flags from rcfile and command line. */
|
||||
for (size_t i = 0; i < sizeof(flags) / sizeof(flags[0]); i++)
|
||||
@@ -2502,11 +2474,16 @@ int main(int argc, char **argv)
|
||||
#ifdef ENABLE_NANORC
|
||||
if (startup_problem != NULL)
|
||||
statusline(ALERT, startup_problem);
|
||||
|
||||
#define NOTREBOUND first_sc_for(MMAIN, do_help) && \
|
||||
first_sc_for(MMAIN, do_help)->keycode == 0x07
|
||||
#else
|
||||
#define NOTREBOUND TRUE
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_HELP
|
||||
if (*openfile->filename == '\0' && openfile->totsize == 0 &&
|
||||
openfile->next == openfile && !ISSET(NO_HELP))
|
||||
openfile->next == openfile && !ISSET(NO_HELP) && NOTREBOUND)
|
||||
statusbar(_("Welcome to nano. For basic help, type Ctrl+G."));
|
||||
#endif
|
||||
|
||||
|
||||
@@ -204,9 +204,9 @@ bool is_cntrl_char(const char *c);
|
||||
bool is_word_char(const char *c, bool allow_punct);
|
||||
char control_mbrep(const char *c, bool isdata);
|
||||
#ifdef ENABLE_UTF8
|
||||
int mbwidth(const char *c);
|
||||
int mbtowide(wchar_t *wc, const char *c);
|
||||
bool is_doublewidth(const char *ch);
|
||||
bool is_zerowidth(const char *ch);
|
||||
char *make_mbchar(long code, int *length);
|
||||
#endif
|
||||
int char_length(const char *pointer);
|
||||
size_t mbstrlen(const char *pointer);
|
||||
@@ -230,9 +230,6 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer);
|
||||
bool has_blank_char(const char *string);
|
||||
#endif
|
||||
bool white_string(const char *string);
|
||||
#ifdef ENABLE_UTF8
|
||||
bool is_valid_unicode(wchar_t wc);
|
||||
#endif
|
||||
|
||||
/* Most functions in color.c. */
|
||||
#ifdef ENABLE_COLOR
|
||||
@@ -412,7 +409,6 @@ void block_sigwinch(bool blockit);
|
||||
#endif
|
||||
#ifndef NANO_TINY
|
||||
void handle_sigwinch(int signal);
|
||||
void compute_the_extra_rows_per_line_from(linestruct *fromline);
|
||||
void regenerate_screen(void);
|
||||
void do_toggle(int flag);
|
||||
#endif
|
||||
@@ -532,9 +528,7 @@ void complete_a_word(void);
|
||||
void get_homedir(void);
|
||||
const char *tail(const char *path);
|
||||
char *concatenate(const char *path, const char *name);
|
||||
#ifdef ENABLE_LINENUMBERS
|
||||
int digits(ssize_t n);
|
||||
#endif
|
||||
bool parse_num(const char *str, ssize_t *result);
|
||||
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column);
|
||||
void recode_NUL_to_LF(char *string, size_t length);
|
||||
|
||||
11
src/rcfile.c
11
src/rcfile.c
@@ -60,7 +60,6 @@ static const rcoption rcopts[] = {
|
||||
#ifdef HAVE_LIBMAGIC
|
||||
{"magic", USE_MAGIC},
|
||||
#endif
|
||||
{"morespace", MORE_SPACE}, /* Deprecated; remove in 2021. */
|
||||
#ifdef ENABLE_MOUSE
|
||||
{"mouse", USE_MOUSE},
|
||||
#endif
|
||||
@@ -69,7 +68,6 @@ static const rcoption rcopts[] = {
|
||||
#endif
|
||||
{"nohelp", NO_HELP},
|
||||
{"nonewlines", NO_NEWLINES},
|
||||
{"nopauses", NO_PAUSES}, /* Obsolete; remove in 2021. */
|
||||
#ifdef ENABLE_WRAPPING
|
||||
{"nowrap", NO_WRAP}, /* Deprecated; remove in 2024. */
|
||||
#endif
|
||||
@@ -114,7 +112,6 @@ static const rcoption rcopts[] = {
|
||||
{"noconvert", NO_CONVERT},
|
||||
{"showcursor", SHOW_CURSOR},
|
||||
{"smarthome", SMART_HOME},
|
||||
{"smooth", SMOOTH_SCROLL}, /* Deprecated; remove in 2021. */
|
||||
{"softwrap", SOFTWRAP},
|
||||
{"stateflags", STATEFLAGS},
|
||||
{"tabsize", 0},
|
||||
@@ -625,9 +622,7 @@ bool compile(const char *expression, int rex_flags, regex_t **packed)
|
||||
regerror(outcome, compiled, message, length);
|
||||
jot_error(N_("Bad regex \"%s\": %s"), expression, message);
|
||||
free(message);
|
||||
}
|
||||
|
||||
if (packed == NULL || outcome != 0) {
|
||||
regfree(compiled);
|
||||
free(compiled);
|
||||
} else
|
||||
@@ -1242,6 +1237,8 @@ void grab_and_store(const char *kind, char *ptr, regexlisttype **storage)
|
||||
|
||||
/* Now gather any valid regexes and add them to the linked list. */
|
||||
while (*ptr != '\0') {
|
||||
regex_t *packed_rgx = NULL;
|
||||
|
||||
regexstring = ++ptr;
|
||||
ptr = parse_next_regex(ptr);
|
||||
|
||||
@@ -1249,12 +1246,12 @@ void grab_and_store(const char *kind, char *ptr, regexlisttype **storage)
|
||||
return;
|
||||
|
||||
/* If the regex string is malformed, skip it. */
|
||||
if (!compile(regexstring, NANO_REG_EXTENDED | REG_NOSUB, NULL))
|
||||
if (!compile(regexstring, NANO_REG_EXTENDED | REG_NOSUB, &packed_rgx))
|
||||
continue;
|
||||
|
||||
/* Copy the regex into a struct, and hook this in at the end. */
|
||||
newthing = nmalloc(sizeof(regexlisttype));
|
||||
newthing->full_regex = copy_of(regexstring);
|
||||
newthing->one_rgx = packed_rgx;
|
||||
newthing->next = NULL;
|
||||
|
||||
if (lastthing == NULL)
|
||||
|
||||
@@ -665,10 +665,6 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
||||
free(openfile->current->data);
|
||||
openfile->current->data = copy;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP))
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
#endif
|
||||
set_modified();
|
||||
as_an_at = TRUE;
|
||||
numreplaced++;
|
||||
|
||||
44
src/text.c
44
src/text.c
@@ -103,9 +103,6 @@ void indent_a_line(linestruct *line, char *indentation)
|
||||
|
||||
openfile->totsize += indent_len;
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
line->extrarows = extra_chunks_in(line);
|
||||
|
||||
/* Compensate for the change in the current line. */
|
||||
if (line == openfile->mark && openfile->mark_x > 0)
|
||||
openfile->mark_x += indent_len;
|
||||
@@ -234,9 +231,6 @@ void unindent_a_line(linestruct *line, size_t indent_len)
|
||||
|
||||
openfile->totsize -= indent_len;
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
line->extrarows = extra_chunks_in(line);
|
||||
|
||||
/* Adjust the positions of mark and cursor, when they are affected. */
|
||||
compensate_leftward(line, indent_len);
|
||||
}
|
||||
@@ -426,10 +420,6 @@ void do_comment(void)
|
||||
* store undo data when a line changed. */
|
||||
for (line = top; line != bot->next; line = line->next) {
|
||||
if (comment_line(action, line, comment_seq)) {
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP))
|
||||
line->extrarows = extra_chunks_in(line);
|
||||
#endif
|
||||
update_multiline_undo(line->lineno, "");
|
||||
}
|
||||
}
|
||||
@@ -573,8 +563,6 @@ void do_undo(void)
|
||||
break;
|
||||
}
|
||||
line->data[u->tail_x] = '\0';
|
||||
if (ISSET(SOFTWRAP))
|
||||
line->extrarows = extra_chunks_in(line);
|
||||
intruder = make_new_node(line);
|
||||
intruder->data = copy_of(u->strdata);
|
||||
splice_node(line, intruder);
|
||||
@@ -676,9 +664,6 @@ void do_undo(void)
|
||||
openfile->mark = NULL;
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
|
||||
openfile->totsize = u->wassize;
|
||||
|
||||
/* When at the point where the file was last saved, unset "Modified". */
|
||||
@@ -725,8 +710,6 @@ void do_redo(void)
|
||||
case ENTER:
|
||||
redidmsg = _("line break");
|
||||
line->data[u->head_x] = '\0';
|
||||
if (ISSET(SOFTWRAP))
|
||||
line->extrarows = extra_chunks_in(line);
|
||||
intruder = make_new_node(line);
|
||||
intruder->data = copy_of(u->strdata);
|
||||
splice_node(line, intruder);
|
||||
@@ -841,9 +824,6 @@ void do_redo(void)
|
||||
openfile->mark = NULL;
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
|
||||
openfile->totsize = u->newsize;
|
||||
|
||||
/* When at the point where the file was last saved, unset "Modified". */
|
||||
@@ -907,11 +887,6 @@ void do_enter(void)
|
||||
openfile->mark = newnode;
|
||||
openfile->mark_x += extra - openfile->current_x;
|
||||
}
|
||||
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
openfile->current->extrarows = extra_chunks_in(openfile->current);
|
||||
newnode->extrarows = extra_chunks_in(newnode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Insert the newly created line after the current one and renumber. */
|
||||
@@ -951,7 +926,7 @@ void discard_until(const undostruct *thisitem)
|
||||
while (group != NULL) {
|
||||
groupstruct *next = group->next;
|
||||
free_chararray(group->indentations,
|
||||
group->bottom_line - group->top_line);
|
||||
group->bottom_line - group->top_line + 1);
|
||||
free(group);
|
||||
group = next;
|
||||
}
|
||||
@@ -1453,21 +1428,12 @@ ssize_t break_line(const char *textstart, ssize_t goal, bool snap_at_nl)
|
||||
* "indentation" of a line is the leading consecutive whitespace. */
|
||||
size_t indent_length(const char *line)
|
||||
{
|
||||
size_t len = 0;
|
||||
char onechar[MAXCHARLEN];
|
||||
int charlen;
|
||||
const char *start = line;
|
||||
|
||||
while (*line != '\0') {
|
||||
charlen = collect_char(line, onechar);
|
||||
while (*line != '\0' && is_blank_char(line))
|
||||
line += char_length(line);
|
||||
|
||||
if (!is_blank_char(onechar))
|
||||
break;
|
||||
|
||||
line += charlen;
|
||||
len += charlen;
|
||||
}
|
||||
|
||||
return len;
|
||||
return (line - start);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
31
src/utils.c
31
src/utils.c
@@ -76,7 +76,6 @@ char *concatenate(const char *path, const char *name)
|
||||
return joined;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LINENUMBERS
|
||||
/* Return the number of digits that the given integer n takes up. */
|
||||
int digits(ssize_t n)
|
||||
{
|
||||
@@ -106,7 +105,6 @@ int digits(ssize_t n)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Read an integer from the given string. If it parses okay,
|
||||
* store it in *result and return TRUE; otherwise, return FALSE. */
|
||||
@@ -195,22 +193,18 @@ void free_chararray(char **array, size_t len)
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SPELLER
|
||||
/* Is the word starting at the given position in buf and of the given length
|
||||
* a separate word? That is: is it not part of a longer word?*/
|
||||
bool is_separate_word(size_t position, size_t length, const char *buf)
|
||||
/* Is the word starting at the given position in 'text' and of the given
|
||||
* length a separate word? That is: is it not part of a longer word? */
|
||||
bool is_separate_word(size_t position, size_t length, const char *text)
|
||||
{
|
||||
char before[MAXCHARLEN], after[MAXCHARLEN];
|
||||
size_t word_end = position + length;
|
||||
|
||||
/* Get the characters before and after the word, if any. */
|
||||
collect_char(buf + step_left(buf, position), before);
|
||||
collect_char(buf + word_end, after);
|
||||
const char *before = text + step_left(text, position);
|
||||
const char *after = text + position + length;
|
||||
|
||||
/* If the word starts at the beginning of the line OR the character before
|
||||
* the word isn't a letter, and if the word ends at the end of the line OR
|
||||
* the character after the word isn't a letter, we have a whole word. */
|
||||
return ((position == 0 || !is_alpha_char(before)) &&
|
||||
(buf[word_end] == '\0' || !is_alpha_char(after)));
|
||||
(*after == '\0' || !is_alpha_char(after)));
|
||||
}
|
||||
#endif /* ENABLE_SPELLER */
|
||||
|
||||
@@ -355,14 +349,12 @@ char *free_and_assign(char *dest, char *src)
|
||||
return src;
|
||||
}
|
||||
|
||||
/* When not in softwrap mode, nano scrolls horizontally within a line in
|
||||
* chunks (a bit smaller than the chunks used in softwrapping). Return the
|
||||
* column number of the first character displayed in the edit window when the
|
||||
* cursor is at the given column. Note that (0 <= column -
|
||||
* get_page_start(column) < COLS). */
|
||||
/* When not softwrapping, nano scrolls the current line horizontally by
|
||||
* chunks ("pages"). Return the column number of the first character
|
||||
* displayed in the edit window when the cursor is at the given column. */
|
||||
size_t get_page_start(size_t column)
|
||||
{
|
||||
if (column + 2 < editwincols || ISSET(SOFTWRAP) || column == 0)
|
||||
if (column == 0 || column + 2 < editwincols || ISSET(SOFTWRAP))
|
||||
return 0;
|
||||
else if (editwincols > 8)
|
||||
return column - 6 - (column - 6) % (editwincols - 8);
|
||||
@@ -437,9 +429,6 @@ void new_magicline(void)
|
||||
openfile->filebot->next = make_new_node(openfile->filebot);
|
||||
openfile->filebot->next->data = copy_of("");
|
||||
openfile->filebot = openfile->filebot->next;
|
||||
#ifndef NANO_TINY
|
||||
openfile->filebot->extrarows = 0;
|
||||
#endif
|
||||
openfile->totsize++;
|
||||
}
|
||||
|
||||
|
||||
193
src/winio.c
193
src/winio.c
@@ -54,6 +54,10 @@ static bool linger_after_escape = FALSE;
|
||||
/* Whether to give ncurses some time to get the next code. */
|
||||
static int statusblank = 0;
|
||||
/* The number of keystrokes left before we blank the status bar. */
|
||||
size_t from_x = 0;
|
||||
/* From where in the relevant line the current row is drawn. */
|
||||
size_t till_x = 0;
|
||||
/* Until where in the relevant line the current row is drawn. */
|
||||
static bool has_more = FALSE;
|
||||
/* Whether the current line has more text after the displayed part. */
|
||||
static bool is_shorter = TRUE;
|
||||
@@ -1377,7 +1381,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
|
||||
* commence Unicode input. Otherwise, put the code back. */
|
||||
if (using_utf8() && (keycode == '0' || keycode == '1')) {
|
||||
long unicode = assemble_unicode(keycode);
|
||||
char *multibyte;
|
||||
char multibyte[MB_CUR_MAX];
|
||||
|
||||
reveal_cursor = FALSE;
|
||||
|
||||
@@ -1407,14 +1411,15 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
|
||||
}
|
||||
|
||||
/* Convert the Unicode value to a multibyte sequence. */
|
||||
multibyte = make_mbchar(unicode, (int *)count);
|
||||
*count = wctomb(multibyte, unicode);
|
||||
|
||||
if (*count > MAXCHARLEN)
|
||||
*count = 0;
|
||||
|
||||
/* Change the multibyte character into a series of integers. */
|
||||
for (size_t i = 0; i < *count; i++)
|
||||
yield[i] = (int)multibyte[i];
|
||||
|
||||
free(multibyte);
|
||||
|
||||
return yield;
|
||||
}
|
||||
#endif /* ENABLE_UTF8 */
|
||||
@@ -1695,32 +1700,35 @@ void set_blankdelay_to_one(void)
|
||||
statusblank = 1;
|
||||
}
|
||||
|
||||
/* Convert buf into a string that can be displayed on screen. The caller
|
||||
* wants to display buf starting with the given column, and extending for
|
||||
/* Convert text into a string that can be displayed on screen. The caller
|
||||
* wants to display text starting with the given column, and extending for
|
||||
* at most span columns. column is zero-based, and span is one-based, so
|
||||
* span == 0 means you get "" returned. The returned string is dynamically
|
||||
* allocated, and should be freed. If isdata is TRUE, the caller might put
|
||||
* "<" at the beginning or ">" at the end of the line if it's too long. If
|
||||
* isprompt is TRUE, the caller might put ">" at the end of the line if it's
|
||||
* too long. */
|
||||
char *display_string(const char *buf, size_t column, size_t span,
|
||||
char *display_string(const char *text, size_t column, size_t span,
|
||||
bool isdata, bool isprompt)
|
||||
{
|
||||
size_t start_index = actual_x(buf, column);
|
||||
const char *origin = text;
|
||||
/* The beginning of the text, to later determine the covered part. */
|
||||
size_t start_x = actual_x(text, column);
|
||||
/* The index of the first character that the caller wishes to show. */
|
||||
size_t start_col = wideness(buf, start_index);
|
||||
size_t start_col = wideness(text, start_x);
|
||||
/* The actual column where that first character starts. */
|
||||
char *converted;
|
||||
/* The expanded string we will return. */
|
||||
size_t stowaways = 20;
|
||||
/* The number of zero-width characters for which to reserve space. */
|
||||
size_t allocsize = (COLS + stowaways) * MAXCHARLEN + 1;
|
||||
/* The amount of memory to reserve for the displayable string. */
|
||||
char *converted = nmalloc(allocsize);
|
||||
/* The displayable string we will return. */
|
||||
size_t index = 0;
|
||||
/* Current position in converted. */
|
||||
size_t beyond = column + span;
|
||||
/* The column number just beyond the last shown character. */
|
||||
|
||||
buf += start_index;
|
||||
|
||||
/* Allocate enough space for converting the relevant part of the line. */
|
||||
converted = nmalloc(strlen(buf) * (MAXCHARLEN + tabsize) + 1);
|
||||
text += start_x;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (span > HIGHEST_POSITIVE) {
|
||||
@@ -1731,17 +1739,17 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
#endif
|
||||
/* If the first character starts before the left edge, or would be
|
||||
* overwritten by a "<" token, then show placeholders instead. */
|
||||
if (*buf != '\0' && *buf != '\t' && (start_col < column ||
|
||||
(start_col > 0 && isdata && !ISSET(SOFTWRAP)))) {
|
||||
if (is_cntrl_char(buf)) {
|
||||
if ((start_col < column || (start_col > 0 && isdata && !ISSET(SOFTWRAP))) &&
|
||||
*text != '\0' && *text != '\t') {
|
||||
if (is_cntrl_char(text)) {
|
||||
if (start_col < column) {
|
||||
converted[index++] = control_mbrep(buf, isdata);
|
||||
converted[index++] = control_mbrep(text, isdata);
|
||||
column++;
|
||||
buf += char_length(buf);
|
||||
text += char_length(text);
|
||||
}
|
||||
}
|
||||
#ifdef ENABLE_UTF8
|
||||
else if (mbwidth(buf) == 2) {
|
||||
else if (is_doublewidth(text)) {
|
||||
if (start_col == column) {
|
||||
converted[index++] = ' ';
|
||||
column++;
|
||||
@@ -1750,29 +1758,29 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
/* Display the right half of a two-column character as ']'. */
|
||||
converted[index++] = ']';
|
||||
column++;
|
||||
buf += char_length(buf);
|
||||
text += char_length(text);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
#define ISO8859_CHAR FALSE
|
||||
#define ZEROWIDTH_CHAR (mbwidth(buf) == 0)
|
||||
#define ZEROWIDTH_CHAR (is_zerowidth(text))
|
||||
#else
|
||||
#define ISO8859_CHAR ((unsigned char)*buf > 0x9F)
|
||||
#define ISO8859_CHAR ((unsigned char)*text > 0x9F)
|
||||
#define ZEROWIDTH_CHAR FALSE
|
||||
#endif
|
||||
|
||||
while (*buf != '\0' && (column < beyond || ZEROWIDTH_CHAR)) {
|
||||
while (*text != '\0' && (column < beyond || ZEROWIDTH_CHAR)) {
|
||||
/* A plain printable ASCII character is one byte, one column. */
|
||||
if (((signed char)*buf > 0x20 && *buf != DEL_CODE) || ISO8859_CHAR) {
|
||||
converted[index++] = *(buf++);
|
||||
if (((signed char)*text > 0x20 && *text != DEL_CODE) || ISO8859_CHAR) {
|
||||
converted[index++] = *(text++);
|
||||
column++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Show a space as a visible character, or as a space. */
|
||||
if (*buf == ' ') {
|
||||
if (*text == ' ') {
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(WHITESPACE_DISPLAY)) {
|
||||
for (int i = whitelen[0]; i < whitelen[0] + whitelen[1];)
|
||||
@@ -1781,12 +1789,12 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
#endif
|
||||
converted[index++] = ' ';
|
||||
column++;
|
||||
buf++;
|
||||
text++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Show a tab as a visible character plus spaces, or as just spaces. */
|
||||
if (*buf == '\t') {
|
||||
if (*text == '\t') {
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(WHITESPACE_DISPLAY) && (index > 0 || !isdata ||
|
||||
!ISSET(SOFTWRAP) || column % tabsize == 0 ||
|
||||
@@ -1802,15 +1810,15 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
converted[index++] = ' ';
|
||||
column++;
|
||||
}
|
||||
buf++;
|
||||
text++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Represent a control character with a leading caret. */
|
||||
if (is_cntrl_char(buf)) {
|
||||
if (is_cntrl_char(text)) {
|
||||
converted[index++] = '^';
|
||||
converted[index++] = control_mbrep(buf, isdata);
|
||||
buf += char_length(buf);
|
||||
converted[index++] = control_mbrep(text, isdata);
|
||||
text += char_length(text);
|
||||
column += 2;
|
||||
continue;
|
||||
}
|
||||
@@ -1820,14 +1828,14 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
wchar_t wc;
|
||||
|
||||
/* Convert a multibyte character to a single code. */
|
||||
charlength = mbtowc(&wc, buf, MAXCHARLEN);
|
||||
charlength = mbtowide(&wc, text);
|
||||
|
||||
/* Represent an invalid character with the Replacement Character. */
|
||||
if (charlength < 0 || !is_valid_unicode(wc)) {
|
||||
if (charlength < 0) {
|
||||
converted[index++] = '\xEF';
|
||||
converted[index++] = '\xBF';
|
||||
converted[index++] = '\xBD';
|
||||
buf += (charlength > 0 ? charlength : 1);
|
||||
text++;
|
||||
column++;
|
||||
continue;
|
||||
}
|
||||
@@ -1835,17 +1843,24 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
/* Determine whether the character takes zero, one, or two columns. */
|
||||
charwidth = wcwidth(wc);
|
||||
|
||||
/* Watch the number of zero-widths, to keep ample memory reserved. */
|
||||
if (charwidth == 0 && --stowaways == 0) {
|
||||
stowaways = 40;
|
||||
allocsize += stowaways * MAXCHARLEN;
|
||||
converted = nrealloc(converted, allocsize);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/* On a Linux console, skip zero-width characters, as it would show
|
||||
* them WITH a width, thus messing up the display. See bug #52954. */
|
||||
if (on_a_vt && charwidth == 0) {
|
||||
buf += charlength;
|
||||
text += charlength;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
/* For any valid character, just copy its bytes. */
|
||||
for (; charlength > 0; charlength--)
|
||||
converted[index++] = *(buf++);
|
||||
converted[index++] = *(text++);
|
||||
|
||||
/* If the codepoint is unassigned, assume a width of one. */
|
||||
column += (charwidth < 0 ? 1 : charwidth);
|
||||
@@ -1853,15 +1868,15 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
}
|
||||
|
||||
/* If there is more text than can be shown, make room for the ">". */
|
||||
if (column > beyond || (*buf != '\0' && (isprompt ||
|
||||
if (column > beyond || (*text != '\0' && (isprompt ||
|
||||
(isdata && !ISSET(SOFTWRAP))))) {
|
||||
#ifdef ENABLE_UTF8
|
||||
do {
|
||||
index = step_left(converted, index);
|
||||
} while (mbwidth(converted + index) == 0);
|
||||
} while (is_zerowidth(converted + index));
|
||||
|
||||
/* Display the left half of a two-column character as '['. */
|
||||
if (mbwidth(converted + index) == 2)
|
||||
if (is_doublewidth(converted + index))
|
||||
converted[index++] = '[';
|
||||
#else
|
||||
index--;
|
||||
@@ -1875,6 +1890,10 @@ char *display_string(const char *buf, size_t column, size_t span,
|
||||
/* Null-terminate the converted string. */
|
||||
converted[index] = '\0';
|
||||
|
||||
/* Remember what part of the original text is covered by converted. */
|
||||
from_x = start_x;
|
||||
till_x = text - origin;
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
@@ -2084,10 +2103,9 @@ void minibar(void)
|
||||
wattron(bottomwin, interface_color_pair[TITLE_BAR]);
|
||||
mvwprintw(bottomwin, 0, 0, "%*s", COLS, " ");
|
||||
|
||||
/* Display the name of the current file, plus a star when modified. */
|
||||
if (openfile->filename[0] != '\0') {
|
||||
as_an_at = FALSE;
|
||||
thename = display_string(openfile->filename, 0, HIGHEST_POSITIVE, FALSE, FALSE);
|
||||
thename = display_string(openfile->filename, 0, COLS, FALSE, FALSE);
|
||||
} else
|
||||
thename = copy_of(_("(nameless)"));
|
||||
|
||||
@@ -2099,8 +2117,9 @@ void minibar(void)
|
||||
if (namewidth + 19 > COLS)
|
||||
padding = 0;
|
||||
|
||||
/* Display the name of the current file (dottifying it if it doesn't fit),
|
||||
* plus a star when the file has been modified. */
|
||||
if (COLS > 4) {
|
||||
/* If the full file name doesn't fit, dottify it. */
|
||||
if (namewidth > COLS - 2) {
|
||||
thename = display_string(thename, namewidth - COLS + 5, COLS - 5, FALSE, FALSE);
|
||||
mvwaddstr(bottomwin, 0, 0, "...");
|
||||
@@ -2111,6 +2130,8 @@ void minibar(void)
|
||||
waddstr(bottomwin, openfile->modified ? " *" : " ");
|
||||
}
|
||||
|
||||
/* Right after reading or writing a file, display its number of lines;
|
||||
* otherwise, when there a mutiple buffers, display an [x/n] counter. */
|
||||
if (report_size && COLS > 35) {
|
||||
size_t count = openfile->filebot->lineno - (openfile->filebot->data[0] == '\0');
|
||||
|
||||
@@ -2136,7 +2157,8 @@ void minibar(void)
|
||||
if (ISSET(CONSTANT_SHOW) && namewidth + tallywidth + placewidth + 32 < COLS)
|
||||
mvwaddstr(bottomwin, 0, COLS - 27 - placewidth, location);
|
||||
|
||||
/* Display the hexadecimal code of the character under the cursor. */
|
||||
/* Display the hexadecimal code of the character under the cursor,
|
||||
* plus the codes of upto two succeeding zero-width characters. */
|
||||
if (ISSET(CONSTANT_SHOW) && namewidth + tallywidth + 28 < COLS) {
|
||||
char *this_position = openfile->current->data + openfile->current_x;
|
||||
|
||||
@@ -2151,7 +2173,7 @@ void minibar(void)
|
||||
#ifdef ENABLE_UTF8
|
||||
else if ((unsigned char)*this_position < 0x80 && using_utf8())
|
||||
sprintf(hexadecimal, "U+%04X", (unsigned char)*this_position);
|
||||
else if (using_utf8() && mbtowc(&widecode, this_position, MAXCHARLEN) >= 0)
|
||||
else if (using_utf8() && mbtowide(&widecode, this_position) > 0)
|
||||
sprintf(hexadecimal, "U+%04X", (int)widecode);
|
||||
#endif
|
||||
else
|
||||
@@ -2163,13 +2185,13 @@ void minibar(void)
|
||||
successor = this_position + char_length(this_position);
|
||||
|
||||
if (*this_position && *successor && is_zerowidth(successor) &&
|
||||
mbtowc(&widecode, successor, MAXCHARLEN) >= 0) {
|
||||
mbtowide(&widecode, successor) > 0) {
|
||||
sprintf(hexadecimal, "|%04X", (int)widecode);
|
||||
waddstr(bottomwin, hexadecimal);
|
||||
|
||||
successor += char_length(successor);
|
||||
|
||||
if (is_zerowidth(successor) && mbtowc(&widecode, successor, MAXCHARLEN) >= 0) {
|
||||
if (is_zerowidth(successor) && mbtowide(&widecode, successor) > 0) {
|
||||
sprintf(hexadecimal, "|%04X", (int)widecode);
|
||||
waddstr(bottomwin, hexadecimal);
|
||||
}
|
||||
@@ -2223,6 +2245,18 @@ void statusline(message_type importance, const char *msg, ...)
|
||||
if (importance < lastmessage && lastmessage > NOTICE)
|
||||
return;
|
||||
|
||||
/* Construct the message out of all the arguments. */
|
||||
compound = nmalloc(MAXCHARLEN * COLS + 1);
|
||||
va_start(ap, msg);
|
||||
vsnprintf(compound, MAXCHARLEN * COLS + 1, msg, ap);
|
||||
va_end(ap);
|
||||
|
||||
#if !defined(NANO_TINY) && defined(ENABLE_MULTIBUFFER)
|
||||
if (!we_are_running && importance == ALERT && openfile && !openfile->fmt &&
|
||||
!openfile->errormessage && openfile->next != openfile)
|
||||
openfile->errormessage = copy_of(compound);
|
||||
#endif
|
||||
|
||||
/* If there are multiple alert messages, add trailing dots to the first. */
|
||||
if (lastmessage == ALERT) {
|
||||
if (start_col > 4) {
|
||||
@@ -2235,6 +2269,7 @@ void statusline(message_type importance, const char *msg, ...)
|
||||
napms(100);
|
||||
beep();
|
||||
}
|
||||
free(compound);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2251,11 +2286,6 @@ void statusline(message_type importance, const char *msg, ...)
|
||||
|
||||
blank_statusbar();
|
||||
|
||||
/* Construct the message out of all the arguments. */
|
||||
compound = nmalloc(MAXCHARLEN * (COLS + 1));
|
||||
va_start(ap, msg);
|
||||
vsnprintf(compound, MAXCHARLEN * (COLS + 1), msg, ap);
|
||||
va_end(ap);
|
||||
message = display_string(compound, 0, COLS, FALSE, FALSE);
|
||||
free(compound);
|
||||
|
||||
@@ -2267,7 +2297,6 @@ void statusline(message_type importance, const char *msg, ...)
|
||||
if (bracketed)
|
||||
waddstr(bottomwin, "[ ");
|
||||
waddstr(bottomwin, message);
|
||||
free(message);
|
||||
if (bracketed)
|
||||
waddstr(bottomwin, " ]");
|
||||
wattroff(bottomwin, colorpair);
|
||||
@@ -2280,6 +2309,7 @@ void statusline(message_type importance, const char *msg, ...)
|
||||
|
||||
/* Push the message to the screen straightaway. */
|
||||
wrefresh(bottomwin);
|
||||
free(message);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (old_whitespace)
|
||||
@@ -2429,15 +2459,6 @@ void place_the_cursor(void)
|
||||
* from_col is the column number of the first character of this "page". */
|
||||
void draw_row(int row, const char *converted, linestruct *line, size_t from_col)
|
||||
{
|
||||
#if !defined(NANO_TINY) || defined(ENABLE_COLOR)
|
||||
size_t from_x = actual_x(line->data, from_col);
|
||||
/* The position in the line's data of the leftmost character
|
||||
* that is at least partially onscreen. */
|
||||
size_t till_x = actual_x(line->data, from_col + editwincols - 1) + 1;
|
||||
/* The position in the line's data just after the start of
|
||||
* the last character that is at least partially onscreen. */
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_LINENUMBERS
|
||||
/* If line numbering is switched on, put a line number in front of
|
||||
* the text -- but only for the parts that are not softwrapped. */
|
||||
@@ -3034,22 +3055,26 @@ bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge)
|
||||
/* Draw a scroll bar on the righthand side of the screen. */
|
||||
void draw_scrollbar(void)
|
||||
{
|
||||
int totalrows = openfile->filebot->lineno;
|
||||
int first_row = openfile->edittop->lineno;
|
||||
int totallines = openfile->filebot->lineno;
|
||||
int fromline = openfile->edittop->lineno - 1;
|
||||
int coveredlines = editwinrows;
|
||||
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
for (linestruct *ln = openfile->filetop; ln != openfile->edittop; ln = ln->next)
|
||||
first_row += ln->extrarows;
|
||||
first_row += chunk_for(openfile->firstcolumn, openfile->edittop);
|
||||
linestruct *line = openfile->edittop;
|
||||
int extras = extra_chunks_in(line) - chunk_for(openfile->firstcolumn, line);
|
||||
|
||||
for (linestruct *ln = openfile->filetop; ln != NULL; ln = ln->next)
|
||||
totalrows += ln->extrarows;
|
||||
while (line->lineno + extras < fromline + editwinrows && line->next) {
|
||||
line = line->next;
|
||||
extras += extra_chunks_in(line);
|
||||
}
|
||||
|
||||
coveredlines = line->lineno - fromline;
|
||||
}
|
||||
|
||||
int lowest = ((first_row - 1) * editwinrows) / totalrows;
|
||||
int highest = lowest + (editwinrows * editwinrows) / totalrows;
|
||||
int lowest = (fromline * editwinrows) / totallines;
|
||||
int highest = lowest + (editwinrows * coveredlines) / totallines;
|
||||
|
||||
if (editwinrows > totalrows)
|
||||
if (editwinrows > totallines)
|
||||
highest = editwinrows;
|
||||
|
||||
for (int row = 0; row < editwinrows; row++) {
|
||||
@@ -3263,14 +3288,11 @@ size_t actual_last_column(size_t leftedge, size_t column)
|
||||
return leftedge + column;
|
||||
}
|
||||
|
||||
/* Return TRUE if current[current_x] is above the top of the screen, and FALSE
|
||||
* otherwise. */
|
||||
/* Return TRUE if current[current_x] is before the viewport. */
|
||||
bool current_is_above_screen(void)
|
||||
{
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP))
|
||||
/* The cursor is above screen when current[current_x] is before edittop
|
||||
* at column firstcolumn. */
|
||||
return (openfile->current->lineno < openfile->edittop->lineno ||
|
||||
(openfile->current->lineno == openfile->edittop->lineno &&
|
||||
xplustabs() < openfile->firstcolumn));
|
||||
@@ -3279,8 +3301,7 @@ bool current_is_above_screen(void)
|
||||
return (openfile->current->lineno < openfile->edittop->lineno);
|
||||
}
|
||||
|
||||
/* Return TRUE if current[current_x] is below the bottom of the screen, and
|
||||
* FALSE otherwise. */
|
||||
/* Return TRUE if current[current_x] is beyond the viewport. */
|
||||
bool current_is_below_screen(void)
|
||||
{
|
||||
#ifndef NANO_TINY
|
||||
@@ -3293,16 +3314,14 @@ bool current_is_below_screen(void)
|
||||
return (go_forward_chunks(editwinrows - 1, &line, &leftedge) == 0 &&
|
||||
(line->lineno < openfile->current->lineno ||
|
||||
(line->lineno == openfile->current->lineno &&
|
||||
leftedge < leftedge_for(xplustabs(),
|
||||
openfile->current))));
|
||||
leftedge < leftedge_for(xplustabs(), openfile->current))));
|
||||
} else
|
||||
#endif
|
||||
return (openfile->current->lineno >=
|
||||
openfile->edittop->lineno + editwinrows);
|
||||
}
|
||||
|
||||
/* Return TRUE if current[current_x] is offscreen relative to edittop, and
|
||||
* FALSE otherwise. */
|
||||
/* Return TRUE if current[current_x] is outside the viewport. */
|
||||
bool current_is_offscreen(void)
|
||||
{
|
||||
return (current_is_above_screen() || current_is_below_screen());
|
||||
@@ -3478,9 +3497,11 @@ void report_cursor_position(void)
|
||||
charpct = (openfile->totsize == 0) ? 0 : 100 * sum / openfile->totsize;
|
||||
|
||||
statusline(INFO,
|
||||
_("line %zd/%zd (%d%%), col %zu/%zu (%d%%), char %zu/%zu (%d%%)"),
|
||||
_("line %*zd/%zd (%2d%%), col %2zu/%2zu (%3d%%), char %*zu/%zu (%2d%%)"),
|
||||
digits(openfile->filebot->lineno),
|
||||
openfile->current->lineno, openfile->filebot->lineno, linepct,
|
||||
column, fullwidth, colpct, sum, openfile->totsize, charpct);
|
||||
column, fullwidth, colpct,
|
||||
digits(openfile->totsize), sum, openfile->totsize, charpct);
|
||||
}
|
||||
|
||||
/* Highlight the text between the given two columns on the current line. */
|
||||
|
||||
@@ -8,8 +8,8 @@ color red "\<[A-Z_]{2,}\>"
|
||||
color brightgreen "\.(data|subsection|text)"
|
||||
color green "\.(align|file|globl|global|hidden|section|size|type|weak)"
|
||||
color brightyellow "\.(ascii|asciz|byte|double|float|hword|int|long|short|single|struct|word)"
|
||||
color brightred "^[[:space:]]*[.0-9A-Za-z_]*:"
|
||||
color brightcyan "^[[:space:]]*#[[:space:]]*(define|undef|include|ifn?def|endif|elif|else|if|warning|error)"
|
||||
color brightred "^[[:blank:]]*[.0-9A-Za-z_]*:"
|
||||
color brightcyan "^[[:blank:]]*#[[:blank:]]*(define|undef|include|ifn?def|endif|elif|else|if|warning|error)"
|
||||
|
||||
# Strings.
|
||||
color brightyellow "<[^= ]*>" ""(\\.|[^"])*""
|
||||
|
||||
@@ -23,7 +23,7 @@ color red ""[^"]*"" "'[^']*'"
|
||||
color green "`[^`]*`"
|
||||
|
||||
# Error lines:
|
||||
color brightred "^[[:space:]]*\*\*\*.*"
|
||||
color brightred "^[[:blank:]]*\*\*\*.*"
|
||||
|
||||
# Brackets:
|
||||
color magenta "\[|\]|\(|\)"
|
||||
|
||||
@@ -31,7 +31,7 @@ color magenta "\<(bindtextdomain|dcgettext|dcngettext)\>"
|
||||
# Strings.
|
||||
color brightyellow "<[^= ]*>" ""(\\.|[^"])*""
|
||||
# Comments.
|
||||
color brightblue "(^|[[:space:]])#.*$"
|
||||
color brightblue "(^|[[:blank:]])#.*$"
|
||||
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
## Syntax highlighting for C and C++ files.
|
||||
|
||||
syntax c "\.([ch](pp|xx)?|C|cc|c\+\+|cu|H|hh|ii?)$"
|
||||
header "-\*-.*\<C(\+\+)?((;|\s).*)?-\*-"
|
||||
header "-\*-.*\<C(\+\+)?((;|[[:blank:]]).*)?-\*-"
|
||||
magic "^(C|C\+\+) (source|program)"
|
||||
comment "//"
|
||||
|
||||
# Constants.
|
||||
color brightred "\<[A-Z_][0-9A-Z_]*\>"
|
||||
# Labels.
|
||||
color brightmagenta "^[[:space:]]*[A-Z_a-z]+:[[:space:]]*$"
|
||||
color brightmagenta "^[[:blank:]]*[A-Z_a-z][0-9A-Z_a-z]*:[[:blank:]]*$"
|
||||
color normal ":[[:blank:]]*$"
|
||||
|
||||
# Types and related keywords.
|
||||
color green "\<(auto|bool|char|const|double|enum|extern|float|inline|int|long|restrict|short|signed|sizeof|static|struct|typedef|union|unsigned|void)\>"
|
||||
@@ -25,15 +26,15 @@ color magenta "\<(break|continue|goto|return)\>"
|
||||
color brightmagenta "'([^'\]|\\(["'\abfnrtv]|x[0-9A-Fa-f]{1,2}|[0-3]?[0-7]{1,2}))'"
|
||||
|
||||
# GCC builtins.
|
||||
color cyan "__attribute__[[:space:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
|
||||
color cyan "__attribute__[[:blank:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
|
||||
|
||||
# Strings. (In general you will want your strings and comments to come last,
|
||||
# because highlighting rules are applied in the order they are read in.)
|
||||
color brightyellow ""([^"]|\\")*"" "#[[:space:]]*include[[:space:]]+<[^[:blank:]=]*>"
|
||||
color brightyellow ""([^"]|\\")*"" "#[[:blank:]]*include[[:blank:]]*<[^>]+>"
|
||||
|
||||
# Preprocessor directives.
|
||||
color brightcyan start="^[[:space:]]*#[[:space:]]*(if(n?def)?|elif|warning|error|pragma)\>" end="(\`|[^\\])$"
|
||||
color brightcyan "^[[:space:]]*#[[:space:]]*((define|else|endif|include(_next)?|line|undef)\>|$)"
|
||||
color brightcyan start="^[[:blank:]]*#[[:blank:]]*(if(n?def)?|elif|warning|error|pragma)\>" end="(\`|[^\\])$"
|
||||
color brightcyan "^[[:blank:]]*#[[:blank:]]*((define|else|endif|include(_next)?|line|undef)\>|$)"
|
||||
|
||||
# Comments.
|
||||
color brightblue "//.*"
|
||||
|
||||
@@ -13,7 +13,7 @@ color red "^(19|20)[0-9-]{8}"
|
||||
color yellow "<[^>]*@[^>]*>"
|
||||
|
||||
# Command-line options.
|
||||
color cyan "[[:space:]]-[a-zA-Z\$]" "--[8a-z-]+"
|
||||
color cyan "[[:blank:]]-[a-zA-Z\$]" "--[8a-z-]+"
|
||||
# Bug and patch numbers.
|
||||
color cyan "(BZ|bug|patch)[ ]#[0-9]+" "PR [[:alnum:]]+/[0-9]+"
|
||||
# Probable constants, for variety.
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
syntax cmake "(CMakeLists\.txt|\.cmake)$"
|
||||
comment "#"
|
||||
|
||||
color green "^[[:space:]]*[0-9A-Za-z_]+"
|
||||
icolor brightyellow "^[[:space:]]*(include|include_directories|include_external_msproject)\>"
|
||||
color green "^[[:blank:]]*[0-9A-Za-z_]+"
|
||||
icolor brightyellow "^[[:blank:]]*(include|include_directories|include_external_msproject)\>"
|
||||
|
||||
icolor brightgreen "^[[:space:]]*((else|end)?if|else|(end)?while|(end)?foreach|break)\>"
|
||||
color brightgreen "\<(NOT|COMMAND|POLICY|TARGET|EXISTS|IS_(DIRECTORY|ABSOLUTE)|DEFINED)[[:space:]]"
|
||||
color brightgreen "[[:space:]](OR|AND|IS_NEWER_THAN|MATCHES|(STR|VERSION_)?(LESS|GREATER|EQUAL))[[:space:]]"
|
||||
icolor brightgreen "^[[:blank:]]*((else|end)?if|else|(end)?while|(end)?foreach|break)\>"
|
||||
color brightgreen "\<(NOT|COMMAND|POLICY|TARGET|EXISTS|IS_(DIRECTORY|ABSOLUTE)|DEFINED)[[:blank:]]"
|
||||
color brightgreen "[[:blank:]](OR|AND|IS_NEWER_THAN|MATCHES|(STR|VERSION_)?(LESS|GREATER|EQUAL))[[:blank:]]"
|
||||
|
||||
icolor brightred "^[[:space:]]*((end)?(function|macro)|return)"
|
||||
icolor brightred "^[[:blank:]]*((end)?(function|macro)|return)"
|
||||
|
||||
icolor cyan start="\$(ENV)?\{" end="\}"
|
||||
color magenta "\<(APPLE|UNIX|WIN32|CYGWIN|BORLAND|MINGW|MSVC(_IDE|60|71|80|90)?)\>"
|
||||
|
||||
color brightblue "(^|[[:space:]])#.*"
|
||||
color brightblue "(^|[[:blank:]])#.*"
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
@@ -5,7 +5,7 @@ syntax default
|
||||
comment "#"
|
||||
|
||||
# Comments.
|
||||
color cyan "^[[:space:]]*#.*"
|
||||
color cyan "^[[:blank:]]*#.*"
|
||||
|
||||
# Spaces in front of tabs.
|
||||
color ,red " + +"
|
||||
|
||||
@@ -30,4 +30,4 @@ color blue ":(\w|[?-])+"
|
||||
color yellow start="^[[:blank:]]+"" end="[^\]""
|
||||
color yellow ""(\\.|[^"])*""
|
||||
# Comments
|
||||
color cyan "(^|[[:space:]]);.*"
|
||||
color cyan "(^|[[:blank:]]);.*"
|
||||
|
||||
@@ -11,7 +11,7 @@ formatter gofmt -w
|
||||
# Types.
|
||||
color green "\<(bool|u?int(8|16|32|64)?|float(32|64)|complex(64|128)|byte|rune|uintptr|string|error)\>"
|
||||
color green "\<(chan|const|func|interface|map|struct|type|var)\>"
|
||||
color green "<-[[:space:]]*chan\>|\<chan[[:space:]]*<-"
|
||||
color green "<-[[:blank:]]*chan\>|\<chan[[:blank:]]*<-"
|
||||
|
||||
# Predefined functions.
|
||||
color blue "\<(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\>"
|
||||
@@ -36,14 +36,14 @@ color red "\<[0-9]+i\>"
|
||||
color red "\<(true|false|nil|iota|_)\>"
|
||||
color red "'(\\.|[^'])+'"
|
||||
color red ""(\\.|[^"])*""
|
||||
color red start=""(\\.|[^"])*\\[[:space:]]*$" end="^(\\.|[^"])*""
|
||||
color red start=""(\\.|[^"])*\\[[:blank:]]*$" end="^(\\.|[^"])*""
|
||||
|
||||
# Comments.
|
||||
color brightblue "//.*"
|
||||
color brightblue start="/\*" end="\*/"
|
||||
|
||||
# Special comments.
|
||||
color brightcyan "//[[:space:]]*\+build[[:space:]]+(([a-zA-Z_0-9]+[[:space:]]*)+,[[:space:]]*)*[a-zA-Z_0-9]+"
|
||||
color brightcyan "//[[:blank:]]*\+build[[:blank:]]+(([a-zA-Z_0-9]+[[:blank:]]*)+,[[:blank:]]*)*[a-zA-Z_0-9]+"
|
||||
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
@@ -13,7 +13,7 @@ color brightmagenta "\\f(.|\(..)" "\\s(\+|\-)?[0-9]"
|
||||
color cyan "\\(\\)?n(.|\(..)"
|
||||
color cyan start="\\(\\)?n\[" end="]"
|
||||
# Requests
|
||||
color brightgreen "^\.[[:space:]]*[^[:space:]]*"
|
||||
color brightgreen "^\.[[:blank:]]*[^[:space:]]*"
|
||||
# Comments
|
||||
color yellow "^\.\\".*"
|
||||
# Strings
|
||||
|
||||
@@ -21,4 +21,4 @@ color blue "#?:(\w|[?-])+"
|
||||
color yellow start="^[[:blank:]]+"" end="[^\]""
|
||||
color yellow ""(\\.|[^"])*""
|
||||
# Comments
|
||||
color cyan "(^|[[:space:]]);.*"
|
||||
color cyan "(^|[[:blank:]]);.*"
|
||||
|
||||
@@ -19,7 +19,7 @@ color cyan "\<(true|false|null|undefined)\>"
|
||||
# Strings.
|
||||
color brightmagenta ""(\\.|[^"])*"" "'(\\.|[^'])*'" "`(\\.|[^`])*`"
|
||||
# Comments.
|
||||
color brightblue "(^|[[:space:]])//.*"
|
||||
color brightblue "(^|[[:blank:]])//.*"
|
||||
color brightblue start="/\*" end="\*/"
|
||||
|
||||
# Trailing whitespace.
|
||||
|
||||
@@ -8,18 +8,18 @@ syntax json "\.json$"
|
||||
comment ""
|
||||
|
||||
# Numbers (used as value).
|
||||
color green ":[[:space:]]*\-?(0|[1-9][0-9]*)(\.[0-9]+)?([Ee]?[-+]?[0-9]+)?"
|
||||
color green ":[[:blank:]]*\-?(0|[1-9][0-9]*)(\.[0-9]+)?([Ee]?[-+]?[0-9]+)?"
|
||||
# Values (well, any string).
|
||||
color brightmagenta "".+""
|
||||
# Hex numbers (used as value).
|
||||
color green ":[[:space:]]*"#[0-9abcdefABCDEF]+""
|
||||
color green ":[[:blank:]]*"#[0-9abcdefABCDEF]+""
|
||||
# Escapes.
|
||||
color green "\\\\" "\\"" "\\[bfnrt]" "\\u[0-9abcdefABCDEF]{4})"
|
||||
# Special words.
|
||||
color green "\<(true|false|null)\>"
|
||||
|
||||
# Names (very unlikely to contain a quote).
|
||||
color brightblue ""[^"]+"[[:space:]]*:"
|
||||
color brightblue ""[^"]+"[[:blank:]]*:"
|
||||
|
||||
# Brackets, braces, and separators.
|
||||
color brightblue "\[" "\]"
|
||||
@@ -27,7 +27,7 @@ color brightred "\{" "\}"
|
||||
color brightred "," ":"
|
||||
|
||||
# Comments.
|
||||
color cyan "(^|[[:space:]]+)(//|#).*"
|
||||
color cyan "(^|[[:blank:]]+)(//|#).*"
|
||||
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
@@ -20,7 +20,7 @@ color normal "\.\.\."
|
||||
color brightblue "\<(do|end|while|repeat|until|if|elseif|then|else|for|in|function|local|return|break)\>"
|
||||
|
||||
# Keywords
|
||||
color brightyellow "\<(_G|_VERSION|assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|load|loadfile|module|next|pairs|pcall|print|rawequal|rawget|rawlen|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall)\s*\("
|
||||
color brightyellow "\<(_G|_VERSION|assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|load|loadfile|module|next|pairs|pcall|print|rawequal|rawget|rawlen|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall)[[:blank:]]*\("
|
||||
|
||||
# Standard library
|
||||
color brightyellow "\<coroutine\.(create|isyieldable|resume|running|status|wrap|yield)\>"
|
||||
|
||||
@@ -18,7 +18,7 @@ color blue "\$+[{(][a-zA-Z0-9_-]+[})]"
|
||||
color brightblue "^[^ ]+:"
|
||||
|
||||
# Comments.
|
||||
color green "(^|[[:space:]]+)#.*"
|
||||
color green "(^|[[:blank:]]+)#.*"
|
||||
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
@@ -7,26 +7,26 @@ comment "#"
|
||||
color brightred ".*"
|
||||
|
||||
# Keywords
|
||||
color brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|boldtext|bookstyle|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|historylog|indicator|jumpyscrolling|linenumbers|locking|magic|minibar|mouse|multibuffer|noconvert|nohelp|nonewlines|positionlog|preserve|quickblank|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|softwrap|stateflags|suspendable|tabstospaces|trimblanks|unix|wordbounds|zap)\>"
|
||||
color yellow "^[[:space:]]*set[[:space:]]+((error|function|key|number|prompt|scroller|selected|spotlight|status|stripe|title)color)[[:space:]]+(bold,)?(italic,)?(bright|light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte)?(,(light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte))?\>"
|
||||
color brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|promptcolor|punct|quotestr|scrollercolor|selectedcolor|speller|spotlightcolor|statuscolor|stripecolor|titlecolor|whitespace|wordchars)[[:space:]]+"
|
||||
color brightgreen "^[[:space:]]*set[[:space:]]+(fill[[:space:]]+-?[[:digit:]]+|(guidestripe|tabsize)[[:space:]]+[1-9][0-9]*)\>"
|
||||
color brightgreen "^[[:space:]]*bind[[:space:]]+((\^([A-Za-z]|[]/@\^_`]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:space:]]+([a-z]+|".*")[[:space:]]+(main|help|search|replace(with)?|yesno|gotoline|writeout|insert|browser|whereisfile|gotodir|execute|spell|linter|all)([[:space:]]+#|[[:space:]]*$)"
|
||||
color brightgreen "^[[:space:]]*unbind[[:space:]]+((\^([A-Za-z]|[]/@\^_`]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:space:]]+(all|main|search|replace(with)?|yesno|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)"
|
||||
color brightgreen "^[[:space:]]*extendsyntax[[:space:]]+[[:alpha:]]+[[:space:]]+(i?color|header|magic|comment|formatter|linter|tabgives)[[:space:]]+.*"
|
||||
color brightgreen "^[[:space:]]*(syntax[[:space:]]+[^[:blank:]]+|(formatter|linter)[[:space:]]+.+)"
|
||||
color green "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment|formatter|linter|tabgives|extendsyntax)\>"
|
||||
color brightgreen "^[[:blank:]]*(set|unset)[[:blank:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|boldtext|bookstyle|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|historylog|indicator|jumpyscrolling|linenumbers|locking|magic|minibar|mouse|multibuffer|noconvert|nohelp|nonewlines|positionlog|preserve|quickblank|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|softwrap|stateflags|suspendable|tabstospaces|trimblanks|unix|wordbounds|zap)\>"
|
||||
color yellow "^[[:blank:]]*set[[:blank:]]+((error|function|key|number|prompt|scroller|selected|spotlight|status|stripe|title)color)[[:blank:]]+(bold,)?(italic,)?(bright|light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte)?(,(light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte))?\>"
|
||||
color brightgreen "^[[:blank:]]*set[[:blank:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|promptcolor|punct|quotestr|scrollercolor|selectedcolor|speller|spotlightcolor|statuscolor|stripecolor|titlecolor|whitespace|wordchars)[[:blank:]]+"
|
||||
color brightgreen "^[[:blank:]]*set[[:blank:]]+(fill[[:blank:]]+-?[[:digit:]]+|(guidestripe|tabsize)[[:blank:]]+[1-9][0-9]*)\>"
|
||||
color brightgreen "^[[:blank:]]*bind[[:blank:]]+((\^([A-Za-z]|[]/@\^_`]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:blank:]]+([a-z]+|".*")[[:blank:]]+(main|help|search|replace(with)?|yesno|gotoline|writeout|insert|browser|whereisfile|gotodir|execute|spell|linter|all)([[:blank:]]+#|[[:blank:]]*$)"
|
||||
color brightgreen "^[[:blank:]]*unbind[[:blank:]]+((\^([A-Za-z]|[]/@\^_`]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:blank:]]+(all|main|search|replace(with)?|yesno|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:blank:]]+#|[[:blank:]]*$)"
|
||||
color brightgreen "^[[:blank:]]*extendsyntax[[:blank:]]+[[:alpha:]]+[[:blank:]]+(i?color|header|magic|comment|formatter|linter|tabgives)[[:blank:]]+.*"
|
||||
color brightgreen "^[[:blank:]]*(syntax[[:blank:]]+[^[:space:]]+|(formatter|linter)[[:blank:]]+.+)"
|
||||
color green "^[[:blank:]]*((un)?(bind|set)|include|syntax|header|magic|comment|formatter|linter|tabgives|extendsyntax)\>"
|
||||
|
||||
# Strings
|
||||
color brightmagenta "([[:space:]]|(start|end)=)".+"([[:space:]]|$)"
|
||||
color brightmagenta "([[:blank:]]|(start|end)=)".+"([[:blank:]]|$)"
|
||||
|
||||
# Colors
|
||||
color yellow "^[[:space:]]*i?color[[:space:]]*(bold,)?(italic,)?(bright|light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte)?(,(light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte))?\>"
|
||||
color magenta "^[[:space:]]*i?color\>" "\<(start|end)="
|
||||
color yellow "^[[:blank:]]*i?color[[:blank:]]*(bold,)?(italic,)?(bright|light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte)?(,(light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte))?\>"
|
||||
color magenta "^[[:blank:]]*i?color\>" "\<(start|end)="
|
||||
|
||||
# Comments
|
||||
color brightblue "(^|[[:space:]]+)#.*"
|
||||
color cyan "^[[:space:]]*##.*"
|
||||
color brightblue "(^|[[:blank:]]+)#.*"
|
||||
color cyan "^[[:blank:]]*##.*"
|
||||
|
||||
# Trailing whitespace
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
@@ -20,7 +20,7 @@ color red "\<(drop|reject)\>"
|
||||
color brightblue "\<(accept|continue|(d|s)nat|goto|jump|masquerade|return)\>"
|
||||
|
||||
# Comments
|
||||
color cyan "(^|[[:space:]])#.*"
|
||||
color cyan "(^|[[:blank:]])#.*"
|
||||
|
||||
# Trailing whitespace
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
@@ -15,13 +15,13 @@ color brightgreen "\<(goto|continue|break|return)\>"
|
||||
color brightgreen "@(encode|end|implementation|interface)|selector)\>"
|
||||
|
||||
# GCC builtins.
|
||||
color cyan "__attribute__[[:space:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
|
||||
color cyan "__attribute__[[:blank:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
|
||||
|
||||
# Selector/method.
|
||||
color brightmagenta "(^|[[:space:]])\[.*[[:space:]].*\]"
|
||||
color brightmagenta "(^|[[:blank:]])\[.*[[:blank:]].*\]"
|
||||
color white ":[[:alnum:]]*"
|
||||
color magenta "[[:alnum:]]*:"
|
||||
color white "\[[^][:space:]]*\]"
|
||||
color white "\[[^][:blank:]]*\]"
|
||||
|
||||
# Strings.
|
||||
color brightblack "'([^'\]|(\\["'abfnrtv\\]))'" "'\\(([0-3]?[0-7]{1,2}))'" "'\\x[0-9A-Fa-f]{1,2}'"
|
||||
@@ -29,7 +29,7 @@ color brightblack "<[^= ]*>" ""(\\.|[^"])*""
|
||||
color brightblue "@"(\\.|[^"])*""
|
||||
|
||||
# Preprocessor commands.
|
||||
color brightblue "^[[:space:]]*#[[:space:]]*(define|include|import|(un|ifn?)def|endif|el(if|se)|if|warning|error)"
|
||||
color brightblue "^[[:blank:]]*#[[:blank:]]*(define|include|import|(un|ifn?)def|endif|el(if|se)|if|warning|error)"
|
||||
|
||||
# Comments.
|
||||
color yellow "//.*"
|
||||
|
||||
@@ -12,13 +12,13 @@ color magenta "\<(continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne
|
||||
color cyan "[$%&@]([A-Za-z_][0-9A-Za-z_]*|\^[][A-Z?\^_]|[0-9]+)\>"
|
||||
color cyan "[$%&@]\{(\^?[A-Za-z_][0-9A-Za-z_]*|\^[][?\^][0-9]+)\}"
|
||||
color cyan "[$%&@]([][!"#'()*+,.:;<=>?`|~-]|\{[][!-/:-@\`|~]\})|\$[$%&@]"
|
||||
color cyan "(^|[[:space:]])[$%@][/\]"
|
||||
color cyan "(^|[[:blank:]])[$%@][/\]"
|
||||
|
||||
color yellow "".*"|qq\|.*\|"
|
||||
color white "[sm]/.*/"
|
||||
color white start="(^use| = new)" end=";"
|
||||
|
||||
# Comments.
|
||||
color green "(^|[[:space:]])#.*"
|
||||
color green "(^|[[:blank:]])#.*"
|
||||
|
||||
color yellow start="<< 'STOP'" end="STOP"
|
||||
|
||||
@@ -28,7 +28,7 @@ color magenta "\<(break|continue|goto|return)\>"
|
||||
color brightyellow ""(\.|[^"])*"" "'(\.|[^'])*'"
|
||||
|
||||
# Comments.
|
||||
color brightblue "(^|[[:space:]]+)//.*"
|
||||
color brightblue "(^|[[:blank:]]+)//.*"
|
||||
color brightblue start="/\*" end="\*/"
|
||||
|
||||
# Trailing whitespace.
|
||||
|
||||
@@ -22,7 +22,7 @@ color brightblue "^(msgid|msgid_plural|msgstr)\>"
|
||||
color red " fuzzy(,|$)"
|
||||
color yellow " (no-)?[-[:alpha:]]+-format(,|$)"
|
||||
# Format specifiers.
|
||||
color brightmagenta "%([1-9]\$)?[a-z]*"
|
||||
color brightmagenta "%([1-9]\$)?[#0 +'I-]?(\*([1-9]\$)?|[1-9](\.[0-9]?)?)?[hlLjzt]?[diouxXeEfFgGaAcspnm%]"
|
||||
# Quotes and escaped characters.
|
||||
color yellow """
|
||||
color cyan "\\([abcefnrtv"\]|x[0-9abcdefABCDEF]{2}|[0-7]{3})"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## Syntax highlighting for Bourne shell scripts.
|
||||
|
||||
syntax sh "(\.sh|(\.|/)(a|ba|c|da|k|mk|pdk|tc|z)sh(rc|_profile)?|/(etc/|\.)profile)$"
|
||||
header "^#!.*/((env\s+)?((a|ba|c|da|k|mk|pdk|tc|z)?sh)|busybox\s+sh|openrc-run|runscript)\>"
|
||||
header "^#!.*/((env[[:blank:]]+)?((a|ba|c|da|k|mk|pdk|tc|z)?sh)|busybox[[:blank:]]+sh|openrc-run|runscript)\>"
|
||||
header "-\*-.*shell-script.*-\*-"
|
||||
magic "(POSIX|Bourne-Again) shell script.*text"
|
||||
comment "#"
|
||||
@@ -27,10 +27,10 @@ color normal "[.-]tar\>"
|
||||
# Basic variable names (no braces).
|
||||
color brightred "\$[-0-9@*#?$!]" "\$[[:alpha:]_][[:alnum:]_]*"
|
||||
# More complicated variable names; handles braces and replacements and arrays.
|
||||
color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"
|
||||
color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:blank:]]*[[:alnum:]_]+[[:blank:]]*|@)\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"
|
||||
|
||||
# Comments.
|
||||
color cyan "(^|[[:space:]])#.*"
|
||||
color cyan "(^|[[:blank:]])#.*"
|
||||
|
||||
# Strings.
|
||||
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
## Syntax highlighting for Tcl files.
|
||||
## Syntax highlighting for Tcl and Expect scripts.
|
||||
|
||||
syntax tcl "\.tcl$"
|
||||
syntax tcl "\.(tcl|exp)$"
|
||||
magic "Tcl(/Tk)? script"
|
||||
comment "#"
|
||||
|
||||
# Standard Tcl [info commands]:
|
||||
color green "\<(after|append|array|auto_execok|auto_import|auto_load|auto_load_index|auto_qualify|binary|break|case|catch|cd|clock|close|concat|continue|encoding|eof|error|eval|exec|exit|expr|fblocked|fconfigure|fcopy|file|fileevent|flush|for|foreach|format|gets|glob|global|history|if|incr|info|interp|join|lappend|lindex|linsert|list|llength|load|lrange|lreplace|lsearch|lset|lsort|namespace|open|package|pid|puts|pwd|read|regexp|regsub|rename|return|scan|seek|set|socket|source|split|string|subst|switch|tclLog|tell|time|trace|unknown|unset|update|uplevel|upvar|variable|vwait|while)\>"
|
||||
|
||||
# Basic Tcl subcommands:
|
||||
color green "\<array (anymore|donesearch|exists|get|names|nextelement|set|size|startsearch|statistics|unset)\>"
|
||||
color green "\<string (bytelength|compare|equal|first|index|is|last|length|map|match|range|repeat|replace|to|tolower|totitle|toupper|trim|trimleft|trimright|will|wordend|wordstart)\>"
|
||||
|
||||
# Extended TclX [info commands]:
|
||||
color green "\<(alarm|auto_load_pkg|bsearch|catclose|catgets|catopen|ccollate|cconcat|cequal|chgrp|chmod|chown|chroot|cindex|clength|cmdtrace|commandloop|crange|csubstr|ctoken|ctype|dup|echo|execl|fcntl|flock|fork|fstat|ftruncate|funlock|host_info|id|infox|keyldel|keylget|keylkeys|keylset|kill|lassign|lcontain|lempty|lgets|link|lmatch|loadlibindex|loop|lvarcat|lvarpop|lvarpush|max|min|nice|pipe|profile|random|readdir|replicate|scancontext|scanfile|scanmatch|select|server_accept|server_create|signal|sleep|sync|system|tclx_findinit|tclx_fork|tclx_load_tndxs|tclx_sleep|tclx_system|tclx_wait|times|translit|try_eval|umask|wait)\>"
|
||||
|
||||
# Syntax:
|
||||
color brightblue "\<proc[[:space:]]|\{|\}"
|
||||
color brightblue "\<proc[[:blank:]]|\{|\}"
|
||||
color green "\(|\)|\;|`|\\|\$|<|>|!|=|&|\|"
|
||||
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
|
||||
color brightred "\$\{?[0-9A-Za-z_!@#$*?-]+\}?"
|
||||
|
||||
# Trailing whitespace:
|
||||
color ,green "[[:space:]]+$"
|
||||
|
||||
# Comments:
|
||||
color cyan "^[[:space:]]*#.*"
|
||||
color cyan "^[[:blank:]]*#.*"
|
||||
|
||||
Reference in New Issue
Block a user