比如我用 Spacemacs 的 Project Layout,
然后把 title format 定义成:
(defun lx/layout-format-name (name pos)
"Format the layout name given by NAME for display in mode-line."
(let* ((layout-name (if (file-directory-p name)
(file-name-nondirectory (directory-file-name name))
name))
(string-name (format "%s" layout-name))
(current (equal name (spacemacs//current-layout-name)))
(caption (concat (number-to-string (if (eq 9 pos) 0 (1+ pos)))
". " string-name)))
(if current
(propertize (concat "❰❰ " caption " ❱❱") 'face 'warning)
caption)))
(defun lx/layouts-for-title-bar ()
"Return a one liner string containing all the layout names."
(let* ((persp-list (or (persp-names-current-frame-fast-ordered)
(list persp-nil-name)))
(formatted-persp-list
(concat " "
(mapconcat (lambda (persp)
(lx/layout-format-name
persp (position persp persp-list)))
persp-list " "))))
formatted-persp-list))
(setq frame-title-format '(:eval (lx/layouts-for-title-bar))))
然后把 s-number
绑定到切换 persp:
(global-set-key (kbd "s-0") 'spacemacs/persp-switch-to-0)
(global-set-key (kbd "s-1") 'spacemacs/persp-switch-to-1)
... ...