Skip to content

Instantly share code, notes, and snippets.

@yosisa
Created January 7, 2011 14:03
Show Gist options
  • Save yosisa/769485 to your computer and use it in GitHub Desktop.
Save yosisa/769485 to your computer and use it in GitHub Desktop.
(defun e2wm-frame-size-save ()
(interactive)
(let ((file "~/.emacs.d/framesize.el")
(width (int-to-string (frame-parameter nil 'width)))
(height (int-to-string (frame-parameter nil 'height)))
(top (int-to-string (frame-parameter nil 'top)))
(left (int-to-string (frame-parameter nil 'left)))
buf beg line init-line)
(if (get-file-buffer (expand-file-name file))
(setq buf (get-file-buffer (expand-file-name file)))
(setq buf (find-file-noselect file)))
(set-buffer buf)
(if (eq 0 (buffer-size))
(setq line "t\n")
(save-excursion
;; modify-frame-parametersだけだと起動後に微妙にずれるので、
;; initial-frame-alistの設定が必要。
;; initial-frame-alistはe2wmのON時には更新しない。
(goto-char (point-min))
(if (and (e2wm:managed-p) (search-forward "(setq initial-frame-alist" nil t))
(progn
(beginning-of-line)
(setq beg (point))
(forward-line)
(setq init-line (buffer-substring beg (point))))
(setq init-line (concat "(setq initial-frame-alist (append '("
"(width . " width ")"
" (height . " height ")"
" (top . " top ")"
" (left . " left "))"
" initial-frame-alist)))\n")))
;; 更新しない方の設定をコピーする
(goto-char (point-min))
(if (not (search-forward "(if " nil t))
(setq line "t\n")
(forward-line (if (e2wm:managed-p) 2 1))
(beginning-of-line 1)
(setq beg (point))
(forward-line)
(setq line (buffer-substring beg (point))))))
(erase-buffer)
(insert (concat
"(unless (assq 'width initial-frame-alist)\n"
init-line
"(if (and (fboundp 'e2wm:managed-p) (e2wm:managed-p))\n"))
(let ((str (concat "(modify-frame-parameters nil "
"'((width . " width ")"
" (height . " height ")"
" (top . " top ")"
" (left . " left ")))\n")))
(if (e2wm:managed-p)
(insert (concat str line ")\n"))
(insert (concat line str ")\n"))))
(save-buffer)
(kill-buffer buf)))
(defun e2wm-frame-size-load ()
(interactive)
(unless run-cli
(let ((file "~/.emacs.d/framesize.el"))
(when (file-exists-p file)
(load file)))))
(defadvice e2wm:start-management (after e2wm-change-frame-size activate)
(e2wm-frame-size-load))
(defadvice e2wm:stop-management (after e2wm-change-frame-size activate)
(e2wm-frame-size-load))
(defadvice save-buffers-kill-emacs (before save-frame-size activate)
(if (not (eq window-system nil))
(e2wm-frame-size-save)))
(if (not (eq window-system nil))
(my-window-size-load))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment