Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1658d4d14f | ||
|
|
5cf95c45d3 | ||
|
|
56a295bc90 | ||
|
|
803379c52c | ||
|
|
4522ca2d1b | ||
|
|
fd265af15a | ||
|
|
58a802fa63 | ||
|
|
364763f4d1 | ||
|
|
ecc245ccca | ||
|
|
61f5c55f7b | ||
|
|
30f278f4a8 | ||
|
|
75dfa8ad42 | ||
|
|
b0f0b7f471 | ||
|
|
25d459aa64 | ||
|
|
2d90cf324e | ||
|
|
2d1bdd0dd6 | ||
|
|
2823c99e72 | ||
|
|
019998a877 | ||
|
|
d47d8cd450 | ||
|
|
0dc26dcd09 | ||
|
|
a117163a4c | ||
|
|
4630102f5b | ||
|
|
2f2f4d3ca9 | ||
|
|
2d189ae46d | ||
|
|
95add8dabe | ||
|
|
973addcde8 | ||
|
|
4e12cb8455 | ||
|
|
2a044ee3ea | ||
|
|
c81cf52cf2 | ||
|
|
c84e765b8e | ||
|
|
5c1c143ed2 | ||
|
|
3c4e99137d | ||
|
|
8f0a921fc1 | ||
|
|
513157dfa0 | ||
|
|
fa195e6d5d | ||
|
|
215eb3645e | ||
|
|
83c3f951f6 | ||
|
|
025548ad29 | ||
|
|
8227d419bb | ||
|
|
f30c1390c7 | ||
|
|
b549f3761a | ||
|
|
e137f12e5e | ||
|
|
86cab67339 | ||
|
|
566635ec16 | ||
|
|
95a9de0d3f | ||
|
|
1d77823f79 | ||
|
|
874969be81 | ||
|
|
6b83e5290c | ||
|
|
faeeb5bd7e | ||
|
|
dc7136a082 | ||
|
|
77bf1b5197 | ||
|
|
90ad8e20b9 | ||
|
|
2cc58882f6 | ||
|
|
93f2ea1194 | ||
|
|
d2780eca94 | ||
|
|
80ea9c5de9 | ||
|
|
b08b38680d | ||
|
|
5c27d723c9 | ||
|
|
447f1b4b75 | ||
|
|
6f681c1be2 | ||
|
|
a50d0e35f7 | ||
|
|
599c559b3c | ||
|
|
ea577874ef | ||
|
|
14c8620e0b | ||
|
|
3c1131a5b3 | ||
|
|
015c74093a | ||
|
|
d31ddb789f | ||
|
|
8f76112084 | ||
|
|
1f37c4514d | ||
|
|
91a1862eed | ||
|
|
e418b694b6 | ||
|
|
12dc8cae80 | ||
|
|
0b499d465b | ||
|
|
fa406949ec | ||
|
|
70859f4a5b | ||
|
|
9fb13fb8f0 | ||
|
|
274142cb10 | ||
|
|
b8576780bf | ||
|
|
a9dea9859d | ||
|
|
a855fa2acc | ||
|
|
09b8124859 | ||
|
|
07fcc4c973 | ||
|
|
1347f22c95 | ||
|
|
9015f187a5 |
4
BUGS
4
BUGS
@@ -1,6 +1,5 @@
|
||||
** Open BUGS **
|
||||
- Cutting the line at the top of the screen recenters to center (71)
|
||||
- Many menu items are probably missing from the new backend (73)
|
||||
|
||||
** Fixed BUGS **
|
||||
- Marked cutting sometimes leaves a newline in the file unintelligently,
|
||||
@@ -143,6 +142,7 @@
|
||||
- Trying to insert a file of 0 bytes will hang nano (70) [FIXED].
|
||||
- Meta-space and ^Space are not yet handled in new backend code (77) [FIXED]
|
||||
- F-keys do not work with new shortcut backend (72) [FIXED]
|
||||
- Many menu items are probably missing from the new backend (73) [FIXED]
|
||||
- Need a 'check-vitals-mapped' function to check that the end used didn't
|
||||
unbind all the keys for exit or cancel before starting up the editor (74) [FIXED]
|
||||
- Browser and prompt code still implement old switch on raw key input instead
|
||||
@@ -154,6 +154,8 @@
|
||||
page up/down, insert, and unbinds all other control and F keys for it,
|
||||
nano will do the wrong thing when reading the key which is normally
|
||||
assigned to it (79 - may not be worth fixing) [FIXED]
|
||||
- Segfault editing at COLS presumably due to new color syntax
|
||||
highlighting (80) [FIXED]
|
||||
|
||||
|
||||
$Id$
|
||||
|
||||
161
ChangeLog
161
ChangeLog
@@ -1,3 +1,164 @@
|
||||
GNU nano 2.1.8 - 2009.02.07
|
||||
2009-02-06 Chris Allegretta <chrisa@asty.org>
|
||||
* rcfile.c (parse_include): Abort on being unable to open an included rcfile. Fixes
|
||||
Savannah bug 25490, nanorc: "include"ing a file which doesn't exist causes nano to segfault.
|
||||
|
||||
2009-02-05 Chris Allegretta <chrisa@asty.org>
|
||||
* More color syntax speedups: Determine in reset_multis() whether we really need to call
|
||||
edit_refresh(). Additional global var edit_refresh_needed() to hopefully reduce
|
||||
repeated calls to the function. New helper funcs reset_multis_before() and
|
||||
reset_multis_after().
|
||||
|
||||
2009-02-02 Chris Allegretta <chrisa@asty.org>
|
||||
* New color precalculation code for mult-line regexes. New function precalc_multicolorinfo(),
|
||||
new structure multidata for keeping track of where regexes start/stop. More
|
||||
performance improvements forthcoming.
|
||||
|
||||
2009-01-29 Chris Allegretta <chrisa@asty.org>
|
||||
* nano.c (move_to_filestruct) - properky initialize new fileage for multiswatching, sigh.
|
||||
Fix cut sefaults discovered by Mike Frysinger.
|
||||
|
||||
2009-01-29 Chris Allegretta <chrisa@asty.org>
|
||||
* nano.c (main): Add support for nano acting like a pager when invoked with - as first
|
||||
file argument.
|
||||
|
||||
2009-01-28 Davide Pesavento <davidepesa@gmail.com>
|
||||
* doc/syntax/gentoo.nanorc: Updates from David and Mike Frysinger.
|
||||
|
||||
2009-01-25 Chris Allegretta <chrisa@asty.org>
|
||||
* files.c (open_file), nanorc.c (parse_include): Don't get_full_path on
|
||||
included rc files, due to it potentially impacting the ability
|
||||
to read files in nano's cwd(). Fixes Savnanah bug #25297 reported by Mike
|
||||
Frysinger)
|
||||
|
||||
2009-01-24 Chris Allegretta <chrisa@asty.org>
|
||||
* First pass at some caching of caching color info. Right now it's only for
|
||||
multi-line regexes but this may not be enough to increase performance.
|
||||
* Add interruptability to search functions. New functions enable_nodelay and
|
||||
disable_nodelay and changes to the routines to handle checking for pending
|
||||
searches. Fixes Savnnah bug 24946: Need interrrupt for search.
|
||||
|
||||
2009-01-19 Chris Allegretta <chrisa@asty.org>
|
||||
* Change function definitions to shorts instead of (void *)s. New mapping function
|
||||
iso_me_harder_funcmap(). Fixes compilation complaints with -pedantic,
|
||||
reported by Eitan Adler <eitanadlerlist@gmail.com>.
|
||||
|
||||
GNU nano 2.1.7 - 2008.11.10
|
||||
2008-10-20 Chris Allegretta <chrisa@asty.org>
|
||||
* files.c (do_writeout): Add check for file modification when saving
|
||||
the file so the user can at least know they may be blowing away changes.
|
||||
|
||||
2008-10-14 Chris Allegretta <chrisa@asty.org>
|
||||
* nanorc.5: Fix redo man page entry and update explanation, reported by
|
||||
Eitan Adler <eitanadlerlist@gmail.com>
|
||||
* global.c (shortcut_init), search.c (search_init): Fix add_to_sclist for ^W^T so
|
||||
invalid messages will display properly. Fixes Savannah bug 24507.
|
||||
|
||||
2008-10-13 Chris Allegretta <chrisa@asty.org>
|
||||
* Remove CUTTOEND as an undo type as it's unneeded, fix u->to_end logic in undo struct.
|
||||
* undo.c (update_undo): Don't free cutbuffer if NULL, fix for Savannah bug #24499
|
||||
|
||||
2008-10-04 Chris Allegretta <chrisa@asty.org>
|
||||
* cut.c (Add_undo): Save last cut undo information so it can be used for next uncut, fixes
|
||||
Savannah bug 24183.
|
||||
|
||||
GNU nano 2.1.6 - 2008.10.03
|
||||
2008-10-03 Pascal Gentil <pascal.gentil@univ-rennes1.fr>
|
||||
* fortran.nanorc: Sample python syntax highlighting file
|
||||
|
||||
2008-09-30 Dirkjan Ochtman <dirkjan@ochtman.nl>
|
||||
* python.nanorc: Small python syntax update
|
||||
|
||||
2008-09-30 <bluestorm_dylc@hotmail.com>
|
||||
* ocaml.nanorc: Sample OCaml syntax highlighting file
|
||||
|
||||
2008-09-30 Dave Geering <dgeering@toshiba-tap.com>
|
||||
* objc.nanorc: Sample Objective-C Syntax Hightlighting file
|
||||
|
||||
2008-09-30 Chris Allegretta <chrisa@asty.org>
|
||||
* configure.ac: Change extra, multibuffer, color and rcfile configure options to default to enabled
|
||||
--enable-tiny will now disable these options as well
|
||||
* python.nanorc, ruby.nanorc: Add header lines for python and ruby as well
|
||||
|
||||
2008-09-21 Chris Allegretta <chrisa@asty.org>
|
||||
* rcfile.c, color.c, nano.h: Add new capability for matching a syntax type by the "header" (1st line)
|
||||
of a file being edited. Based on Savannah bug 24197 and inital proof of concept by Dave Geering
|
||||
<dgeering@toshiba-tap.com>
|
||||
|
||||
2008-09-16 Chris Allegretta <chrisa@asty.org>
|
||||
* text.c: Add support for undoing a text uncut. Split out the undo and redo of a text cut
|
||||
in order to avoid code duplication.
|
||||
|
||||
2008-09-06 Chris Allegretta <chrisa@asty.org>
|
||||
* nano.c: Do call disable_signals at startup regardless, since under cygwin we can't generate
|
||||
^C without it.
|
||||
|
||||
GNU nano 2.1.5 - 2008.08.30
|
||||
2008-08-29 Chris Allegretta <chrisa@asty.org>
|
||||
* configure.ac, color.c, rcfile.c, utils.c: 1st attempt at supporting systems which don't support
|
||||
GNU-style word boundaries. New function fixbounds() to translate from GNU-style to
|
||||
BSD-style, autoconf option GNU_WORDBOUNDS.
|
||||
* nano-regress: New perl script to check for some of the more obvious issues with compilation
|
||||
issues with certain configure options.
|
||||
* global.c, help.c, browser.c, files.c, proto.h: Fix several compipation and programmatic
|
||||
issues with --disable-help, especially that do-writeout was treating ^G the same as ^M.
|
||||
|
||||
2008-08-28 Chris Allegretta <chrisa@asty.org>
|
||||
* configure.ac, rcfile.c: Add support for an alternate rcfilename at configure time. Maybe this
|
||||
should become a command line option some day, but I don't see the need currently. Start of
|
||||
fix for Savannah bug #24128: Add nanorc support to win32 platform.
|
||||
|
||||
2008-08-21 Chris Allegretta <chrisa@asty.org>
|
||||
* text.c: Change error messages where we may possibly get into a bad state and urge
|
||||
the user to save when this happens. Originally by Benno Schulenberg <bensberg@justemail.net>
|
||||
* text.c (do_enter): Fix issue when compiled with --enable-debug, fixes Savannah bug 24092.
|
||||
|
||||
2008-08-08 Magnus Granberg <zorry@ume.nu> / Adam Conrad <?>
|
||||
* files.c (write_file): Add needed flags to open() calls when writing out files. Fixes Savannah bug
|
||||
#23827: Compilation fails with -D_FORTIFY_SOURCE=2
|
||||
|
||||
2008-08-08 Chris Allegretta <chrisa@asty.org>
|
||||
* files.c (write_file): Check exit code of fclose(), since in certain out of space conditions the OS will
|
||||
happily report successful fwrite()s until you try and close the file. Fix for Savannah bug
|
||||
#24000: no free space on partition - nano claims successful write - file empty
|
||||
|
||||
GNU nano 2.1.4 - 2008.08.09
|
||||
2008-08-08 Chris Allegretta <chrisa@asty.org>
|
||||
* files.c (write_file): Do not go on and attempt to write the main file if writing the backup file failed,
|
||||
related to Savannah bug 24000.
|
||||
* text.c (do_redo): Fix improperly restoring the text when redoing a line split.
|
||||
* text.c (add_undo): Fix check for multi-line cut check skips adding other new legit events.
|
||||
|
||||
2008-07-23 Chris Allegretta <chrisa@asty.org>
|
||||
* text.c: Reset openfile-> to OTHER after an undo or redo so we don't mistakenly
|
||||
mistakenly think this is an update when it's really an add. Also
|
||||
Fix an extra ; after an if statement which makes nano try to free a struct which
|
||||
may be NULL
|
||||
|
||||
GNU nano 2.1.3 - 2008.08.04
|
||||
2008-07-23 Chris Allegretta <chrisa@asty.org>
|
||||
* configure.ac: Add ncursesw dir to include path if lib detected
|
||||
|
||||
2008-07-11 Mike Frysinger <vapier@gentoo.org>
|
||||
* doc/nanorc.sample.in: Include the updates files in the default sample nanorc.
|
||||
|
||||
2008-07-11 Fabian Groffen <grobian@gentoo.org>
|
||||
* nano.c: Don't include langinfo.h if not using ENABLE_UTF8
|
||||
(Savannah patch 6565)
|
||||
|
||||
2008-07-11 Mitsuya Shibata <mty.shibata@gmail.com>
|
||||
* text.c: Fix crashing in help menu when using certain locales
|
||||
(Savannah bug 23751)
|
||||
|
||||
2008-07-09 Chris Allegretta <chrisa@asty.org>
|
||||
* nano.c/nano.h/global.c/text.c: New generalized undo code, currently
|
||||
just works for adding and deleting text and splitting and unsplitting lines.
|
||||
|
||||
2008-06-29 Chris Allegretta <chrisa@asty.org>
|
||||
* global.c: Fix for not having search history when --disable-justify is used
|
||||
(Savannah bug 23733)
|
||||
|
||||
|
||||
GNU nano 2.1.2 - 2008.06.24
|
||||
2008-06-24 Chris Allegretta <chrisa@asty.org>
|
||||
* rcfile.c: Added function check_bad_binding() to look for sequences which
|
||||
|
||||
85
NEWS
85
NEWS
@@ -1,4 +1,77 @@
|
||||
2008/04/24 - GNU nano 2.1.2 "New York City" is released. This release
|
||||
2009.02.07 - GNU nano 2.1.8 "unsafe at any speed" is released. This
|
||||
release include some long overdue performance
|
||||
improvements in syntax color highlighting, the ability
|
||||
to abort running searches (useful mainly when
|
||||
editing very large files) and the ability to use nano
|
||||
like a pager for viewing standard input (i.e. "nano -").
|
||||
Additionally, there are gentoo syntax highlighting
|
||||
updates and fixes for issues with reading files
|
||||
in a directory with strange parent directory permissions.
|
||||
The key bindings code was also substantially changed
|
||||
in order to be more ISO-C compatible. Be sure to use
|
||||
the Savannah page not only for bug reports but for any
|
||||
features you would like to see before the next stable
|
||||
series is released. Have fun with it!
|
||||
|
||||
|
||||
2008.11.10 - GNU nano 2.1.7 "Effingham" is ready to make good on those
|
||||
campaign promises of lower bug rates and 50% more pie.
|
||||
This release includes a new check for external
|
||||
modifications when saving a file, some code and
|
||||
documentation cleanups, and more bug fixes for
|
||||
the new undo code (but we continue to welcome your bug
|
||||
reports via the Savananh bug page at
|
||||
http://savannah.gnu.org/bugs/?func=additem&group=nano.
|
||||
Come get some.
|
||||
|
||||
2008.10.03 - GNU nano 2.1.6 was for new features before it was against
|
||||
them. This release includes more undo capability,
|
||||
several new syntax highlighting configurations including
|
||||
Objective C, OCaml, and Fortran, and a new capability
|
||||
to activate highlighting based on the 1st line of the
|
||||
file being edited. Also, the new default configure
|
||||
options now include color syntax highlighting, .nanorc
|
||||
support, multibuffer and extras. These items can still
|
||||
be disabled and are not enabled with --enable-tiny. Bug
|
||||
fixes include better signal handling under Cygwin, and
|
||||
that's about it. Again please remember to
|
||||
submit bug reports via Savannah at
|
||||
http://savannah.gnu.org/bugs/?func=additem&group=nano
|
||||
as undo functions certainly need more testing.
|
||||
Bon appetit.
|
||||
|
||||
2008.08.30 - GNU nano 2.1.5 is ready to lead on day one. This release
|
||||
contains a better fix for incorrectly reported successful
|
||||
writes on full filesystems, more helpful messages when
|
||||
an internal error occurs in the undo code, and fixes for
|
||||
various combinations of configure-time options and
|
||||
compiler flags. Also included is new support for
|
||||
changing the rc file name at configure time, and
|
||||
using GNU-style regexes for word-boundaries on systems
|
||||
which do not support them natively, as well as the ever
|
||||
popular translation updates. Rock the tarball.
|
||||
|
||||
2008.08.09 - GNU nano 2.1.4 "I told you so!" is released. This release
|
||||
includes fixes for several severe issues with the new
|
||||
undo/redo code. Also the behavior of writing
|
||||
files when using backup mode has changed as well: if writing
|
||||
the backup file fails, nano will not attempt to write the
|
||||
current file. This should help folks who enjoy "extreme
|
||||
text editing" i.e. editing files on file systems which
|
||||
are likely to run out of space; see Savannah bug 24000.
|
||||
Have fun with it!
|
||||
|
||||
2008.08.04 - GNY nano 2.1.3 "least stable version ever" is released. This
|
||||
release includes new (and experimental) undo and redo
|
||||
functionality for most text operations. The default
|
||||
key bindings are Meta-U for undo and Meta-E for redo, but
|
||||
these can be remapped using the new 2.1 keybinding code.
|
||||
Also included are some fixes for configuring using wide
|
||||
curses, crashing when invoking the help menu with
|
||||
certain locales, and not saving the search history when
|
||||
compiled with configure options.
|
||||
|
||||
2008.04.24 - GNU nano 2.1.2 "New York City" is released. This release
|
||||
contains fixes for binding bad keys, some
|
||||
configure-specific compilation failures, and more issues
|
||||
with the new input back end and in particular the status
|
||||
@@ -6,7 +79,7 @@
|
||||
compiling on AIX, and a segfault when making the terminal
|
||||
window too small. Rest in Peace Tim and George!
|
||||
|
||||
2008/04/01 - GNU nano 2.1.1 wont get fooled again. This release contains
|
||||
2008.04.01 - GNU nano 2.1.1 wont get fooled again. This release contains
|
||||
fixes for the new user-rebindable keys (in particular
|
||||
bracket match which was mis-bound), and various
|
||||
problems with translations and configure-related
|
||||
@@ -18,7 +91,7 @@
|
||||
binding code to the Savannah page
|
||||
(https://savannah.gnu.org/bugs/?group=nano).
|
||||
|
||||
2008/03/18 - GNU nano 2.1.0 "under old mismanagement" is released.
|
||||
2008.03.18 - GNU nano 2.1.0 "under old mismanagement" is released.
|
||||
This first release in the 2.1 development series
|
||||
introduces rebinadble keys for most actions inside
|
||||
the editor. Please see the nanorc(5) page for
|
||||
@@ -28,7 +101,7 @@
|
||||
https://savannah.gnu.org/bugs/?group=nano and
|
||||
thanks for sticking with us!
|
||||
|
||||
2007/12/20 - GNU nano 2.0.7 keeps its balance. This release fixes
|
||||
2007.12.20- GNU nano 2.0.7 keeps its balance. This release fixes
|
||||
several bugs, among others: a segfault and several
|
||||
cursor positioning problems when uncutting text or
|
||||
inserting files into the current buffer; a problem where
|
||||
@@ -50,12 +123,12 @@
|
||||
under the GNU GPL version 3 or later and the GNU FDL
|
||||
version 1.2 or later. Have fun.
|
||||
|
||||
2007/04/26 - GNU nano 2.0.6 "that was quick" is released. This release
|
||||
2007.04.26- GNU nano 2.0.6 "that was quick" is released. This release
|
||||
fixes a potential segfault after justifying text marked
|
||||
from the bottom up. It also adds one more minor
|
||||
documentation update. Enjoy.
|
||||
|
||||
2007/04/22 - GNU nano 2.0.5 braces for impact. Among other things, this
|
||||
2007.04.22- GNU nano 2.0.5 braces for impact. Among other things, this
|
||||
release fixes various problems (including a segfault)
|
||||
when trying to open or save a file in a directory
|
||||
beginning with "~" that isn't a home directory; fixes a
|
||||
|
||||
102
configure.ac
102
configure.ac
@@ -20,7 +20,7 @@
|
||||
#
|
||||
# $Id$
|
||||
|
||||
AC_INIT([GNU nano], [2.1.2], [nano-devel@gnu.org], [nano])
|
||||
AC_INIT([GNU nano], [2.1.8], [nano-devel@gnu.org], [nano])
|
||||
AC_CONFIG_SRCDIR([src/nano.c])
|
||||
AC_CANONICAL_TARGET([])
|
||||
AM_INIT_AUTOMAKE
|
||||
@@ -64,12 +64,6 @@ if test x$debug_support != xyes; then
|
||||
AC_DEFINE(NDEBUG, 1, [Shut up assert warnings :-)])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(extra,
|
||||
[ --enable-extra Enable extra features, currently only easter eggs],
|
||||
[if test x$enableval = xyes; then
|
||||
AC_DEFINE(NANO_EXTRA, 1, [Define this to enable extra stuff.]) extra_support=yes
|
||||
fi])
|
||||
|
||||
AC_ARG_ENABLE(tiny,
|
||||
[ --enable-tiny Disable features for the sake of size],
|
||||
[if test x$enableval = xyes; then
|
||||
@@ -84,6 +78,16 @@ AC_ARG_ENABLE(tiny,
|
||||
AC_DEFINE(DISABLE_WRAPPING, 1, [Define this to disable all text wrapping.])
|
||||
fi])
|
||||
|
||||
|
||||
AC_ARG_ENABLE(extra,
|
||||
[ --disable-extra Disable extra features, currently only easter eggs],
|
||||
[if test x$enableval != xno; then
|
||||
AC_DEFINE(NANO_EXTRA, 1, [Define this to enable extra stuff.]) extra_support=yes
|
||||
fi],
|
||||
[if test x$enable_tiny != xyes; then
|
||||
AC_DEFINE(NANO_EXTRA, 1, [Define this to enable extra stuff.]) extra_support=yes
|
||||
fi])
|
||||
|
||||
AC_ARG_ENABLE(browser,
|
||||
[ --disable-browser Disable built-in file browser],
|
||||
[if test x$enableval != xyes; then
|
||||
@@ -139,8 +143,8 @@ AC_ARG_ENABLE(wrapping-as-root,
|
||||
fi])
|
||||
|
||||
AC_ARG_ENABLE(color,
|
||||
[ --enable-color Enable color and syntax highlighting],
|
||||
[if test x$enableval = xyes; then
|
||||
[ --disable-color Disable color and syntax highlighting],
|
||||
[if test x$enableval != xno; then
|
||||
if test x$ac_cv_header_regex_h = xyes; then
|
||||
AC_DEFINE(ENABLE_NANORC, 1, [Define this to use .nanorc files.]) nanorc_support=yes
|
||||
AC_DEFINE(ENABLE_COLOR, 1, [Define this to have syntax highlighting, requires regex.h and ENABLE_NANORC too!]) color_support=yes
|
||||
@@ -148,32 +152,76 @@ AC_ARG_ENABLE(color,
|
||||
AC_MSG_ERROR([
|
||||
*** The header file regex.h was not found. If you wish to use color
|
||||
*** support this header file is required. Please either install C
|
||||
*** libraries that include the regex.h file or do not call the configure
|
||||
*** script with --enable-color.])
|
||||
*** libraries that include the regex.h file or call the configure
|
||||
*** script with --disable-color.])
|
||||
fi
|
||||
fi])
|
||||
fi], [
|
||||
if test x$enable_tiny != xyes; then
|
||||
if test x$ac_cv_header_regex_h = xyes; then
|
||||
AC_DEFINE(ENABLE_NANORC, 1, [Define this to use .nanorc files.]) nanorc_support=yes
|
||||
AC_DEFINE(ENABLE_COLOR, 1, [Define this to have syntax highlighting, requires regex.h and ENABLE_NANORC too!]) color_support=yes
|
||||
else
|
||||
AC_MSG_ERROR([
|
||||
*** The header file regex.h was not found. If you wish to use color
|
||||
*** support this header file is required. Please either install C
|
||||
*** libraries that include the regex.h file or call the configure
|
||||
*** script with --disable-color.])
|
||||
fi
|
||||
fi
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(multibuffer,
|
||||
[ --enable-multibuffer Enable multiple file buffers],
|
||||
[if test x$enableval = xyes; then
|
||||
[ --disable-multibuffer Disable multiple file buffers],
|
||||
[if test x$enableval != xno; then
|
||||
AC_DEFINE(ENABLE_MULTIBUFFER, 1, [Define this to enable multiple file buffers.]) multibuffer_support=yes
|
||||
fi])
|
||||
fi],
|
||||
[if test x$enable_tiny != xyes; then
|
||||
AC_DEFINE(ENABLE_MULTIBUFFER, 1, [Define this to enable multiple file buffers.]) multibuffer_support=yes
|
||||
fi])
|
||||
|
||||
AC_ARG_ENABLE(nanorc,
|
||||
[ --enable-nanorc Enable use of .nanorc files],
|
||||
[if test x$enableval = xyes; then
|
||||
[ --disable-nanorc Disable use of .nanorc files],
|
||||
[if test x$enableval != xno; then
|
||||
AC_DEFINE(ENABLE_NANORC, 1, [Define this to use .nanorc files.]) nanorc_support=yes
|
||||
fi])
|
||||
fi],
|
||||
[if test x$enable_tiny != xyes; then
|
||||
AC_DEFINE(ENABLE_NANORC, 1, [Define this to use .nanorc files.]) nanorc_support=yes
|
||||
fi])
|
||||
|
||||
AC_ARG_ENABLE(all,
|
||||
[ --enable-all Enable ALL extra nano functionality (kitchen sink option)],
|
||||
[ --enable-all Enable ALL extra nano functionality (ignored for compatibility as all options default to on)],
|
||||
[if test x$enableval = xyes; then
|
||||
AC_DEFINE(ENABLE_NANORC, 1, [Define this to use .nanorc files.]) nanorc_support=yes
|
||||
AC_DEFINE(ENABLE_COLOR, 1, [Define this to have syntax highlighting, requires regex.h and ENABLE_NANORC too!]) color_support=yes
|
||||
AC_DEFINE(ENABLE_MULTIBUFFER, 1, [Define this to enable multiple file buffers.]) multibuffer_support=yes
|
||||
AC_DEFINE(NANO_EXTRA, 1, [Define this to enable extra stuff.]) extra_support=yes
|
||||
echo "--enable-all option no longer needed, ignoring for compatiblity"
|
||||
fi])
|
||||
|
||||
if test x$color_support = xyes; then
|
||||
# now check for the end of word boundary support (/< and />)
|
||||
AC_MSG_CHECKING([for GNU-style word boundary regex support])
|
||||
AC_TRY_RUN([
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <regex.h>
|
||||
int main(void)
|
||||
{
|
||||
regex_t r;
|
||||
size_t nmatch;
|
||||
regmatch_t pmatch;
|
||||
|
||||
if (regcomp(&r, "\\\\>", REG_EXTENDED|REG_NOSUB))
|
||||
return 1;
|
||||
if (regexec(&r, "word boundary", nmatch, &pmatch, 0))
|
||||
return 1;
|
||||
return 0;
|
||||
}],
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(GNU_WORDBOUNDS, 1, [Define if the system supports GNU-style word boundaries in regexes.]) gnu_wordbounds=yes,
|
||||
AC_MSG_RESULT(no),
|
||||
AC_MSG_WARN([*** Can't check for gnu word boundary support when cross-compiling])
|
||||
)
|
||||
fi
|
||||
|
||||
|
||||
AC_MSG_CHECKING([whether to enable UTF-8 support])
|
||||
AC_ARG_ENABLE(utf8,
|
||||
[ --enable-utf8 Enable UTF-8 support],
|
||||
@@ -387,6 +435,12 @@ fi
|
||||
AM_CONDITIONAL(USE_COLOR, test x$color_support = xyes)
|
||||
AM_CONDITIONAL(USE_NANORC, test x$nanorc_support = xyes)
|
||||
|
||||
AC_ARG_ENABLE(altrcname,
|
||||
[ --enable-altrcname Specify alternate rcfile name (default: .nanorc)],
|
||||
[if test x$enableval != no; then
|
||||
AC_DEFINE_UNQUOTED(RCFILE_NAME, "$enableval", [Specify alternate rcfile name (default: .nanorc)]) rcfilename=$enableval
|
||||
fi])
|
||||
|
||||
dnl Checks for functions.
|
||||
|
||||
AC_CHECK_FUNCS(getdelim getline isblank strcasecmp strcasestr strncasecmp strnlen vsnprintf)
|
||||
@@ -417,7 +471,7 @@ if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
AC_CHECK_HEADERS(ncurses.h)
|
||||
|
||||
if test x$enable_utf8 != xno; then
|
||||
AC_CHECK_LIB(ncursesw, get_wch, [CURSES_LIB="-lncursesw" CURSES_LIB_NAME=ncursesw CURSES_LIB_WIDE=yes])
|
||||
AC_CHECK_LIB(ncursesw, get_wch, [CURSES_LIB="-lncursesw" CPPFLAGS="-I/usr/include/ncursesw $CPPFLAGS" CURSES_LIB_NAME=ncursesw CURSES_LIB_WIDE=yes])
|
||||
fi
|
||||
|
||||
if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
|
||||
@@ -396,6 +396,12 @@ Count the number of words in the current buffer.
|
||||
.B refresh
|
||||
Refresh the screen.
|
||||
.TP
|
||||
.B undo
|
||||
Undo the text action peformed (add text, delete text, etc).
|
||||
.TP
|
||||
.B redo
|
||||
"Re-do" the last undone action (i.e. undo an undo)
|
||||
.TP
|
||||
.B suspend
|
||||
Suspend the editor (if the suspend function is enabled, see the
|
||||
"suspendenable" entry below).
|
||||
|
||||
@@ -222,6 +222,9 @@
|
||||
# bind M-A casesens search
|
||||
# bind ^S research main
|
||||
|
||||
## Set this if your backspace key sends delete most of the time (2.1.3+)
|
||||
# bind kdel backspace all
|
||||
|
||||
|
||||
## Nanorc files
|
||||
# include "@PKGDATADIR@/nanorc.nanorc"
|
||||
@@ -229,9 +232,24 @@
|
||||
## C/C++
|
||||
# include "@PKGDATADIR@/c.nanorc"
|
||||
|
||||
## Cascading Style Sheets
|
||||
# include "@PKGDATADIR@/css.nanorc"
|
||||
|
||||
## Debian files
|
||||
# include "@PKGDATADIR@/debian.nanorc"
|
||||
|
||||
## Gentoo files
|
||||
# include "@PKGDATADIR@/gentoo.nanorc"
|
||||
|
||||
## HTML
|
||||
# include "@PKGDATADIR@/html.nanorc"
|
||||
|
||||
## PHP
|
||||
# include "@PKGDATADIR@/php.nanorc"
|
||||
|
||||
## TCL
|
||||
# include "@PKGDATADIR@/tcl.nanorc"
|
||||
|
||||
## TeX
|
||||
# include "@PKGDATADIR@/tex.nanorc"
|
||||
|
||||
@@ -259,6 +277,9 @@
|
||||
## Java
|
||||
# include "@PKGDATADIR@/java.nanorc"
|
||||
|
||||
## AWK
|
||||
# include "@PKGDATADIR@/awk.nanorc"
|
||||
|
||||
## Assembler
|
||||
# include "@PKGDATADIR@/asm.nanorc"
|
||||
|
||||
@@ -267,3 +288,6 @@
|
||||
|
||||
## POV-Ray
|
||||
# include "@PKGDATADIR@/pov.nanorc"
|
||||
|
||||
## XML-type files
|
||||
# include "@PKGDATADIR@/xml.nanorc"
|
||||
|
||||
@@ -19,6 +19,9 @@ pkgdata_DATA = asm.nanorc \
|
||||
debian.nanorc \
|
||||
awk.nanorc \
|
||||
css.nanorc \
|
||||
xml.nanorc
|
||||
xml.nanorc \
|
||||
ocaml.nanorc \
|
||||
objc.nanorc \
|
||||
fortran.nanorc
|
||||
|
||||
EXTRA_DIST = $(pkgdata_DATA)
|
||||
|
||||
41
doc/syntax/fortran.nanorc
Normal file
41
doc/syntax/fortran.nanorc
Normal file
@@ -0,0 +1,41 @@
|
||||
## Here is an example for Fortran 90/95
|
||||
|
||||
syntax "fortran" "\.(f|f90|f95)$"
|
||||
|
||||
#color red "\<[A-Z_]a[0-9A-Z_]+\>"
|
||||
color red "\<[0-9]+\>"
|
||||
|
||||
icolor green "\<(action|advance|all|allocatable|allocated|any|apostrophe)\>"
|
||||
icolor green "\<(append|asis|assign|assignment|associated|character|common)\>"
|
||||
icolor green "\<(complex|data|default|delim|dimension|double precision)\>"
|
||||
icolor green "\<(elemental|epsilon|external|file|fmt|form|format|huge)\>"
|
||||
icolor green "\<(implicit|include|index|inquire|integer|intent|interface)\>"
|
||||
icolor green "\<(intrinsic|iostat|kind|logical|module|none|null|only)>"
|
||||
icolor green "\<(operator|optional|pack|parameter|pointer|position|private)\>"
|
||||
icolor green "\<(program|public|real|recl|recursive|selected_int_kind)\>"
|
||||
icolor green "\<(selected_real_kind|subroutine|status)\>"
|
||||
|
||||
icolor cyan "\<(abs|achar|adjustl|adjustr|allocate|bit_size|call|char)\>"
|
||||
icolor cyan "\<(close|contains|count|cpu_time|cshift|date_and_time)\>"
|
||||
icolor cyan "\<(deallocate|digits|dot_product|eor|eoshift|function|iachar)\>"
|
||||
icolor cyan "\<(iand|ibclr|ibits|ibset|ichar|ieor|iolength|ior|ishft|ishftc)\>"
|
||||
icolor cyan "\<(lbound|len|len_trim|matmul|maxexponent|maxloc|maxval|merge)\>"
|
||||
icolor cyan "\<(minexponent|minloc|minval|mvbits|namelist|nearest|nullify)\>"
|
||||
icolor cyan "\<(open|pad|present|print|product|pure|quote|radix)\>"
|
||||
icolor cyan "\<(random_number|random_seed|range|read|readwrite|replace)\>"
|
||||
icolor cyan "\<(reshape|rewind|save|scan|sequence|shape|sign|size|spacing)\>"
|
||||
icolor cyan "\<(spread|sum|system_clock|target|transfer|transpose|trim)\>"
|
||||
icolor cyan "\<(ubound|unpack|verify|write|tiny|type|use|yes)\>"
|
||||
|
||||
icolor yellow "\<(.and.|case|do|else|else?if|else?where|end|end?do|end?if)\>"
|
||||
icolor yellow "\<(end?select|.eqv.|forall|if|lge|lgt|lle|llt|.neqv.|.not.)\>"
|
||||
icolor yellow "\<(.or.|repeat|select case|then|where|while)\>"
|
||||
|
||||
icolor magenta "\<(continue|cycle|exit|go?to|result|return)\>"
|
||||
|
||||
## String highlighting.
|
||||
icolor yellow "<[^= ]*>" ""(\\.|[^"])*""
|
||||
|
||||
## Comment highlighting
|
||||
icolor blue "!.*"
|
||||
|
||||
@@ -2,26 +2,30 @@
|
||||
##
|
||||
syntax "ebuild" "\.e(build|class)$"
|
||||
## All the standard portage functions
|
||||
color brightgreen "^src_(unpack|compile|install|test)" "^pkg_(config|nofetch|setup|(pre|post)(inst|rm))"
|
||||
color brightgreen "^src_(unpack|prepare|configure|compile|install|test)" "^pkg_(config|nofetch|setup|(pre|post)(inst|rm))"
|
||||
## Highlight bash related syntax
|
||||
color green "\<(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while|continue|break)\>"
|
||||
color green "\<(declare|eval|exec|let)\>"
|
||||
color green "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
|
||||
color green "-(e|d|f|r|g|u|w|x|L)\>"
|
||||
color green "-[edfgruwxL]\>"
|
||||
color green "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
|
||||
## Highlight variables ... official portage ones in red, all others in bright red
|
||||
color brightred "\$\{?[a-zA-Z_0-9]+\}?"
|
||||
color red "\<(ARCH|HOMEPAGE|DESCRIPTION|IUSE|SRC_URI|LICENSE|SLOT|KEYWORDS|FILESDIR|WORKDIR|(P|R)?DEPEND|PROVIDE|DISTDIR|RESTRICT|USERLAND)\>"
|
||||
color red "\<(S|D|T|PV|PF|P|PN|A)\>" "\<C(XX)?FLAGS\>" "\<LDFLAGS\>" "\<C(HOST|TARGET|BUILD)\>"
|
||||
color red "\<(EAPI|ARCH|HOMEPAGE|DESCRIPTION|IUSE|SRC_URI|LICENSE|SLOT|KEYWORDS|(P|R)?DEPEND|PROVIDE|PROPERTIES|RESTRICT|USERLAND)\>"
|
||||
color red "\<(S|D|T|PV|PF|P|PN|PR|PVR|A|CATEGORY|DISTDIR|FILESDIR|ROOT|WORKDIR)\>" "\<(AS|C(PP|XX)?|LD)FLAGS\>" "\<C(HOST|TARGET|BUILD)\>"
|
||||
color red "\<QA_((TEXTRELS|EXECSTACK|WX_LOAD)(_[a-zA-Z_0-9]+)?|DT_HASH|PRESTRIPPED)\>" "\<WANT_AUTO(CONF|MAKE)\>" "\<AT_M4DIR\>"
|
||||
## Highlight portage commands
|
||||
color magenta "\<use(_(with|enable))?\> [!a-zA-Z0-9_+ -]*" "inherit.*"
|
||||
color brightblue "\<e(begin|end|conf|install|make|warn|infon?|error|log|patch|new(group|user))\>"
|
||||
color brightblue "\<die\>" "\<use(_(with|enable))?\>" "\<inherit\>" "\<has\>" "\<(has|best)_version\>" "\<unpack\>"
|
||||
color brightblue "\<(do|new)(ins|s?bin|doc|lib(|\.so|\.a)|man|info|exe|initd|confd|envd|pam|menu|icon)\>"
|
||||
color brightblue "\<e(begin|end|conf|install|make|qmake[34]|ant|(qa)?warn|infon?|error|log|patch|new(group|user))\>"
|
||||
color brightblue "\<e(pause|beep|mktemp|(cvs|svn)_clean|punt_cxx)\>" "\<e(aclocal|auto(reconf|header|conf|make))\>"
|
||||
color brightblue "\<built_with_use\>" "\<make_desktop_entry\>" "\<unpack(_(makeself|pdv))?\>"
|
||||
color brightblue "\<die\>" "\<use(_(with|enable))?\>" "\<inherit\>" "\<has\>" "\<(has|best)_version\>"
|
||||
color brightblue "\<(do|new)(ins|(games)?s?bin|doc|lib(|\.so|\.a)|man|info|exe|initd|confd|envd|pam|menu|icon)\>"
|
||||
color brightblue "\<do(python|sed|dir|hard|sym|html|jar|mo)\>" "\<keepdir\>"
|
||||
color brightblue "prepall(|docs|info|man|strip)" "prep(info|lib|lib\.(so|a)|man|strip)"
|
||||
color brightblue "\<(|doc|ins|exe)into\>" "\<f(owners|perms)\>" "\<(exe|ins|dir)opts\>"
|
||||
color brightblue "prepall(|docs|info|man|strip)" "prep(info|lib|lib\.(so|a)|man|strip|gamesdirs)"
|
||||
color brightblue "\<(|doc|ins|exe)into\>" "\<(f|games)(owners|perms)\>" "\<(exe|ins|dir)opts\>"
|
||||
## Highlight common commands used in ebuilds
|
||||
color blue "\<make\>" "\<(cat|cd|chmod|chown|cp|echo|env|export|grep|let|ln|mkdir|mv|rm|sed|set|tar|touch|unset)\>"
|
||||
color blue "\<make\>" "\<(awk|cat|cd|chmod|chown|cp|echo|env|export|find|e?grep|ln|mkdir|mv|rm|sed|set|tar|touch|unset|xargs)\>"
|
||||
## Highlight comments (doesnt work that well)
|
||||
color yellow "#.*$"
|
||||
## Highlight strings (doesnt work that well)
|
||||
@@ -31,17 +35,18 @@ color ,green "[[:space:]]+$"
|
||||
|
||||
## Here is an example for Portage control files
|
||||
##
|
||||
syntax "/etc/portage" "\.(keywords|mask|unmask|use)$"
|
||||
syntax "/etc/portage" "\.(keywords|mask|unmask|use)(/.+)?$"
|
||||
## Base text:
|
||||
color green "^.+$"
|
||||
## Use flags:
|
||||
color brightred "[[:space:]]+\+?[a-zA-Z0-9_-]+"
|
||||
color brightblue "[[:space:]]+-[a-zA-Z0-9_-]+"
|
||||
## Likely version numbers:
|
||||
## Likely version and slot numbers:
|
||||
color magenta "-[[:digit:]].*([[:space:]]|$)"
|
||||
color magenta ":[^[:space:]]+([[:space:]]|$)"
|
||||
## Accepted arches:
|
||||
color white "[~-]?\<(alpha|amd64|arm|hppa|ia64|mips|ppc|ppc64|s390|sh|sparc|x86|x86-fbsd)\>"
|
||||
color white "[[:space:]][~-]?\*"
|
||||
color white "[~-]?\<(alpha|amd64|arm|hppa|ia64|mips|ppc|ppc64|s390|sh|sparc(-fbsd)?|x86(-fbsd)?)\>"
|
||||
color white "[[:space:]][*~-]?\*"
|
||||
## Categories:
|
||||
color cyan "^[[:space:]]*.*/"
|
||||
## Masking regulators:
|
||||
|
||||
@@ -5,7 +5,7 @@ syntax "nanorc" "\.?nanorc$"
|
||||
icolor brightwhite "^[[:space:]]*((un)?set|include|syntax|i?color).*$"
|
||||
## Keywords
|
||||
icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|boldtext|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quickblank|quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace|wordbounds)\>"
|
||||
icolor green "^[[:space:]]*(set|unset|include|syntax)\>"
|
||||
icolor green "^[[:space:]]*(set|unset|include|syntax|header)\>"
|
||||
## Colors
|
||||
icolor yellow "^[[:space:]]*i?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>"
|
||||
icolor magenta "^[[:space:]]*i?color\>" "\<(start|end)="
|
||||
|
||||
41
doc/syntax/objc.nanorc
Normal file
41
doc/syntax/objc.nanorc
Normal file
@@ -0,0 +1,41 @@
|
||||
## Here is an example for C/C++/Obj-C.
|
||||
##
|
||||
syntax "m" "\.m$"
|
||||
|
||||
|
||||
## Stuffs
|
||||
color brightwhite "\<[A-Z_][0-9A-Z_]+\>"
|
||||
color green "\<(float|double|BOOL|bool|char|int|short|long|id|sizeof|enum|void|static|const|struct|union|typedef|extern|(un)?signed|inline)\>"
|
||||
color green "\<[[:alpha:]_][[:alnum:]_]*_t\>"
|
||||
color green "\<(class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)\>"
|
||||
color brightgreen "\<(for|if|while|do|else|case|default|switch)\>"
|
||||
color brightgreen "\<(try|throw|catch|operator|new|delete)\>"
|
||||
color brightgreen "\<(goto|continue|break|return)\>"
|
||||
color brightgreen "@\<(en(code|d)|i(mplementation|nterface)|selector)\>"
|
||||
##
|
||||
## GCC builtins
|
||||
color cyan "__attribute__[[:space:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
|
||||
|
||||
## Selector/method
|
||||
color brightmagenta "(^|[[:space:]])\[.*[[:space:]].*\]"
|
||||
color white ":[[:alnum:]]*"
|
||||
color magenta "[[:alnum:]]*:"
|
||||
color white "\[[^][:space:]]*\]"
|
||||
|
||||
##
|
||||
## String highlighting. You will in general want your comments and
|
||||
## strings to come last, because syntax highlighting rules will be
|
||||
## applied in the order they are read in.
|
||||
color brightblack "'([^'\]|(\\["'abfnrtv\\]))'" "'\\(([0-3]?[0-7]{1,2}))'" "'\\x[0-9A-Fa-f]{1,2}'"
|
||||
color brightblack "<[^= ]*>" ""(\\.|[^"])*""
|
||||
color brightblue "@"(\\.|[^"])*""
|
||||
##
|
||||
## This string is VERY resource intensive!
|
||||
## color brightyellow start=""(\\.|[^"])*\\[[:space:]]*$" end="^(\\.|[^"])*""
|
||||
|
||||
color brightblue "^[[:space:]]*#[[:space:]]*(define|include|import|(un|ifn?)def|endif|el(if|se)|if|warning|error)"
|
||||
|
||||
## Comment highlighting
|
||||
color yellow "//.*"
|
||||
color yellow start="/\*" end="\*/"
|
||||
|
||||
27
doc/syntax/ocaml.nanorc
Normal file
27
doc/syntax/ocaml.nanorc
Normal file
@@ -0,0 +1,27 @@
|
||||
# OCaml sample nanorc
|
||||
#
|
||||
syntax "ocaml" "\.mli?$"
|
||||
#uid
|
||||
color red "\<[A-Z][0-9a-z_]{2,}\>"
|
||||
#declarations
|
||||
color green "\<(let|val|method|in|and|rec|private|virtual|constraint)\>"
|
||||
#structure items
|
||||
color red "\<(type|open|class|module|exception|external)\>"
|
||||
#patterns
|
||||
color blue "\<(fun|function|functor|match|try|with)\>"
|
||||
#patterns-modifiers
|
||||
color yellow "\<(as|when|of)\>"
|
||||
#conditions
|
||||
color cyan "\<(if|then|else)\>"
|
||||
#blocs
|
||||
color magenta "\<(begin|end|object|struct|sig|for|while|do|done|to|downto)\>"
|
||||
#constantes
|
||||
color green "\<(true|false)\>"
|
||||
#modules/classes
|
||||
color green "\<(include|inherit|initializer)\>"
|
||||
#expr modifiers
|
||||
color yellow "\<(new|ref|mutable|lazy|assert|raise)\>"
|
||||
#comments
|
||||
color white start="\(\*" end="\*\)"
|
||||
#strings (no multiline handling yet)
|
||||
color brightblack ""[^\"]*""
|
||||
@@ -1,6 +1,7 @@
|
||||
## Here is an example for Perl.
|
||||
##
|
||||
syntax "perl" "\.p[lm]$"
|
||||
header "^#!.*/perl[-0-9._]*"
|
||||
color red "\<(accept|alarm|atan2|bin(d|mode)|c(aller|h(dir|mod|op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close|open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|ists|it|p))|f(cntl|ileno|lock|ork))\>" "\<(get(c|login|peername|pgrp|ppid|priority|pwnam|(host|net|proto|serv)byname|pwuid|grgid|(host|net)byaddr|protobynumber|servbyport)|([gs]et|end)(pw|gr|host|net|proto|serv)ent|getsock(name|opt)|gmtime|goto|grep|hex|index|int|ioctl|join)\>" "\<(keys|kill|last|length|link|listen|local(time)?|log|lstat|m|mkdir|msg(ctl|get|snd|rcv)|next|oct|open(dir)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re(ad(dir|link)?|cv|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|s|scalar|seek(dir)?)\>" "\<(se(lect|mctl|mget|mop|nd|tpgrp|tpriority|tsockopt)|shift|shm(ctl|get|read|write)|shutdown|sin|sleep|socket(pair)?|sort|spli(ce|t)|sprintf|sqrt|srand|stat|study|substr|symlink|sys(call|read|tem|write)|tell(dir)?|time|tr(y)?|truncate|umask)\>" "\<(un(def|link|pack|shift)|utime|values|vec|wait(pid)?|wantarray|warn|write)\>"
|
||||
color magenta "\<(continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|sub|use|package|can|isa)\>"
|
||||
icolor cyan start="[$@%]" end="( |[^0-9A-Z_]|-)"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
## Here is an example for Python.
|
||||
##
|
||||
syntax "python" "\.py$"
|
||||
header "^#!.*/python[-0-9._]*"
|
||||
icolor brightblue "def [0-9A-Z_]+"
|
||||
color brightcyan "\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>"
|
||||
color brightcyan "\<(and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield)\>"
|
||||
color brightgreen "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}"
|
||||
color brightgreen "["][^"]*[^\\]["]" "["]{3}.*[^\\]["]{3}"
|
||||
color brightgreen start=""""[^"]" end=""""" start="'''[^']" end="'''"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
## Here is an example for Ruby.
|
||||
##
|
||||
syntax "ruby" "\.rb$"
|
||||
header "^#!.*/ruby[-0-9._]*"
|
||||
## Asciibetical list of reserved words
|
||||
color yellow "\<(BEGIN|END|alias|and|begin|break|case|class|def|defined\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\>"
|
||||
## Constants
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
## Here is an example for Bourne shell scripts.
|
||||
##
|
||||
syntax "sh" "\.sh$"
|
||||
header "^#!.*/(ba|k|pdk|)sh[-0-9_]*"
|
||||
icolor brightgreen "^[0-9A-Z_]+\(\)"
|
||||
color green "\<(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\>"
|
||||
color green "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
|
||||
|
||||
27
nano-regress
Executable file
27
nano-regress
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
|
||||
sub combinations {
|
||||
return [] unless @_;
|
||||
my $first = shift;
|
||||
my @rest = combinations(@_);
|
||||
return @rest, map { [$first, @$_] } @rest;
|
||||
}
|
||||
|
||||
my @allargs=("--enable-debug", "--disable-justify", "--disable-extra", "--enable-tiny", "--disable-browser --disable-help --disable-mouse --disable-operatingdir --disable-speller", "--disable-multibuffer", "--disable-nanorc", "--with-slang");
|
||||
my @combos = combinations(@allargs);
|
||||
|
||||
my $i = 0;
|
||||
foreach my $name (@combos) {
|
||||
my @args = @$name;
|
||||
my $pct = $i / $#combos * 100;
|
||||
printf "Trying with options: @args, %d%% done...\n", $pct;
|
||||
if (system "(./configure @args && make clean all) >/dev/null 2>&1") {
|
||||
print "Build failed for args: @args\n";
|
||||
print "Try running make to reproduce\n";
|
||||
exit(1);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
print "All options completed successfully!\n";
|
||||
872
po/nano.pot
872
po/nano.pot
File diff suppressed because it is too large
Load Diff
888
po/pt_BR.po
888
po/pt_BR.po
File diff suppressed because it is too large
Load Diff
995
po/zh_CN.po
995
po/zh_CN.po
File diff suppressed because it is too large
Load Diff
863
po/zh_TW.po
863
po/zh_TW.po
File diff suppressed because it is too large
Load Diff
@@ -156,7 +156,7 @@ char *do_browser(char *path, DIR *dir)
|
||||
* time, put back the Enter key so that it's
|
||||
* read in. */
|
||||
if (old_selected == selected)
|
||||
unget_kbinput(sc_seq_or(do_enter, 0), FALSE, FALSE);
|
||||
unget_kbinput(sc_seq_or(DO_ENTER, 0), FALSE, FALSE);
|
||||
}
|
||||
}
|
||||
#endif /* !DISABLE_MOUSE */
|
||||
@@ -169,43 +169,43 @@ char *do_browser(char *path, DIR *dir)
|
||||
if (!f)
|
||||
break;
|
||||
|
||||
if (f->scfunc == total_refresh) {
|
||||
if (f->scfunc == TOTAL_REFRESH) {
|
||||
total_redraw();
|
||||
} else if (f->scfunc == do_help_void) {
|
||||
} else if (f->scfunc == DO_HELP_VOID) {
|
||||
#ifndef DISABLE_HELP
|
||||
do_browser_help();
|
||||
curs_set(0);
|
||||
do_browser_help();
|
||||
curs_set(0);
|
||||
#else
|
||||
nano_disabled_msg();
|
||||
#endif
|
||||
/* Search for a filename. */
|
||||
} else if (f->scfunc == do_search) {
|
||||
} else if (f->scfunc == DO_SEARCH) {
|
||||
curs_set(1);
|
||||
do_filesearch();
|
||||
curs_set(0);
|
||||
/* Search for another filename. */
|
||||
} else if (f->scfunc == (void *) whereis_next_msg) {
|
||||
} else if (f->scfunc == WHEREIS_NEXT_MSG) {
|
||||
do_fileresearch();
|
||||
} else if (f->scfunc == do_page_up) {
|
||||
} else if (f->scfunc == DO_PAGE_UP) {
|
||||
if (selected >= (editwinrows + fileline % editwinrows) *
|
||||
width)
|
||||
selected -= (editwinrows + fileline % editwinrows) *
|
||||
width;
|
||||
else
|
||||
selected = 0;
|
||||
} else if (f->scfunc == do_page_down) {
|
||||
} else if (f->scfunc == DO_PAGE_DOWN) {
|
||||
selected += (editwinrows - fileline % editwinrows) *
|
||||
width;
|
||||
if (selected > filelist_len - 1)
|
||||
selected = filelist_len - 1;
|
||||
} else if (f->scfunc == (void *) first_file_msg) {
|
||||
} else if (f->scfunc == FIRST_FILE_MSG) {
|
||||
if (meta_key)
|
||||
selected = 0;
|
||||
} else if (f->scfunc == (void *) last_file_msg) {
|
||||
} else if (f->scfunc == LAST_FILE_MSG) {
|
||||
if (meta_key)
|
||||
selected = filelist_len - 1;
|
||||
/* Go to a specific directory. */
|
||||
} else if (f->scfunc == (void *) goto_dir_msg) {
|
||||
} else if (f->scfunc == GOTO_DIR_MSG) {
|
||||
curs_set(1);
|
||||
|
||||
i = do_prompt(TRUE,
|
||||
@@ -238,7 +238,7 @@ char *do_browser(char *path, DIR *dir)
|
||||
* answer in ans, so that the file list is displayed
|
||||
* again, the prompt is displayed again, and what we
|
||||
* typed before at the prompt is displayed again. */
|
||||
unget_kbinput(sc_seq_or(do_gotolinecolumn_void, 0), FALSE, FALSE);
|
||||
unget_kbinput(sc_seq_or(DO_GOTOLINECOLUMN_VOID, 0), FALSE, FALSE);
|
||||
ans = mallocstrcpy(ans, answer);
|
||||
break;
|
||||
}
|
||||
@@ -285,19 +285,19 @@ char *do_browser(char *path, DIR *dir)
|
||||
free(path);
|
||||
path = new_path;
|
||||
goto change_browser_directory;
|
||||
} else if (f->scfunc == do_up_void) {
|
||||
} else if (f->scfunc == DO_UP_VOID) {
|
||||
if (selected >= width)
|
||||
selected -= width;
|
||||
} else if (f->scfunc == do_left) {
|
||||
} else if (f->scfunc == DO_LEFT) {
|
||||
if (selected > 0)
|
||||
selected--;
|
||||
} else if (f->scfunc == do_down_void) {
|
||||
} else if (f->scfunc == DO_DOWN_VOID) {
|
||||
if (selected + width <= filelist_len - 1)
|
||||
selected += width;
|
||||
} else if (f->scfunc == do_right) {
|
||||
} else if (f->scfunc == DO_RIGHT) {
|
||||
if (selected < filelist_len - 1)
|
||||
selected++;
|
||||
} else if (f->scfunc == do_enter) {
|
||||
} else if (f->scfunc == DO_ENTER) {
|
||||
/* We can't move up from "/". */
|
||||
if (strcmp(filelist[selected], "/..") == 0) {
|
||||
statusbar(_("Can't move up a directory"));
|
||||
@@ -355,7 +355,7 @@ char *do_browser(char *path, DIR *dir)
|
||||
/* Start over again with the new path value. */
|
||||
goto change_browser_directory;
|
||||
/* Abort the file browser. */
|
||||
} else if (f->scfunc == do_exit) {
|
||||
} else if (f->scfunc == DO_EXIT) {
|
||||
abort = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -552,30 +552,32 @@ void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key)
|
||||
if (!*meta_key) {
|
||||
switch (*kbinput) {
|
||||
case ' ':
|
||||
*kbinput = sc_seq_or(do_page_down, 0);
|
||||
*kbinput = sc_seq_or(DO_PAGE_DOWN, 0);
|
||||
break;
|
||||
case '-':
|
||||
*kbinput = sc_seq_or(do_page_up, 0);
|
||||
*kbinput = sc_seq_or(DO_PAGE_UP, 0);
|
||||
break;
|
||||
case '?':
|
||||
*kbinput = sc_seq_or(do_help_void, 0);
|
||||
#ifndef DISABLE_HELP
|
||||
*kbinput = sc_seq_or(DO_HELP_VOID, 0);
|
||||
#endif
|
||||
break;
|
||||
/* Cancel equivalent to Exit here. */
|
||||
case 'E':
|
||||
case 'e':
|
||||
*kbinput = sc_seq_or(do_exit, 0);
|
||||
*kbinput = sc_seq_or(DO_EXIT, 0);
|
||||
break;
|
||||
case 'G':
|
||||
case 'g':
|
||||
*kbinput = sc_seq_or((void *) goto_dir_msg, 0);
|
||||
*kbinput = sc_seq_or(GOTO_DIR_MSG, 0);
|
||||
break;
|
||||
case 'S':
|
||||
case 's':
|
||||
*kbinput = sc_seq_or(do_enter, 0);
|
||||
*kbinput = sc_seq_or(DO_ENTER, 0);
|
||||
break;
|
||||
case 'W':
|
||||
case 'w':
|
||||
*kbinput = sc_seq_or(do_search, 0);
|
||||
*kbinput = sc_seq_or(DO_SEARCH, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -839,18 +841,18 @@ int filesearch_init(void)
|
||||
#endif
|
||||
} else
|
||||
#ifndef NANO_TINY
|
||||
if (s && s->scfunc == (void *) case_sens_msg) {
|
||||
if (s && s->scfunc == CASE_SENS_MSG) {
|
||||
TOGGLE(CASE_SENSITIVE);
|
||||
backupstring = mallocstrcpy(backupstring, answer);
|
||||
return 1;
|
||||
} else if (s && s->scfunc == (void *) backwards_msg) {
|
||||
} else if (s && s->scfunc == BACKWARDS_MSG) {
|
||||
TOGGLE(BACKWARDS_SEARCH);
|
||||
backupstring = mallocstrcpy(backupstring, answer);
|
||||
return 1;
|
||||
} else
|
||||
#endif
|
||||
#ifdef HAVE_REGEX_H
|
||||
if (s && s->scfunc == (void *) regexp_msg) {
|
||||
if (s && s->scfunc == REGEXP_MSG) {
|
||||
TOGGLE(USE_REGEXP);
|
||||
backupstring = mallocstrcpy(backupstring, answer);
|
||||
return 1;
|
||||
|
||||
137
src/color.c
137
src/color.c
@@ -105,11 +105,13 @@ void color_init(void)
|
||||
/* Update the color information based on the current filename. */
|
||||
void color_update(void)
|
||||
{
|
||||
const syntaxtype *tmpsyntax;
|
||||
syntaxtype *tmpsyntax;
|
||||
syntaxtype *defsyntax = NULL;
|
||||
colortype *tmpcolor, *defcolor = NULL;
|
||||
|
||||
assert(openfile != NULL);
|
||||
|
||||
openfile->syntax = NULL;
|
||||
openfile->colorstrings = NULL;
|
||||
|
||||
/* If we specified a syntax override string, use it. */
|
||||
@@ -121,8 +123,10 @@ void color_update(void)
|
||||
|
||||
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
||||
tmpsyntax = tmpsyntax->next) {
|
||||
if (strcmp(tmpsyntax->desc, syntaxstr) == 0)
|
||||
if (strcmp(tmpsyntax->desc, syntaxstr) == 0) {
|
||||
openfile->syntax = tmpsyntax;
|
||||
openfile->colorstrings = tmpsyntax->color;
|
||||
}
|
||||
|
||||
if (openfile->colorstrings != NULL)
|
||||
break;
|
||||
@@ -131,7 +135,7 @@ void color_update(void)
|
||||
|
||||
/* If we didn't specify a syntax override string, or if we did and
|
||||
* there was no syntax by that name, get the syntax based on the
|
||||
* file extension. */
|
||||
* file extension, and then look in the header. */
|
||||
if (openfile->colorstrings == NULL) {
|
||||
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
||||
tmpsyntax = tmpsyntax->next) {
|
||||
@@ -141,6 +145,7 @@ void color_update(void)
|
||||
* extensions, which we've checked for elsewhere. Skip over
|
||||
* it here, but keep track of its color regexes. */
|
||||
if (strcmp(tmpsyntax->desc, "default") == 0) {
|
||||
defsyntax = tmpsyntax;
|
||||
defcolor = tmpsyntax->color;
|
||||
continue;
|
||||
}
|
||||
@@ -153,14 +158,16 @@ void color_update(void)
|
||||
* already. */
|
||||
if (not_compiled) {
|
||||
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
|
||||
regcomp(e->ext, e->ext_regex, REG_EXTENDED);
|
||||
regcomp(e->ext, fixbounds(e->ext_regex), REG_EXTENDED);
|
||||
}
|
||||
|
||||
/* Set colorstrings if we matched the extension
|
||||
* regex. */
|
||||
if (regexec(e->ext, openfile->filename, 0, NULL,
|
||||
0) == 0)
|
||||
0) == 0) {
|
||||
openfile->syntax = tmpsyntax;
|
||||
openfile->colorstrings = tmpsyntax->color;
|
||||
}
|
||||
|
||||
if (openfile->colorstrings != NULL)
|
||||
break;
|
||||
@@ -174,12 +181,59 @@ void color_update(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we haven't matched anything yet, try the headers */
|
||||
if (openfile->colorstrings == NULL) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "No match for file extensions, looking at headers...\n");
|
||||
#endif
|
||||
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
||||
tmpsyntax = tmpsyntax->next) {
|
||||
exttype *e;
|
||||
|
||||
for (e = tmpsyntax->headers; e != NULL; e = e->next) {
|
||||
bool not_compiled = (e->ext == NULL);
|
||||
|
||||
/* e->ext_regex has already been checked for validity
|
||||
* elsewhere. Compile its specified regex if we haven't
|
||||
* already. */
|
||||
if (not_compiled) {
|
||||
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
|
||||
regcomp(e->ext, fixbounds(e->ext_regex), REG_EXTENDED);
|
||||
}
|
||||
|
||||
/* Set colorstrings if we matched the extension
|
||||
* regex. */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Comparing header regex \"%s\" to fileage \"%s\"...\n", e->ext_regex, openfile->fileage->data);
|
||||
#endif
|
||||
if (regexec(e->ext, openfile->fileage->data, 0, NULL, 0) == 0) {
|
||||
openfile->syntax = tmpsyntax;
|
||||
openfile->colorstrings = tmpsyntax->color;
|
||||
}
|
||||
|
||||
if (openfile->colorstrings != NULL)
|
||||
break;
|
||||
|
||||
/* Decompile e->ext_regex's specified regex if we aren't
|
||||
* going to use it. */
|
||||
if (not_compiled) {
|
||||
regfree(e->ext);
|
||||
free(e->ext);
|
||||
e->ext = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If we didn't get a syntax based on the file extension, and we
|
||||
* have a default syntax, use it. */
|
||||
if (openfile->colorstrings == NULL && defcolor != NULL)
|
||||
if (openfile->colorstrings == NULL && defcolor != NULL) {
|
||||
openfile->syntax = defsyntax;
|
||||
openfile->colorstrings = defcolor;
|
||||
}
|
||||
|
||||
for (tmpcolor = openfile->colorstrings; tmpcolor != NULL;
|
||||
tmpcolor = tmpcolor->next) {
|
||||
@@ -188,16 +242,83 @@ void color_update(void)
|
||||
* regexes if we haven't already. */
|
||||
if (tmpcolor->start == NULL) {
|
||||
tmpcolor->start = (regex_t *)nmalloc(sizeof(regex_t));
|
||||
regcomp(tmpcolor->start, tmpcolor->start_regex,
|
||||
regcomp(tmpcolor->start, fixbounds(tmpcolor->start_regex),
|
||||
REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0));
|
||||
}
|
||||
|
||||
if (tmpcolor->end_regex != NULL && tmpcolor->end == NULL) {
|
||||
tmpcolor->end = (regex_t *)nmalloc(sizeof(regex_t));
|
||||
regcomp(tmpcolor->end, tmpcolor->end_regex,
|
||||
regcomp(tmpcolor->end, fixbounds(tmpcolor->end_regex),
|
||||
REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset the multicolor info cache for records for any lines which need
|
||||
to be recalculated */
|
||||
void reset_multis_after(filestruct *fileptr, int mindex)
|
||||
{
|
||||
filestruct *oof;
|
||||
for (oof = fileptr->next; oof != NULL; oof = oof->next) {
|
||||
alloc_multidata_if_needed(oof);
|
||||
if (oof->multidata == NULL)
|
||||
continue;
|
||||
if (oof->multidata[mindex] != CNONE)
|
||||
oof->multidata[mindex] = -1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void reset_multis_before(filestruct *fileptr, int mindex)
|
||||
{
|
||||
filestruct *oof;
|
||||
for (oof = fileptr->prev; oof != NULL; oof = oof->prev) {
|
||||
alloc_multidata_if_needed(oof);
|
||||
if (oof->multidata == NULL)
|
||||
continue;
|
||||
if (oof->multidata[mindex] != CNONE)
|
||||
oof->multidata[mindex] = -1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Reset multi line strings around a filestruct ptr, trying to be smart about stopping */
|
||||
void reset_multis(filestruct *fileptr)
|
||||
{
|
||||
int nobegin, noend;
|
||||
regmatch_t startmatch, endmatch;
|
||||
const colortype *tmpcolor = openfile->colorstrings;
|
||||
|
||||
if (!openfile->syntax)
|
||||
return;
|
||||
|
||||
for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
|
||||
|
||||
/* If it's not a multi-line regex, amscray */
|
||||
if (tmpcolor->end == NULL)
|
||||
continue;
|
||||
|
||||
alloc_multidata_if_needed(fileptr);
|
||||
/* Figure out where the first begin and end are to determine if
|
||||
things changed drastically for the precalculated multi values */
|
||||
nobegin = regexec(tmpcolor->start, fileptr->data, 1, &startmatch, 0);
|
||||
noend = regexec(tmpcolor->end, fileptr->data, 1, &endmatch, 0);
|
||||
if (fileptr->multidata[tmpcolor->id] == CWHOLELINE) {
|
||||
if (nobegin && noend)
|
||||
continue;
|
||||
} else if (fileptr->multidata[tmpcolor->id] & CBEGINBEFORE && !noend
|
||||
&& (nobegin || endmatch.rm_eo > startmatch.rm_eo)) {
|
||||
reset_multis_after(fileptr, tmpcolor->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If we got here assume the worst */
|
||||
reset_multis_before(fileptr, tmpcolor->id);
|
||||
reset_multis_after(fileptr, tmpcolor->id);
|
||||
fileptr->multidata[tmpcolor->id] = -1;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_COLOR */
|
||||
|
||||
24
src/cut.c
24
src/cut.c
@@ -28,7 +28,6 @@
|
||||
|
||||
static bool keep_cutbuffer = FALSE;
|
||||
/* Should we keep the contents of the cutbuffer? */
|
||||
static filestruct *cutbottom = NULL;
|
||||
/* Pointer to the end of the cutbuffer. */
|
||||
|
||||
/* Indicate that we should no longer keep the contents of the
|
||||
@@ -114,7 +113,7 @@ void cut_to_eof(void)
|
||||
* position to the end of the file into the cutbuffer. */
|
||||
void do_cut_text(
|
||||
#ifndef NANO_TINY
|
||||
bool copy_text, bool cut_till_end
|
||||
bool copy_text, bool cut_till_end, bool undoing
|
||||
#else
|
||||
void
|
||||
#endif
|
||||
@@ -163,6 +162,7 @@ void do_cut_text(
|
||||
keep_cutbuffer = TRUE;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
|
||||
if (cut_till_end) {
|
||||
/* If cut_till_end is TRUE, move all text up to the end of the
|
||||
* file into the cutbuffer. */
|
||||
@@ -204,12 +204,14 @@ void do_cut_text(
|
||||
* disturbing the text. */
|
||||
if (!old_no_newlines)
|
||||
UNSET(NO_NEWLINES);
|
||||
} else
|
||||
} else if (!undoing)
|
||||
update_undo(CUT);
|
||||
#endif
|
||||
/* Leave the text in the cutbuffer, and mark the file as
|
||||
* modified. */
|
||||
set_modified();
|
||||
|
||||
|
||||
/* Update the screen. */
|
||||
edit_refresh();
|
||||
|
||||
@@ -221,9 +223,12 @@ void do_cut_text(
|
||||
/* Move text from the current filestruct into the cutbuffer. */
|
||||
void do_cut_text_void(void)
|
||||
{
|
||||
#ifndef NANO_TINY
|
||||
add_undo(CUT);
|
||||
#endif
|
||||
do_cut_text(
|
||||
#ifndef NANO_TINY
|
||||
FALSE, FALSE
|
||||
FALSE, FALSE, FALSE
|
||||
#endif
|
||||
);
|
||||
}
|
||||
@@ -233,13 +238,16 @@ void do_cut_text_void(void)
|
||||
* back into the filestruct afterward. */
|
||||
void do_copy_text(void)
|
||||
{
|
||||
do_cut_text(TRUE, FALSE);
|
||||
do_cut_text(TRUE, FALSE, FALSE);
|
||||
}
|
||||
|
||||
/* Cut from the current cursor position to the end of the file. */
|
||||
void do_cut_till_end(void)
|
||||
{
|
||||
do_cut_text(FALSE, TRUE);
|
||||
#ifndef NANO_TINY
|
||||
add_undo(CUT);
|
||||
#endif
|
||||
do_cut_text(FALSE, TRUE, FALSE);
|
||||
}
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
@@ -252,6 +260,10 @@ void do_uncut_text(void)
|
||||
if (cutbuffer == NULL)
|
||||
return;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
update_undo(UNCUT);
|
||||
#endif
|
||||
|
||||
/* Add a copy of the text in the cutbuffer to the current filestruct
|
||||
* at the current cursor position. */
|
||||
copy_from_filestruct(cutbuffer, cutbottom);
|
||||
|
||||
119
src/files.c
119
src/files.c
@@ -75,6 +75,8 @@ void initialize_buffer(void)
|
||||
openfile->fmt = NIX_FILE;
|
||||
|
||||
openfile->current_stat = NULL;
|
||||
openfile->undotop = NULL;
|
||||
openfile->current_undo = NULL;
|
||||
#endif
|
||||
#ifdef ENABLE_COLOR
|
||||
openfile->colorstrings = NULL;
|
||||
@@ -99,7 +101,7 @@ void initialize_buffer_text(void)
|
||||
|
||||
/* If it's not "", filename is a file to open. We make a new buffer, if
|
||||
* necessary, and then open and read the file, if applicable. */
|
||||
void open_buffer(const char *filename)
|
||||
void open_buffer(const char *filename, bool undoable)
|
||||
{
|
||||
bool new_buffer = (openfile == NULL
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
@@ -140,7 +142,7 @@ void open_buffer(const char *filename)
|
||||
/* If we have a non-new file, read it in. Then, if the buffer has
|
||||
* no stat, update the stat, if applicable. */
|
||||
if (rc == 0) {
|
||||
read_file(f, filename);
|
||||
read_file(f, filename, undoable);
|
||||
#ifndef NANO_TINY
|
||||
if (openfile->current_stat == NULL) {
|
||||
openfile->current_stat =
|
||||
@@ -190,7 +192,7 @@ void replace_buffer(const char *filename)
|
||||
|
||||
/* If we have a non-new file, read it in. */
|
||||
if (rc == 0)
|
||||
read_file(f, filename);
|
||||
read_file(f, filename, FALSE);
|
||||
|
||||
/* Move back to the beginning of the first line of the buffer. */
|
||||
openfile->current = openfile->fileage;
|
||||
@@ -309,6 +311,10 @@ filestruct *read_line(char *buf, filestruct *prevnode, bool
|
||||
fileptr->data[buf_len - 1] = '\0';
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
fileptr->multidata = NULL;
|
||||
#endif
|
||||
|
||||
if (*first_line_ins) {
|
||||
/* Special case: We're inserting with the cursor on the first
|
||||
* line. */
|
||||
@@ -337,8 +343,9 @@ filestruct *read_line(char *buf, filestruct *prevnode, bool
|
||||
}
|
||||
|
||||
/* Read an open file into the current buffer. f should be set to the
|
||||
* open file, and filename should be set to the name of the file. */
|
||||
void read_file(FILE *f, const char *filename)
|
||||
* open file, and filename should be set to the name of the file.
|
||||
undoable means do we want to create undo records to try and undo this */
|
||||
void read_file(FILE *f, const char *filename, bool undoable)
|
||||
{
|
||||
size_t num_lines = 0;
|
||||
/* The number of lines in the file. */
|
||||
@@ -369,6 +376,11 @@ void read_file(FILE *f, const char *filename)
|
||||
buf = charalloc(bufx);
|
||||
buf[0] = '\0';
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (undoable)
|
||||
add_undo(INSERT);
|
||||
#endif
|
||||
|
||||
if (openfile->current == openfile->fileage)
|
||||
first_line_ins = TRUE;
|
||||
else
|
||||
@@ -487,7 +499,7 @@ void read_file(FILE *f, const char *filename)
|
||||
/* If we didn't get a file and we don't already have one, open a
|
||||
* blank buffer. */
|
||||
if (fileptr == NULL)
|
||||
open_buffer("");
|
||||
open_buffer("", FALSE);
|
||||
|
||||
/* Attach the file we got to the filestruct. If we got a file of
|
||||
* zero bytes, don't do anything. */
|
||||
@@ -559,6 +571,9 @@ void read_file(FILE *f, const char *filename)
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (undoable)
|
||||
update_undo(INSERT);
|
||||
|
||||
if (format == 3)
|
||||
statusbar(
|
||||
P_("Read %lu line (Converted from DOS and Mac format)",
|
||||
@@ -589,7 +604,7 @@ void read_file(FILE *f, const char *filename)
|
||||
* return value. *f is set to the opened file. */
|
||||
int open_file(const char *filename, bool newfie, FILE **f)
|
||||
{
|
||||
struct stat fileinfo;
|
||||
struct stat fileinfo, fileinfo2;
|
||||
int fd;
|
||||
char *full_filename;
|
||||
|
||||
@@ -598,10 +613,21 @@ int open_file(const char *filename, bool newfie, FILE **f)
|
||||
/* Get the specified file's full path. */
|
||||
full_filename = get_full_path(filename);
|
||||
|
||||
if (full_filename == NULL)
|
||||
/* Okay, if we can't stat the path due to a component's
|
||||
permissions, just try the relative one */
|
||||
if (full_filename == NULL
|
||||
|| (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1))
|
||||
full_filename = mallocstrcpy(NULL, filename);
|
||||
|
||||
if (stat(full_filename, &fileinfo) == -1) {
|
||||
/* Well, maybe we can open the file even if the OS
|
||||
says its not there */
|
||||
if ((fd = open(filename, O_RDONLY)) != -1) {
|
||||
statusbar(_("Reading File"));
|
||||
free(full_filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (newfie) {
|
||||
statusbar(_("New File"));
|
||||
return -2;
|
||||
@@ -769,14 +795,14 @@ void do_insertfile(
|
||||
#ifndef NANO_TINY
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
|
||||
if (s && s->scfunc == (void *) new_buffer_msg) {
|
||||
if (s && s->scfunc == NEW_BUFFER_MSG) {
|
||||
/* Don't allow toggling if we're in view mode. */
|
||||
if (!ISSET(VIEW_MODE))
|
||||
TOGGLE(MULTIBUFFER);
|
||||
continue;
|
||||
} else
|
||||
#endif
|
||||
if (s && s->scfunc == (void *) ext_cmd_msg) {
|
||||
if (s && s->scfunc == EXT_CMD_MSG) {
|
||||
execute = !execute;
|
||||
continue;
|
||||
}
|
||||
@@ -786,7 +812,7 @@ void do_insertfile(
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
#ifndef DISABLE_BROWSER
|
||||
if (s && s->scfunc == (void *) to_files_msg) {
|
||||
if (s && s->scfunc == TO_FILES_MSG) {
|
||||
char *tmp = do_browse_from(answer);
|
||||
|
||||
if (tmp == NULL)
|
||||
@@ -851,7 +877,7 @@ void do_insertfile(
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
if (ISSET(MULTIBUFFER))
|
||||
/* Open a blank buffer. */
|
||||
open_buffer("");
|
||||
open_buffer("", FALSE);
|
||||
#endif
|
||||
|
||||
/* Save the command's output in the current buffer. */
|
||||
@@ -875,7 +901,7 @@ void do_insertfile(
|
||||
|
||||
/* Save the file specified in answer in the current
|
||||
* buffer. */
|
||||
open_buffer(answer);
|
||||
open_buffer(answer, TRUE);
|
||||
#ifndef NANO_TINY
|
||||
}
|
||||
#endif
|
||||
@@ -1463,14 +1489,15 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
||||
free(backuptemp);
|
||||
backuptemp = get_next_filename(backupname, "~");
|
||||
if (*backuptemp == '\0') {
|
||||
statusbar(_("Error writing %s: %s"), backupname,
|
||||
statusbar(_("Error writing backup file %s: %s"), backupname,
|
||||
_("Too many backup files?"));
|
||||
free(backuptemp);
|
||||
free(backupname);
|
||||
/* If we can't write to the backup, go on, since only
|
||||
* saving the original file is better than saving
|
||||
* nothing. */
|
||||
goto skip_backup;
|
||||
/* If we can't write to the backup, DONT go on, since
|
||||
whatever caused the backup file to fail (e.g. disk
|
||||
full may well cause the real file write to fail, which
|
||||
means we could lose both the backup and the original! */
|
||||
goto cleanup_and_exit;
|
||||
} else {
|
||||
free(backupname);
|
||||
backupname = backuptemp;
|
||||
@@ -1487,14 +1514,16 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
||||
|
||||
if (backup_file == NULL || chmod(backupname,
|
||||
openfile->current_stat->st_mode) == -1) {
|
||||
statusbar(_("Error writing %s: %s"), backupname,
|
||||
statusbar(_("Error writing backup file %s: %s"), backupname,
|
||||
strerror(errno));
|
||||
free(backupname);
|
||||
if (backup_file != NULL)
|
||||
fclose(backup_file);
|
||||
/* If we can't write to the backup, go on, since only saving
|
||||
* the original file is better than saving nothing. */
|
||||
goto skip_backup;
|
||||
/* If we can't write to the backup, DONT go on, since
|
||||
whatever caused the backup file to fail (e.g. disk
|
||||
full may well cause the real file write to fail, which
|
||||
means we could lose both the backup and the original! */
|
||||
goto cleanup_and_exit;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -1514,17 +1543,19 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
||||
strerror(errno));
|
||||
beep();
|
||||
} else
|
||||
statusbar(_("Error writing %s: %s"), backupname,
|
||||
statusbar(_("Error writing backup file %s: %s"), backupname,
|
||||
strerror(errno));
|
||||
/* If we can't read from or write to the backup, go on,
|
||||
* since only saving the original file is better than saving
|
||||
* nothing. */
|
||||
/* If we can't write to the backup, DONT go on, since
|
||||
whatever caused the backup file to fail (e.g. disk
|
||||
full may well cause the real file write to fail, which
|
||||
means we could lose both the backup and the original! */
|
||||
goto cleanup_and_exit;
|
||||
}
|
||||
|
||||
free(backupname);
|
||||
}
|
||||
|
||||
skip_backup:
|
||||
skip_backup:
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
/* If NOFOLLOW_SYMLINKS is set and the file is a link, we aren't
|
||||
@@ -1572,7 +1603,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
||||
}
|
||||
|
||||
if (f_open == NULL) {
|
||||
fd_source = open(realname, O_RDONLY | O_CREAT);
|
||||
fd_source = open(realname, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
|
||||
if (fd_source != -1) {
|
||||
f_source = fdopen(fd_source, "rb");
|
||||
@@ -1691,7 +1722,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
||||
int fd_source;
|
||||
FILE *f_source = NULL;
|
||||
|
||||
fd_source = open(tempname, O_RDONLY | O_CREAT);
|
||||
fd_source = open(tempname, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
|
||||
if (fd_source != -1) {
|
||||
f_source = fdopen(fd_source, "rb");
|
||||
@@ -1712,8 +1743,11 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
||||
strerror(errno));
|
||||
goto cleanup_and_exit;
|
||||
}
|
||||
} else
|
||||
fclose(f);
|
||||
} else if (fclose(f) != 0) {
|
||||
statusbar(_("Error writing %s: %s"), realname,
|
||||
strerror(errno));
|
||||
goto cleanup_and_exit;
|
||||
}
|
||||
|
||||
if (!tmp && append == OVERWRITE) {
|
||||
if (!nonamechange) {
|
||||
@@ -1898,7 +1932,7 @@ bool do_writeout(bool exiting)
|
||||
s = get_shortcut(currmenu, &i, &meta_key, &func_key);
|
||||
|
||||
#ifndef DISABLE_BROWSER
|
||||
if (s && s->scfunc == (void *) to_files_msg) {
|
||||
if (s && s->scfunc == TO_FILES_MSG) {
|
||||
char *tmp = do_browse_from(answer);
|
||||
|
||||
if (tmp == NULL)
|
||||
@@ -1910,25 +1944,27 @@ bool do_writeout(bool exiting)
|
||||
} else
|
||||
#endif /* !DISABLE_BROWSER */
|
||||
#ifndef NANO_TINY
|
||||
if (s && s->scfunc == (void *) dos_format_msg) {
|
||||
if (s && s->scfunc == DOS_FORMAT_MSG) {
|
||||
openfile->fmt = (openfile->fmt == DOS_FILE) ? NIX_FILE :
|
||||
DOS_FILE;
|
||||
continue;
|
||||
} else if (s && s->scfunc == (void *) mac_format_msg) {
|
||||
} else if (s && s->scfunc == MAC_FORMAT_MSG) {
|
||||
openfile->fmt = (openfile->fmt == MAC_FILE) ? NIX_FILE :
|
||||
MAC_FILE;
|
||||
continue;
|
||||
} else if (s && s->scfunc == (void *) backup_file_msg) {
|
||||
} else if (s && s->scfunc == BACKUP_FILE_MSG) {
|
||||
TOGGLE(BACKUP_FILE);
|
||||
continue;
|
||||
} else
|
||||
#endif /* !NANO_TINY */
|
||||
if (s && s->scfunc == (void *) prepend_msg) {
|
||||
if (s && s->scfunc == PREPEND_MSG) {
|
||||
append = (append == PREPEND) ? OVERWRITE : PREPEND;
|
||||
continue;
|
||||
} else if (s && s->scfunc == (void *) append_msg) {
|
||||
} else if (s && s->scfunc == APPEND_MSG) {
|
||||
append = (append == APPEND) ? OVERWRITE : APPEND;
|
||||
continue;
|
||||
} else if (s && s->scfunc == DO_HELP_VOID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -2007,6 +2043,15 @@ bool do_writeout(bool exiting)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#ifndef NANO_TINY
|
||||
if (openfile->current_stat && openfile->current_stat->st_mtime < st.st_mtime) {
|
||||
i = do_yesno_prompt(FALSE,
|
||||
_("File was modified since you opened it, continue saving ? "));
|
||||
if (i == 0 || i == -1)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* Convert newlines to nulls, just before we save the
|
||||
|
||||
851
src/global.c
851
src/global.c
File diff suppressed because it is too large
Load Diff
47
src/help.c
47
src/help.c
@@ -145,35 +145,35 @@ void do_help(void (*refresh_func)(void))
|
||||
if (!f)
|
||||
continue;
|
||||
|
||||
if (f->scfunc == total_refresh) {
|
||||
if (f->scfunc == TOTAL_REFRESH) {
|
||||
total_redraw();
|
||||
break;
|
||||
} else if (f->scfunc == do_page_up) {
|
||||
} else if (f->scfunc == DO_PAGE_UP) {
|
||||
if (line > editwinrows - 2)
|
||||
line -= editwinrows - 2;
|
||||
else
|
||||
line = 0;
|
||||
} else if (f->scfunc == do_page_down) {
|
||||
} else if (f->scfunc == DO_PAGE_DOWN) {
|
||||
if (line + (editwinrows - 1) < last_line)
|
||||
line += editwinrows - 2;
|
||||
} else if (f->scfunc == do_up_void) {
|
||||
} else if (f->scfunc == DO_UP_VOID) {
|
||||
if (line > 0)
|
||||
line--;
|
||||
} else if (f->scfunc == do_down_void) {
|
||||
} else if (f->scfunc == DO_DOWN_VOID) {
|
||||
if (line + (editwinrows - 1) < last_line)
|
||||
line++;
|
||||
} else if (f->scfunc == do_first_line) {
|
||||
} else if (f->scfunc == DO_FIRST_LINE) {
|
||||
if (meta_key)
|
||||
line = 0;
|
||||
break;
|
||||
} else if (f->scfunc == do_last_line) {
|
||||
} else if (f->scfunc == DO_LAST_LINE) {
|
||||
if (meta_key) {
|
||||
if (line + (editwinrows - 1) < last_line)
|
||||
line = last_line - (editwinrows - 1);
|
||||
}
|
||||
break;
|
||||
/* Abort the help browser. */
|
||||
} else if (f->scfunc == do_exit) {
|
||||
} else if (f->scfunc == DO_EXIT) {
|
||||
abort = TRUE;
|
||||
break;
|
||||
}
|
||||
@@ -201,12 +201,6 @@ void do_help(void (*refresh_func)(void))
|
||||
help_text = NULL;
|
||||
}
|
||||
|
||||
/* Start the help browser for the edit window. */
|
||||
void do_help_void(void)
|
||||
{
|
||||
do_help(&edit_refresh);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_BROWSER
|
||||
/* Start the help browser for the file browser. */
|
||||
void do_browser_help(void)
|
||||
@@ -413,7 +407,7 @@ void help_init(void)
|
||||
size_t endis_len = strlen(_("enable/disable"));
|
||||
|
||||
for (s = sclist; s != NULL; s = s->next)
|
||||
if (s->scfunc == (void *) do_toggle)
|
||||
if (s->scfunc == DO_TOGGLE)
|
||||
allocsize += strlen(_(flagtostr(s->toggle))) + endis_len + 9;
|
||||
|
||||
}
|
||||
@@ -484,7 +478,7 @@ void help_init(void)
|
||||
/* And the toggles... */
|
||||
if (currmenu == MMAIN)
|
||||
for (s = sclist; s != NULL; s = s->next)
|
||||
if (s->scfunc == (void *) do_toggle)
|
||||
if (s->scfunc == DO_TOGGLE)
|
||||
ptr += sprintf(ptr, "(%s)\t\t\t%s %s\n",
|
||||
s->keystr, _(flagtostr(s->toggle)), _("enable/disable"));
|
||||
|
||||
@@ -513,15 +507,15 @@ void parse_help_input(int *kbinput, bool *meta_key, bool *func_key)
|
||||
switch (*kbinput) {
|
||||
/* For consistency with the file browser. */
|
||||
case ' ':
|
||||
*kbinput = sc_seq_or(do_page_up, 0);
|
||||
*kbinput = sc_seq_or(DO_PAGE_UP, 0);
|
||||
break;
|
||||
case '-':
|
||||
*kbinput = sc_seq_or(do_page_down, 0);;
|
||||
*kbinput = sc_seq_or(DO_PAGE_DOWN, 0);;
|
||||
break;
|
||||
/* Cancel is equivalent to Exit here. */
|
||||
case 'E':
|
||||
case 'e':
|
||||
*kbinput = sc_seq_or(do_exit, 0);;
|
||||
*kbinput = sc_seq_or(DO_EXIT, 0);;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -552,3 +546,18 @@ size_t help_line_len(const char *ptr)
|
||||
}
|
||||
|
||||
#endif /* !DISABLE_HELP */
|
||||
|
||||
/* Start the help browser for the edit window. */
|
||||
void do_help_void(void)
|
||||
{
|
||||
|
||||
#ifndef DISABLE_HELP
|
||||
/* Start the help browser for the edit window. */
|
||||
do_help(&edit_refresh);
|
||||
#else
|
||||
if (currmenu == MMAIN)
|
||||
nano_disabled_msg();
|
||||
else
|
||||
beep();
|
||||
#endif
|
||||
}
|
||||
|
||||
12
src/move.c
12
src/move.c
@@ -29,7 +29,7 @@
|
||||
/* Move to the first line of the file. */
|
||||
void do_first_line(void)
|
||||
{
|
||||
const filestruct *current_save = openfile->current;
|
||||
filestruct *current_save = openfile->current;
|
||||
size_t pww_save = openfile->placewewant;
|
||||
|
||||
openfile->current = openfile->fileage;
|
||||
@@ -42,7 +42,7 @@ void do_first_line(void)
|
||||
/* Move to the last line of the file. */
|
||||
void do_last_line(void)
|
||||
{
|
||||
const filestruct *current_save = openfile->current;
|
||||
filestruct *current_save = openfile->current;
|
||||
size_t pww_save = openfile->placewewant;
|
||||
|
||||
openfile->current = openfile->filebot;
|
||||
@@ -130,7 +130,7 @@ void do_page_down(void)
|
||||
* afterwards. */
|
||||
void do_para_begin(bool allow_update)
|
||||
{
|
||||
const filestruct *current_save = openfile->current;
|
||||
filestruct *current_save = openfile->current;
|
||||
const size_t pww_save = openfile->placewewant;
|
||||
|
||||
if (openfile->current != openfile->fileage) {
|
||||
@@ -162,7 +162,7 @@ void do_para_begin_void(void)
|
||||
* paragraph or isn't in a paragraph. */
|
||||
void do_para_end(bool allow_update)
|
||||
{
|
||||
const filestruct *const current_save = openfile->current;
|
||||
filestruct *const current_save = openfile->current;
|
||||
const size_t pww_save = openfile->placewewant;
|
||||
|
||||
while (openfile->current != openfile->filebot &&
|
||||
@@ -206,7 +206,7 @@ void do_para_end_void(void)
|
||||
bool do_next_word(bool allow_punct, bool allow_update)
|
||||
{
|
||||
size_t pww_save = openfile->placewewant;
|
||||
const filestruct *current_save = openfile->current;
|
||||
filestruct *current_save = openfile->current;
|
||||
char *char_mb;
|
||||
int char_mb_len;
|
||||
bool end_line = FALSE, started_on_word = FALSE;
|
||||
@@ -301,7 +301,7 @@ void do_next_word_void(void)
|
||||
bool do_prev_word(bool allow_punct, bool allow_update)
|
||||
{
|
||||
size_t pww_save = openfile->placewewant;
|
||||
const filestruct *current_save = openfile->current;
|
||||
filestruct *current_save = openfile->current;
|
||||
char *char_mb;
|
||||
int char_mb_len;
|
||||
bool begin_line = FALSE, started_on_word = FALSE;
|
||||
|
||||
247
src/nano.c
247
src/nano.c
@@ -1,4 +1,4 @@
|
||||
/* $Id$ */
|
||||
/* $Id$ */
|
||||
/**************************************************************************
|
||||
* nano.c *
|
||||
* *
|
||||
@@ -32,7 +32,10 @@
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
#ifdef ENABLE_UTF8
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
#include <termios.h>
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
@@ -65,6 +68,10 @@ filestruct *make_new_node(filestruct *prevnode)
|
||||
newnode->next = NULL;
|
||||
newnode->lineno = (prevnode != NULL) ? prevnode->lineno + 1 : 1;
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
newnode->multidata = NULL;
|
||||
#endif
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
@@ -81,6 +88,9 @@ filestruct *copy_node(const filestruct *src)
|
||||
dst->next = src->next;
|
||||
dst->prev = src->prev;
|
||||
dst->lineno = src->lineno;
|
||||
#ifdef ENABLE_COLOR
|
||||
dst->multidata = NULL;
|
||||
#endif
|
||||
|
||||
return dst;
|
||||
}
|
||||
@@ -117,6 +127,11 @@ void delete_node(filestruct *fileptr)
|
||||
if (fileptr->data != NULL)
|
||||
free(fileptr->data);
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
if (fileptr->multidata)
|
||||
free(fileptr->multidata);
|
||||
#endif
|
||||
|
||||
free(fileptr);
|
||||
}
|
||||
|
||||
@@ -354,6 +369,10 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
|
||||
openfile->fileage->data = mallocstrcpy(NULL, "");
|
||||
openfile->filebot = openfile->fileage;
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
openfile->fileage->multidata = NULL;
|
||||
#endif
|
||||
|
||||
/* Restore the current line and cursor position. If the mark begins
|
||||
* inside the partition, set the beginning of the mark to where the
|
||||
* saved text used to start. */
|
||||
@@ -502,6 +521,9 @@ openfilestruct *make_new_opennode(void)
|
||||
newnode->filebot = NULL;
|
||||
newnode->edittop = NULL;
|
||||
newnode->current = NULL;
|
||||
#ifndef NANO_TINY
|
||||
newnode->last_action = OTHER;
|
||||
#endif
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -1014,6 +1036,75 @@ void do_exit(void)
|
||||
display_main_list();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static struct sigaction pager_oldaction, pager_newaction; /* Original and temporary handlers for SIGINT. */
|
||||
static bool pager_sig_failed = FALSE; /* Did sigaction() fail without changing the signal handlers? */
|
||||
|
||||
/* Things which need to be run regardless of whether
|
||||
we finished the stdin pipe correctly or not */
|
||||
void finish_stdin_pager(void)
|
||||
{
|
||||
FILE *f;
|
||||
int ttystdin;
|
||||
|
||||
/* Read whatever we did get from stdin */
|
||||
f = fopen("/dev/stdin", "rb");
|
||||
if (f == NULL)
|
||||
nperror("fopen");
|
||||
|
||||
read_file(f, "stdin", TRUE);
|
||||
ttystdin = open("/dev/tty", O_RDONLY);
|
||||
if (!ttystdin)
|
||||
die(_("Couldn't reopen stdin from keyboard, sorry\n"));
|
||||
|
||||
dup2(ttystdin,0);
|
||||
close(ttystdin);
|
||||
tcgetattr(0, &oldterm);
|
||||
if (!pager_sig_failed && sigaction(SIGINT, &pager_oldaction, NULL) == -1)
|
||||
nperror("sigaction");
|
||||
terminal_init();
|
||||
doupdate();
|
||||
}
|
||||
|
||||
|
||||
/* Cancel reading from stdin like a pager */
|
||||
RETSIGTYPE cancel_stdin_pager(int signal)
|
||||
{
|
||||
/* Currently do nothing, just handle the intr silently */
|
||||
}
|
||||
|
||||
/* Let nano read stdin for the first file at least */
|
||||
void stdin_pager(void)
|
||||
{
|
||||
endwin();
|
||||
tcsetattr(0, TCSANOW, &oldterm);
|
||||
fprintf(stderr, _("Reading from stdin, ^C to abort\n"));
|
||||
|
||||
/* Set things up so that Ctrl-C will cancel the new process. */
|
||||
/* Enable interpretation of the special control keys so that we get
|
||||
* SIGINT when Ctrl-C is pressed. */
|
||||
#ifndef NANO_TINY
|
||||
enable_signals();
|
||||
#endif
|
||||
|
||||
if (sigaction(SIGINT, NULL, &pager_newaction) == -1) {
|
||||
pager_sig_failed = TRUE;
|
||||
nperror("sigaction");
|
||||
} else {
|
||||
pager_newaction.sa_handler = cancel_stdin_pager;
|
||||
if (sigaction(SIGINT, &pager_newaction, &pager_oldaction) == -1) {
|
||||
pager_sig_failed = TRUE;
|
||||
nperror("sigaction");
|
||||
}
|
||||
}
|
||||
|
||||
open_buffer("", FALSE);
|
||||
finish_stdin_pager();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Initialize the signal handlers. */
|
||||
void signal_init(void)
|
||||
{
|
||||
@@ -1268,7 +1359,6 @@ void disable_extended_io(void)
|
||||
tcsetattr(0, TCSANOW, &term);
|
||||
}
|
||||
|
||||
#ifdef USE_SLANG
|
||||
/* Disable interpretation of the special control keys in our terminal
|
||||
* settings. */
|
||||
void disable_signals(void)
|
||||
@@ -1279,7 +1369,6 @@ void disable_signals(void)
|
||||
term.c_lflag &= ~ISIG;
|
||||
tcsetattr(0, TCSANOW, &term);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* Enable interpretation of the special control keys in our terminal
|
||||
@@ -1346,8 +1435,8 @@ void terminal_init(void)
|
||||
if (ISSET(PRESERVE))
|
||||
enable_flow_control();
|
||||
|
||||
#ifdef USE_SLANG
|
||||
disable_signals();
|
||||
#ifdef USE_SLANG
|
||||
if (!ISSET(PRESERVE))
|
||||
disable_flow_control();
|
||||
|
||||
@@ -1436,6 +1525,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||
kbinput = (int *)nrealloc(kbinput, kbinput_len *
|
||||
sizeof(int));
|
||||
kbinput[kbinput_len - 1] = input;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1450,7 +1540,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||
* for verbatim input, turn off prepending of wrapped
|
||||
* text. */
|
||||
if (have_shortcut && (!have_shortcut || s == NULL || s->scfunc !=
|
||||
do_verbatim_input))
|
||||
DO_VERBATIM_INPUT))
|
||||
wrap_reset();
|
||||
#endif
|
||||
|
||||
@@ -1485,27 +1575,40 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||
default:
|
||||
/* If the function associated with this shortcut is
|
||||
* cutting or copying text, indicate this. */
|
||||
if (s->scfunc == do_cut_text_void
|
||||
if (s->scfunc == DO_CUT_TEXT_VOID
|
||||
#ifndef NANO_TINY
|
||||
|| s->scfunc == do_copy_text || s->scfunc ==
|
||||
do_cut_till_end
|
||||
|| s->scfunc == DO_COPY_TEXT || s->scfunc ==
|
||||
DO_CUT_TILL_END
|
||||
#endif
|
||||
)
|
||||
cut_copy = TRUE;
|
||||
|
||||
if (s->scfunc != NULL) {
|
||||
if (s->scfunc != 0) {
|
||||
const subnfunc *f = sctofunc((sc *) s);
|
||||
*ran_func = TRUE;
|
||||
if (ISSET(VIEW_MODE) && f && !f->viewok)
|
||||
print_view_warning();
|
||||
else
|
||||
#ifndef NANO_TINY
|
||||
if (s->scfunc == (void *) do_toggle)
|
||||
if (s->scfunc == DO_TOGGLE)
|
||||
do_toggle(s->toggle);
|
||||
else
|
||||
else {
|
||||
#endif
|
||||
s->scfunc();
|
||||
iso_me_harder_funcmap(s->scfunc);
|
||||
#ifdef ENABLE_COLOR
|
||||
if (!f->viewok && openfile->syntax != NULL
|
||||
&& openfile->current->multidata && openfile->syntax->nmultis > 0) {
|
||||
reset_multis(openfile->current);
|
||||
}
|
||||
if (edit_refresh_needed) {
|
||||
edit_refresh();
|
||||
edit_refresh_needed = FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifndef NANO_TINY
|
||||
}
|
||||
#endif
|
||||
*finished = TRUE;
|
||||
break;
|
||||
}
|
||||
@@ -1543,7 +1646,7 @@ int do_mouse(void)
|
||||
bool sameline;
|
||||
/* Did they click on the line with the cursor? If they
|
||||
* clicked on the cursor, we set the mark. */
|
||||
const filestruct *current_save = openfile->current;
|
||||
filestruct *current_save = openfile->current;
|
||||
size_t current_x_save = openfile->current_x;
|
||||
size_t pww_save = openfile->placewewant;
|
||||
|
||||
@@ -1576,6 +1679,94 @@ int do_mouse(void)
|
||||
}
|
||||
#endif /* !DISABLE_MOUSE */
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
void alloc_multidata_if_needed(filestruct *fileptr)
|
||||
{
|
||||
if (!fileptr->multidata)
|
||||
fileptr->multidata = nmalloc(openfile->syntax->nmultis * sizeof(short));
|
||||
}
|
||||
|
||||
/* Precalculate the multi-line start and end regex info so we can speed up
|
||||
rendering (with any hope at all...) */
|
||||
void precalc_multicolorinfo(void)
|
||||
{
|
||||
if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) {
|
||||
const colortype *tmpcolor = openfile->colorstrings;
|
||||
regmatch_t startmatch, endmatch;
|
||||
filestruct *fileptr, *endptr;
|
||||
time_t last_check = time(NULL), cur_check = 0;
|
||||
|
||||
/* Let us get keypresses to see if the user is trying to
|
||||
start editing. We may want to throw up a statusbar
|
||||
message before starting this later if it takes
|
||||
too long to do this routine. For now silently
|
||||
abort if they hit a key */
|
||||
nodelay(edit, FALSE);
|
||||
|
||||
for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
|
||||
|
||||
/* If it's not a multi-line regex, amscray */
|
||||
if (tmpcolor->end == NULL)
|
||||
continue;
|
||||
|
||||
for (fileptr = openfile->fileage; fileptr != NULL; fileptr = fileptr->next) {
|
||||
int startx = 0;
|
||||
|
||||
alloc_multidata_if_needed(fileptr);
|
||||
|
||||
if ((cur_check = time(NULL)) - last_check > 1) {
|
||||
last_check = cur_check;
|
||||
if (wgetch(edit) != ERR)
|
||||
goto precalc_cleanup;
|
||||
}
|
||||
|
||||
fileptr->multidata[tmpcolor->id] = CNONE;
|
||||
while (regexec(tmpcolor->start, &fileptr->data[startx], 1, &startmatch, 0) == 0) {
|
||||
/* Look for end and start marking how many lines are encompassed
|
||||
whcih should speed up rendering later */
|
||||
startx += startmatch.rm_eo;
|
||||
|
||||
/* Look on this line first for end */
|
||||
if (regexec(tmpcolor->end, &fileptr->data[startx], 1, &endmatch, 0) == 0) {
|
||||
startx += endmatch.rm_eo;
|
||||
fileptr->multidata[tmpcolor->id] |= CSTARTENDHERE;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Nice, we didn't find the end regex on this line. Let's start looking for it */
|
||||
for (endptr = fileptr->next; endptr != NULL; endptr = endptr->next) {
|
||||
|
||||
/* Check for keyboard input again */
|
||||
if ((cur_check = time(NULL)) - last_check > 1) {
|
||||
last_check = cur_check;
|
||||
if (wgetch(edit) != ERR)
|
||||
goto precalc_cleanup;
|
||||
}
|
||||
if (regexec(tmpcolor->end, &endptr->data[startx], 1, &endmatch, 0) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (endptr == NULL)
|
||||
break;
|
||||
|
||||
/* We found it, we found it, la la la la la. Mark all the
|
||||
lines in between and the ends properly */
|
||||
fileptr->multidata[tmpcolor->id] |= CENDAFTER;
|
||||
for (fileptr = fileptr->next; fileptr != endptr; fileptr = fileptr->next) {
|
||||
alloc_multidata_if_needed(fileptr);
|
||||
fileptr->multidata[tmpcolor->id] = CWHOLELINE;
|
||||
}
|
||||
alloc_multidata_if_needed(endptr);
|
||||
endptr->multidata[tmpcolor->id] |= CBEGINBEFORE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
precalc_cleanup:
|
||||
nodelay(edit, FALSE);
|
||||
}
|
||||
#endif /* ENABLE_COLOR */
|
||||
|
||||
/* The user typed output_len multibyte characters. Add them to the edit
|
||||
* buffer, filtering out all ASCII control characters if allow_cntrls is
|
||||
* TRUE. */
|
||||
@@ -1642,6 +1833,9 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
||||
set_modified();
|
||||
|
||||
#ifndef NANO_TINY
|
||||
update_undo(ADD);
|
||||
|
||||
|
||||
/* Note that current_x has not yet been incremented. */
|
||||
if (openfile->mark_set && openfile->current ==
|
||||
openfile->mark_begin && openfile->current_x <
|
||||
@@ -1677,9 +1871,14 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
||||
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
if (do_refresh)
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
reset_multis(openfile->current);
|
||||
#endif
|
||||
if (do_refresh) {
|
||||
edit_refresh();
|
||||
else
|
||||
edit_refresh_needed = FALSE;
|
||||
} else
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
}
|
||||
|
||||
@@ -2206,6 +2405,12 @@ int main(int argc, char **argv)
|
||||
optind++;
|
||||
}
|
||||
|
||||
if (optind < argc && !strcmp(argv[optind], "-")) {
|
||||
stdin_pager();
|
||||
set_modified();
|
||||
optind++;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
old_multibuffer = ISSET(MULTIBUFFER);
|
||||
SET(MULTIBUFFER);
|
||||
@@ -2224,7 +2429,7 @@ int main(int argc, char **argv)
|
||||
icol == 1)
|
||||
parse_line_column(&argv[i][1], &iline, &icol);
|
||||
else {
|
||||
open_buffer(argv[i]);
|
||||
open_buffer(argv[i], FALSE);
|
||||
|
||||
if (iline > 1 || icol > 1) {
|
||||
do_gotolinecolumn(iline, icol, FALSE, FALSE, FALSE,
|
||||
@@ -2241,14 +2446,14 @@ int main(int argc, char **argv)
|
||||
* buffer or a new buffer, depending on whether multibuffer mode is
|
||||
* enabled. */
|
||||
if (optind < argc)
|
||||
open_buffer(argv[optind]);
|
||||
open_buffer(argv[optind], FALSE);
|
||||
|
||||
/* We didn't open any files if all the command line arguments were
|
||||
* invalid files like directories or if there were no command line
|
||||
* arguments given. In this case, we have to load a blank buffer.
|
||||
* Also, we unset view mode to allow editing. */
|
||||
if (openfile == NULL) {
|
||||
open_buffer("");
|
||||
open_buffer("", FALSE);
|
||||
UNSET(VIEW_MODE);
|
||||
}
|
||||
|
||||
@@ -2261,6 +2466,11 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "Main: top and bottom win\n");
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
if (openfile->syntax && openfile->syntax->nmultis > 0)
|
||||
precalc_multicolorinfo();
|
||||
#endif
|
||||
|
||||
if (startline > 1 || startcol > 1)
|
||||
do_gotolinecolumn(startline, startcol, FALSE, FALSE, FALSE,
|
||||
FALSE);
|
||||
@@ -2307,3 +2517,4 @@ int main(int argc, char **argv)
|
||||
/* We should never get here. */
|
||||
assert(FALSE);
|
||||
}
|
||||
|
||||
|
||||
312
src/nano.h
312
src/nano.h
@@ -169,35 +169,9 @@ typedef enum {
|
||||
CONTROL, META, FKEY, RAW
|
||||
} function_type;
|
||||
|
||||
/* Structure types. */
|
||||
typedef struct filestruct {
|
||||
char *data;
|
||||
/* The text of this line. */
|
||||
ssize_t lineno;
|
||||
/* The number of this line. */
|
||||
struct filestruct *next;
|
||||
/* Next node. */
|
||||
struct filestruct *prev;
|
||||
/* Previous node. */
|
||||
} filestruct;
|
||||
|
||||
typedef struct partition {
|
||||
filestruct *fileage;
|
||||
/* The top line of this portion of the file. */
|
||||
filestruct *top_prev;
|
||||
/* The line before the top line of this portion of the file. */
|
||||
char *top_data;
|
||||
/* The text before the beginning of the top line of this portion
|
||||
* of the file. */
|
||||
filestruct *filebot;
|
||||
/* The bottom line of this portion of the file. */
|
||||
filestruct *bot_next;
|
||||
/* The line after the bottom line of this portion of the
|
||||
* file. */
|
||||
char *bot_data;
|
||||
/* The text after the end of the bottom line of this portion of
|
||||
* the file. */
|
||||
} partition;
|
||||
typedef enum {
|
||||
ADD, DEL, REPLACE, SPLIT, UNSPLIT, CUT, UNCUT, INSERT, OTHER
|
||||
} undo_type;
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
typedef struct colortype {
|
||||
@@ -222,6 +196,8 @@ typedef struct colortype {
|
||||
/* The compiled end (if any) of the regex string. */
|
||||
struct colortype *next;
|
||||
/* Next set of colors. */
|
||||
int id;
|
||||
/* basic id for assigning to lines later */
|
||||
} colortype;
|
||||
|
||||
typedef struct exttype {
|
||||
@@ -238,13 +214,97 @@ typedef struct syntaxtype {
|
||||
/* The name of this syntax. */
|
||||
exttype *extensions;
|
||||
/* The list of extensions that this syntax applies to. */
|
||||
exttype *headers;
|
||||
/* Regexes to match on the 'header' (1st line) of the file */
|
||||
colortype *color;
|
||||
/* The colors used in this syntax. */
|
||||
int nmultis;
|
||||
/* How many multi line strings this syntax has */
|
||||
struct syntaxtype *next;
|
||||
/* Next syntax. */
|
||||
} syntaxtype;
|
||||
|
||||
#define CNONE (1<<1)
|
||||
/* Yay, regex doesn't apply to this line at all! */
|
||||
#define CBEGINBEFORE (1<<2)
|
||||
/* regex starts on an earlier line, ends on this one */
|
||||
#define CENDAFTER (1<<3)
|
||||
/* regex sraers on this line and ends on a later one */
|
||||
#define CWHOLELINE (1<<4)
|
||||
/* whole line engulfed by the regex start < me, end > me */
|
||||
#define CSTARTENDHERE (1<<5)
|
||||
/* regex starts and ends within this line */
|
||||
#define CWTF (1<<6)
|
||||
/* Something else */
|
||||
|
||||
#endif /* ENABLE_COLOR */
|
||||
|
||||
|
||||
/* Structure types. */
|
||||
typedef struct filestruct {
|
||||
char *data;
|
||||
/* The text of this line. */
|
||||
ssize_t lineno;
|
||||
/* The number of this line. */
|
||||
struct filestruct *next;
|
||||
/* Next node. */
|
||||
struct filestruct *prev;
|
||||
/* Previous node. */
|
||||
#ifdef ENABLE_COLOR
|
||||
short *multidata; /* Array of which multi-line regexes apply to this line */
|
||||
#endif
|
||||
} filestruct;
|
||||
|
||||
typedef struct partition {
|
||||
filestruct *fileage;
|
||||
/* The top line of this portion of the file. */
|
||||
filestruct *top_prev;
|
||||
/* The line before the top line of this portion of the file. */
|
||||
char *top_data;
|
||||
/* The text before the beginning of the top line of this portion
|
||||
* of the file. */
|
||||
filestruct *filebot;
|
||||
/* The bottom line of this portion of the file. */
|
||||
filestruct *bot_next;
|
||||
/* The line after the bottom line of this portion of the
|
||||
* file. */
|
||||
char *bot_data;
|
||||
/* The text after the end of the bottom line of this portion of
|
||||
* the file. */
|
||||
} partition;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
typedef struct undo {
|
||||
ssize_t lineno;
|
||||
undo_type type;
|
||||
/* What type of undo was this */
|
||||
int begin;
|
||||
/* Where did this action begin or end */
|
||||
char *strdata;
|
||||
/* String type data we will use for ccopying the affected line back */
|
||||
int xflags;
|
||||
/* Some flag data we need */
|
||||
|
||||
/* Cut specific stuff we need */
|
||||
filestruct *cutbuffer;
|
||||
/* Copy of the cutbuffer */
|
||||
filestruct *cutbottom;
|
||||
/* Copy of cutbottom */
|
||||
bool mark_set;
|
||||
/* was the marker set when we cut */
|
||||
bool to_end;
|
||||
/* was this a cut to end */
|
||||
ssize_t mark_begin_lineno;
|
||||
/* copy copy copy */
|
||||
ssize_t mark_begin_x;
|
||||
/* Another shadow variable */
|
||||
struct undo *next;
|
||||
} undo;
|
||||
|
||||
|
||||
#endif /* NANO_TINY */
|
||||
|
||||
|
||||
typedef struct openfilestruct {
|
||||
char *filename;
|
||||
/* The current file's name. */
|
||||
@@ -278,8 +338,15 @@ typedef struct openfilestruct {
|
||||
/* The current file's format. */
|
||||
struct stat *current_stat;
|
||||
/* The current file's stat. */
|
||||
undo *undotop;
|
||||
/* Top of the undo list */
|
||||
undo *current_undo;
|
||||
/* The current (i.e. n ext) level of undo */
|
||||
undo_type last_action;
|
||||
#endif
|
||||
#ifdef ENABLE_COLOR
|
||||
syntaxtype *syntax;
|
||||
/* The syntax struct for this file, if any */
|
||||
colortype *colorstrings;
|
||||
/* The current file's associated colors. */
|
||||
#endif
|
||||
@@ -318,25 +385,6 @@ typedef struct shortcut {
|
||||
/* Next shortcut. */
|
||||
} shortcut;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
typedef struct toggle {
|
||||
int val;
|
||||
/* The sequence to toggle the key. We should only need one. */
|
||||
const char *desc;
|
||||
/* The description of the toggle, e.g. "Cut to end"; we'll
|
||||
* append Enabled or Disabled to it. */
|
||||
#ifndef DISABLE_HELP
|
||||
bool blank_after;
|
||||
/* Whether there should be a blank line after the description of
|
||||
* the toggle. */
|
||||
#endif
|
||||
long flag;
|
||||
/* Which flag actually gets toggled. */
|
||||
struct toggle *next;
|
||||
/* Next toggle. */
|
||||
} toggle;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_NANORC
|
||||
typedef struct rcoption {
|
||||
const char *name;
|
||||
@@ -356,7 +404,7 @@ typedef struct sc {
|
||||
/* The actual sequence to check on the the type is determined */
|
||||
int menu;
|
||||
/* What list does this apply to */
|
||||
void (*scfunc)(void);
|
||||
short scfunc;
|
||||
/* The function we're going to run */
|
||||
int toggle;
|
||||
/* If a toggle, what we're toggling */
|
||||
@@ -368,7 +416,7 @@ typedef struct sc {
|
||||
} sc;
|
||||
|
||||
typedef struct subnfunc {
|
||||
void (*scfunc)(void);
|
||||
short scfunc;
|
||||
/* What function is this */
|
||||
int menus;
|
||||
/* In what menus does this function applu */
|
||||
@@ -667,8 +715,172 @@ typedef struct subnfunc {
|
||||
#define TOGGLE_BACKWARDS_KEY NANO_META_B
|
||||
#define TOGGLE_DOS_KEY NANO_META_D
|
||||
#define TOGGLE_MAC_KEY NANO_META_M
|
||||
|
||||
/* Extra bits for the undo function */
|
||||
#define UNDO_DEL_DEL (1<<0)
|
||||
#define UNDO_DEL_BACKSPACE (1<<1)
|
||||
|
||||
/* Since in ISO C you can't pass around function pointers anymore,
|
||||
let's make some integer macros for function names, and then I
|
||||
can go cut my wrists after writing the big switch statement
|
||||
that will necessitate. */
|
||||
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
#define CASE_SENS_MSG 1
|
||||
#define BACKWARDS_MSG 2
|
||||
#define REGEXP_MSG 3
|
||||
#define WHEREIS_NEXT_MSG 4
|
||||
#define FIRST_FILE_MSG 5
|
||||
#define LAST_FILE_MSG 6
|
||||
#define GOTO_DIR_MSG 7
|
||||
#define TOTAL_REFRESH 8
|
||||
#define DO_HELP_VOID 9
|
||||
#define DO_SEARCH 10
|
||||
#define DO_PAGE_UP 11
|
||||
#define DO_PAGE_DOWN 12
|
||||
#define DO_UP_VOID 13
|
||||
#define DO_LEFT 14
|
||||
#define DO_DOWN_VOID 15
|
||||
#define DO_RIGHT 16
|
||||
#define DO_ENTER 17
|
||||
#define DO_EXIT 18
|
||||
#define NEW_BUFFER_MSG 19
|
||||
#define EXT_CMD_MSG 20
|
||||
#define TO_FILES_MSG 21
|
||||
#define DOS_FORMAT_MSG 23
|
||||
#define MAC_FORMAT_MSG 24
|
||||
#define BACKUP_FILE_MSG 25
|
||||
#define PREPEND_MSG 26
|
||||
#define APPEND_MSG 27
|
||||
#define DO_FIRST_LINE 28
|
||||
#define DO_LAST_LINE 29
|
||||
#define DO_TOGGLE 30
|
||||
#define GOTOTEXT_MSG 31
|
||||
#define NO_REPLACE_MSG 32
|
||||
#define DO_BACKSPACE 33
|
||||
#define DO_DELETE 34
|
||||
#define DO_TAB 35
|
||||
#define DO_VERBATIM_INPUT 36
|
||||
#define SWITCH_TO_NEXT_BUFFER_VOID 37
|
||||
#define SWITCH_TO_PREV_BUFFER_VOID 38
|
||||
#define DO_END 39
|
||||
#define DO_HOME 40
|
||||
#define NEXT_HISTORY_MSG 41
|
||||
#define PREV_HISTORY_MSG 42
|
||||
#define DO_REDO 43
|
||||
#define DO_UNDO 44
|
||||
#define DO_WORDLINECHAR_COUNT 45
|
||||
#define DO_FIND_BRACKET 46
|
||||
#define DO_PREV_WORD_VOID 47
|
||||
#define DO_SUSPEND_VOID 48
|
||||
#define CANCEL_MSG 49
|
||||
#define DO_WRITEOUT_VOID 50
|
||||
#define DO_INSERTFILE_VOID 51
|
||||
#define DO_CUT_TEXT_VOID 52
|
||||
#define DO_UNCUT_TEXT 53
|
||||
#define DO_CURSORPOS_VOID 54
|
||||
#define DO_GOTOLINECOLUMN_VOID 55
|
||||
#define DO_REPLACE 56
|
||||
#define DO_JUSTIFY_VOID 57
|
||||
#define DO_PARA_BEGIN_VOID 58
|
||||
#define DO_PARA_END_VOID 59
|
||||
#define DO_FULL_JUSTIFY 60
|
||||
#define DO_MARK 61
|
||||
#define DO_RESEARCH 62
|
||||
#define DO_COPY_TEXT 63
|
||||
#define DO_INDENT_VOID 64
|
||||
#define DO_UNINDENT 65
|
||||
#define DO_SCROLL_UP 66
|
||||
#define DO_SCROLL_DOWN 67
|
||||
#define DO_NEXT_WORD_VOID 68
|
||||
#define DO_CUT_TILL_END 69
|
||||
#define NANO_GOTODIR_MSG 70
|
||||
#define NANO_LASTFILE_MSG 71
|
||||
#define NANO_FIRSTFILE_MSG 72
|
||||
#define INSERT_FILE_MSG 73
|
||||
#define NANO_MULTIBUFFER_MSG 74
|
||||
#define NANO_EXECUTE_MSG 75
|
||||
#define NANO_BACKUP_MSG 76
|
||||
#define NANO_PREPEND_MSG 77
|
||||
#define NANO_APPEND_MSG 78
|
||||
#define NANO_MAC_MSG 79
|
||||
#define NANO_DOS_MSG 80
|
||||
#define NANO_TOFILES_MSG 81
|
||||
#define NANO_NEXT_HISTORY_MSG 82
|
||||
#define NANO_PREV_HISTORY_MSG 83
|
||||
#define NANO_REGEXP_MSG 84
|
||||
#define NANO_REVERSE_MSG 85
|
||||
#define NANO_CASE_MSG 86
|
||||
#define NANO_SUSPEND_MSG 87
|
||||
#define SUSPEND_MSG 88
|
||||
#define NANO_REFRESH_MSG 89
|
||||
#define REFRESH_MSG 90
|
||||
#define NANO_WORDCOUNT_MSG 91
|
||||
#define NANO_FULLJUSTIFY_MSG 92
|
||||
#define FULLJSTIFY_MSG 93
|
||||
#define XOFF_COMPLAINT 94
|
||||
#define XON_COMPLAINT 95
|
||||
#define NANO_CUT_TILL_END_MSG 96
|
||||
#define NANO_BACKSPACE_MSG 97
|
||||
#define NANO_DELETE_MSG 98
|
||||
#define NANO_ENTER_MSG 99
|
||||
#define NANO_TAB_MSG 100
|
||||
#define NANO_VERBATIM_MSG 101
|
||||
#define NANO_NEXTFILE_MSG 102
|
||||
#define NANO_PREVFILE_MSG 103
|
||||
#define NANO_SCROLLDOWN_MSG 104
|
||||
#define NANO_SCROLLUP_MSG 105
|
||||
#define NANO_BRACKET_MSG 106
|
||||
#define NANO_PARAEND_MSG 107
|
||||
#define END_OF_PAR_MSG 108
|
||||
#define NANO_PARABEGIN_MSG 109
|
||||
#define BEG_OF_PAR_MSG 110
|
||||
#define NANO_END_MSG 111
|
||||
#define NANO_HOME_MSG 112
|
||||
#define NANO_NEXTLINE_MSG 113
|
||||
#define NANO_PREVLINE_MSG 114
|
||||
#define NANO_PREVWORD_MSG 115
|
||||
#define NANO_NEXTWORD_MSG 116
|
||||
#define NANO_BACK_MSG 117
|
||||
#define NANO_FORWARD_MSG 118
|
||||
#define NANO_REDO_MSG 119
|
||||
#define NANO_UNDO_MSG 120
|
||||
#define NANO_UNINDENT_MSG 121
|
||||
#define NANO_INDENT_MSG 122
|
||||
#define NANO_COPY_MSG 123
|
||||
#define NANO_WHEREIS_NEXT_MSG 124
|
||||
#define NANO_MARK_MSG 125
|
||||
#define NANO_REPLACE_MSG 126
|
||||
#define REPLACE_MSG 127
|
||||
#define NANO_GOTOLINE_MSG 128
|
||||
#define NANO_LASTLINE_MSG 129
|
||||
#define NANO_FIRSTLINE_MSG 130
|
||||
#define NANO_SPELL_MSG 131
|
||||
#define DO_SPELL 132
|
||||
#define NANO_CURSORPOS_MSG 133
|
||||
#define NANO_UNCUT_MSG 134
|
||||
#define GET_HELP_MSG 135
|
||||
#define NANO_HELP_MSG 136
|
||||
#define NANO_CANCEL_MSG 137
|
||||
#define NANO_EXIT_MSG 138
|
||||
#define EXIT_MSG 139
|
||||
#define NANO_EXITBROWSER_MSG 140
|
||||
#define NANO_WRITEOUT_MSG 141
|
||||
#define NANO_DISABLED_MSG 142
|
||||
#define NANO_INSERT_MSG 143
|
||||
#define WHEREIS_MSG 144
|
||||
#define NANO_WHEREIS_MSG 145
|
||||
#define NANO_PREVPAGE_MSG 146
|
||||
#define NANO_NEXTPAGE_MSG 147
|
||||
#define NANO_CUT_MSG 148
|
||||
#define DO_CUT_TEXT 149
|
||||
#define DO_NEXT_WORD 150
|
||||
#define DO_PREV_WORD 151
|
||||
|
||||
|
||||
|
||||
|
||||
#define VIEW TRUE
|
||||
#define NOVIEW FALSE
|
||||
|
||||
|
||||
56
src/prompt.c
56
src/prompt.c
@@ -152,38 +152,38 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *have_shortcut,
|
||||
}
|
||||
|
||||
if (*have_shortcut) {
|
||||
if (s->scfunc == do_tab || s->scfunc == do_enter)
|
||||
if (s->scfunc == DO_TAB || s->scfunc == DO_ENTER)
|
||||
;
|
||||
else if (s->scfunc == total_refresh)
|
||||
else if (s->scfunc == TOTAL_REFRESH)
|
||||
total_statusbar_refresh(refresh_func);
|
||||
else if (s->scfunc == (void *) do_cut_text) {
|
||||
else if (s->scfunc == DO_CUT_TEXT) {
|
||||
/* If we're using restricted mode, the filename
|
||||
* isn't blank, and we're at the "Write File"
|
||||
* prompt, disable Cut. */
|
||||
if (!ISSET(RESTRICTED) || openfile->filename[0] ==
|
||||
'\0' || currmenu != MWRITEFILE)
|
||||
do_statusbar_cut_text();
|
||||
} else if (s->scfunc == do_right)
|
||||
} else if (s->scfunc == DO_RIGHT)
|
||||
do_statusbar_right();
|
||||
else if (s->scfunc == do_left)
|
||||
else if (s->scfunc == DO_LEFT)
|
||||
do_statusbar_left();
|
||||
|
||||
#ifndef NANO_TINY
|
||||
else if (s->scfunc == (void *) do_next_word)
|
||||
else if (s->scfunc == DO_NEXT_WORD)
|
||||
do_statusbar_next_word(FALSE);
|
||||
else if (s->scfunc == (void *) do_prev_word)
|
||||
else if (s->scfunc == DO_PREV_WORD)
|
||||
do_statusbar_prev_word(FALSE);
|
||||
#endif
|
||||
else if (s->scfunc == do_home)
|
||||
else if (s->scfunc == DO_HOME)
|
||||
do_statusbar_home();
|
||||
else if (s->scfunc == do_end)
|
||||
else if (s->scfunc == DO_END)
|
||||
do_statusbar_end();
|
||||
|
||||
#ifndef NANO_TINY
|
||||
else if (s->scfunc == do_find_bracket)
|
||||
else if (s->scfunc == DO_FIND_BRACKET)
|
||||
do_statusbar_find_bracket();
|
||||
#endif
|
||||
else if (s->scfunc == do_verbatim_input) {
|
||||
else if (s->scfunc == DO_VERBATIM_INPUT) {
|
||||
/* If we're using restricted mode, the filename
|
||||
* isn't blank, and we're at the "Write File"
|
||||
* prompt, disable verbatim input. */
|
||||
@@ -201,18 +201,18 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *have_shortcut,
|
||||
* to indicate that we're done. */
|
||||
if (got_enter) {
|
||||
get_input(NULL, 1);
|
||||
input = sc_seq_or(do_enter, 0);
|
||||
input = sc_seq_or(DO_ENTER, 0);
|
||||
*finished = TRUE;
|
||||
}
|
||||
}
|
||||
} else if (s->scfunc == do_delete) {
|
||||
} else if (s->scfunc == DO_DELETE) {
|
||||
/* If we're using restricted mode, the filename
|
||||
* isn't blank, and we're at the "Write File"
|
||||
* prompt, disable Delete. */
|
||||
if (!ISSET(RESTRICTED) || openfile->filename[0] ==
|
||||
'\0' || currmenu != MWRITEFILE)
|
||||
do_statusbar_delete();
|
||||
} else if (s->scfunc == do_backspace) {
|
||||
} else if (s->scfunc == DO_BACKSPACE) {
|
||||
/* If we're using restricted mode, the filename
|
||||
* isn't blank, and we're at the "Write File"
|
||||
* prompt, disable Backspace. */
|
||||
@@ -227,10 +227,10 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *have_shortcut,
|
||||
* associated functions. */
|
||||
|
||||
f = sctofunc((sc *) s);
|
||||
if (s->scfunc != NULL && s->execute == TRUE) {
|
||||
if (s->scfunc != 0 && s->execute == TRUE) {
|
||||
*ran_func = TRUE;
|
||||
if (!ISSET(VIEW_MODE) || f->viewok)
|
||||
f->scfunc();
|
||||
iso_me_harder_funcmap(f->scfunc);
|
||||
}
|
||||
*finished = TRUE;
|
||||
}
|
||||
@@ -979,19 +979,19 @@ fprintf(stderr, "get_prompt_string: answer = \"%s\", statusbar_x = %d\n", answer
|
||||
s = get_shortcut(currmenu, &kbinput, meta_key, func_key);
|
||||
|
||||
if (s)
|
||||
if (s->scfunc == (void *) cancel_msg || s->scfunc == do_enter)
|
||||
if (s->scfunc == CANCEL_MSG || s->scfunc == DO_ENTER)
|
||||
break;
|
||||
|
||||
#ifndef DISABLE_TABCOMP
|
||||
if (s && s->scfunc != do_tab)
|
||||
if (s && s->scfunc != DO_TAB)
|
||||
tabbed = FALSE;
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_TABCOMP
|
||||
#ifndef NANO_TINY
|
||||
if (s && s->scfunc == do_tab) {
|
||||
if (s && s->scfunc == DO_TAB) {
|
||||
if (history_list != NULL) {
|
||||
if (last_kbinput != sc_seq_or(do_tab, NANO_CONTROL_I))
|
||||
if (last_kbinput != sc_seq_or(DO_TAB, NANO_CONTROL_I))
|
||||
complete_len = strlen(answer);
|
||||
|
||||
if (complete_len > 0) {
|
||||
@@ -1010,7 +1010,7 @@ fprintf(stderr, "get_prompt_string: answer = \"%s\", statusbar_x = %d\n", answer
|
||||
} else
|
||||
#endif /* !DISABLE_TABCOMP */
|
||||
#ifndef NANO_TINY
|
||||
if (s && s->scfunc == (void *) prev_history_msg) {
|
||||
if (s && s->scfunc == PREV_HISTORY_MSG) {
|
||||
if (history_list != NULL) {
|
||||
/* If we're scrolling up at the bottom of the
|
||||
* history list and answer isn't blank, save answer
|
||||
@@ -1038,7 +1038,7 @@ fprintf(stderr, "get_prompt_string: answer = \"%s\", statusbar_x = %d\n", answer
|
||||
* statusbar prompt. */
|
||||
finished = FALSE;
|
||||
}
|
||||
} else if (s && s->scfunc == (void *) next_history_msg) {
|
||||
} else if (s && s->scfunc == NEXT_HISTORY_MSG) {
|
||||
if (history_list != NULL) {
|
||||
/* Get the newer search from the history list and
|
||||
* save it in answer. If there is no newer search,
|
||||
@@ -1071,7 +1071,7 @@ fprintf(stderr, "get_prompt_string: answer = \"%s\", statusbar_x = %d\n", answer
|
||||
} else
|
||||
#endif /* !NANO_TINY */
|
||||
#ifndef DISABLE_HELP
|
||||
if (s && s->scfunc == do_help_void) {
|
||||
if (s && s->scfunc == DO_HELP_VOID) {
|
||||
update_statusbar_line(answer, statusbar_x);
|
||||
|
||||
/* This key has a shortcut list entry when it's used to
|
||||
@@ -1116,7 +1116,7 @@ fprintf(stderr, "get_prompt_string: answer = \"%s\", statusbar_x = %d\n", answer
|
||||
* we've finished putting in an answer, reset the statusbar cursor
|
||||
* position too. */
|
||||
if (s) {
|
||||
if (s->scfunc == (void *) cancel_msg || s->scfunc == do_enter ||
|
||||
if (s->scfunc == CANCEL_MSG || s->scfunc == DO_ENTER ||
|
||||
ran_func) {
|
||||
statusbar_x = old_statusbar_x;
|
||||
statusbar_pww = old_pww;
|
||||
@@ -1203,9 +1203,9 @@ int do_prompt(bool allow_tabs,
|
||||
|
||||
/* If we left the prompt via Cancel or Enter, set the return value
|
||||
* properly. */
|
||||
if (s && s->scfunc == (void *) cancel_msg)
|
||||
if (s && s->scfunc == CANCEL_MSG)
|
||||
retval = -1;
|
||||
else if (s && s->scfunc == do_enter)
|
||||
else if (s && s->scfunc == DO_ENTER)
|
||||
retval = (*answer == '\0') ? -2 : 0;
|
||||
|
||||
blank_statusbar();
|
||||
@@ -1313,7 +1313,7 @@ int do_yesno_prompt(bool all, const char *msg)
|
||||
kbinput = get_kbinput(bottomwin, &meta_key, &func_key);
|
||||
s = get_shortcut(currmenu, &kbinput, &meta_key, &func_key);
|
||||
|
||||
if (s && s->scfunc == (void *) cancel_msg)
|
||||
if (s && s->scfunc == CANCEL_MSG)
|
||||
ok = -1;
|
||||
#ifndef DISABLE_MOUSE
|
||||
else if (kbinput == KEY_MOUSE) {
|
||||
@@ -1345,7 +1345,7 @@ int do_yesno_prompt(bool all, const char *msg)
|
||||
}
|
||||
}
|
||||
#endif /* !DISABLE_MOUSE */
|
||||
else if (s && s->scfunc == total_refresh) {
|
||||
else if (s && s->scfunc == TOTAL_REFRESH) {
|
||||
total_redraw();
|
||||
continue;
|
||||
} else {
|
||||
|
||||
45
src/proto.h
45
src/proto.h
@@ -47,6 +47,7 @@ extern WINDOW *bottomwin;
|
||||
extern int editwinrows;
|
||||
|
||||
extern filestruct *cutbuffer;
|
||||
extern filestruct *cutbottom;
|
||||
#ifndef DISABLE_JUSTIFY
|
||||
extern filestruct *jusbuffer;
|
||||
#endif
|
||||
@@ -60,6 +61,7 @@ extern char *matchbrackets;
|
||||
#if !defined(NANO_TINY) && defined(ENABLE_NANORC)
|
||||
extern char *whitespace;
|
||||
extern int whitespace_len[2];
|
||||
extern undo_type last_action;
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_JUSTIFY
|
||||
@@ -74,7 +76,7 @@ extern char *quoteerr;
|
||||
extern size_t quotelen;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool nodelay_mode;
|
||||
extern char *answer;
|
||||
|
||||
extern ssize_t tabsize;
|
||||
@@ -98,11 +100,9 @@ extern syntaxtype *syntaxes;
|
||||
extern char *syntaxstr;
|
||||
#endif
|
||||
|
||||
extern bool edit_refresh_needed;
|
||||
extern const shortcut *currshortcut;
|
||||
extern int currmenu;
|
||||
#ifndef NANO_TINY
|
||||
extern toggle *toggles;
|
||||
#endif
|
||||
|
||||
#ifndef NANO_TINY
|
||||
extern filestruct *search_history;
|
||||
@@ -240,7 +240,7 @@ void cut_to_eof(void);
|
||||
#endif
|
||||
void do_cut_text(
|
||||
#ifndef NANO_TINY
|
||||
bool copy_text, bool cut_till_end
|
||||
bool copy_text, bool cut_till_end, bool undoing
|
||||
#else
|
||||
void
|
||||
#endif
|
||||
@@ -256,7 +256,7 @@ void do_uncut_text(void);
|
||||
void make_new_buffer(void);
|
||||
void initialize_buffer(void);
|
||||
void initialize_buffer_text(void);
|
||||
void open_buffer(const char *filename);
|
||||
void open_buffer(const char *filename, bool undoable);
|
||||
#ifndef DISABLE_SPELLER
|
||||
void replace_buffer(const char *filename);
|
||||
#endif
|
||||
@@ -269,7 +269,7 @@ bool close_buffer(void);
|
||||
#endif
|
||||
filestruct *read_line(char *buf, filestruct *prevnode, bool
|
||||
*first_line_ins, size_t buf_len);
|
||||
void read_file(FILE *f, const char *filename);
|
||||
void read_file(FILE *f, const char *filename, bool undoable);
|
||||
int open_file(const char *filename, bool newfie, FILE **f);
|
||||
char *get_next_filename(const char *name, const char *suffix);
|
||||
void do_insertfile(
|
||||
@@ -344,12 +344,12 @@ void thanks_for_all_the_fish(void);
|
||||
#endif
|
||||
|
||||
/* All functions in help.c. */
|
||||
#ifndef DISABLE_HELP
|
||||
void do_help(void (*refresh_func)(void));
|
||||
void do_help_void(void);
|
||||
#ifndef DISABLE_BROWSER
|
||||
void do_browser_help(void);
|
||||
#endif
|
||||
void do_help_void(void);
|
||||
#ifndef DISABLE_HELP
|
||||
void do_help(void (*refresh_func)(void));
|
||||
void help_init(void);
|
||||
void parse_help_input(int *kbinput, bool *meta_key, bool *func_key);
|
||||
size_t help_line_len(const char *ptr);
|
||||
@@ -543,6 +543,8 @@ void parse_syntax(char *ptr);
|
||||
void parse_include(char *ptr);
|
||||
short color_to_short(const char *colorname, bool *bright);
|
||||
void parse_colors(char *ptr, bool icase);
|
||||
void reset_multis(filestruct *fileptr);
|
||||
void alloc_multidata_if_needed(filestruct *fileptr);
|
||||
#endif
|
||||
void parse_rcfile(FILE *rcstream
|
||||
#ifdef ENABLE_COLOR
|
||||
@@ -619,6 +621,8 @@ void do_tab(void);
|
||||
void do_indent(ssize_t cols);
|
||||
void do_indent_void(void);
|
||||
void do_unindent(void);
|
||||
void do_undo(void);
|
||||
void do_redo(void);
|
||||
#endif
|
||||
void do_enter(void);
|
||||
#ifndef NANO_TINY
|
||||
@@ -684,6 +688,7 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream);
|
||||
#endif
|
||||
#ifdef HAVE_REGEX_H
|
||||
bool regexp_bol_or_eol(const regex_t *preg, const char *string);
|
||||
const char *fixbounds(const char *r);
|
||||
#endif
|
||||
#ifndef DISABLE_SPELLER
|
||||
bool is_whole_word(size_t pos, const char *buf, const char *word);
|
||||
@@ -706,8 +711,11 @@ void new_magicline(void);
|
||||
void remove_magicline(void);
|
||||
void mark_order(const filestruct **top, size_t *top_x, const filestruct
|
||||
**bot, size_t *bot_x, bool *right_side_up);
|
||||
void add_undo(undo_type current_action);
|
||||
void update_undo(undo_type action);
|
||||
#endif
|
||||
size_t get_totsize(const filestruct *begin, const filestruct *end);
|
||||
filestruct *fsfromline(ssize_t lineno);
|
||||
#ifdef DEBUG
|
||||
void dump_filestruct(const filestruct *inptr);
|
||||
void dump_filestruct_reverse(void);
|
||||
@@ -738,10 +746,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
|
||||
#endif
|
||||
const sc *get_shortcut(int menu, int *kbinput, bool
|
||||
*meta_key, bool *func_key);
|
||||
const sc *first_sc_for(int menu, void *func);
|
||||
#ifndef NANO_TINY
|
||||
const toggle *get_toggle(int kbinput, bool meta_key);
|
||||
#endif
|
||||
const sc *first_sc_for(int menu, short func);
|
||||
void blank_line(WINDOW *win, int y, int x, int n);
|
||||
void blank_titlebar(void);
|
||||
void blank_topbar(void);
|
||||
@@ -757,13 +762,13 @@ void statusbar(const char *msg, ...);
|
||||
void bottombars(int menu);
|
||||
void onekey(const char *keystroke, const char *desc, size_t len);
|
||||
void reset_cursor(void);
|
||||
void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
void edit_draw(filestruct *fileptr, const char *converted, int
|
||||
line, size_t start);
|
||||
void update_line(const filestruct *fileptr, size_t index);
|
||||
void update_line(filestruct *fileptr, size_t index);
|
||||
bool need_horizontal_update(size_t pww_save);
|
||||
bool need_vertical_update(size_t pww_save);
|
||||
void edit_scroll(scroll_dir direction, ssize_t nlines);
|
||||
void edit_redraw(const filestruct *old_current, size_t pww_save);
|
||||
void edit_redraw(filestruct *old_current, size_t pww_save);
|
||||
void edit_refresh(void);
|
||||
void edit_update(update_type location);
|
||||
void total_redraw(void);
|
||||
@@ -774,6 +779,7 @@ void do_cursorpos_void(void);
|
||||
void do_replace_highlight(bool highlight, const char *word);
|
||||
char *flagtostr(int flag);
|
||||
const subnfunc *sctofunc(sc *s);
|
||||
const subnfunc *getfuncfromkey(WINDOW *win);
|
||||
void print_sclist(void);
|
||||
sc *strtosc(int menu, char *input);
|
||||
function_type strtokeytype(char *str);
|
||||
@@ -781,7 +787,7 @@ int strtomenu(char *input);
|
||||
void assign_keyinfo(sc *s);
|
||||
void xon_complaint(void);
|
||||
void xoff_complaint(void);
|
||||
int sc_seq_or (void *func, int defaultval);
|
||||
int sc_seq_or (short func, int defaultval);
|
||||
void do_suspend_void(void);
|
||||
|
||||
const char *cancel_msg;
|
||||
@@ -812,6 +818,9 @@ const char *prepend_msg;
|
||||
const char *backup_file_msg;
|
||||
const char *gototext_msg;
|
||||
const char *new_buffer_msg;
|
||||
void iso_me_harder_funcmap(short func);
|
||||
void enable_nodelay(void);
|
||||
void disable_nodelay(void);
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
const char *regexp_msg;
|
||||
|
||||
118
src/rcfile.c
118
src/rcfile.c
@@ -103,8 +103,11 @@ static char *nanorc = NULL;
|
||||
#ifdef ENABLE_COLOR
|
||||
static syntaxtype *endsyntax = NULL;
|
||||
/* The end of the list of syntaxes. */
|
||||
static exttype *endheader = NULL;
|
||||
/* End of header list */
|
||||
static colortype *endcolor = NULL;
|
||||
/* The end of the color list for the current syntax. */
|
||||
|
||||
#endif
|
||||
|
||||
/* We have an error in some part of the rcfile. Print the error message
|
||||
@@ -217,19 +220,19 @@ char *parse_next_regex(char *ptr)
|
||||
bool nregcomp(const char *regex, int eflags)
|
||||
{
|
||||
regex_t preg;
|
||||
int rc = regcomp(&preg, regex, REG_EXTENDED | eflags);
|
||||
const char *r = fixbounds(regex);
|
||||
int rc = regcomp(&preg, r, REG_EXTENDED | eflags);
|
||||
|
||||
if (rc != 0) {
|
||||
size_t len = regerror(rc, &preg, NULL, 0);
|
||||
char *str = charalloc(len);
|
||||
|
||||
regerror(rc, &preg, str, len);
|
||||
rcfile_error(N_("Bad regex \"%s\": %s"), regex, str);
|
||||
rcfile_error(N_("Bad regex \"%s\": %s"), r, str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
regfree(&preg);
|
||||
|
||||
return (rc == 0);
|
||||
}
|
||||
|
||||
@@ -290,8 +293,11 @@ void parse_syntax(char *ptr)
|
||||
endsyntax->desc = mallocstrcpy(NULL, nameptr);
|
||||
endsyntax->color = NULL;
|
||||
endcolor = NULL;
|
||||
endheader = NULL;
|
||||
endsyntax->extensions = NULL;
|
||||
endsyntax->headers = NULL;
|
||||
endsyntax->next = NULL;
|
||||
endsyntax->nmultis = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Starting a new syntax type: \"%s\"\n", nameptr);
|
||||
@@ -380,7 +386,7 @@ void parse_keybinding(char *ptr)
|
||||
for (i = 0; i < strlen(keycopy); i++)
|
||||
keycopy[i] = toupper(keycopy[i]);
|
||||
|
||||
if (keycopy[0] != 'M' && keycopy[0] != '^' && keycopy[0] != 'F') {
|
||||
if (keycopy[0] != 'M' && keycopy[0] != '^' && keycopy[0] != 'F' && keycopy[0] != 'K') {
|
||||
rcfile_error(
|
||||
N_("keybindings must begin with \"^\", \"M\", or \"F\"\n"));
|
||||
return;
|
||||
@@ -423,7 +429,7 @@ void parse_keybinding(char *ptr)
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "newsc now address %d, menu func assigned = %d, menu = %d\n",
|
||||
(int) newsc, (int) newsc->scfunc, menu);
|
||||
&newsc, newsc->scfunc, menu);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -464,7 +470,7 @@ void parse_include(char *ptr)
|
||||
{
|
||||
struct stat rcinfo;
|
||||
FILE *rcstream;
|
||||
char *option, *full_option, *nanorc_save = nanorc;
|
||||
char *option, *nanorc_save = nanorc;
|
||||
size_t lineno_save = lineno;
|
||||
|
||||
option = ptr;
|
||||
@@ -472,37 +478,33 @@ void parse_include(char *ptr)
|
||||
option++;
|
||||
ptr = parse_argument(ptr);
|
||||
|
||||
/* Get the specified file's full path. */
|
||||
full_option = get_full_path(option);
|
||||
|
||||
if (full_option == NULL)
|
||||
full_option = mallocstrcpy(NULL, option);
|
||||
/* Can't get the specified file's full path cause it may screw up
|
||||
our cwd depending on the parent dirs' permissions, (see Savannah bug 25297) */
|
||||
|
||||
/* Don't open directories, character files, or block files. */
|
||||
if (stat(full_option, &rcinfo) != -1) {
|
||||
if (stat(option, &rcinfo) != -1) {
|
||||
if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) ||
|
||||
S_ISBLK(rcinfo.st_mode)) {
|
||||
rcfile_error(S_ISDIR(rcinfo.st_mode) ?
|
||||
_("\"%s\" is a directory") :
|
||||
_("\"%s\" is a device file"), option);
|
||||
goto cleanup_include;
|
||||
}
|
||||
}
|
||||
|
||||
/* Open the new syntax file. */
|
||||
if ((rcstream = fopen(full_option, "rb")) == NULL) {
|
||||
if ((rcstream = fopen(option, "rb")) == NULL) {
|
||||
rcfile_error(_("Error reading %s: %s"), option,
|
||||
strerror(errno));
|
||||
goto cleanup_include;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Use the name and line number position of the new syntax file
|
||||
* while parsing it, so we can know where any errors in it are. */
|
||||
nanorc = full_option;
|
||||
nanorc = option;
|
||||
lineno = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Parsing file \"%s\"\n", full_option);
|
||||
fprintf(stderr, "Parsing file \"%s\"\n", option);
|
||||
#endif
|
||||
|
||||
parse_rcfile(rcstream
|
||||
@@ -516,8 +518,6 @@ void parse_include(char *ptr)
|
||||
nanorc = nanorc_save;
|
||||
lineno = lineno_save;
|
||||
|
||||
cleanup_include:
|
||||
free(full_option);
|
||||
}
|
||||
|
||||
/* Return the short value corresponding to the color named in colorname,
|
||||
@@ -712,9 +712,76 @@ void parse_colors(char *ptr, bool icase)
|
||||
/* Save the ending regex string if it's valid. */
|
||||
newcolor->end_regex = (nregcomp(fgstr, icase ? REG_ICASE :
|
||||
0)) ? mallocstrcpy(NULL, fgstr) : NULL;
|
||||
|
||||
/* Lame way to skip another static counter */
|
||||
newcolor->id = endsyntax->nmultis;
|
||||
endsyntax->nmultis++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse the headers (1st line) of the file which may influence the regex used. */
|
||||
void parse_headers(char *ptr)
|
||||
{
|
||||
char *regstr;
|
||||
|
||||
assert(ptr != NULL);
|
||||
|
||||
if (syntaxes == NULL) {
|
||||
rcfile_error(
|
||||
N_("Cannot add a header regex without a syntax command"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (*ptr == '\0') {
|
||||
rcfile_error(N_("Missing regex string"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Now for the fun part. Start adding regexes to individual strings
|
||||
* in the colorstrings array, woo! */
|
||||
while (ptr != NULL && *ptr != '\0') {
|
||||
exttype *newheader;
|
||||
/* The new color structure. */
|
||||
|
||||
if (*ptr != '"') {
|
||||
rcfile_error(
|
||||
N_("Regex strings must begin and end with a \" character"));
|
||||
ptr = parse_next_regex(ptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
|
||||
regstr = ptr;
|
||||
ptr = parse_next_regex(ptr);
|
||||
if (ptr == NULL)
|
||||
break;
|
||||
|
||||
newheader = (exttype *)nmalloc(sizeof(exttype));
|
||||
|
||||
/* Save the regex string if it's valid */
|
||||
if (nregcomp(regstr, 0)) {
|
||||
newheader->ext_regex = mallocstrcpy(NULL, regstr);
|
||||
newheader->ext = NULL;
|
||||
newheader->next = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Starting a new header entry: %s\n", newheader->ext_regex);
|
||||
#endif
|
||||
|
||||
if (endheader == NULL) {
|
||||
endsyntax->headers = newheader;
|
||||
} else {
|
||||
endheader->next = newheader;
|
||||
}
|
||||
|
||||
endheader = newheader;
|
||||
} else
|
||||
free(newheader);
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_COLOR */
|
||||
|
||||
/* Check whether the user has unmapped every shortcut for a
|
||||
@@ -724,7 +791,7 @@ static void check_vitals_mapped(void)
|
||||
subnfunc *f;
|
||||
int v;
|
||||
#define VITALS 5
|
||||
void *vitals[VITALS] = { do_exit, do_exit, (void *) cancel_msg, (void *) cancel_msg, (void *) cancel_msg };
|
||||
short vitals[VITALS] = { DO_EXIT, DO_EXIT, CANCEL_MSG, CANCEL_MSG, CANCEL_MSG };
|
||||
int inmenus[VITALS] = { MMAIN, MHELP, MWHEREIS, MREPLACE, MGOTOLINE };
|
||||
|
||||
for (v = 0; v < VITALS; v++) {
|
||||
@@ -812,7 +879,9 @@ void parse_rcfile(FILE *rcstream
|
||||
rcfile_error(N_("Syntax \"%s\" has no color commands"),
|
||||
endsyntax->desc);
|
||||
parse_syntax(ptr);
|
||||
} else if (strcasecmp(keyword, "color") == 0)
|
||||
} else if (strcasecmp(keyword, "header") == 0)
|
||||
parse_headers(ptr);
|
||||
else if (strcasecmp(keyword, "color") == 0)
|
||||
parse_colors(ptr, FALSE);
|
||||
else if (strcasecmp(keyword, "icolor") == 0)
|
||||
parse_colors(ptr, TRUE);
|
||||
@@ -1044,8 +1113,11 @@ void do_rcfile(void)
|
||||
if (homedir == NULL)
|
||||
rcfile_error(N_("I can't find my home directory! Wah!"));
|
||||
else {
|
||||
nanorc = charealloc(nanorc, strlen(homedir) + 9);
|
||||
sprintf(nanorc, "%s/.nanorc", homedir);
|
||||
#ifndef RCFILE_NAME
|
||||
#define RCFILE_NAME ".nanorc"
|
||||
#endif
|
||||
nanorc = charealloc(nanorc, strlen(homedir) + strlen(RCFILE_NAME) + 2);
|
||||
sprintf(nanorc, "%s/%s", homedir, RCFILE_NAME);
|
||||
|
||||
/* Don't open directories, character files, or block files. */
|
||||
if (stat(nanorc, &rcinfo) != -1) {
|
||||
|
||||
36
src/search.c
36
src/search.c
@@ -28,6 +28,7 @@
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
static bool search_last_line = FALSE;
|
||||
/* Have we gone past the last line while searching? */
|
||||
@@ -137,7 +138,7 @@ int search_init(bool replacing, bool use_answer)
|
||||
int i = 0;
|
||||
char *buf;
|
||||
sc *s;
|
||||
void *func = NULL;
|
||||
char func = 0;
|
||||
bool meta_key = FALSE, func_key = FALSE;
|
||||
static char *backupstring = NULL;
|
||||
/* The search string we'll be using. */
|
||||
@@ -235,31 +236,32 @@ int search_init(bool replacing, bool use_answer)
|
||||
#endif
|
||||
;
|
||||
#ifndef NANO_TINY
|
||||
} else if (func == (void *) case_sens_msg) {
|
||||
} else if (func == CASE_SENS_MSG) {
|
||||
TOGGLE(CASE_SENSITIVE);
|
||||
backupstring = mallocstrcpy(backupstring, answer);
|
||||
return 1;
|
||||
} else if (func == (void *) backwards_msg) {
|
||||
} else if (func == BACKWARDS_MSG) {
|
||||
TOGGLE(BACKWARDS_SEARCH);
|
||||
backupstring = mallocstrcpy(backupstring, answer);
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef HAVE_REGEX_H
|
||||
} else if (func == (void *) regexp_msg) {
|
||||
} else if (func == REGEXP_MSG) {
|
||||
TOGGLE(USE_REGEXP);
|
||||
backupstring = mallocstrcpy(backupstring, answer);
|
||||
return 1;
|
||||
#endif
|
||||
} else if (func == (void *) do_replace ||
|
||||
func == (void *) no_replace_msg) {
|
||||
} else if (func == DO_REPLACE ||
|
||||
func == NO_REPLACE_MSG) {
|
||||
backupstring = mallocstrcpy(backupstring, answer);
|
||||
return -2; /* Call the opposite search function. */
|
||||
} else if (func == (void *) go_to_line_msg) {
|
||||
} else if (func == DO_GOTOLINECOLUMN_VOID) {
|
||||
do_gotolinecolumn(openfile->current->lineno,
|
||||
openfile->placewewant + 1, TRUE, TRUE, FALSE,
|
||||
TRUE);
|
||||
/* Put answer up on the statusbar and
|
||||
* fall through. */
|
||||
return 3;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
@@ -287,6 +289,8 @@ bool findnextstr(
|
||||
ssize_t current_y_find = openfile->current_y;
|
||||
filestruct *fileptr = openfile->current;
|
||||
const char *rev_start = fileptr->data, *found = NULL;
|
||||
const subnfunc *f;
|
||||
time_t lastkbcheck = time(NULL);
|
||||
|
||||
/* rev_start might end up 1 character before the start or after the
|
||||
* end of the line. This won't be a problem because strstrwrapper()
|
||||
@@ -301,7 +305,17 @@ bool findnextstr(
|
||||
openfile->current_x + 1;
|
||||
|
||||
/* Look for needle in the current line we're searching. */
|
||||
enable_nodelay();
|
||||
while (TRUE) {
|
||||
if (time(NULL) - lastkbcheck > 1) {
|
||||
lastkbcheck = time(NULL);
|
||||
f = getfuncfromkey(edit);
|
||||
if (f && f->scfunc == CANCEL_MSG) {
|
||||
statusbar(_("Cancelled"));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
found = strstrwrapper(fileptr->data, needle, rev_start);
|
||||
|
||||
/* We've found a potential match. */
|
||||
@@ -347,6 +361,7 @@ bool findnextstr(
|
||||
/* We've finished processing the file, so get out. */
|
||||
if (search_last_line) {
|
||||
not_found_msg(needle);
|
||||
disable_nodelay();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -404,9 +419,11 @@ bool findnextstr(
|
||||
#endif
|
||||
) {
|
||||
not_found_msg(needle);
|
||||
disable_nodelay();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
disable_nodelay();
|
||||
/* We've definitely found something. */
|
||||
openfile->current = fileptr;
|
||||
openfile->current_x = current_x_find;
|
||||
@@ -788,6 +805,9 @@ ssize_t do_replace_loop(
|
||||
char *copy;
|
||||
size_t length_change;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
update_undo(REPLACE);
|
||||
#endif
|
||||
if (i == 2)
|
||||
replaceall = TRUE;
|
||||
|
||||
@@ -1017,7 +1037,7 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
|
||||
|
||||
|
||||
s = get_shortcut(currmenu, &i, &meta_key, &func_key);
|
||||
if (s && s->scfunc == (void *) gototext_msg) {
|
||||
if (s && s->scfunc == GOTOTEXT_MSG) {
|
||||
/* Keep answer up on the statusbar. */
|
||||
search_init(TRUE, TRUE);
|
||||
|
||||
|
||||
555
src/text.c
555
src/text.c
@@ -1,4 +1,4 @@
|
||||
/* $Id$ */
|
||||
/* $Id$ */
|
||||
/**************************************************************************
|
||||
* text.c *
|
||||
* *
|
||||
@@ -70,6 +70,10 @@ void do_delete(void)
|
||||
/* Do we have to call edit_refresh(), or can we get away with
|
||||
* just update_line()? */
|
||||
|
||||
#ifndef NANO_TINY
|
||||
update_undo(DEL);
|
||||
#endif
|
||||
|
||||
assert(openfile->current != NULL && openfile->current->data != NULL && openfile->current_x <= strlen(openfile->current->data));
|
||||
|
||||
openfile->placewewant = xplustabs();
|
||||
@@ -144,7 +148,7 @@ void do_delete(void)
|
||||
#endif
|
||||
|
||||
if (do_refresh)
|
||||
edit_refresh();
|
||||
edit_refresh_needed = TRUE;
|
||||
else
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
}
|
||||
@@ -342,7 +346,7 @@ void do_indent(ssize_t cols)
|
||||
set_modified();
|
||||
|
||||
/* Update the screen. */
|
||||
edit_refresh();
|
||||
edit_refresh_needed = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,6 +363,299 @@ void do_unindent(void)
|
||||
{
|
||||
do_indent(-tabsize);
|
||||
}
|
||||
|
||||
/* undo a cut, or re-do an uncut */
|
||||
void undo_cut(undo *u)
|
||||
{
|
||||
cutbuffer = copy_filestruct(u->cutbuffer);
|
||||
|
||||
/* Compute cutbottom for the uncut using out copy */
|
||||
for (cutbottom = cutbuffer; cutbottom->next != NULL; cutbottom = cutbottom->next)
|
||||
;
|
||||
|
||||
/* Get to where we need to uncut from */
|
||||
if (u->mark_set && u->mark_begin_lineno < u->lineno)
|
||||
do_gotolinecolumn(u->mark_begin_lineno, u->mark_begin_x+1, FALSE, FALSE, FALSE, FALSE);
|
||||
else
|
||||
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
|
||||
|
||||
copy_from_filestruct(cutbuffer, cutbottom);
|
||||
free_filestruct(cutbuffer);
|
||||
cutbuffer = NULL;
|
||||
|
||||
}
|
||||
|
||||
/* Re-do a cut, or undo an uncut */
|
||||
void redo_cut(undo *u) {
|
||||
int i;
|
||||
filestruct *t, *c;
|
||||
|
||||
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
|
||||
openfile->mark_set = u->mark_set;
|
||||
if (cutbuffer)
|
||||
free(cutbuffer);
|
||||
cutbuffer = NULL;
|
||||
|
||||
/* Move ahead the same # lines we had if a marked cut */
|
||||
if (u->mark_set) {
|
||||
for (i = 1, t = openfile->fileage; i != u->mark_begin_lineno; i++)
|
||||
t = t->next;
|
||||
openfile->mark_begin = t;
|
||||
} else if (!u->to_end) {
|
||||
/* Here we have a regular old potentially multi-line ^K cut. We'll
|
||||
need to trick nano into thinking it's a marked cut to cut more
|
||||
than one line again */
|
||||
for (c = u->cutbuffer, t = openfile->current; c->next != NULL && t->next != NULL; ) {
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Advancing, lineno = %d, data = \"%s\"\n", t->lineno, t->data);
|
||||
#endif
|
||||
c = c->next;
|
||||
t = t->next;
|
||||
}
|
||||
openfile->mark_begin = t;
|
||||
openfile->mark_begin_x = 0;
|
||||
openfile->mark_set = TRUE;
|
||||
}
|
||||
|
||||
openfile->mark_begin_x = u->mark_begin_x;
|
||||
do_cut_text(FALSE, u->to_end, TRUE);
|
||||
openfile->mark_set = FALSE;
|
||||
openfile->mark_begin = NULL;
|
||||
openfile->mark_begin_x = 0;
|
||||
edit_refresh_needed = TRUE;
|
||||
}
|
||||
|
||||
/* Undo the last thing(s) we did */
|
||||
void do_undo(void)
|
||||
{
|
||||
undo *u = openfile->current_undo;
|
||||
filestruct *f = openfile->current, *t;
|
||||
int len = 0;
|
||||
char *undidmsg, *data;
|
||||
filestruct *oldcutbuffer = cutbuffer, *oldcutbottom = cutbottom;
|
||||
|
||||
if (!u) {
|
||||
statusbar(_("Nothing in undo buffer!"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (u->lineno <= f->lineno)
|
||||
for (; f->prev != NULL && f->lineno != u->lineno; f = f->prev)
|
||||
;
|
||||
else
|
||||
for (; f->next != NULL && f->lineno != u->lineno; f = f->next)
|
||||
;
|
||||
if (f->lineno != u->lineno) {
|
||||
statusbar(_("Internal error: can't match line %d. Please save your work"), u->lineno);
|
||||
return;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "data we're about to undo = \"%s\"\n", f->data);
|
||||
fprintf(stderr, "Undo running for type %d\n", u->type);
|
||||
#endif
|
||||
|
||||
openfile->current_x = u->begin;
|
||||
switch(u->type) {
|
||||
case ADD:
|
||||
undidmsg = _("text add");
|
||||
len = strlen(f->data) - strlen(u->strdata) + 1;
|
||||
data = charalloc(len);
|
||||
strncpy(data, f->data, u->begin);
|
||||
strcpy(&data[u->begin], &f->data[u->begin + strlen(u->strdata)]);
|
||||
free(f->data);
|
||||
f->data = data;
|
||||
break;
|
||||
case DEL:
|
||||
undidmsg = _("text delete");
|
||||
len = strlen(f->data) + strlen(u->strdata) + 1;
|
||||
data = charalloc(len);
|
||||
|
||||
strncpy(data, f->data, u->begin);
|
||||
strcpy(&data[u->begin], u->strdata);
|
||||
strcpy(&data[u->begin + strlen(u->strdata)], &f->data[u->begin]);
|
||||
free(f->data);
|
||||
f->data = data;
|
||||
if (u->xflags == UNDO_DEL_BACKSPACE)
|
||||
openfile->current_x += strlen(u->strdata);
|
||||
break;
|
||||
case SPLIT:
|
||||
undidmsg = _("line split");
|
||||
free(f->data);
|
||||
f->data = mallocstrcpy(NULL, u->strdata);
|
||||
if (f->next != NULL) {
|
||||
filestruct *tmp = f->next;
|
||||
unlink_node(tmp);
|
||||
delete_node(tmp);
|
||||
}
|
||||
renumber(f);
|
||||
break;
|
||||
case UNSPLIT:
|
||||
undidmsg = _("line join");
|
||||
t = make_new_node(f);
|
||||
t->data = mallocstrcpy(NULL, u->strdata);
|
||||
data = mallocstrncpy(NULL, f->data, u->begin);
|
||||
data[u->begin] = '\0';
|
||||
free(f->data);
|
||||
f->data = data;
|
||||
splice_node(f, t, f->next);
|
||||
renumber(f);
|
||||
break;
|
||||
case CUT:
|
||||
undidmsg = _("text cut");
|
||||
undo_cut(u);
|
||||
break;
|
||||
case UNCUT:
|
||||
undidmsg = _("text uncut");
|
||||
redo_cut(u);
|
||||
break;
|
||||
case INSERT:
|
||||
undidmsg = _("text insert");
|
||||
cutbuffer = NULL;
|
||||
cutbottom = NULL;
|
||||
/* When we updated mark_begin_lineno in update_undo, it was effectively how many line
|
||||
were inserted due to being partitioned before read_file was called. So we
|
||||
add its value here */
|
||||
openfile->mark_begin = fsfromline(u->lineno + u->mark_begin_lineno - 1);
|
||||
openfile->mark_begin_x = 0;
|
||||
openfile->mark_set = TRUE;
|
||||
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
|
||||
cut_marked();
|
||||
u->cutbuffer = cutbuffer;
|
||||
u->cutbottom = cutbottom;
|
||||
cutbuffer = oldcutbuffer;
|
||||
cutbottom = oldcutbottom;
|
||||
openfile->mark_set = FALSE;
|
||||
break;
|
||||
case REPLACE:
|
||||
undidmsg = _("text replace");
|
||||
data = u->strdata;
|
||||
u->strdata = f->data;
|
||||
f->data = data;
|
||||
break;
|
||||
default:
|
||||
undidmsg = _("Internal error: unknown type. Please save your work");
|
||||
break;
|
||||
|
||||
}
|
||||
do_gotolinecolumn(u->lineno, u->begin, FALSE, FALSE, FALSE, TRUE);
|
||||
statusbar(_("Undid action (%s)"), undidmsg);
|
||||
openfile->current_undo = openfile->current_undo->next;
|
||||
openfile->last_action = OTHER;
|
||||
}
|
||||
|
||||
void do_redo(void)
|
||||
{
|
||||
undo *u = openfile->undotop;
|
||||
filestruct *f = openfile->current, *t;
|
||||
int len = 0;
|
||||
char *undidmsg, *data;
|
||||
|
||||
for (; u != NULL && u->next != openfile->current_undo; u = u->next)
|
||||
;
|
||||
if (!u) {
|
||||
statusbar(_("Nothing to re-do!"));
|
||||
return;
|
||||
}
|
||||
if (u->next != openfile->current_undo) {
|
||||
statusbar(_("Internal error: Redo setup failed. Please save your work"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (u->lineno <= f->lineno)
|
||||
for (; f->prev != NULL && f->lineno != u->lineno; f = f->prev)
|
||||
;
|
||||
else
|
||||
for (; f->next != NULL && f->lineno != u->lineno; f = f->next)
|
||||
;
|
||||
if (f->lineno != u->lineno) {
|
||||
statusbar(_("Internal error: can't match line %d. Please save your work"), u->lineno);
|
||||
return;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "data we're about to redo = \"%s\"\n", f->data);
|
||||
fprintf(stderr, "Redo running for type %d\n", u->type);
|
||||
#endif
|
||||
|
||||
switch(u->type) {
|
||||
case ADD:
|
||||
undidmsg = _("text add");
|
||||
len = strlen(f->data) + strlen(u->strdata) + 1;
|
||||
data = charalloc(len);
|
||||
strncpy(data, f->data, u->begin);
|
||||
strcpy(&data[u->begin], u->strdata);
|
||||
strcpy(&data[u->begin + strlen(u->strdata)], &f->data[u->begin]);
|
||||
free(f->data);
|
||||
f->data = data;
|
||||
break;
|
||||
case DEL:
|
||||
undidmsg = _("text delete");
|
||||
len = strlen(f->data) + strlen(u->strdata) + 1;
|
||||
data = charalloc(len);
|
||||
strncpy(data, f->data, u->begin);
|
||||
strcpy(&data[u->begin], &f->data[u->begin + strlen(u->strdata)]);
|
||||
free(f->data);
|
||||
f->data = data;
|
||||
break;
|
||||
case SPLIT:
|
||||
undidmsg = _("line split");
|
||||
t = make_new_node(f);
|
||||
t->data = mallocstrcpy(NULL, &u->strdata[u->begin]);
|
||||
data = mallocstrncpy(NULL, f->data, u->begin);
|
||||
data[u->begin] = '\0';
|
||||
free(f->data);
|
||||
f->data = data;
|
||||
splice_node(f, t, f->next);
|
||||
renumber(f);
|
||||
break;
|
||||
case UNSPLIT:
|
||||
undidmsg = _("line join");
|
||||
len = strlen(f->data) + strlen(u->strdata + 1);
|
||||
data = charalloc(len);
|
||||
strcpy(data, f->data);
|
||||
strcat(data, u->strdata);
|
||||
free(f->data);
|
||||
f->data = data;
|
||||
if (f->next != NULL) {
|
||||
filestruct *tmp = f->next;
|
||||
unlink_node(tmp);
|
||||
delete_node(tmp);
|
||||
}
|
||||
renumber(f);
|
||||
break;
|
||||
case CUT:
|
||||
undidmsg = _("text cut");
|
||||
redo_cut(u);
|
||||
break;
|
||||
case UNCUT:
|
||||
undidmsg = _("text uncut");
|
||||
undo_cut(u);
|
||||
break;
|
||||
case REPLACE:
|
||||
undidmsg = _("text replace");
|
||||
data = u->strdata;
|
||||
u->strdata = f->data;
|
||||
f->data = data;
|
||||
break;
|
||||
case INSERT:
|
||||
undidmsg = _("text insert");
|
||||
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
|
||||
copy_from_filestruct(u->cutbuffer, u->cutbottom);
|
||||
openfile->placewewant = xplustabs();
|
||||
break;
|
||||
default:
|
||||
undidmsg = _("Internal error: unknown type. Please save your work");
|
||||
break;
|
||||
|
||||
}
|
||||
do_gotolinecolumn(u->lineno, u->begin, FALSE, FALSE, FALSE, TRUE);
|
||||
statusbar(_("Redid action (%s)"), undidmsg);
|
||||
|
||||
openfile->current_undo = u;
|
||||
openfile->last_action = OTHER;
|
||||
|
||||
}
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
/* Someone hits Enter *gasp!* */
|
||||
@@ -370,6 +667,9 @@ void do_enter(void)
|
||||
assert(openfile->current != NULL && openfile->current->data != NULL);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
update_undo(SPLIT);
|
||||
|
||||
|
||||
/* Do auto-indenting, like the neolithic Turbo Pascal editor. */
|
||||
if (ISSET(AUTOINDENT)) {
|
||||
/* If we are breaking the line in the indentation, the new
|
||||
@@ -414,7 +714,7 @@ void do_enter(void)
|
||||
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
edit_refresh();
|
||||
edit_refresh_needed = TRUE;
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
@@ -495,7 +795,7 @@ bool execute_command(const char *command)
|
||||
if (f == NULL)
|
||||
nperror("fdopen");
|
||||
|
||||
read_file(f, "stdin");
|
||||
read_file(f, "stdin", TRUE);
|
||||
|
||||
if (wait(NULL) == -1)
|
||||
nperror("wait");
|
||||
@@ -510,6 +810,233 @@ bool execute_command(const char *command)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Add a new undo struct to the top of the current pile */
|
||||
void add_undo(undo_type current_action)
|
||||
{
|
||||
undo *u;
|
||||
char *data;
|
||||
openfilestruct *fs = openfile;
|
||||
static undo *last_cutu = NULL; /* Last thing we cut to set up the undo for uncut */
|
||||
|
||||
/* Ugh, if we were called while cutting not-to-end, non-marked and on the same lineno,
|
||||
we need to abort here */
|
||||
u = fs->current_undo;
|
||||
if (current_action == CUT && u && u->type == CUT
|
||||
&& !u->mark_set && u->lineno == fs->current->lineno)
|
||||
return;
|
||||
|
||||
/* Blow away the old undo stack if we are starting from the middle */
|
||||
while (fs->undotop != NULL && fs->undotop != fs->current_undo) {
|
||||
undo *u2 = fs->undotop;
|
||||
fs->undotop = fs->undotop->next;
|
||||
if (u2->strdata != NULL)
|
||||
free(u2->strdata);
|
||||
if (u2->cutbuffer)
|
||||
free_filestruct(u2->cutbuffer);
|
||||
free(u2);
|
||||
}
|
||||
|
||||
/* Allocate and initialize a new undo type */
|
||||
u = nmalloc(sizeof(undo));
|
||||
u->type = current_action;
|
||||
u->lineno = fs->current->lineno;
|
||||
u->begin = fs->current_x;
|
||||
u->next = fs->undotop;
|
||||
fs->undotop = u;
|
||||
fs->current_undo = u;
|
||||
u->strdata = NULL;
|
||||
u->cutbuffer = NULL;
|
||||
u->cutbottom = NULL;
|
||||
u->mark_set = 0;
|
||||
u->mark_begin_lineno = 0;
|
||||
u->mark_begin_x = 0;
|
||||
u->xflags = 0;
|
||||
u->to_end = FALSE;
|
||||
|
||||
switch (u->type) {
|
||||
/* We need to start copying data into the undo buffer or we wont be able
|
||||
to restore it later */
|
||||
case ADD:
|
||||
data = charalloc(2);
|
||||
data[0] = fs->current->data[fs->current_x];
|
||||
data[1] = '\0';
|
||||
u->strdata = data;
|
||||
break;
|
||||
case DEL:
|
||||
if (u->begin != strlen(fs->current->data)) {
|
||||
data = mallocstrncpy(NULL, &fs->current->data[u->begin], 2);
|
||||
data[1] = '\0';
|
||||
u->strdata = data;
|
||||
break;
|
||||
}
|
||||
/* Else purposely fall into unsplit code */
|
||||
current_action = u->type = UNSPLIT;
|
||||
case UNSPLIT:
|
||||
if (fs->current->next) {
|
||||
data = mallocstrcpy(NULL, fs->current->next->data);
|
||||
u->strdata = data;
|
||||
}
|
||||
break;
|
||||
case INSERT:
|
||||
case SPLIT:
|
||||
case REPLACE:
|
||||
data = mallocstrcpy(NULL, fs->current->data);
|
||||
u->strdata = data;
|
||||
break;
|
||||
case CUT:
|
||||
u->mark_set = openfile->mark_set;
|
||||
if (u->mark_set) {
|
||||
u->mark_begin_lineno = openfile->mark_begin->lineno;
|
||||
u->mark_begin_x = openfile->mark_begin_x;
|
||||
}
|
||||
u->to_end = (ISSET(CUT_TO_END)) ? TRUE : FALSE;
|
||||
last_cutu = u;
|
||||
break;
|
||||
case UNCUT:
|
||||
if (!last_cutu)
|
||||
statusbar(_("Internal error: can't setup uncut. Please save your work."));
|
||||
else if (last_cutu->type == CUT) {
|
||||
u->cutbuffer = last_cutu->cutbuffer;
|
||||
u->cutbottom = last_cutu->cutbottom;
|
||||
}
|
||||
break;
|
||||
case OTHER:
|
||||
statusbar(_("Internal error: unknown type. Please save your work."));
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "fs->current->data = \"%s\", current_x = %d, u->begin = %d, type = %d\n",
|
||||
fs->current->data, fs->current_x, u->begin, current_action);
|
||||
fprintf(stderr, "left update_add...\n");
|
||||
#endif
|
||||
fs->last_action = current_action;
|
||||
}
|
||||
|
||||
/* Update an undo item, or determine whether a new one
|
||||
is really needed and bounce the data to add_undo
|
||||
instead. The latter functionality just feels
|
||||
gimmicky and may just be more hassle than
|
||||
it's worth, so it should be axed if needed. */
|
||||
void update_undo(undo_type action)
|
||||
{
|
||||
undo *u;
|
||||
char *data;
|
||||
int len = 0;
|
||||
openfilestruct *fs = openfile;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "action = %d, fs->last_action = %d, openfile->current->lineno = %d",
|
||||
action, fs->last_action, openfile->current->lineno);
|
||||
if (fs->current_undo)
|
||||
fprintf(stderr, "fs->current_undo->lineno = %d\n", fs->current_undo->lineno);
|
||||
else
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
|
||||
/* Change to an add if we're not using the same undo struct
|
||||
that we should be using */
|
||||
if (action != fs->last_action
|
||||
|| (action != CUT && action != INSERT
|
||||
&& openfile->current->lineno != fs->current_undo->lineno)) {
|
||||
add_undo(action);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(fs->undotop != NULL);
|
||||
u = fs->undotop;
|
||||
|
||||
switch (u->type) {
|
||||
case ADD:
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "fs->current->data = \"%s\", current_x = %d, u->begin = %d\n",
|
||||
fs->current->data, fs->current_x, u->begin);
|
||||
#endif
|
||||
len = strlen(u->strdata) + 2;
|
||||
data = nrealloc((void *) u->strdata, len * sizeof(char *));
|
||||
data[len-2] = fs->current->data[fs->current_x];
|
||||
data[len-1] = '\0';
|
||||
u->strdata = (char *) data;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "current undo data now \"%s\"\n", u->strdata);
|
||||
#endif
|
||||
break;
|
||||
case DEL:
|
||||
len = strlen(u->strdata) + 2;
|
||||
assert(len > 2);
|
||||
if (fs->current_x == u->begin) {
|
||||
/* They're deleting */
|
||||
if (!u->xflags)
|
||||
u->xflags = UNDO_DEL_DEL;
|
||||
else if (u->xflags != UNDO_DEL_DEL) {
|
||||
add_undo(action);
|
||||
return;
|
||||
}
|
||||
data = charalloc(len);
|
||||
strcpy(data, u->strdata);
|
||||
data[len-2] = fs->current->data[fs->current_x];;
|
||||
data[len-1] = '\0';
|
||||
free(u->strdata);
|
||||
u->strdata = data;
|
||||
} else if (fs->current_x == u->begin - 1) {
|
||||
/* They're backspacing */
|
||||
if (!u->xflags)
|
||||
u->xflags = UNDO_DEL_BACKSPACE;
|
||||
else if (u->xflags != UNDO_DEL_BACKSPACE) {
|
||||
add_undo(action);
|
||||
return;
|
||||
}
|
||||
data = charalloc(len);
|
||||
data[0] = fs->current->data[fs->current_x];
|
||||
strcpy(&data[1], u->strdata);
|
||||
free(u->strdata);
|
||||
u->strdata = data;
|
||||
u->begin--;
|
||||
} else {
|
||||
/* They deleted something else on the line */
|
||||
add_undo(DEL);
|
||||
return;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "current undo data now \"%s\"\nu->begin = %d\n", u->strdata, u->begin);
|
||||
#endif
|
||||
break;
|
||||
case CUT:
|
||||
if (!cutbuffer)
|
||||
break;
|
||||
if (u->cutbuffer)
|
||||
free(u->cutbuffer);
|
||||
u->cutbuffer = copy_filestruct(cutbuffer);
|
||||
/* Compute cutbottom for the uncut using out copy */
|
||||
for (u->cutbottom = u->cutbuffer; u->cutbottom->next != NULL; u->cutbottom = u->cutbottom->next)
|
||||
;
|
||||
break;
|
||||
case REPLACE:
|
||||
case UNCUT:
|
||||
add_undo(action);
|
||||
break;
|
||||
case INSERT:
|
||||
u->mark_begin_lineno = openfile->current->lineno;
|
||||
case SPLIT:
|
||||
case UNSPLIT:
|
||||
/* These cases are handled by the earlier check for a new line and action */
|
||||
case OTHER:
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Done in udpate_undo (type was %d)\n", action);
|
||||
#endif
|
||||
if (fs->last_action != action) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Starting add_undo for new action as it does not match last_action\n");
|
||||
#endif
|
||||
add_undo(action);
|
||||
}
|
||||
fs->last_action = action;
|
||||
}
|
||||
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
#ifndef DISABLE_WRAPPING
|
||||
@@ -800,6 +1327,15 @@ ssize_t break_line(const char *line, ssize_t goal
|
||||
/* In fact, the whole line displays shorter than goal. */
|
||||
return cur_loc;
|
||||
|
||||
#ifndef DISABLE_HELP
|
||||
if (newln && blank_loc <= 0) {
|
||||
/* If blank was not found or was found only first character,
|
||||
* force line break. */
|
||||
cur_loc -= line_len;
|
||||
return cur_loc;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (blank_loc == -1) {
|
||||
/* No blank was found that was short enough. */
|
||||
bool found_blank = FALSE;
|
||||
@@ -1420,7 +1956,7 @@ void do_justify(bool full_justify)
|
||||
last_par_line = openfile->filebot;
|
||||
break;
|
||||
} else {
|
||||
edit_refresh();
|
||||
edit_refresh_needed = TRUE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1684,7 +2220,7 @@ void do_justify(bool full_justify)
|
||||
&finished, FALSE);
|
||||
s = get_shortcut(currmenu, &kbinput, &meta_key, &func_key);
|
||||
|
||||
if (s && s->scfunc == do_uncut_text) {
|
||||
if (s && s->scfunc == DO_UNCUT_TEXT) {
|
||||
/* Splice the justify buffer back into the file, but only if we
|
||||
* actually justified something. */
|
||||
if (first_par_line != NULL) {
|
||||
@@ -1732,7 +2268,7 @@ void do_justify(bool full_justify)
|
||||
|
||||
if (!openfile->modified)
|
||||
titlebar(NULL);
|
||||
edit_refresh();
|
||||
edit_refresh_needed = TRUE;
|
||||
}
|
||||
} else {
|
||||
unget_kbinput(kbinput, meta_key, func_key);
|
||||
@@ -2085,7 +2621,7 @@ const char *do_int_speller(const char *tempfile_name)
|
||||
|
||||
free(read_buff);
|
||||
search_replace_abort();
|
||||
edit_refresh();
|
||||
edit_refresh_needed = TRUE;
|
||||
|
||||
/* Process the end of the spell process. */
|
||||
waitpid(pid_spell, &spell_status, 0);
|
||||
@@ -2464,3 +3000,4 @@ void do_verbatim_input(void)
|
||||
|
||||
free(output);
|
||||
}
|
||||
|
||||
|
||||
72
src/utils.c
72
src/utils.c
@@ -183,14 +183,7 @@ void sunder(char *str)
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA. */
|
||||
|
||||
#if !defined(NANO_TINY) && defined(ENABLE_NANORC)
|
||||
#ifndef HAVE_GETLINE
|
||||
/* This function is equivalent to getline(). */
|
||||
ssize_t ngetline(char **lineptr, size_t *n, FILE *stream)
|
||||
{
|
||||
return getdelim(lineptr, n, '\n', stream);
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_NANORC
|
||||
|
||||
#ifndef HAVE_GETDELIM
|
||||
/* This function is equivalent to getdelim(). */
|
||||
@@ -242,7 +235,15 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream)
|
||||
return (c == EOF && (indx - 1) == 0) ? -1 : indx - 1;
|
||||
}
|
||||
#endif
|
||||
#endif /* !NANO_TINY && ENABLE_NANORC */
|
||||
|
||||
#ifndef HAVE_GETLINE
|
||||
/* This function is equivalent to getline(). */
|
||||
ssize_t ngetline(char **lineptr, size_t *n, FILE *stream)
|
||||
{
|
||||
return getdelim(lineptr, n, '\n', stream);
|
||||
}
|
||||
#endif
|
||||
#endif /* ENABLE_NANORC */
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
/* Do the compiled regex in preg and the regex in string match the
|
||||
@@ -253,6 +254,42 @@ bool regexp_bol_or_eol(const regex_t *preg, const char *string)
|
||||
regexec(preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) ==
|
||||
REG_NOMATCH);
|
||||
}
|
||||
|
||||
/* Fix the regex if we're on platforms which requires an adjustment
|
||||
* from GNU-style to BSD-style word boundaries. */
|
||||
const char *fixbounds(const char *r) {
|
||||
#ifndef GNU_WORDBOUNDS
|
||||
int i, j = 0;
|
||||
char *r2 = charalloc(strlen(r) * 5);
|
||||
char *r3;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "fixbounds(): Start string = \"%s\"\n", r);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < strlen(r); i++) {
|
||||
if (r[i] != '\0' && r[i] == '\\' && (r[i+1] == '>' || r[i+1] == '<')) {
|
||||
strcpy(&r2[j], "[[:");
|
||||
r2[j+3] = r[i+1];
|
||||
strcpy(&r2[j+4], ":]]");
|
||||
i++;
|
||||
j += 6;
|
||||
} else
|
||||
r2[j] = r[i];
|
||||
j++;
|
||||
}
|
||||
r2[j] = '\0';
|
||||
r3 = mallocstrcpy(NULL, r2);
|
||||
free(r2);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "fixbounds(): Ending string = \"%s\"\n", r3);
|
||||
#endif
|
||||
return (const char *) r3;
|
||||
#endif
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_SPELLER
|
||||
@@ -586,6 +623,23 @@ size_t get_totsize(const filestruct *begin, const filestruct *end)
|
||||
return totsize;
|
||||
}
|
||||
|
||||
/* Get back a pointer given a line number in the current openfilestruct */
|
||||
filestruct *fsfromline(ssize_t lineno)
|
||||
{
|
||||
filestruct *f = openfile->current;
|
||||
|
||||
if (lineno <= openfile->current->lineno)
|
||||
for (; f->lineno != lineno && f != openfile->fileage; f = f->prev)
|
||||
;
|
||||
else
|
||||
for (; f->lineno != lineno && f->next != NULL; f = f->next)
|
||||
;
|
||||
|
||||
if (f->lineno != lineno)
|
||||
f = NULL;
|
||||
return f;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
/* Dump the filestruct inptr to stderr. */
|
||||
void dump_filestruct(const filestruct *inptr)
|
||||
|
||||
239
src/winio.c
239
src/winio.c
@@ -1,4 +1,3 @@
|
||||
|
||||
/* $Id$ */
|
||||
/**************************************************************************
|
||||
* winio.c *
|
||||
@@ -123,17 +122,21 @@ void get_key_buffer(WINDOW *win)
|
||||
doupdate();
|
||||
|
||||
errcount = 0;
|
||||
while ((input = wgetch(win)) == ERR) {
|
||||
errcount++;
|
||||
if (nodelay_mode) {
|
||||
if ((input = wgetch(win)) == ERR)
|
||||
return;
|
||||
} else
|
||||
while ((input = wgetch(win)) == ERR) {
|
||||
errcount++;
|
||||
|
||||
/* If we've failed to get a character MAX_BUF_SIZE times in a
|
||||
* row, assume that the input source we were using is gone and
|
||||
* die gracefully. We could check if errno is set to EIO
|
||||
* ("Input/output error") and die gracefully in that case, but
|
||||
* it's not always set properly. Argh. */
|
||||
if (errcount == MAX_BUF_SIZE)
|
||||
handle_hupterm(0);
|
||||
}
|
||||
/* If we've failed to get a character MAX_BUF_SIZE times in a
|
||||
* row, assume that the input source we were using is gone and
|
||||
* die gracefully. We could check if errno is set to EIO
|
||||
* ("Input/output error") and die gracefully in that case, but
|
||||
* it's not always set properly. Argh. */
|
||||
if (errcount == MAX_BUF_SIZE)
|
||||
handle_hupterm(0);
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
allow_pending_sigwinch(FALSE);
|
||||
@@ -331,7 +334,12 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
|
||||
*func_key = FALSE;
|
||||
|
||||
/* Read in a character. */
|
||||
while ((kbinput = get_input(win, 1)) == NULL);
|
||||
if (nodelay_mode) {
|
||||
kbinput = get_input(win, 1);
|
||||
if (kbinput == 0)
|
||||
return 0;
|
||||
} else
|
||||
while ((kbinput = get_input(win, 1)) == NULL);
|
||||
|
||||
switch (*kbinput) {
|
||||
case ERR:
|
||||
@@ -489,36 +497,36 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
|
||||
if (retval != ERR) {
|
||||
switch (retval) {
|
||||
case NANO_CONTROL_8:
|
||||
retval = ISSET(REBIND_DELETE) ? sc_seq_or(do_delete, 0) :
|
||||
sc_seq_or(do_backspace, 0);
|
||||
retval = ISSET(REBIND_DELETE) ? sc_seq_or(DO_DELETE, 0) :
|
||||
sc_seq_or(DO_BACKSPACE, 0);
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
#ifdef KEY_SDOWN
|
||||
/* ncurses and Slang don't support KEY_SDOWN. */
|
||||
case KEY_SDOWN:
|
||||
#endif
|
||||
retval = sc_seq_or((void *) do_down_void, *kbinput);
|
||||
retval = sc_seq_or(DO_DOWN_VOID, *kbinput);
|
||||
break;
|
||||
case KEY_UP:
|
||||
#ifdef KEY_SUP
|
||||
/* ncurses and Slang don't support KEY_SUP. */
|
||||
case KEY_SUP:
|
||||
#endif
|
||||
retval = sc_seq_or((void *) do_up_void, *kbinput);
|
||||
retval = sc_seq_or(DO_UP_VOID, *kbinput);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
#ifdef KEY_SLEFT
|
||||
/* Slang doesn't support KEY_SLEFT. */
|
||||
case KEY_SLEFT:
|
||||
#endif
|
||||
retval = sc_seq_or((void *) do_left, *kbinput);
|
||||
retval = sc_seq_or(DO_LEFT, *kbinput);
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
#ifdef KEY_SRIGHT
|
||||
/* Slang doesn't support KEY_SRIGHT. */
|
||||
case KEY_SRIGHT:
|
||||
#endif
|
||||
retval = sc_seq_or((void *) do_right, *kbinput);
|
||||
retval = sc_seq_or(DO_RIGHT, *kbinput);
|
||||
break;
|
||||
#ifdef KEY_SHOME
|
||||
/* HP-UX 10-11 and Slang don't support KEY_SHOME. */
|
||||
@@ -526,36 +534,36 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
|
||||
#endif
|
||||
case KEY_A1: /* Home (7) on numeric keypad with
|
||||
* NumLock off. */
|
||||
retval = sc_seq_or((void *) do_home, *kbinput);
|
||||
retval = sc_seq_or(DO_HOME, *kbinput);
|
||||
break;
|
||||
case KEY_BACKSPACE:
|
||||
retval = sc_seq_or((void *) do_backspace, *kbinput);
|
||||
retval = sc_seq_or(DO_BACKSPACE, *kbinput);
|
||||
break;
|
||||
#ifdef KEY_SDC
|
||||
/* Slang doesn't support KEY_SDC. */
|
||||
case KEY_SDC:
|
||||
if (ISSET(REBIND_DELETE))
|
||||
retval = sc_seq_or((void *) do_delete, *kbinput);
|
||||
retval = sc_seq_or(DO_DELETE, *kbinput);
|
||||
else
|
||||
retval = sc_seq_or((void *) do_backspace, *kbinput);
|
||||
retval = sc_seq_or(DO_BACKSPACE, *kbinput);
|
||||
break;
|
||||
#endif
|
||||
#ifdef KEY_SIC
|
||||
/* Slang doesn't support KEY_SIC. */
|
||||
case KEY_SIC:
|
||||
retval = sc_seq_or((void *) do_insertfile_void, *kbinput);
|
||||
retval = sc_seq_or(DO_INSERTFILE_VOID, *kbinput);
|
||||
break;
|
||||
#endif
|
||||
case KEY_C3: /* PageDown (4) on numeric keypad with
|
||||
* NumLock off. */
|
||||
retval = sc_seq_or((void *) do_page_down, *kbinput);
|
||||
retval = sc_seq_or(DO_PAGE_DOWN, *kbinput);
|
||||
break;
|
||||
case KEY_A3: /* PageUp (9) on numeric keypad with
|
||||
* NumLock off. */
|
||||
retval = sc_seq_or((void *) do_page_up, *kbinput);
|
||||
retval = sc_seq_or(DO_PAGE_UP, *kbinput);
|
||||
break;
|
||||
case KEY_ENTER:
|
||||
retval = sc_seq_or((void *) do_enter, *kbinput);
|
||||
retval = sc_seq_or(DO_ENTER, *kbinput);
|
||||
break;
|
||||
case KEY_B2: /* Center (5) on numeric keypad with
|
||||
* NumLock off. */
|
||||
@@ -567,7 +575,7 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
|
||||
/* HP-UX 10-11 and Slang don't support KEY_SEND. */
|
||||
case KEY_SEND:
|
||||
#endif
|
||||
retval = sc_seq_or((void *) do_end, *kbinput);
|
||||
retval = sc_seq_or(DO_END, *kbinput);
|
||||
break;
|
||||
#ifdef KEY_BEG
|
||||
/* Slang doesn't support KEY_BEG. */
|
||||
@@ -583,7 +591,7 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
|
||||
/* Slang doesn't support KEY_SCANCEL. */
|
||||
case KEY_SCANCEL:
|
||||
#endif
|
||||
retval = first_sc_for(currmenu, (void *) cancel_msg)->seq;
|
||||
retval = first_sc_for(currmenu, CANCEL_MSG)->seq;
|
||||
break;
|
||||
#endif
|
||||
#ifdef KEY_SBEG
|
||||
@@ -596,13 +604,13 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
|
||||
#ifdef KEY_SSUSPEND
|
||||
/* Slang doesn't support KEY_SSUSPEND. */
|
||||
case KEY_SSUSPEND:
|
||||
retval = sc_seq_or(do_suspend_void, 0);
|
||||
retval = sc_seq_or(DO_SUSPEND_VOID, 0);
|
||||
break;
|
||||
#endif
|
||||
#ifdef KEY_SUSPEND
|
||||
/* Slang doesn't support KEY_SUSPEND. */
|
||||
case KEY_SUSPEND:
|
||||
retval = sc_seq_or(do_suspend_void, 0);
|
||||
retval = sc_seq_or(DO_SUSPEND_VOID, 0);
|
||||
break;
|
||||
#endif
|
||||
#ifdef PDCURSES
|
||||
@@ -750,15 +758,15 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
retval = KEY_B2;
|
||||
break;
|
||||
case 'F': /* Esc O F == End on xterm/Terminal. */
|
||||
retval = sc_seq_or(do_end, 0);
|
||||
retval = sc_seq_or(DO_END, 0);
|
||||
break;
|
||||
case 'H': /* Esc O H == Home on xterm/Terminal. */
|
||||
retval = sc_seq_or(do_home, 0);;
|
||||
retval = sc_seq_or(DO_HOME, 0);;
|
||||
break;
|
||||
case 'M': /* Esc O M == Enter on numeric keypad with
|
||||
* NumLock off on VT100/VT220/VT320/xterm/
|
||||
* rxvt/Eterm. */
|
||||
retval = sc_seq_or(do_home, 0);;
|
||||
retval = sc_seq_or(DO_HOME, 0);;
|
||||
break;
|
||||
case 'P': /* Esc O P == F1 on VT100/VT220/VT320/Mach
|
||||
* console. */
|
||||
@@ -823,7 +831,7 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
case 'n': /* Esc O n == Delete (.) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* xterm/rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_delete, 0);;
|
||||
retval = sc_seq_or(DO_DELETE, 0);;
|
||||
break;
|
||||
case 'o': /* Esc O o == '/' on numeric keypad with
|
||||
* NumLock off on VT100/VT220/VT320/xterm/
|
||||
@@ -833,27 +841,27 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
case 'p': /* Esc O p == Insert (0) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_insertfile_void, 0);;
|
||||
retval = sc_seq_or(DO_INSERTFILE_VOID, 0);;
|
||||
break;
|
||||
case 'q': /* Esc O q == End (1) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_end, 0);;
|
||||
retval = sc_seq_or(DO_END, 0);;
|
||||
break;
|
||||
case 'r': /* Esc O r == Down (2) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_down_void, 0);;
|
||||
retval = sc_seq_or(DO_DOWN_VOID, 0);;
|
||||
break;
|
||||
case 's': /* Esc O s == PageDown (3) on numeric
|
||||
* keypad with NumLock off on VT100/VT220/
|
||||
* VT320/rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_page_down, 0);;
|
||||
retval = sc_seq_or(DO_PAGE_DOWN, 0);;
|
||||
break;
|
||||
case 't': /* Esc O t == Left (4) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_left, 0);;
|
||||
retval = sc_seq_or(DO_LEFT, 0);;
|
||||
break;
|
||||
case 'u': /* Esc O u == Center (5) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
@@ -863,22 +871,22 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
case 'v': /* Esc O v == Right (6) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_right, 0);
|
||||
retval = sc_seq_or(DO_RIGHT, 0);
|
||||
break;
|
||||
case 'w': /* Esc O w == Home (7) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_home, 0);;
|
||||
retval = sc_seq_or(DO_HOME, 0);
|
||||
break;
|
||||
case 'x': /* Esc O x == Up (8) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_up_void, 0);;
|
||||
retval = sc_seq_or(DO_UP_VOID, 0);
|
||||
break;
|
||||
case 'y': /* Esc O y == PageUp (9) on numeric keypad
|
||||
* with NumLock off on VT100/VT220/VT320/
|
||||
* rxvt/Eterm/Terminal. */
|
||||
retval = sc_seq_or(do_up, 0);;
|
||||
retval = sc_seq_or(DO_PAGE_UP, 0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -972,7 +980,7 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
break;
|
||||
default: /* Esc [ 1 ~ == Home on
|
||||
* VT320/Linux console. */
|
||||
retval = sc_seq_or(do_home, 0);;
|
||||
retval = sc_seq_or(DO_HOME, 0);;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1023,40 +1031,40 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
default: /* Esc [ 2 ~ == Insert on
|
||||
* VT220/VT320/Linux console/
|
||||
* xterm/Terminal. */
|
||||
retval = sc_seq_or(do_insertfile_void, 0);;
|
||||
retval = sc_seq_or(DO_INSERTFILE_VOID, 0);;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '3': /* Esc [ 3 ~ == Delete on VT220/VT320/
|
||||
* Linux console/xterm/Terminal. */
|
||||
retval = sc_seq_or(do_delete, 0);;
|
||||
retval = sc_seq_or(DO_DELETE, 0);;
|
||||
break;
|
||||
case '4': /* Esc [ 4 ~ == End on VT220/VT320/Linux
|
||||
* console/xterm. */
|
||||
retval = sc_seq_or(do_end, 0);;
|
||||
retval = sc_seq_or(DO_END, 0);;
|
||||
break;
|
||||
case '5': /* Esc [ 5 ~ == PageUp on VT220/VT320/
|
||||
* Linux console/xterm/Terminal;
|
||||
* Esc [ 5 ^ == PageUp on Eterm. */
|
||||
retval = sc_seq_or(do_page_up, 0);;
|
||||
retval = sc_seq_or(DO_PAGE_UP, 0);;
|
||||
break;
|
||||
case '6': /* Esc [ 6 ~ == PageDown on VT220/VT320/
|
||||
* Linux console/xterm/Terminal;
|
||||
* Esc [ 6 ^ == PageDown on Eterm. */
|
||||
retval = sc_seq_or(do_page_down, 0);;
|
||||
retval = sc_seq_or(DO_PAGE_DOWN, 0);;
|
||||
break;
|
||||
case '7': /* Esc [ 7 ~ == Home on rxvt. */
|
||||
retval = sc_seq_or(do_home, 0);
|
||||
retval = sc_seq_or(DO_HOME, 0);
|
||||
break;
|
||||
case '8': /* Esc [ 8 ~ == End on rxvt. */
|
||||
retval = sc_seq_or(do_end, 0);
|
||||
retval = sc_seq_or(DO_END, 0);
|
||||
break;
|
||||
case '9': /* Esc [ 9 == Delete on Mach console. */
|
||||
retval = sc_seq_or(do_delete, 0);;
|
||||
retval = sc_seq_or(DO_DELETE, 0);;
|
||||
break;
|
||||
case '@': /* Esc [ @ == Insert on Mach console. */
|
||||
retval = sc_seq_or(do_insertfile_void, 0);;
|
||||
retval = sc_seq_or(DO_INSERTFILE_VOID, 0);;
|
||||
break;
|
||||
case 'A': /* Esc [ A == Up on ANSI/VT220/Linux
|
||||
* console/FreeBSD console/Mach console/
|
||||
@@ -1079,23 +1087,23 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
break;
|
||||
case 'F': /* Esc [ F == End on FreeBSD
|
||||
* console/Eterm. */
|
||||
retval = sc_seq_or(do_end, 0);
|
||||
retval = sc_seq_or(DO_END, 0);
|
||||
break;
|
||||
case 'G': /* Esc [ G == PageDown on FreeBSD
|
||||
* console. */
|
||||
retval = sc_seq_or(do_page_down, 0);
|
||||
retval = sc_seq_or(DO_PAGE_DOWN, 0);
|
||||
break;
|
||||
case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD
|
||||
* console/Mach console/Eterm. */
|
||||
retval = sc_seq_or(do_home, 0);
|
||||
retval = sc_seq_or(DO_HOME, 0);
|
||||
break;
|
||||
case 'I': /* Esc [ I == PageUp on FreeBSD
|
||||
* console. */
|
||||
retval = sc_seq_or(do_page_up, 0);
|
||||
retval = sc_seq_or(DO_PAGE_UP, 0);
|
||||
break;
|
||||
case 'L': /* Esc [ L == Insert on ANSI/FreeBSD
|
||||
* console. */
|
||||
retval = sc_seq_or(do_insertfile_void, 0);
|
||||
retval = sc_seq_or(DO_INSERTFILE_VOID, 0);
|
||||
break;
|
||||
case 'M': /* Esc [ M == F1 on FreeBSD console. */
|
||||
retval = KEY_F(1);
|
||||
@@ -1143,10 +1151,10 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
retval = KEY_F(8);
|
||||
break;
|
||||
case 'U': /* Esc [ U == PageDown on Mach console. */
|
||||
retval = sc_seq_or(do_page_down, 0);
|
||||
retval = sc_seq_or(DO_PAGE_DOWN, 0);
|
||||
break;
|
||||
case 'V': /* Esc [ V == PageUp on Mach console. */
|
||||
retval = sc_seq_or(do_page_up, 0);
|
||||
retval = sc_seq_or(DO_PAGE_UP, 0);
|
||||
break;
|
||||
case 'W': /* Esc [ W == F11 on FreeBSD console. */
|
||||
retval = KEY_F(11);
|
||||
@@ -1155,7 +1163,7 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
||||
retval = KEY_F(12);
|
||||
break;
|
||||
case 'Y': /* Esc [ Y == End on Mach console. */
|
||||
retval = sc_seq_or(do_end, 0);
|
||||
retval = sc_seq_or(DO_END, 0);
|
||||
break;
|
||||
case 'Z': /* Esc [ Z == F14 on FreeBSD console. */
|
||||
retval = KEY_F(14);
|
||||
@@ -1212,13 +1220,13 @@ int get_escape_seq_abcd(int kbinput)
|
||||
{
|
||||
switch (tolower(kbinput)) {
|
||||
case 'a':
|
||||
return sc_seq_or(do_up_void, 0);;
|
||||
return sc_seq_or(DO_UP_VOID, 0);;
|
||||
case 'b':
|
||||
return sc_seq_or(do_down_void, 0);;
|
||||
return sc_seq_or(DO_DOWN_VOID, 0);;
|
||||
case 'c':
|
||||
return sc_seq_or(do_right, 0);;
|
||||
return sc_seq_or(DO_RIGHT, 0);;
|
||||
case 'd':
|
||||
return sc_seq_or(do_left, 0);;
|
||||
return sc_seq_or(DO_LEFT, 0);;
|
||||
default:
|
||||
return ERR;
|
||||
}
|
||||
@@ -1697,14 +1705,19 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
for (; j > 0; j--) {
|
||||
if (f->next != NULL)
|
||||
f = f->next;
|
||||
while (f->next != NULL && ((f->menus & currmenu) == 0 || strlen(f->help) == 0))
|
||||
|
||||
while (f->next != NULL && ((f->menus & currmenu) == 0
|
||||
#ifndef DISABLE_HELP
|
||||
|| strlen(f->help) == 0
|
||||
#endif
|
||||
))
|
||||
f = f->next;
|
||||
}
|
||||
|
||||
|
||||
/* And put back the equivalent key. */
|
||||
if (f != NULL) {
|
||||
const sc *s = first_sc_for(currmenu, (void *) f->scfunc);
|
||||
const sc *s = first_sc_for(currmenu, f->scfunc);
|
||||
if (s != NULL)
|
||||
unget_kbinput(s->seq, s->type == META, FALSE);
|
||||
}
|
||||
@@ -1733,7 +1746,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
* wheel is equivalent to moving down three lines. */
|
||||
for (i = 0; i < 3; i++)
|
||||
unget_kbinput((mevent.bstate & BUTTON4_PRESSED) ?
|
||||
sc_seq_or(do_up_void, 0) : sc_seq_or(do_down_void, 0);, FALSE,
|
||||
sc_seq_or(do_up_void, 0) : sc_seq_or(DO_DOWN_VOID, 0);, FALSE,
|
||||
FALSE);
|
||||
|
||||
return 1;
|
||||
@@ -1785,6 +1798,32 @@ const sc *get_shortcut(int menu, int *kbinput, bool
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Try to get a function back from a window. Just a wrapper so
|
||||
functions to need to create function_key meta_key blah blah
|
||||
mmenu - what menu name to look through for valid funcs */
|
||||
const subnfunc *getfuncfromkey(WINDOW *win)
|
||||
{
|
||||
int kbinput;
|
||||
bool func_key = FALSE, meta_key = FALSE;
|
||||
const sc *s;
|
||||
const subnfunc *f;
|
||||
|
||||
kbinput = parse_kbinput(win, &meta_key, &func_key);
|
||||
if (kbinput == 0)
|
||||
return NULL;
|
||||
|
||||
s = get_shortcut(currmenu, &kbinput, &meta_key, &func_key);
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
f = sctofunc((sc *) s);
|
||||
return f;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Move to (x, y) in win, and display a line of n spaces with the
|
||||
* current attributes. */
|
||||
void blank_line(WINDOW *win, int y, int x, int n)
|
||||
@@ -2411,7 +2450,7 @@ void reset_cursor(void)
|
||||
* character of this page. That is, the first character of converted
|
||||
* corresponds to character number actual_x(fileptr->data, start) of the
|
||||
* line. */
|
||||
void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
void edit_draw(filestruct *fileptr, const char *converted, int
|
||||
line, size_t start)
|
||||
{
|
||||
#if !defined(NANO_TINY) || defined(ENABLE_COLOR)
|
||||
@@ -2439,6 +2478,14 @@ void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) {
|
||||
const colortype *tmpcolor = openfile->colorstrings;
|
||||
|
||||
/* Set up multi-line color data for this line if it's not yet calculated */
|
||||
if (fileptr->multidata == NULL && openfile->syntax
|
||||
&& openfile->syntax->nmultis > 0) {
|
||||
int i;
|
||||
fileptr->multidata = nmalloc(openfile->syntax->nmultis * sizeof(short));
|
||||
for (i = 0; i < openfile->syntax->nmultis; i++)
|
||||
fileptr->multidata[i] = -1; /* Assue this applies until we know otherwise */
|
||||
}
|
||||
for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
|
||||
int x_start;
|
||||
/* Starting column for mvwaddnstr. Zero-based. */
|
||||
@@ -2504,7 +2551,7 @@ void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
}
|
||||
k = startmatch.rm_eo;
|
||||
}
|
||||
} else {
|
||||
} else if (fileptr->multidata != NULL && fileptr->multidata[tmpcolor->id] != CNONE) {
|
||||
/* This is a multi-line regex. There are two steps.
|
||||
* First, we have to see if the beginning of the line is
|
||||
* colored by a start on an earlier line, and an end on
|
||||
@@ -2521,6 +2568,22 @@ void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
regoff_t start_col;
|
||||
/* Where it starts in that line. */
|
||||
const filestruct *end_line;
|
||||
short md = fileptr->multidata[tmpcolor->id];
|
||||
|
||||
if (md == -1)
|
||||
fileptr->multidata[tmpcolor->id] = CNONE; /* until we find out otherwise */
|
||||
else if (md == CNONE)
|
||||
continue;
|
||||
else if (md == CWHOLELINE) {
|
||||
mvwaddnstr(edit, line, 0, converted, -1);
|
||||
continue;
|
||||
} else if (md == CBEGINBEFORE) {
|
||||
regexec(tmpcolor->end, fileptr->data, 1, &endmatch, 0);
|
||||
paintlen = actual_x(converted, strnlenpt(fileptr->data,
|
||||
endmatch.rm_eo) - start);
|
||||
mvwaddnstr(edit, line, 0, converted, paintlen);
|
||||
continue;
|
||||
}
|
||||
|
||||
while (start_line != NULL && regexec(tmpcolor->start,
|
||||
start_line->data, 1, &startmatch, 0) ==
|
||||
@@ -2584,15 +2647,16 @@ void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
* expanded location of the end of the match minus
|
||||
* the expanded location of the beginning of the
|
||||
* page. */
|
||||
if (end_line != fileptr)
|
||||
if (end_line != fileptr) {
|
||||
paintlen = -1;
|
||||
else
|
||||
fileptr->multidata[tmpcolor->id] = CWHOLELINE;
|
||||
} else {
|
||||
paintlen = actual_x(converted,
|
||||
strnlenpt(fileptr->data,
|
||||
endmatch.rm_eo) - start);
|
||||
|
||||
fileptr->multidata[tmpcolor->id] = CBEGINBEFORE;
|
||||
}
|
||||
mvwaddnstr(edit, line, 0, converted, paintlen);
|
||||
|
||||
step_two:
|
||||
/* Second step, we look for starts on this line. */
|
||||
start_col = 0;
|
||||
@@ -2637,6 +2701,9 @@ void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
|
||||
mvwaddnstr(edit, line, x_start,
|
||||
converted + index, paintlen);
|
||||
if (paintlen > 0)
|
||||
fileptr->multidata[tmpcolor->id] = CSTARTENDHERE;
|
||||
|
||||
}
|
||||
} else {
|
||||
/* There is no end on this line. But we
|
||||
@@ -2657,6 +2724,7 @@ void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
/* We painted to the end of the line, so
|
||||
* don't bother checking any more
|
||||
* starts. */
|
||||
fileptr->multidata[tmpcolor->id] = CENDAFTER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2746,7 +2814,7 @@ void edit_draw(const filestruct *fileptr, const char *converted, int
|
||||
/* Just update one line in the edit buffer. This is basically a wrapper
|
||||
* for edit_draw(). The line will be displayed starting with
|
||||
* fileptr->data[index]. Likely arguments are current_x or zero. */
|
||||
void update_line(const filestruct *fileptr, size_t index)
|
||||
void update_line(filestruct *fileptr, size_t index)
|
||||
{
|
||||
int line;
|
||||
/* The line in the edit window that we want to update. */
|
||||
@@ -2819,7 +2887,7 @@ bool need_vertical_update(size_t pww_save)
|
||||
void edit_scroll(scroll_dir direction, ssize_t nlines)
|
||||
{
|
||||
bool do_redraw = need_vertical_update(0);
|
||||
const filestruct *foo;
|
||||
filestruct *foo;
|
||||
ssize_t i;
|
||||
|
||||
/* Don't bother scrolling less than one line. */
|
||||
@@ -2914,11 +2982,11 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
|
||||
|
||||
/* Update any lines between old_current and current that need to be
|
||||
* updated. Use this if we've moved without changing any text. */
|
||||
void edit_redraw(const filestruct *old_current, size_t pww_save)
|
||||
void edit_redraw(filestruct *old_current, size_t pww_save)
|
||||
{
|
||||
bool do_redraw = need_vertical_update(0) ||
|
||||
need_vertical_update(pww_save);
|
||||
const filestruct *foo = NULL;
|
||||
filestruct *foo = NULL;
|
||||
|
||||
/* If either old_current or current is offscreen, scroll the edit
|
||||
* window until it's onscreen and get out. */
|
||||
@@ -3026,7 +3094,7 @@ void edit_redraw(const filestruct *old_current, size_t pww_save)
|
||||
* if we've moved and changed text. */
|
||||
void edit_refresh(void)
|
||||
{
|
||||
const filestruct *foo;
|
||||
filestruct *foo;
|
||||
int nlines;
|
||||
|
||||
if (openfile->current->lineno < openfile->edittop->lineno ||
|
||||
@@ -3178,6 +3246,19 @@ void do_cursorpos_void(void)
|
||||
do_cursorpos(FALSE);
|
||||
}
|
||||
|
||||
void enable_nodelay(void)
|
||||
{
|
||||
nodelay_mode = TRUE;
|
||||
nodelay(edit, TRUE);
|
||||
}
|
||||
|
||||
void disable_nodelay(void)
|
||||
{
|
||||
nodelay_mode = FALSE;
|
||||
nodelay(edit, FALSE);
|
||||
}
|
||||
|
||||
|
||||
/* Highlight the current word being replaced or spell checked. We
|
||||
* expect word to have tabs and control characters expanded. */
|
||||
void do_replace_highlight(bool highlight, const char *word)
|
||||
|
||||
Reference in New Issue
Block a user