Commit Graph

490 Commits (ad451933c6914a592417e1cb10cde0964d114001)

Author SHA1 Message Date
Benno Schulenberg 56d98052d1 tweaks: adjust the indentation after the previous change 2019-10-08 11:51:47 +02:00
Benno Schulenberg 265d3245af rcfile: process extensions to file-matching commands straightaway
When 'extendsyntax' is used with a 'header' or 'magic' command, it
must be processed immediately.  It is pointless to store the command,
because when then it is processed (when the syntax gets used), it is
too late to have any effect.

This fixes https://savannah.gnu.org/bugs/?56997.

With-help-from: Brand Huntsman <alpha@qzx.com>

Bug existed since version 4.3, commit cba9d8d0.
2019-10-08 11:37:02 +02:00
Benno Schulenberg c8dc67717b tweaks: mark as 'const' a parameter that takes fixed strings [coverity] 2019-10-01 15:02:08 +02:00
Benno Schulenberg a4933873c9 tweaks: avoid leaking memory when finding an invalid string [coverity] 2019-09-30 19:42:27 +02:00
Benno Schulenberg 2307b31887 tweaks: use 'void' in prototypes of parameterless functions [coverity] 2019-09-30 19:06:25 +02:00
Benno Schulenberg 3644d51b97 new feature: a 'tabgives' command to define what the Tab key produces
The 'tabgives' command is syntax-specific and should be followed by a
string containing the character(s) that a single press of the <Tab> key
should produce -- most likely a single TAB or a small bunch of spaces,
but any string is allowed.  This overrides the 'tabstospaces' option.

When one wants to make sure <Tab> inserts always four spaces and never
a TAB when editing a Python file, one could add to one's nanorc:

  extendsyntax python tabgives "    "

where there are four spaces between the quotes.  And when one wants
to ensure, when editing a Makefile, that <Tab> always inserts a TAB
and never spaces, independent of what tabstospaces is set to, one
could add to one's nanorc:

  extendsyntax makefile tabgives "	"

where there is a literal TAB character between the quotes.

This fulfills https://savannah.gnu.org/bugs/?53661,
Requested-by: Andrew Pennebaker <andrew.pennebaker@gmail.com>
And addresses https://savannah.gnu.org/bugs/?54760.
Requested-by: Henry van Megen <hvanmegen@gmail.com>
And addresses part of https://savannah.gnu.org/bugs/?54775.
Requested-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
2019-09-25 19:35:07 +02:00
Benno Schulenberg 073bd3ad6e rcfile: properly handle an empty syntax before an 'include' statement
So that in the error message the correct filename gets shown
instead of the name of the (first) include file.

Reported-by: Brand Huntsman <alpha@qzx.com>
2019-08-18 10:56:17 +02:00
Brand Huntsman 304f07258b rcfile: for an empty syntax, show the line number of the 'syntax' command
When reporting a syntax without any color commands, show the line number
of the relevant 'syntax' command instead of the line number where the
emptiness is concluded, because the latter can be many lines later.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2019-08-17 13:47:19 +02:00
Benno Schulenberg e1c2573c7a tweaks: improve a comment, and drop a superfluous one 2019-08-17 13:28:47 +02:00
Benno Schulenberg 07ec7de8eb tweaks: remove a saving and restoring that has become superfluous
The previous commit saves and restores filename and linenumber for
each single included file (after globbing), so it is now redundant
to do it for each 'include' command.
2019-08-17 13:21:34 +02:00
Brand Huntsman 82f5fed45a rcfile: report the correct command location for an invalid 'include'
For each included file, save and restore file name and line number of
the including file, so that an error message about a faulty 'include'
command can indicate the location of this 'include'.

This fixes https://savannah.gnu.org/bugs/?56488.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2019-08-17 13:07:20 +02:00
Benno Schulenberg 47068c3770 build: fix compilation when configured with --disable-color 2019-06-17 09:59:15 +02:00
Benno Schulenberg c7ca60b046 tweaks: don't check the user's nanorc file for accessibility twice
Also, condense some alternatives into a single 'if'.
2019-06-16 17:53:44 +02:00
Benno Schulenberg 01e4f85f29 tweaks: remove a check that is no longer relevant
Since commit 7028adf2 from three days ago, also the color commands of
syntaxes that are defined in a main nanorc will get parsed during a
second pass, so it is perfectly possible to extend such syntaxes
later on in the same (or another) nanorc file.
2019-06-16 11:02:03 +02:00
Benno Schulenberg 6bfbb2bcd9 tweaks: remove two more unneeded assignments
'opensyntax' is relevant only during the first pass through all the
nanorc files (intros_only == TRUE) when it is checked that syntax
commands are grouped properly and not mixed with others.  And
'lastcolor' is relevant only during the second pass of a specific
syntax, because only then the color commands are actually parsed.
2019-06-16 10:41:53 +02:00
Benno Schulenberg d82c753ba4 rcfile: at terminating points, verify that a defined syntax is not empty
Whenever, in an rcfile, a command is encountered that is not part of a
syntax definition, a currently open syntax should be closed, but only
after checking that the syntax contains at least one color command.

