如何指定要使用 emacsclient 加载的用户的 emacs 初始化文件?
问题
如何指定用户的 emacs 初始化文件由 emacsclient 加载?
emacsclient 不理解“-u user”并且“-a ALTERNATE-EDITOR”不允许我引用它并提供“-u user”。
例如,运行:
/usr/bin/emacsclient -n -a '/usr/bin/emacs -u <username>' ~<username>/notes.txt
返回
/usr/bin/emacsclient: error executing alternate editor "/usr/bin/emacs -u <username>"
Background
我正在使用 emacs 版本 23.1.1 和 emacsclient 版本 23.1。
emacs本身支持'-u user'来加载指定用户的init文件。
我在别名文件中使用以下 bash 函数来调用 emacs
# a wrapper is needed to sandwich multiple command line arguments in bash
# 2>/dev/null hides
# "emacsclient: can't find socket; have you started the server?"
emacs_wrapper () {
if [ 0 -eq $# ]
then
/usr/bin/emacsclient -n -a /usr/bin/emacs ~<username>/notes.txt 2>/dev/null &
else
/usr/bin/emacsclient -n -a /usr/bin/emacs $* 2>/dev/null &
fi
}
alias x='emacs_wrapper'
键入 x 后跟文件列表:
- 如果服务器正在运行,则连接到现有的 emacs 服务器,否则启动一个新服务器
- 作为后台进程执行
- 打开文件列表或我的文件列表如果没有提供文件,则为注释文件
当我以自己的身份登录时,这非常有用。然而,许多生产盒子要求我以生产用户身份登录。我已将别名分离到 bash 脚本中,因此只需运行即可获取别名和 bash 函数。
. ~<username>/alias.sh
不幸的是,这不允许我使用我的 .emacs 文件 (~
这个问题一直让我发疯。
Question
How can one specify a user's emacs init file to load with emacsclient?
emacsclient does not understand '-u user' and '-a ALTERNATE-EDITOR' does not allow me to quote it and provide '-u user'.
For example, running:
/usr/bin/emacsclient -n -a '/usr/bin/emacs -u <username>' ~<username>/notes.txt
returns
/usr/bin/emacsclient: error executing alternate editor "/usr/bin/emacs -u <username>"
Background
I'm using emacs version 23.1.1 and emacsclient version 23.1.
emacs itself supports '-u user' to load a specified user's init file.
I use the following bash function in my aliases file to invoke emacs
# a wrapper is needed to sandwich multiple command line arguments in bash
# 2>/dev/null hides
# "emacsclient: can't find socket; have you started the server?"
emacs_wrapper () {
if [ 0 -eq $# ]
then
/usr/bin/emacsclient -n -a /usr/bin/emacs ~<username>/notes.txt 2>/dev/null &
else
/usr/bin/emacsclient -n -a /usr/bin/emacs $* 2>/dev/null &
fi
}
alias x='emacs_wrapper'
Typing x followed by a list of files:
- Connects to an existing emacs server if one is running, otherwise starts a new one
- Executes as a background process
- Opens the list of files or my notes file if no files are provided
This works great when I'm logged in as myself. However, many production boxes require me to log in as a production user. I've separated my aliases into a bash script, therefore I can get my aliases and bash functions by simply running.
. ~<username>/alias.sh
Unfortunately, this won't let me use my .emacs file (~<username>/.emacs) :(
This problem has been driving me crazy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法在备用编辑器规范中包含命令行参数,则只需编写一个为您执行此操作的 shell 脚本,并将其作为备用编辑器参数提供即可。
If you can't include command line arguments in your alternate editor specification, then simply write a shell script which does that for you, and supply that as the alternate editor argument instead.
服务器/客户端模型的要点是,您拥有一个具有自己的一组配置的现有 Emacs,然后通过一个或多个客户端进行连接。
如果服务器已经配置为显示菜单栏(全局设置),并且客户端说不显示它,客户端应该做什么?如果另一个客户附上说明来展示怎么办?
如果您想对 Emacs 使用不同的设置,请使用不同的 emacs 会话。
The point of the server/client model is that you have an existing Emacs with its own set of configurations, and then you connect via one or more clients.
What should the client do if the server was already configured to show the menu bar (a global setting), and the client says not to show it? What if another client attaches saying to show it?
If you want to use different settings for Emacs, use different emacs sessions.