vim-pad

minimal etherpad alternative - vim plugin
git clone https://git.ce9e.org/vim-pad.git

commit
4ec02cfdbcb5fe4389b0bf18af0c9140838be91f
parent
7b48a168713b6bae69545f3aaf828aa2c8431dbb
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-05-29 14:30
use different client ID for each pad

Diffstat

M python/pad/__init__.py 8 ++++----

1 files changed, 4 insertions, 4 deletions


diff --git a/python/pad/__init__.py b/python/pad/__init__.py

@@ -9,7 +9,6 @@ import vim
    9     9 from . import diff
   10    10 
   11    11 BASE_URL = 'https://via.ce9e.org/hmsg/pad/'
   12    -1 CLIENT_ID = ''.join(random.sample(string.hexdigits, 6))
   13    12 
   14    13 pads = {}
   15    14 
@@ -20,6 +19,7 @@ class Pad:
   20    19 		self.local_changes = []
   21    20 		self.staged_changes = []
   22    21 		self.old = self.get_text()
   -1    22 		self.id = ''.join(random.sample(string.hexdigits, 6))
   23    23 
   24    24 		self.name = os.path.basename(buffer.name).removesuffix('.pad')
   25    25 		self.url = BASE_URL + self.name
@@ -47,7 +47,7 @@ class Pad:
   47    47 		else:
   48    48 			self.staged_changes = self.local_changes
   49    49 			self.local_changes = []
   50    -1 			data = [CLIENT_ID, 'changes', self.staged_changes]
   -1    50 			data = [self.id, 'changes', self.staged_changes]
   51    51 			try:
   52    52 				r = requests.post(self.url, json=data)
   53    53 				r.raise_for_status()
@@ -87,7 +87,7 @@ class Pad:
   87    87 
   88    88 	def handle_message(self, msg):
   89    89 		if msg[1] == 'changes':
   90    -1 			if msg[0] == CLIENT_ID:
   -1    90 			if msg[0] == self.id:
   91    91 				self.stagedChanges = []
   92    92 			else:
   93    93 				self.apply_changes(msg[2])
@@ -123,7 +123,7 @@ def on_channel(msg):
  123   123 	data = json.loads(msg.split(': ', 1)[1])
  124   124 	if data[1] == 'changes':
  125   125 		pad = pads[vim.current.buffer]
  126    -1 		if data[0] == CLIENT_ID:
   -1   126 		if data[0] == pad.id:
  127   127 			pad.staged_changes = []
  128   128 		else:
  129   129 			pad.apply_changes(data[2])