Prefix with syntax?
michaelblyons opened this issue · 2 comments
Cool idea!
What if the prefix was chosen by the syntax highlighting?
- Python 1
- Python 2
- Plain Text 1
- SQL 1
- Plain Text 2
Thanks!
Very interesting suggestion. I will put some thought into this.
I don't think it's possible to know the filetype(syntax) when opening a new buffer.
Maybe we could add the filetype prefix when on_modified and gather the type from the syntax setting:
[file type prefix]<custom name><numbering>
, e.g., [Python] Pastebin 1
I do want to keep the current plugin as simple as possible.
But let's do some testing and see.
Hey @michaelblyons
I finally found time to work on this idea and generated a PoC. However, I'm unsure where to place separate counters for different syntaxes. This code will only label the buffer name with a [Syntax Name]
prefix while editing. I've decided not to integrate this back into the plugin, as there are too many considerations for customization.
But I will leave it here:
class commandBufferFileTypeLabel(sublime_plugin.EventListener):
def on_modified_async(self, view):
# Extract the file type (syntax) of the current view
syntax_path = view.settings().get('syntax')
current_file_type = syntax_path.split('/')[-1].split('.')[0] if syntax_path else "Something Went Wrong"
# If the view is not associated with a file (unsaved tab), handle the buffer name
if not view.file_name():
current_buffer_name = view.name()
# Remove any existing file type label from the buffer name
buffer_name_without_label = re.sub(r'^\[[^\]]+\] ', '', current_buffer_name)
# Construct the labeled buffer name
updated_buffer_name = f"[{current_file_type}] {buffer_name_without_label}"
# Only set the buffer name if it's different from the current name
if updated_buffer_name != current_buffer_name:
# Print the buffer name before modification
print(f"Before Modification: {current_buffer_name}")
view.set_name(updated_buffer_name)
# Print the buffer name after modification
print(f"After Modification: {updated_buffer_name}")