[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nano-devel] nano bug #54928: a syntax file should be fully read onl
From: |
Brand Huntsman |
Subject: |
Re: [Nano-devel] nano bug #54928: a syntax file should be fully read only when the syntax gets actually used |
Date: |
Wed, 14 Nov 2018 01:42:11 -0700 |
On Wed, 14 Nov 2018 00:14:17 -0700
Vlad Vladov <address@hidden> wrote:
> Is anyone working on this right now? If not I would be interested in
> taking a stab at it. Any suggestions where in the code I should look
> (I am new to this codebase)?
parse_rcfile() in rcfile.c with syntax_only==TRUE. The syntaxtype struct used
by live_syntax is in nano.h, you will need to copy and store (at the end of
parse_one_include()) the filename for the syntax in syntaxtype and once loaded,
free it and set field to null. A single conditional between "magic" and
"comment" can abort if (syntax_only && only_parse_syntax_headers).
Opening a file in a new buffer or renaming a file will need to load the syntax
if not already loaded. Look for code that sets the syntax field in an
openfilestruct. Syntaxes are probably currently read before any files from the
command line are known, so that will be fun figuring out which initial syntaxes
to load. Maybe just initialize an only_parse_syntax_headers global to false
which causes parse_rcfile() to only read headers during load, and then flip it
to true when finished reading in all syntax headers, at the end of
do_rcfiles(). The command line files are probably loaded with the same code
used to open a file in a new buffer, so they might just work without any extra
code.
The actual loading can be done with parse_one_include(), but you need to ignore
"syntax", "header" and "magic" commands since they already executed, and
calling them again will cause problems. The live_syntax global will need to be
set to the syntax you are loading before calling parse_one_include().
You could add a reference count to syntaxtype and increment everytime a buffer
uses the syntax and decrement when buffer is closed. When count reaches zero
you could free the regexes. But that adds more complexity for a case that will
rarely trigger. So I'd just leave the syntax loaded even if no files are still
using it.
Syntaxes can also be declared inside nanorc, these will need to be fully loaded
at startup. I believe syntax_only will be false while loading these, so you
might not have to do anything special, other than verifying they still work.
Thank you for wanting to implement this, it will help a lot in reducing memory
usage.