diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2017-02-19 17:14:35 +0100 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2017-02-19 17:14:35 +0100 |
commit | 143bc75c414434badcb324db056ad37c15893bd9 (patch) | |
tree | edb4c926bd940e39ec9a88ea13324d55f925223c /lisp/files-x.el | |
parent | b6a1a74522120979fe1a63b2d5517a490ee572b0 (diff) | |
download | emacs-143bc75c414434badcb324db056ad37c15893bd9.tar.gz emacs-143bc75c414434badcb324db056ad37c15893bd9.tar.bz2 emacs-143bc75c414434badcb324db056ad37c15893bd9.zip |
Rework connection local variables
For connection local variables interface, `class' is renamed
to `profile'. All arguments `criteria' are a plist now.
* doc/lispref/variables.texi (Connection Local Variables):
Rewrite.
* lisp/files-x.el (connection-local-profile-alist): Rename
from `connection-local-class-alist'. Adapt docstring.
(connection-local-criteria-alist): Adapt docstring.
(connection-local-normalize-criteria): New defun.
(connection-local-get-profiles): Rename from
`connection-local-get-classes'. Rewrite.
(connection-local-set-profiles): Rename from
`connection-local-set-classes'. Rewrite.
(connection-local-get-profile-variables): Rename from
`connection-local-get-class-variables'. Rewrite.
(connection-local-set-profile-variables): Rename from
`connection-local-set-class-variables'. Rewrite.
(hack-connection-local-variables)
(hack-connection-local-variables-apply)): Rewrite.
(with-connection-local-profiles): Rename from
`ith-connection-local-classes'. Rewrite.
* lisp/net/tramp.el (tramp-set-connection-local-variables):
Compute criteria.
* lisp/net/tramp-cmds.el (tramp-bug):
Use `connection-local-profile-alist'.
* test/lisp/files-x-tests.el (files-x-test--variables1)
(files-x-test--variables2, files-x-test--variables3)
(files-x-test--variables4, files-x-test--criteria1)
(files-x-test--criteria2): Make them a defconst.
(files-x-test--application)
(files-x-test--another-application, files-x-test--protocol)
(files-x-test--user, files-x-test--machine): New defconst.
(files-x-test--criteria): New defvar.
(files-x-test--criteria3): Remove.
(files-x-test-connection-local-set-profile-variables):
Rename from `files-x-test-connection-local-set-class-variables'.
Rewrite.
(files-x-test-connection-local-set-profiles): Rename from
`files-x-test-connection-local-set-classes'. Rewrite.
(files-x-test-hack-connection-local-variables-apply) Rewrite.
(files-x-test-with-connection-local-profiles): Rename from
`files-x-test-with-connection-local-classes'. Rewrite.
Diffstat (limited to 'lisp/files-x.el')
-rw-r--r-- | lisp/files-x.el | 167 |
1 files changed, 90 insertions, 77 deletions
diff --git a/lisp/files-x.el b/lisp/files-x.el index 2b4658f6429..a0cad708425 100644 --- a/lisp/files-x.el +++ b/lisp/files-x.el @@ -559,119 +559,132 @@ changed by the user.") (setq ignored-local-variables (cons 'connection-local-variables-alist ignored-local-variables)) -(defvar connection-local-class-alist '() - "Alist mapping connection-local variable classes (symbols) to variable lists. -Each element in this list has the form (CLASS VARIABLES). -CLASS is the name of a variable class (a symbol). +(defvar connection-local-profile-alist '() + "Alist mapping connection profiles to variable lists. +Each element in this list has the form (PROFILE VARIABLES). +PROFILE is the name of a connection profile (a symbol). VARIABLES is a list that declares connection-local variables for -CLASS. An element in VARIABLES is an alist whose elements are of -the form (VAR . VALUE).") +PROFILE. An element in VARIABLES is an alist whose elements are +of the form (VAR . VALUE).") (defvar connection-local-criteria-alist '() - "Alist mapping criteria to connection-local variable classes (symbols). -Each element in this list has the form (CRITERIA CLASSES). -CRITERIA is either a regular expression identifying a remote -server, or a function with one argument IDENTIFICATION, which -returns non-nil when a remote server shall apply CLASS'es -variables. If CRITERIA is nil, it always applies. -CLASSES is a list of variable classes (symbols).") - -(defsubst connection-local-get-classes (criteria &optional identification) - "Return the connection-local classes list for CRITERIA. -CRITERIA is either a regular expression identifying a remote -server, or a function with one argument IDENTIFICATION, which -returns non-nil when a remote server shall apply CLASS'es -variables. If CRITERIA is nil, it always applies. -If IDENTIFICATION is non-nil, CRITERIA must be nil, or match -IDENTIFICATION accordingly." - (and (cond ((null identification)) - ((not (stringp identification)) - (error "Wrong identification `%s'" identification)) - ((null criteria)) - ((stringp criteria) (string-match criteria identification)) - ((functionp criteria) (funcall criteria identification)) - (t "Wrong criteria `%s'" criteria)) - (cdr (assoc criteria connection-local-criteria-alist)))) + "Alist mapping connection criteria to connection profiles. +Each element in this list has the form (CRITERIA PROFILES). +CRITERIA is a plist identifying a connection and the application +using this connection. Property names might be `:application', +`:protocol', `:user' and `:machine'. The property value of +`:application' is a symbol, all other property values are +strings. All properties are optional; if CRITERIA is nil, it +always applies. +PROFILES is a list of connection profiles (symbols).") + +(defsubst connection-local-normalize-criteria (criteria &rest properties) + "Normalize plist CRITERIA according to PROPERTIES. +Return a new ordered plist list containing only property names from PROPERTIES." + (delq + nil + (mapcar + (lambda (property) + (when (plist-member criteria property) + (list property (plist-get criteria property)))) + properties))) + +(defsubst connection-local-get-profiles (criteria) + "Return the connection profiles list for CRITERIA. +CRITERIA is a plist identifying a connection and the application +using this connection, see `connection-local-criteria-alist'." + (or (cdr + (assoc + (connection-local-normalize-criteria + criteria :application :protocol :user :machine) + connection-local-criteria-alist)) + ;; Try it without :application. + (cdr + (assoc + (connection-local-normalize-criteria criteria :protocol :user :machine) + connection-local-criteria-alist)))) ;;;###autoload -(defun connection-local-set-classes (criteria &rest classes) - "Add CLASSES for remote servers. +(defun connection-local-set-profiles (criteria &rest profiles) + "Add PROFILES for remote servers. CRITERIA is either a regular expression identifying a remote server, or a function with one argument IDENTIFICATION, which -returns non-nil when a remote server shall apply CLASS'es +returns non-nil when a remote server shall apply PROFILE's variables. If CRITERIA is nil, it always applies. -CLASSES are the names of a variable class (a symbol). +PROFILES are the names of a connection profile (a symbol). When a connection to a remote server is opened and CRITERIA -matches to that server, the connection-local variables from CLASSES -are applied to the corresponding process buffer. The variables -for a class are defined using `connection-local-set-class-variables'." - (unless (or (null criteria) (stringp criteria) (functionp criteria)) +matches to that server, the connection-local variables from +PROFILES are applied to the corresponding process buffer. The +variables for a connection profile are defined using +`connection-local-set-profile-variables'." + (unless (listp criteria) (error "Wrong criteria `%s'" criteria)) - (dolist (class classes) - (unless (assq class connection-local-class-alist) - (error "No such class `%s'" (symbol-name class)))) - (let ((slot (assoc criteria connection-local-criteria-alist))) + (dolist (profile profiles) + (unless (assq profile connection-local-profile-alist) + (error "No such connection profile `%s'" (symbol-name profile)))) + (let* ((criteria (connection-local-normalize-criteria + criteria :application :protocol :user :machine)) + (slot (assoc criteria connection-local-criteria-alist))) (if slot - (setcdr slot (delete-dups (append (cdr slot) classes))) + (setcdr slot (delete-dups (append (cdr slot) profiles))) (setq connection-local-criteria-alist - (cons (cons criteria (delete-dups classes)) + (cons (cons criteria (delete-dups profiles)) connection-local-criteria-alist))))) -(defsubst connection-local-get-class-variables (class) - "Return the connection-local variable list for CLASS." - (cdr (assq class connection-local-class-alist))) +(defsubst connection-local-get-profile-variables (profile) + "Return the connection-local variable list for PROFILE." + (cdr (assq profile connection-local-profile-alist))) ;;;###autoload -(defun connection-local-set-class-variables (class variables) - "Map the symbol CLASS to a list of variable settings. +(defun connection-local-set-profile-variables (profile variables) + "Map the symbol PROFILE to a list of variable settings. VARIABLES is a list that declares connection-local variables for -the class. An element in VARIABLES is an alist whose elements -are of the form (VAR . VALUE). +the connection profile. An element in VARIABLES is an alist +whose elements are of the form (VAR . VALUE). When a connection to a remote server is opened, the server's -classes are found. A server may be assigned a class using -`connection-local-set-class'. Then variables are set in the -server's process buffer according to the VARIABLES list of the -class. The list is processed in order." - (setf (alist-get class connection-local-class-alist) variables)) - -(defun hack-connection-local-variables () - "Read per-connection local variables for the current buffer. -Store the connection-local variables in `connection-local-variables-alist'. +connection profiles are found. A server may be assigned a +connection profile using `connection-local-set-profile'. Then +variables are set in the server's process buffer according to the +VARIABLES list of the connection profile. The list is processed +in order." + (setf (alist-get profile connection-local-profile-alist) variables)) + +(defun hack-connection-local-variables (criteria) + "Read connection-local variables according to CRITERIA. +Store the connection-local variables in buffer local +variable`connection-local-variables-alist'. This does nothing if `enable-connection-local-variables' is nil." - (let ((identification (file-remote-p default-directory))) - (when (and enable-connection-local-variables identification) - ;; Loop over criteria. - (dolist (criteria (mapcar 'car connection-local-criteria-alist)) - ;; Filter classes which map identification. - (dolist (class (connection-local-get-classes criteria identification)) - ;; Loop over variables. - (dolist (variable (connection-local-get-class-variables class)) - (unless (assq (car variable) connection-local-variables-alist) - (push variable connection-local-variables-alist)))))))) + (when enable-connection-local-variables + ;; Filter connection profiles. + (dolist (profile (connection-local-get-profiles criteria)) + ;; Loop over variables. + (dolist (variable (connection-local-get-profile-variables profile)) + (unless (assq (car variable) connection-local-variables-alist) + (push variable connection-local-variables-alist)))))) ;;;###autoload -(defun hack-connection-local-variables-apply () - "Apply connection-local variables identified by `default-directory'. +(defun hack-connection-local-variables-apply (criteria) + "Apply connection-local variables identified by CRITERIA. Other local variables, like file-local and dir-local variables, will not be changed." - (hack-connection-local-variables) + (hack-connection-local-variables criteria) (let ((file-local-variables-alist (copy-tree connection-local-variables-alist))) (hack-local-variables-apply))) ;;;###autoload -(defmacro with-connection-local-classes (classes &rest body) - "Apply connection-local variables according to CLASSES in current buffer. +(defmacro with-connection-local-profiles (profiles &rest body) + "Apply connection-local variables according to PROFILES in current buffer. Execute BODY, and unwind connection local variables." (declare (indent 1) (debug t)) `(let ((enable-connection-local-variables t) (old-buffer-local-variables (buffer-local-variables)) connection-local-variables-alist connection-local-criteria-alist) - (apply 'connection-local-set-classes "" ,classes) - (hack-connection-local-variables-apply) + (apply 'connection-local-set-profiles nil ,profiles) + (hack-connection-local-variables-apply nil) (unwind-protect (progn ,@body) ;; Cleanup. |