Kirill Simonov avatar Kirill Simonov committed 8b4df6e

Load yaml_hl.cfg from the script path.

Comments (0)

Files changed (1)

examples/yaml-hl/yaml_hl.py

 #!/usr/bin/python
 
-import yaml, codecs, sys, optparse
+import yaml, codecs, sys, os.path, optparse
 
 class Style:
 
             self.output = sys.stdout
 
     def highlight(self):
-        if self.style.header:
-            self.output.write(self.style.header)
         input = self.input.read()
         if input.startswith(codecs.BOM_UTF16_LE):
             input = unicode(input, 'utf-16-le')
             chunks.append(substitution)
         chunks.reverse()
         result = u''.join(chunks)
+        if self.style.header:
+            self.output.write(self.style.header)
         self.output.write(result.encode('utf-8'))
         if self.style.footer:
             self.output.write(self.style.footer)
     parser = optparse.OptionParser()
     parser.add_option('-s', '--style', dest='style', default='ascii',
             help="specify the highlighting style", metavar='STYLE')
-    parser.add_option('-c', '--config', dest='config', default='yaml_hl.cfg',
+    parser.add_option('-c', '--config', dest='config',
+            default=os.path.join(os.path.dirname(sys.argv[0]), 'yaml_hl.cfg'),
             help="set an alternative configuration file", metavar='CONFIG')
     parser.add_option('-i', '--input', dest='input', default=None,
             help="set the input file (default: stdin)", metavar='FILE')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.