Sublime Forum

Regular expression from plugin to yaml file

#1

I would like to introduce a variable containing the regular expression into the yaml file, is it possible?

so that i can use configurations for syntax.

0 Likes

#2

Not sure what you mean in this vague context. Can you provide an actual case which you think it should work like?

0 Likes

#3

i have a log file with different interesting contents to which i wish to make it as symbols to quickly jump using ctrl+R.

but i wanted strings to be read from a config file, so that i can make it generic.

‘.(Entering.)\b’
‘.*(\b[a-zA-Z]+::init.Initializing.)\b’

i want more like this be added, but not modifying the yaml file, instead read it from a settings or config file.

my current yaml file as below,

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Logging stubs
file_extensions: [log]
scope: source.log
contexts:
  main:
    # tuts captured
    - match: '.*(Entering.*)\b'
      scope: meta.function.text.plain
      captures:
        1: entity.name.function.text.plain
    # tuts captured
    - match: '.*(\b[a-zA-Z]+::init.*Initializing.*)\b'
      scope: meta.function.text.plain
      captures:
        1: entity.name.function.text.plain

my tmpreferences file as below,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>name</key>
  <string>Symbol List</string>
  <key>scope</key>
  <string>markup.bold</string>
  <key>settings</key>
  <dict>
    <key>showInSymbolList</key>
    <integer>1</integer>
  </dict>
</dict>
</plist>
0 Likes

#4

That’s not possible without generating the syntax definition file dynamically.

0 Likes

#5

so you mean i can write directly to the syntax file from the plugin.

if that is the way i think it is cool too…

0 Likes

#6

Your plugin can write to the place like Packages/my_plugin/my_syntax.sublime-syntax when ST starts or the settings file changed for sure. ST will reload the changed syntax file.

1 Like

#7

This sounds good enough for my situation. but if i have to deploy in store, will this logic work?

0 Likes

#8

what logic?

0 Likes

#9

by logic, i mean writing to the file directly inside Packages/my_plugin/my_syntax.sublime-syntax file.

0 Likes

#10

Any place under Packages/ will work.

1 Like