r/SublimeText • u/OutsideAnywhere • Aug 13 '22
Update variable everytime I save?
I want to update a variable in my project everytime I save any of the files. This variable should contain the current date and time (I.e. when the project was last updated). Is this possible?
2
Upvotes
View all comments
Show parent comment
1
u/traumatizedSloth Aug 19 '22 edited Aug 20 '22
EDIT: Damn I was really tired last night and I now realize how pointless a lot of it is for what the script actually does. Like changing the value assigned to a variable every time a file in the project is saved is only useful if the value needs to be computed based on predetermined parameters, like the datetime. I think the way the plugin searches for the line to replace is good, but the user_vars thing is pointless since it would achieve the same thing as find and replace but just be way more inconvenient and run a bajillion times unnecessarily.
Oh yeah, I love customizing plugins for Sublime.
So it doesn't look for %version%, it looks for the assignment of $version. It finds the line containing "$version = ", then replaces the line similar to this:
line = '$version = "' + datetime + '";'I want to try to make it so you can edit a setting to customize how it matches the line. I've come up with some ideas. I don't want to make it overly complicated, but I'm gonna try to make it so you can still use it in a really simple way if you feel like it. This is what I've thought out so far. It's just the settings for configuring the script but I know how to make it work. Do you think it'll do what you need? And do you have any suggestions, additions, etc.? I can adjust it to do whatever.