branch: externals/crdt commit 10f423bbefd175f12fddf96b753101f0560fb469 Merge: 3dcc9958f6 270a4099bb Author: Qiantan Hong <qh...@mit.edu> Commit: Qiantan Hong <qh...@mit.edu>
Merge branch 'fix' into development --- crdt.el | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/crdt.el b/crdt.el index 317f9c6420..11994aed9c 100644 --- a/crdt.el +++ b/crdt.el @@ -35,7 +35,6 @@ (require 'url) (require 'color) (require 'forms) -(require 'tramp) (defconst crdt-version "0.3.0") (defconst crdt-protocol-version "0.3.0") @@ -54,6 +53,10 @@ "Default display name." :type 'string) +(defcustom crdt-default-session-name (format "%s_session" (user-login-name)) + "Default session name." + :type 'string) + (defcustom crdt-confirm-disconnect t "Ask for confirmation when a CRDT server is to stop the connection from some client." :type 'boolean) @@ -546,7 +549,7 @@ after synchronization is completed." (with-current-buffer crdt-buffer ,@body) (unless (process-contact (crdt--session-network-process crdt--session) :server) - (setq crdt-buffer (create-file-buffer (concat (crdt--tramp-prefix crdt--session) ,name))) + (setq crdt-buffer (generate-new-buffer (format "%s<%s>" ,name (crdt--session-name crdt--session)))) (puthash ,name crdt-buffer (crdt--session-buffer-table crdt--session)) (let ((session crdt--session)) (with-current-buffer crdt-buffer @@ -1917,7 +1920,12 @@ of the current buffer." (when (and crdt-mode crdt--session) (error "Current buffer is already shared in a CRDT session")) (list (let* ((session-names (crdt--get-session-names t)) - (default-name (concat crdt-default-name ":" (buffer-name (current-buffer)))) + (default-name (if (member crdt-default-session-name session-names) + (cl-loop for i from 1 + for name = (concat crdt-default-session-name "_" (number-to-string i)) + unless (member name session-names) + do (cl-return name)) + crdt-default-session-name)) (session-name (if session-names (completing-read "Choose a server session (create if not exist): " session-names) @@ -2027,7 +2035,7 @@ Setup up the server with PASSWORD and assign this Emacs DISPLAY-NAME." (kill-buffer process-buffer)) (when (and proxy-process (process-live-p proxy-process)) (interrupt-process proxy-process))) - (unless (memq last-command '(crdt-disconnect crdt-stop-session)) + (unless (memq this-command '(crdt-disconnect crdt-stop-session crdt--stop-session)) (warn "CRDT session %s disconnected." (crdt--session-name session))))) (defun crdt-stop-session (&optional session) @@ -2785,35 +2793,6 @@ Use CRDT--UNINSTALL-PROCESS-ADVICES to disable those advices for the rescue." (crdt--with-buffer-name buffer-name (process-send-string (get-buffer-process (current-buffer)) string))) -;;; URL and TRAMP - -(defsubst tramp-crdt-file-name-p (filename) - "Check if it's a FILENAME for crdt.el." - (and (tramp-tramp-file-p filename) - (string= (tramp-file-name-method (tramp-dissect-file-name filename)) "crdt"))) - -(defconst tramp-crdt-file-name-handler-alist '() - "Alist of handler functions for Tramp crdt.el method. -Operations not mentioned here will be handled by the default Emacs primitives.") - -(defun tramp-crdt-file-name-handler (operation &rest args) - "Invoke the crdt.el handler for OPERATION and ARGS. -First arg specifies the OPERATION, second arg is a list of arguments to -pass to the OPERATION." - (if-let ((fn (assoc operation tramp-crdt-file-name-handler-alist))) - (save-match-data (apply (cdr fn) args)) - (tramp-run-real-handler operation args))) - -(tramp-register-foreign-file-name-handler #'tramp-crdt-file-name-p #'tramp-crdt-file-name-handler) -(add-to-list 'tramp-methods '("crdt")) - -(defun crdt--tramp-prefix (session) - "Compute TRAMP filename prefix for SESSION." - (let ((contact (process-contact (crdt--session-network-process session)))) - (let ((ipv6-p (string-match-p ":" (car contact)))) ;; poor man's ipv6 test - (concat "/crdt:" (when ipv6-p "[") (car contact) (when ipv6-p "]") - (if (= (cadr contact) 6530) nil (format "#%s" (cdr contact))) ":/")))) - ;;; Built-in package integrations ;;;; Org