Emacs 使用连接局部配置文件(connection-local profiles)来保存要应用到特定连接的变量配置。
之后你可以通过 connection-local-set-profiles 定义生效条件,将这些配置文件与远程连接关联起来。
该函数为连接配置文件 profile(一个符号)定义一组变量配置。
你可以在后续将该连接配置文件分配给一个或多个远程连接,
Emacs 会将这些变量配置应用到这些连接对应的所有进程缓冲区。
variables 列表是一个格式为 (name . value) 的关联列表。
示例:
(connection-local-set-profile-variables
'remote-bash
'((shell-file-name . "/bin/bash")
(shell-command-switch . "-c")
(shell-interactive-switch . "-i")
(shell-login-switch . "-l")))
(connection-local-set-profile-variables
'remote-ksh
'((shell-file-name . "/bin/ksh")
(shell-command-switch . "-c")
(shell-interactive-switch . "-i")
(shell-login-switch . "-l")))
(connection-local-set-profile-variables 'remote-null-device '((null-device . "/dev/null")))
若你希望向已有配置文件追加变量配置,可调用函数 connection-local-get-profile-variables
来获取该配置文件中已有的配置,示例如下:
(connection-local-set-profile-variables 'remote-bash (append (connection-local-get-profile-variables 'remote-bash) '((shell-command-dont-erase-buffer . t))))
该关联列表(alist)存储连接配置文件符号及其对应的变量配置。
它会由 connection-local-set-profile-variables 函数更新。
该函数将符号类型的 profiles(配置文件)分配给所有由 criteria(判定条件)
标识的远程连接。criteria 是一个属性列表(plist),用于标识某一连接
以及使用该连接的应用程序。其属性名可能包括 :application(应用程序)、
:protocol(协议)、:user(用户)和 :machine(主机)。
其中 :application 的属性值为符号类型,其余属性的值均为字符串类型。
所有属性均为可选;若 criteria 为 nil,则该配置始终生效。示例:
(connection-local-set-profiles '(:application tramp :protocol "ssh" :machine "localhost") 'remote-bash 'remote-null-device)
(connection-local-set-profiles
'(:application tramp :protocol "sudo"
:user "root" :machine "localhost")
'remote-ksh 'remote-null-device)
如果 criteria 为 nil,则该配置对所有远程连接都生效。因此,上面的示例等价于:
(connection-local-set-profiles '(:application tramp :protocol "ssh" :machine "localhost") 'remote-bash)
(connection-local-set-profiles
'(:application tramp :protocol "sudo"
:user "root" :machine "localhost")
'remote-ksh)
(connection-local-set-profiles nil 'remote-null-device)
profiles 中的任意一个连接配置文件,都必须已通过
connection-local-set-profile-variables 函数完成定义。
该关联列表(alist)包含连接判定条件及其分配的配置文件名。
connection-local-set-profiles 函数会更新此列表。