diff options
| author | Stefan Monnier | 2022-05-28 12:02:15 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2022-05-28 12:02:15 -0400 |
| commit | 2301f13a677aa4ea05bfa2372bdc66c458c0ff38 (patch) | |
| tree | 82e30db37ca9ad9300db523ab65c8bf17f9dad46 | |
| parent | f65536015b143571b81f8eb1f064d73014a86fec (diff) | |
| download | emacs-2301f13a677aa4ea05bfa2372bdc66c458c0ff38.tar.gz emacs-2301f13a677aa4ea05bfa2372bdc66c458c0ff38.zip | |
with-connection-local-variables: Avoid code duplication
Move the bulk of the code of `with-connection-local-variables` into
a separate function, which both avoids duplicating that code but also
avoids duplicating the code passed as the body of
a `with-connection-local-variables`. Also makes it easier to
debug the code, or change the implementation of
`with-connection-local-variables` without having to recompile all
the users.
* lisp/files-x.el (with-connection-local-variables-1): New function,
extracted from `with-connection-local-variables`.
(with-connection-local-variables): Use it.
| -rw-r--r-- | lisp/files-x.el | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lisp/files-x.el b/lisp/files-x.el index 0ae9fb076eb..4db6fbd22cc 100644 --- a/lisp/files-x.el +++ b/lisp/files-x.el | |||
| @@ -740,22 +740,28 @@ If APPLICATION is nil, `connection-local-default-application' is used." | |||
| 740 | "Apply connection-local variables according to `default-directory'. | 740 | "Apply connection-local variables according to `default-directory'. |
| 741 | Execute BODY, and unwind connection-local variables." | 741 | Execute BODY, and unwind connection-local variables." |
| 742 | (declare (debug t)) | 742 | (declare (debug t)) |
| 743 | `(if (file-remote-p default-directory) | 743 | `(with-connection-local-variables-1 (lambda () ,@body))) |
| 744 | (let ((enable-connection-local-variables t) | 744 | |
| 745 | (old-buffer-local-variables (buffer-local-variables)) | 745 | ;;;###autoload |
| 746 | connection-local-variables-alist) | 746 | (defun with-connection-local-variables-1 (body-fun) |
| 747 | (hack-connection-local-variables-apply | 747 | "Apply connection-local variables according to `default-directory'. |
| 748 | (connection-local-criteria-for-default-directory)) | 748 | Call BODY-FUN with no args, and then unwind connection-local variables." |
| 749 | (unwind-protect | 749 | (if (file-remote-p default-directory) |
| 750 | (progn ,@body) | 750 | (let ((enable-connection-local-variables t) |
| 751 | ;; Cleanup. | 751 | (old-buffer-local-variables (buffer-local-variables)) |
| 752 | (dolist (variable connection-local-variables-alist) | 752 | connection-local-variables-alist) |
| 753 | (let ((elt (assq (car variable) old-buffer-local-variables))) | 753 | (hack-connection-local-variables-apply |
| 754 | (if elt | 754 | (connection-local-criteria-for-default-directory)) |
| 755 | (set (make-local-variable (car elt)) (cdr elt)) | 755 | (unwind-protect |
| 756 | (kill-local-variable (car variable))))))) | 756 | (funcall body-fun) |
| 757 | ;; No connection-local variables to apply. | 757 | ;; Cleanup. |
| 758 | ,@body)) | 758 | (dolist (variable connection-local-variables-alist) |
| 759 | (let ((elt (assq (car variable) old-buffer-local-variables))) | ||
| 760 | (if elt | ||
| 761 | (set (make-local-variable (car elt)) (cdr elt)) | ||
| 762 | (kill-local-variable (car variable))))))) | ||
| 763 | ;; No connection-local variables to apply. | ||
| 764 | (funcall body-fun))) | ||
| 759 | 765 | ||
| 760 | ;;;###autoload | 766 | ;;;###autoload |
| 761 | (defun path-separator () | 767 | (defun path-separator () |