custom-set-faces 仅适用于非服务器 emacs,但不适用于 /usr/bin/emacsclient 和 emacs 服务器

问题描述 投票:0回答:1

我一直在尝试使用 emacs 客户端/服务器功能来避免启动新的 emacs 会话时出现长时间延迟。 (Ubuntu MATE 上的 emacs 版本 27.1,顺便说一句)

当我直接启动 emacs 时(即没有客户端服务器设置),我的

.emacs.d/custom.el
文件中的以下代码将被正确应用,并且我会得到一个“深洋红色”光标。耶!

但是,当我使用 emacsclient 加入预先存在的守护进程时,我必须使用

custom.el
在会话中重新加载
M-x load-file
,以便我的光标更改为“暗洋红色”,这将成为 PITA。

我真的很感激一些帮助理解这种行为以及如何解决它的帮助。

背景

定制.el

我使用以下代码在

custom.el
文件末尾加载
init.el

.
.
.
;; loading custom.el at end of init.el
;; This ensures the themes are loaded before they are modified
;; Create custom.el file if it's missing, otherwise load it.
(defconst custom-file "~/.emacs.d/custom.el")
(unless (file-exists-p custom-file)
  (with-temp-file custom-file
    (insert ";; Autogenerated Emacs custom.el file")))
(load custom-file)