This fixes https://savannah.gnu.org/bugs/?56501.

Bug existed since version 2.3.3.
2019-06-15 19:42:31 +02:00
Benno Schulenberg 0af9ce926b rcfile: close off a syntax when a non-syntax command is encountered
The 'color' commands of a syntax definition should not be allowed to
be interspersed with other, non-syntax commands.

This fixes https://savannah.gnu.org/bugs/?56498.

Bug existed since before version 2.6.0.
2019-06-15 15:07:57 +02:00
Benno Schulenberg 4e14a8a977 tweaks: remove two unneeded assignments, and improve a comment
Also reshuffle a line, for esthetics.
2019-06-15 14:35:53 +02:00
Benno Schulenberg accd17c249 tweaks: remove four unneeded pre-processor directives
The parse_next_word() function is not being used by the history code
anymore since commit ecd18c16, more than two years ago.
2019-06-15 14:17:13 +02:00
Benno Schulenberg e8eb30cad6 tweaks: just mark four rcfile errors for translation, like the others
The messages get translated when they get stored in the linked list.
This is to economize on the number of actual calls of gettext().
2019-06-15 14:13:20 +02:00
Benno Schulenberg 36bd68f3ab tweaks: rename a function, to better suit what it does 2019-06-15 14:07:57 +02:00
Benno Schulenberg 03692363a2 tweaks: move a syntax check to a better place, to reduce duplication 2019-06-15 13:04:01 +02:00
Benno Schulenberg 0e94575c6b rcfile: check for missing color commands only when a syntax is still open
This fixes https://savannah.gnu.org/bugs/?56497.

Bug existed since commit 7028adf2 from two days ago.
2019-06-15 12:17:33 +02:00
Benno Schulenberg 27cc3117e2 tweaks: rename two parameters, for more contrast, and elide another
Also rename a function.
2019-06-14 10:56:49 +02:00
Benno Schulenberg 19f71632c8 tweaks: remove an unneeded "closing" of a syntax after extending it
As 'extendsyntax' commands are no longer interpreted immediately when
the rcfiles are read, there is no need to set 'opensyntax' to FALSE
after interpreting such a command -- for a single syntax they are all
interpreted in a row.
2019-06-14 10:56:49 +02:00
Benno Schulenberg e3f18e7a6c tweaks: rename two variables, and frob some comments
Also reshuffle the newline stripping, as it's pointless for lines
that are skipped.
2019-06-14 10:56:49 +02:00
Benno Schulenberg b55923f5ec tweaks: reshuffle some lines, to group things more sensibly 2019-06-14 10:56:49 +02:00
Benno Schulenberg 7028adf211 rcfile: fully read each included file, so all its syntaxes are seen
An included file can contain multiple syntaxes.  If reading would stop
as soon as a command different from 'syntax' and 'header' and 'magic'
is found, any later syntaxes would not be seen.  So each nanorc file
needs to be fully scanned -- it's just the interpretation of all the
color commands that we want to delay until the syntax gets actually
used.

This fixes https://savannah.gnu.org/bugs/?56478.

Bug existed since commit cba9d8d0 from a month ago.
2019-06-14 10:49:30 +02:00
Benno Schulenberg d7df7c694a tweaks: elide a pre-processor #else clause, by using braces instead 2019-06-13 15:47:29 +02:00
Benno Schulenberg 781c7a7a5f chars: create a dedicated function for getting the length of a character
Instead of calling in twenty places parse_mbchar(pointer, NULL, NULL),
use a simpler and faster char_length(pointer).  This saves pushing two
unneeded parameters onto the stack, avoids two needless ifs, and elides
an intermediate variable.

