From 40073be5094f8576f2dd72d06133f62fe097e3f5 Mon Sep 17 00:00:00 2001
From: cschen <camillo.schenone@gmail.com>
Date: Sat, 15 Feb 2025 22:19:42 +0100
Subject: [PATCH] feat: adds small utility to check if a view is a codemp
 buffer

---
 Codemp.sublime-commands | 16 +++++++---------
 main.py                 |  7 +++++--
 plugin/utils.py         |  5 +++++
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/Codemp.sublime-commands b/Codemp.sublime-commands
index c40e4b6..5391fe6 100644
--- a/Codemp.sublime-commands
+++ b/Codemp.sublime-commands
@@ -13,12 +13,12 @@
       "default": "[\n\t$0\n]\n"
     }
   },
-  { "caption": "Codemp: Open Readme",
-    "command": "open_file",
-    "args": {
-      "file": "${packages}/CodempClient/README.md"
-    }
-  },
+  // { "caption": "Codemp: Open Readme",
+  //   "command": "open_file",
+  //   "args": {
+  //     "file": "${packages}/CodempClient/README.md"
+  //   }
+  // },
   {
     "caption": "Codemp: Browse Server",
     "command": "codemp_browse_server",
@@ -27,9 +27,7 @@
   {
     "caption": "Codemp: Browse Workspace",
     "command": "codemp_browse_workspace",
-    "args": {
-
-    }
+    "args": {}
   },
   {
     // # on_window_command, does not trigger when called from the command palette
diff --git a/main.py b/main.py
index 7e7e8c5..0163ca4 100644
--- a/main.py
+++ b/main.py
@@ -51,7 +51,7 @@ def kill_all():
     session.stop()
 
 def vbuff_form_view(view):
-    if not view.settings().get(g.CODEMP_VIEW_TAG, False):
+    if not is_codemp_buffer(view):
         raise ValueError("The view is not a Codemp Buffer.")
 
     buffid = str(view.settings().get(g.CODEMP_BUFFER_ID))
@@ -103,8 +103,11 @@ class CodempReplaceTextCommand(sublime_plugin.TextCommand):
 
 
 class CodempSyncBuffer(sublime_plugin.TextCommand):
+    def is_enabled(self) -> bool:
+        return is_codemp_buffer(self.view)
+
     def run(self, edit):
-        buff = buffers.lookupId(str(self.view.settings().get(g.CODEMP_BUFFER_ID)))
+        buff = vbuff_form_view(self.view)
         buff.sync(TEXT_LISTENER)
 
 
diff --git a/plugin/utils.py b/plugin/utils.py
index e2fd018..ae1011c 100644
--- a/plugin/utils.py
+++ b/plugin/utils.py
@@ -99,6 +99,11 @@ def view_from_local_path(path):
             if view.file_name() == path:
                 return view
 
+def is_codemp_buffer(view):
+    if view.settings().get(g.CODEMP_VIEW_TAG, False):
+        return True
+    else:
+        return False
 
 def draw_cursor_region(view, start, end, user):
     reg = rowcol_to_region(view, start, end)