Anonymous avatar Anonymous committed 876fdf8

Use tmLanguage feature for syntax highlighting, don't try to do it programmatically.

Programmatic syntax highlighting via add_regions swapped foreground and background colors. The current approach via regex matching cheats by using column separators that differ slightly from each other. It ain't pretty.

Comments (0)

Files changed (4)

 syntax:glob
-*.tmLanguage
 *.tmLanguage.cache
 *.pyc

Tablist.JSON-tmLanguage

 { "name": "Tablist",
   "scopeName": "text.tablist", 
-  "fileTypes": [""], 
+  "fileTypes": [], 
   "patterns": [
+  	{
+  		"match": "^[ 0-9]*:",
+  		"name": "comment",
+  		"comment": "Make numeric view id stand out less."
+  	},
+  	{
+  		"match": "([0-9.]+[bkMG]) ([bf])",
+  		"name": "tablist.size-and-type",
+  		"comment": "Buffer size and type",
+  		"captures": {
+  			"1": { "name": "constant.numeric" },
+  			"2": { "name": "support.type" }
+  		}
+  	},
+  	{
+  		"match": "[|] <([^>])>",
+  		"name": "tablist.directory",
+  		"comment": "Directory name",
+  		"captures": {
+  			"1": { "name": "comment" }
+  		}
+  	},
+  	{
+  		"match": "[|]: (.*)$",
+  		"name": "tablist.filename",
+  		"comment": "Filename",
+  		"captures": {
+  			"1": { "name": "entity.name.type" }
+  		}
+  	}
   ],
   "uuid": "58481c47-e772-47be-aad2-0cb53aca69bf"
 }

Tablist.tmLanguage

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>fileTypes</key>
+	<array>
+	</array>
+	<key>name</key>
+	<string>Tablist</string>
+	<key>patterns</key>
+	<array>
+		<dict>
+			<key>comment</key>
+			<string>Make numeric view id stand out less.</string>
+			<key>match</key>
+			<string>^[ 0-9]*:</string>
+			<key>name</key>
+			<string>comment</string>
+		</dict>
+		<dict>
+			<key>captures</key>
+			<dict>
+				<key>1</key>
+				<dict>
+					<key>name</key>
+					<string>constant.numeric</string>
+				</dict>
+				<key>2</key>
+				<dict>
+					<key>name</key>
+					<string>support.type</string>
+				</dict>
+			</dict>
+			<key>comment</key>
+			<string>Buffer size and type</string>
+			<key>match</key>
+			<string>([0-9.]+[bkMG]) ([bf])</string>
+			<key>name</key>
+			<string>tablist.size-and-type</string>
+		</dict>
+		<dict>
+			<key>captures</key>
+			<dict>
+				<key>1</key>
+				<dict>
+					<key>name</key>
+					<string>comment</string>
+				</dict>
+			</dict>
+			<key>comment</key>
+			<string>Directory name</string>
+			<key>match</key>
+			<string>[|] &lt;([^&gt;])&gt;</string>
+			<key>name</key>
+			<string>tablist.directory</string>
+		</dict>
+		<dict>
+			<key>captures</key>
+			<dict>
+				<key>1</key>
+				<dict>
+					<key>name</key>
+					<string>entity.name.type</string>
+				</dict>
+			</dict>
+			<key>comment</key>
+			<string>Filename</string>
+			<key>match</key>
+			<string>[|]: (.*)$</string>
+			<key>name</key>
+			<string>tablist.filename</string>
+		</dict>
+	</array>
+	<key>scopeName</key>
+	<string>text.tablist</string>
+	<key>uuid</key>
+	<string>58481c47-e772-47be-aad2-0cb53aca69bf</string>
+</dict>
+</plist>
 	def __init__(self, arg):
 		super(TablistCommand, self).__init__(arg)
 		self.pt = 0
-		self.id_regions = []
-		self.dirty_regions = []
-		self.size_regions = []
-		self.type_regions = []
-		self.directory_regions = []
-		self.name_regions = []
 
 	def find_view(self):
 		views = self.window.views()
 		view.settings().set('command_mode', False)
 		view.settings().set('tablist_current_line', 0)
 		self.pt = 0
-		self.id_regions = []
-		self.dirty_regions = []
-		self.size_regions = []
-		self.type_regions = []
-		self.directory_regions = []
-		self.name_regions = []
 		return view
 	
 	def erase_view(self, view):
 			return string
 		return string[0:(length-1)] + u'…'
 	
-	def insert_for_region(self, view, edit, string, regions):
-		b = self.pt
-		self.pt += view.insert(edit, self.pt, string)
-		e = self.pt
-		regions.append(sublime.Region(b, e))
-	
-	def insert_no_region(self, view, edit, string):
-		self.pt += view.insert(edit, self.pt, string)
-
 	def insert_view_line(self, v, edit, view):
 		if (v.name()):
 			name = v.name()
 			vdirty = '*'
 		else:
 			vdirty = ' '
-		self.insert_for_region(view, edit, '{0:>5d}'.format(v.id()) + ': ', self.id_regions)
-		self.insert_for_region(view, edit, vdirty, self.dirty_regions)
-		self.insert_no_region(view, edit, ' ')
-		self.insert_for_region(view, edit, view_size, self.size_regions)
-		self.insert_no_region(view, edit, ' ')
-		self.insert_for_region(view, edit, ntype, self.type_regions)
-		self.insert_no_region(view, edit, ' | ')
-		self.insert_for_region(view, edit, self.ltruncate(dname, 30), self.directory_regions)
-		self.insert_no_region(view, edit, ' | ')
-		self.insert_for_region(view, edit, self.rtruncate(name, 50), self.name_regions)
-		self.insert_no_region(view, edit, "\n")
-
-	def add_highlight(self, v):
-		v.add_regions('dired_id', self.id_regions, 'comment')
-		v.add_regions('dired_dirty', self.dirty_regions, 'class')
-		v.add_regions('dired_size', self.size_regions, 'constant.numeric')
-		v.add_regions('dired_type', self.type_regions, 'storage.type')
-		v.add_regions('dired_directory', self.directory_regions, 'entity.name.type')
-		v.add_regions('dired_name', self.name_regions, 'string')
+		self.pt += view.insert(edit, self.pt,
+			'{0:>5d}'.format(v.id()) + ': ' +
+			vdirty +
+			' ' +
+			view_size +
+			' ' +
+			ntype +
+			' | <' + self.ltruncate(dname, 30) + '> |: ' +
+			self.rtruncate(name, 50) +
+			"\n")
 
 	def run(self):
 		view = self.find_view()
 		for v in all_views:
 			self.insert_view_line(v, edit, view)
 		view.end_edit(edit)
-		self.add_highlight(view)
 		line = view.settings().get('tablist_current_line')
 		pt = view.text_point(line, 0)
 		r = sublime.Region(pt)
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.