如何从统一启动器运行 emacsclient 重用现有的 emacs 窗口

jam*_*son 15 emacs unity launcher window

如果您通过复制 .desktop 文件(例如 Emacs 文件)来创建 emacsclient 启动器,它不会以标准的 Unity 启动器方式运行。它总是启动一个新窗口;它不承认现有的 Emacsclient 窗口存在以跳转到它们。我怎样才能让它表现?

作为背景,这是 Emacs 的一种非常有用的使用模式,您可以将它作为守护程序运行: emacs --daemon,然后使用emacsclient. 对于习惯的 emacs 用户来说,这样做的一个好方法是放入emacs --daemon您的启动应用程序中。

jam*_*son 19

解决方案是创建一个emacsclient.desktop文件,其中包含使用 StartupWMClass 设置的窗口类指令。没有它,Unity 无法判断该窗口来自 Emacsclient。这将根据 Emacs one (/usr/share/applications/emacs23.desktop) 的内容创建一个:

mkdir -p ~/.local/share/applications
cat > !$/emacsclient.desktop <<EOF
[Desktop Entry]
Version=1.0
Name=Emacsclient
GenericName=Text Editor
Comment=View and edit files
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/usr/bin/emacsclient -c %F
Icon=/usr/share/icons/hicolor/scalable/apps/emacs23.svg
Type=Application
Terminal=false
Categories=Utility;Development;TextEditor;
StartupWMClass=Emacs
EOF
Run Code Online (Sandbox Code Playgroud)

将 emacsclient 放在启动器中(例如点击 Super,键入“emacsclient”,将其拖上),然后注销/登录。