finer macro selection

This commit is contained in:
Maximilian Keßler 2022-02-18 10:05:43 +01:00
parent a64f5a01bf
commit 065734a628
2 changed files with 15 additions and 8 deletions

View file

@ -48,7 +48,7 @@ def formatter_from_file_extension(
allow_infile_config=allow_infile_config allow_infile_config=allow_infile_config
) )
if default_macros: if default_macros:
formatter.macros = get_default_macros(formatter.config.tex_flavour) formatter.macros = get_default_macros(formatter.config.tex_flavour, formatter.config.tex_type)
return formatter return formatter

View file

@ -1,5 +1,5 @@
from .macros import * from .macros import *
from .enums import TeXFlavour, Argument from .enums import TeXFlavour, Argument, TeXType
def make_simple_macro(name: str, arg): def make_simple_macro(name: str, arg):
@ -12,7 +12,7 @@ def make_simple_macro(name: str, arg):
) )
def get_default_macros(tex_flavour: TeXFlavour): def get_default_macros(tex_flavour: TeXFlavour, tex_type: TeXType):
both = [ both = [
make_simple_macro('!', FormatterProperty.file_prefix), make_simple_macro('!', FormatterProperty.file_prefix),
make_simple_macro('name', FormatterProperty.name), make_simple_macro('name', FormatterProperty.name),
@ -28,14 +28,16 @@ def get_default_macros(tex_flavour: TeXFlavour):
make_simple_macro('repocommit', FormatterProperty.repo_commit), make_simple_macro('repocommit', FormatterProperty.repo_commit),
make_simple_macro('repodirty', FormatterProperty.repo_dirty), make_simple_macro('repodirty', FormatterProperty.repo_dirty),
make_simple_macro('sourcename', FormatterProperty.source_file_name), make_simple_macro('sourcename', FormatterProperty.source_file_name),
make_simple_macro('outtype', FormatterProperty.tex_out_type),
ImplementationBeginMacro(),
ImplementationEndMacro(),
ConfigEndMacro(), ConfigEndMacro(),
ConfigBeginMacro(), ConfigBeginMacro(),
]
docstrip = [
make_simple_macro('outtype', FormatterProperty.tex_out_type),
MacroCodeBeginMacro(), MacroCodeBeginMacro(),
MacroCodeEndMacro(), MacroCodeEndMacro(),
GuardMacro(), GuardMacro(),
ImplementationBeginMacro(),
ImplementationEndMacro(),
] ]
tex2 = [ tex2 = [
ArgumentMacro( ArgumentMacro(
@ -97,9 +99,14 @@ def get_default_macros(tex_flavour: TeXFlavour):
) )
) )
] ]
macros = both
if tex_flavour == TeXFlavour.LaTeX2e: if tex_flavour == TeXFlavour.LaTeX2e:
return tex2 + both macros += tex2
elif tex_flavour == TeXFlavour.LaTeX3: elif tex_flavour == TeXFlavour.LaTeX3:
return tex3 + both macros += tex3
else: else:
raise NotImplementedError raise NotImplementedError
if tex_type == TeXType.TeXDocstrip:
macros += docstrip
return macros