You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置Spacemacs server/daemon模式下各frame拥有独立窗口编号

解决Spacemacs Daemon模式下winum跨Frame共享窗口编号问题

方案一:使用winum原生配置(推荐)

winum本身已提供Frame隔离的配置参数,只需针对Daemon模式的初始化逻辑做适配即可:

  1. 核心变量配置
    将winum-scope设置为'frame,即可限定窗口编号的生效范围为当前激活的Frame,而非全局所有窗口。
  2. 适配Daemon模式的初始化逻辑
    Daemon模式下初始无Frame,后续创建的Frame需要重新初始化winum的计数逻辑,完整配置如下:
;; 放在Spacemacs配置的user-config段中
(setq winum-scope 'frame)
;; 新Frame创建时重启winum以重置当前Frame的编号计数
(add-hook 'after-make-frame-functions
          (lambda (frame)
            (select-frame frame)
            (when (bound-and-true-p winum-mode)
              (winum-mode -1)
              (winum-mode 1))))
;; 全局启用winum模式
(global-winum-mode 1)

注意:不要将上述配置放在user-init段,需保证winum包加载完成后再执行配置

方案二:自定义编号表隔离(原生配置不生效时使用)

如果你的winum版本存在兼容问题,可以通过重写winum的编号存储逻辑,手动实现每个Frame的独立编号映射:

;; 存储每个Frame对应的窗口编号哈希表
(defvar my-winum-frame-number-tables (make-hash-table :test 'equal)
  "Frame与winum编号表的映射关系")

;; 重写winum内置的编号表获取逻辑
(defun winum--get-numbers-table ()
  (let ((current-frame (selected-frame)))
    (or (gethash current-frame my-winum-frame-number-tables)
        (puthash current-frame (make-hash-table :test 'equal) my-winum-frame-number-tables))))

;; Frame销毁时清理对应的编号表,避免内存泄漏
(add-hook 'delete-frame-functions
          (lambda (frame)
            (remhash frame my-winum-frame-number-tables)))

效果验证

  • 启动Spacemacs Daemon:emacs --daemon
  • 打开第一个Frame,拆分出2个窗口,按下M-1/M-2可正常切换当前Frame的窗口
  • 打开第二个Frame,拆分窗口后编号从1开始计数,与第一个Frame的编号互不影响

内容的提问来源于stack exchange,提问作者emanrbesu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 23:57:04