Its main purpose will follow in a later commit: to speed up searching.
2019-06-09 18:38:46 +02:00
Benno Schulenberg cdc9482d8f tweaks: rename three variables, to use full words instead of abbrevs 2019-06-05 14:50:01 +02:00
Benno Schulenberg 7c1b649eb8 tweaks: rename a function and its parameters, to be more fitting
Also, reshuffle their order, and improve or adjust some comments.
And change the type of 'pairnum' to short, what ncurses uses too.
2019-06-05 13:08:14 +02:00
Brand Huntsman 57b3f83cfe rcfile: compile the color regexes just once
When a syntax gets parsed, store the compiled color regexes right away,
instead of compiling them a second time in color_update().

This addresses https://savannah.gnu.org/bugs/?56432.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2019-06-04 19:57:46 +02:00
Brand Huntsman 8bc2d18fa9 tweaks: remove an unneeded pre-processor '#else' clause
Commit 1e2e6733 added braces and made the semicolon no longer needed
when libmagic is not used.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2019-06-04 19:27:34 +02:00
Benno Schulenberg 9b30bb15cc tweaks: adjust the indentation after the previous change
And reshuffle two declarations.
2019-06-03 15:51:07 +02:00
Benno Schulenberg a1669e1bfd rcfile: disallow extending a syntax that is defined in a main nanorc
The /etc/nanorc file should not define any syntax directly (and
preferably not include any either, to not slow startup down with
syntaxes the user is never going to use), and if the ~/.nanorc file
defines a syntax directly, there is no need to use 'extendsyntax':
the command can be added to the syntax itself -- it would be better
even: it keeps things together.
2019-06-03 15:42:06 +02:00
Benno Schulenberg 3d6eca3f26 tweaks: reshuffle some lines, to put the most likely candidate first 2019-06-03 15:04:00 +02:00
Benno Schulenberg c025a60ce9 tweaks: rename a function and a variable, for contrast and variety 2019-06-03 15:01:28 +02:00
Benno Schulenberg 5e1f90d8fa tweaks: don't bother to free the content of 'extendsyntax' commands
Extending a syntax will be rather rare, so the amount of memory it
takes up will be minimal.  It's not worth the trouble to free this
memory -- it only takes time.  Plus: we don't bother to free the
memory of a syntax that gets fully redefined either.
2019-06-03 14:37:27 +02:00
Benno Schulenberg 7f3ffe8544 tweaks: remove a bit of redundant code
When an included file has just been fully parsed, 'lastcolor' is still
pointing at the last color regex that was added to the list -- no need
to refind the end of this list.
2019-06-03 14:21:17 +02:00
Benno Schulenberg 844214b4a0 tweaks: rename two variables, to not be abbreviations
Also reshuffle two declarations.
2019-05-31 12:54:20 +02:00
Benno Schulenberg f9dfca7d5a tweaks: rename a variable, to be shorter 2019-05-31 12:46:15 +02:00
Benno Schulenberg fe40e8867d tweaks: rename a struct element, to be distinct
And to match the style of its sisters.
2019-05-31 12:25:15 +02:00
Benno Schulenberg 923a90cba0 tweaks: rename a type, for more contrast 2019-05-31 12:18:30 +02:00
Benno Schulenberg 1e2e6733df tweaks: add a pair of braces, to silence a compiler warning
Also, put an 'else' on the same line as the preceding closing brace.
2019-05-21 17:25:45 +02:00
Benno Schulenberg da8c74a44f docs: note Brand as the author of the delayed syntax parsing 2019-05-20 10:45:33 +02:00
Brand Huntsman cba9d8d05e rcfile: fully parse a syntax file only when needed
When parsing an included syntax file, stop reading when a command other
than 'syntax', 'header' or 'magic' is encountered.  The syntax file is
fully parsed the first time that a file needs it.  Each 'extendsyntax'
command is stored for unloaded syntaxes and applied after the syntax
is loaded.

Closing a buffer does not unload the syntax, even if no longer used by
another buffer.

This addresses https://savannah.gnu.org/bugs/?54928.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2019-05-20 10:25:47 +02:00
Brand Huntsman 0e29c2a24a rcfile: store errors and display them when nano terminates
This is needed to implement the demand loading of syntax files, as any
errors that these files may contain would otherwise overwrite things on
the screen and the messages wouldn't be on the terminal when nano exits.

It also allows nano to start up on a Linux console when there are errors.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2019-05-20 10:25:47 +02:00
Benno Schulenberg 8720cfcce9 tweaks: rename two more functions, to be simpler too 2019-05-04 11:21:45 +02:00
Benno Schulenberg 954c4d03ac tweaks: rename two functions, to be simpler 2019-05-04 11:21:45 +02:00