Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. ;; Save and restore window configuration
  2. (defvar window-confs (make-hash-table))
  3. ;; window-confs is equvalent to this:
  4. ;;
  5. ;; { frame1: {"zoomed": false, "conf": <some conf>},
  6. ;; frame2: {"zoomed": true, "conf": <some other conf>} }
  7.  
  8. (defun save-window-conf ()
  9. "Save current window configuration of current frame."
  10. (let ((this-frame (selected-frame))
  11. (this-conf (current-window-configuration)))
  12. (if (gethash this-frame window-confs)
  13. (puthash 'conf this-conf
  14. (gethash this-frame window-confs))
  15. (let ((new-state (make-hash-table)))
  16. (puthash 'zoomed nil new-state)
  17. (puthash 'conf this-conf new-state)
  18. (puthash this-frame new-state window-confs)))))
  19.  
  20. (defun load-window-conf ()
  21. "Load saved window configuration of current frame."
  22. (let* ((this-frame (selected-frame))
  23. (saved-state (gethash this-frame window-confs)))
  24. (if saved-state
  25. (set-window-configuration (gethash 'conf saved-state)))))
  26.  
  27. (defun maximize-or-restore-window ()
  28. "If current window is not maximized, or no window in current
  29. frame has been maximized before, store window configuration, and
  30. maximize current window. If current window is maximized, and
  31. there's a saved window configuration for current frame, restore
  32. that window configuartion."
  33. (interactive)
  34. (let* ((this-frame (selected-frame))
  35. (saved-state (gethash this-frame window-confs)))
  36. (if saved-state
  37. (if (gethash 'zoomed saved-state)
  38. ;; Already maximized. Restore.
  39. (progn
  40. (load-window-conf)
  41. (puthash 'zoomed nil saved-state))
  42. ;; Not maximized. Save window conf and maximize.
  43. (progn
  44. (save-window-conf)
  45. (delete-other-windows)
  46. (puthash 'zoomed t saved-state)))
  47.  
  48. ;; Never maximized before. Save window conf and maximize.
  49. (progn
  50. (save-window-conf)
  51. (delete-other-windows)
  52. (puthash 'zoomed t saved-state)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement