(破事水) 简单写了段代码, 帮助使用 server 的各位提高生活幸福感:
;;; your _emacs -*- lexical-binding: t; -*-
;; 当最后一个 frame 关闭时, 存入它的位置和尺寸; 当桌面上没有 frame 时, 下一个打开的 frame 将使用那个被存入的位置和尺寸.
(let ((size&position-relayer `(,(cons 'top 0) ,(cons 'left 0)
;; ‘fullscreen’ 放最后, 以覆盖 ‘width’&‘height’ 的设置.
,(cons 'width 0) ,(cons 'height 0) ,(cons 'fullscreen nil))))
(put 'size&position-relayer :holding? nil)
(letrec ((get-size&position (lambda ()
(when (get 'size&position-relayer :holding?)
(dolist (parameter-value size&position-relayer)
(set-frame-parameter nil (car parameter-value) (cdr parameter-value))))
(remove-hook 'server-after-make-frame-hook get-size&position)
( add-hook 'delete-frame-functions put-size&position)))
(put-size&position (lambda (frame-to-be-deleted)
(when (length= (frames-on-display-list) 1)
(dolist (parameter-value size&position-relayer)
(setcdr parameter-value (frame-parameter frame-to-be-deleted (car parameter-value))))
(put 'size&position-relayer :holding? t)
(remove-hook 'delete-frame-functions put-size&position)
;; 当需要调用该 λ 时, 必然没有除此以外的其它 frame 了, 因此之后新建的 frame 必然是 server 弹出的,
;; 所以此处没有使用 ‘after-make-frame-functions’, 而是指向性更强的 ‘server-after-make-frame-hook’.
( add-hook 'server-after-make-frame-hook get-size&position)))))
(add-hook 'server-after-make-frame-hook get-size&position)))