(provide 'init)

;;; init.el ends here

客户端/服务器场景

启动 Emacs 的代码

这是我在 emacs 服务器/客户端场景中使用的代码。它检查适当的服务器是否已存在,如果不存在,则创建它,如果存在,则加入它并启动一个新服务器以供将来使用。

#!/bin/bash
# Script for controlling whether emacs uses pre-existing daemon or creates new one
#
# IF you want to kill all Rmd-* servers, try
# pkill  -fe -9  "/usr/bin/emacs \-\-daemon=Rmd-*"


declare -a args="( $@ )"; ## need to use parentheses to prevent array of strings from being contatenated into one string

echo "Passed arguments: ${args[@]}"

# "$ids[@]}" returns space separated string
if [[ "${args[@]}" =~  .*\.("Rmd") ]]; then
    daemonCategory="Rmd"
else
    daemonCategory="nonR"
fi

## Get largest id # of --daemon=Rmd-[0-9]+
lastID=$(pgrep -a -f -u "$USER"  "/usr/bin/emacs \-\-daemon=$daemonCategory-[0-9]+" | sed -e 's/.*='"$daemonCategory"'-\([0-9]\+\)/\1/' | sort -rn | head -n 1)

echo "Daemon $daemonCategory detected lastID = $lastID"

## test to see if lastID is empty
if [ -z "$lastID" ]
then
    lastID=1
    echo "starting new daemon $daemonCategory-$lastID"
    ## Start new service
    /usr/bin/emacs --daemon="$daemonCategory-$lastID" 2>/dev/null
fi

## join already started service
## -c = create frame
## -s = socket-name
echo "Joining daemon $daemonCategory-$lastID"
/usr/bin/emacsclient -s "$daemonCategory-$lastID" -c "$@" &

nextID=$((lastID + 1))
## Start new service in anticipation of future needs
echo "starting new daemon $daemonCategory-$nextID"
/usr/bin/emacs --daemon="$daemonCategory-$nextID" 2>/dev/null

消息输出

这是我使用客户端/服务器设置时的Messages缓冲区的样子

Loading /etc/emacs/site-start.d/00debian.el (source)...done
Loading /etc/emacs/site-start.d/50auctex.el (source)...
Loading /home/mikeg/.emacs.d/elpa/auctex-13.0.15/auctex.el (source)...done
Loading /usr/share/emacs/site-lisp/preview-latex.el (source)...done
Loading /etc/emacs/site-start.d/50auctex.el (source)...done
Loading /etc/emacs/site-start.d/50autoconf.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...done
Loading debian-ispell...done
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50emacs-goodies-el.el (source)...
Package emacs-goodies-el removed but not purged.  Skipping setup.
Loading /etc/emacs/site-start.d/50emacs-goodies-el.el (source)...done
Loading /etc/emacs/site-start.d/50git-core.el (source)...
git removed but not purged, skipping setup
Loading /etc/emacs/site-start.d/50git-core.el (source)...done
Loading /etc/emacs/site-start.d/50tcsh.el (source)...done
Importing gnu-elpa.gpg-keyring...done
Loading /home/mikeg/.emacs.d/elpa/ess-20201004.1522/ess-tracebug.el (source)...done
[yas] Prepared just-in-time loading of snippets successfully.
Importing package-keyring.gpg...done
Contacting host: elpa.gnu.org:443
Contacting host: melpa.org:443
Contacting host: elpa.nongnu.org:443
Package refresh done
Loading /home/mikeg/.emacs.d/lisp/personal.el (source)...
Loading /home/mikeg/.emacs.d/lisp/no-x-settings.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/ssh.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/personal.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/beamer.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/modify-other-keys-extension.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/jnm-term.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/ess-init.el (source)...
[yas] Prepared just-in-time loading of snippets successfully.
Loading /home/mikeg/.emacs.d/lisp/ess-init.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/my-tramp.el (source)...done
Loading /home/mikeg/.emacs.d/custom.el (source)...done
Turning on magit-auto-revert-mode...done
Starting Emacs daemon.
(New file)
When done with a buffer, type C-x #

如果使用`M-x加载文件“.emacs.d/custom.el”,光标将变成洋红色并且线条

加载/home/mikeg/.emacs.d/custom.el(源)...完成 被附加到消息

Emacs 独立场景

在独立场景中,例如

/usr/bin/emacs file.txt
一切都按预期进行,我的光标变成洋红色,只需要一段时间就可以开始工作。在这种情况下,我得到的 Messages 缓冲区与之前的场景几乎相同。具体来说,它看起来像这样

Loading /etc/emacs/site-start.d/00debian.el (source)...done
Loading /etc/emacs/site-start.d/50auctex.el (source)...
Loading /home/mikeg/.emacs.d/elpa/auctex-13.0.15/auctex.el (source)...done
Loading /usr/share/emacs/site-lisp/preview-latex.el (source)...done
Loading /etc/emacs/site-start.d/50auctex.el (source)...done
Loading /etc/emacs/site-start.d/50autoconf.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...done
Loading debian-ispell...done
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50emacs-goodies-el.el (source)...
Package emacs-goodies-el removed but not purged.  Skipping setup.
Loading /etc/emacs/site-start.d/50emacs-goodies-el.el (source)...done
Loading /etc/emacs/site-start.d/50git-core.el (source)...
git removed but not purged, skipping setup
Loading /etc/emacs/site-start.d/50git-core.el (source)...done
Loading /etc/emacs/site-start.d/50tcsh.el (source)...done
Importing gnu-elpa.gpg-keyring...done
Loading /home/mikeg/.emacs.d/elpa/ess-20201004.1522/ess-tracebug.el (source)...done
[yas] Prepared just-in-time loading of snippets successfully.
Importing package-keyring.gpg...done
Contacting host: elpa.gnu.org:443
Contacting host: melpa.org:443
Contacting host: elpa.nongnu.org:443
Package refresh done
Loading /home/mikeg/.emacs.d/lisp/personal.el (source)...
Loading /home/mikeg/.emacs.d/lisp/no-x-settings.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/ssh.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/personal.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/beamer.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/modify-other-keys-extension.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/jnm-term.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/ess-init.el (source)...
[yas] Prepared just-in-time loading of snippets successfully.
Loading /home/mikeg/.emacs.d/lisp/ess-init.el (source)...done
Loading /home/mikeg/.emacs.d/lisp/my-tramp.el (source)...done
Loading /home/mikeg/.emacs.d/custom.el (source)...done
Turning on magit-auto-revert-mode...done
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)
Mark set

最后注意事项

即使我的

(load custom-file)
中有第二个
init.el file
命令,问题仍然存在。所以看来我必须有一个活动窗口才能工作。

非常感谢提供的任何帮助。

emacs client-server
1个回答
0
投票

我认为这个问题与 Emacs StackExchange 上的 问题相同。

简而言之,这样定制你的 Emacs 界面:

;;; init.el -*- lexical-binding: t; -*- (letrec ((custom-faces (lambda () (custom-set-faces ; Put your original ...) ; “(custom-set-faces ...)” here. (remove-hook 'server-after-make-frame-hook custom-faces)))) (add-hook 'server-after-make-frame-hook custom-faces))
    
© www.soinside.com 2019 - 2024. All rights reserved.