UP | HOME

emacs-变相在Windows上使用Emacs-Client

[2024-07-13 周六 15:29]

在配置中设置默认启动server:

(defun my/set-gui ()
  (set-font "Cascadia Code" "HarmonyOS Sans SC" 32 32)
  (set-frame-position (selected-frame) 100 100)
  ;;设置宽和高,我的十寸小本是110,33,大家可以调整这个参数来适应自己屏幕大小
  (set-frame-width (selected-frame) 170)
  (set-frame-height (selected-frame) 30)
)
(setq server-auth-dir "~/emacs-local")
(if (not (server-running-p))
    (progn (server-start)
           (add-hook 'server-after-make-frame-hook #'my/set-gui)
           ))

然后将启动Emacs的快捷方式路径改为

D:\Emacs\bin\emacsclientw.exe  -c -n -f %APPDATA%\emacs-local\server -e "(raise-frame)" -a "D:\Emacs\bin\runemacs.exe"

再将 C-x C-c 绑定到 make-frame-invisible 函数上:

(global-set-key (kbd "C-x C-c") (lambda () (interactive) (make-frame-invisible nil t)))

这样一来,按组合键时就会让当前窗口消失,再次点击上述快捷方式又能呼出,且窗口内容保持不变;点击窗口右上角为彻底关闭当前Emacs程序。

在实现Daemon、Client的功能同时,避免了直接使用Emacs-Server导致的GUI、配置加载等问题。

[2024-07-25 周四 09:02]:利用 %APPDATA% 这个系统变量自动化为每台电脑创建一个不同的Server文件。

注意此时若使用org-captude的chrome插件 ,需要将reg文件用bat批量生成(以便自动化嵌入系统名称)。

创建emacs-org-protocol.bat文件,内容如下:

@echo off
echo REGEDIT4 >t1.reg
echo [HKEY_CLASSES_ROOT\org-protocol] >>e1.reg
echo @="URL:Org Protocol" >>e1.reg
echo "URL Protocol"="" >>e1.reg
echo [HKEY_CLASSES_ROOT\org-protocol\shell] >>e1.reg
echo [HKEY_CLASSES_ROOT\org-protocol\shell\open] >>e1.reg
echo [HKEY_CLASSES_ROOT\org-protocol\shell\open\command] >>e1.reg
echo @="\"D:\\Emacs\\bin\\emacsclientw.exe\"  -f %APPDATA%\emacs-local\server \"%%1\"" >>e1.reg

然后新电脑运行该文件,再运行生成后的e1.reg就完成了协议注册。

▲ 编辑于 [2024-08-22 周四 11:09] | © Published by Emacs 30.0.50 (Org mode 9.7.10) on [2024-08-22 周四 11:25] | RSS