I've made a simple plugin that updates meta data in an HTML page on command. The problem is when a closing slash is included in the tag, the search doesn't match it. When I copy and paste the regex into the editor directly, it matches perfectly. I don't know if this is a regex problem (with the trailing slash being interpreted as a segmentation character), if this is a view.find() problem, both, or something else entirely. The relevant part of my code is below:
- Code: Select all
import sublime, sublime_plugin, os
class UpdatemetaCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Get the current user environment variable. Windows uses 'USERNAME', while Mac uses 'USER'
user = os.environ.get( "USERNAME" )
if not user:
user = os.environ.get( "USER" )
#Searches and replaces the developer tag;
#Regex here matches in regular find/replace with regex turned on.
#In code, it matches:
#<meta name="developer" content="foo">
#but not
#<meta name="developer" content="foo"/>
#or
#<meta name="developer" content="foo" />
tag = self.view.find('<meta name="developer" content=".[^>]*>', sublime.IGNORECASE)
self.view.replace(edit, tag, '<meta name="developer" content="' + user + '">')
I've tried a couple variations of the regex to no avail. The above and below:
- Code: Select all
<meta name="developer" content=".*
The console gives me an error that seems to be related to the fact that tag is ending up null because view.find() isn't matching anything.
Boost.Python.ArgumentError: Python argument types in
View.replace(View, Edit, NoneType, str)
did not match C++ signature:
replace(SP<TextBufferView>, SP<Edit>, SelectionRegion, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >)
I'm fairly new to plugin (and Python for that matter) development, so I apologize in advance if this is documented someplace. Any help would be appreciated.