Refactor zoom-frame microstate to use spacemacs microstate macro.

Modify zoom in and out to keep frame the same size.
This commit is contained in:
Rich Alesi 2015-03-25 22:53:57 -07:00 committed by syl20bnr
parent 31deb94d7f
commit 3edf542762

View file

@ -130,55 +130,49 @@
zoom-frm-in) zoom-frm-in)
:init :init
(progn (progn
(defun spacemacs/zoom-frame-overlay-map () (spacemacs|define-micro-state zoom-frm
"Set a temporary overlay map to easily change the font size." :doc "Zoom Frame [+] zoom frame in [-] zoom frame out [=] reset zoom"
(set-temporary-overlay-map :evil-leader "zf"
(let ((map (make-sparse-keymap))) :use-minibuffer t
(define-key map (kbd "+") 'spacemacs/zoom-in-frame) :bindings
(define-key map (kbd "-") 'spacemacs/zoom-out-frame) ("+" spacemacs/zoom-frm-in :post 'spacemacs//powerline-calc)
(define-key map (kbd "=") 'spacemacs/reset-zoom) ("-" spacemacs/zoom-frm-out :post 'spacemacs//powerline-calc)
map) t)) ("=" spacemacs/zoom-frm-unzoom :post 'spacemacs//powerline-calc))
(defun spacemacs/zoom-frame-micro-state-doc () (defun spacemacs//powerline-calc ()
"Display a short documentation in the mini buffer."
(echo "Zoom Frame micro-state
+ to zoom frame in
- to zoom frame out
= to reset zoom
Press any other key to exit."))
(defun spacemacs/zoom-in-frame ()
"Zoom in frame."
(interactive)
(spacemacs/zoom-in-or-out 1))
(defun spacemacs/zoom-out-frame ()
"Zoom out frame."
(interactive)
(spacemacs/zoom-in-or-out -1))
(defun spacemacs/reset-zoom ()
"Reset the zoom."
(interactive)
(spacemacs/zoom-in-or-out 0))
(defun spacemacs/zoom-in-or-out (direction)
"Zoom the buffer in/out. If DIRECTION is positive or zero the frame text is enlarged,
otherwise it is reduced."
(interactive)
(cond
((eq direction 0) (zoom-frm-unzoom))
((< direction 0) (zoom-frm-out))
((> direction 0) (zoom-frm-in)))
(when (fboundp 'powerline-reset) (when (fboundp 'powerline-reset)
(setq-default powerline-height (spacemacs/compute-powerline-height)) (setq-default powerline-height (spacemacs/compute-powerline-height))
(powerline-reset)) (powerline-reset)))
(spacemacs/zoom-frame-overlay-map)
(spacemacs/zoom-frame-micro-state-doc)) (defun spacemacs/zoom-frm-in ()
(evil-leader/set-key "zoom in frame, but keep the same pixel size"
"zf+" 'spacemacs/zoom-in-frame (interactive)
"zf-" 'spacemacs/zoom-out-frame (let ((fwp (* (frame-char-width) (frame-width)))
"zf=" 'spacemacs/reset-zoom)))) (fhp (* (frame-char-height) (frame-height))))
(zoom-frm-in)
(set-frame-size nil fwp fhp t)
))
(defun spacemacs/zoom-frm-out ()
"zoom out frame, but keep the same pixel size"
(interactive)
(let ((fwp (* (frame-char-width) (frame-width)))
(fhp (* (frame-char-height) (frame-height))))
(zoom-frm-out)
(set-frame-size nil fwp fhp t)
))
(defun spacemacs/zoom-frm-unzoom ()
"Unzoom current frame, keeping the same pixel size"
(interactive)
(let ((fwp (* (frame-char-width) (frame-width)))
(fhp (* (frame-char-height) (frame-height))))
(zoom-frm-unzoom)
(set-frame-size nil fwp fhp t)
))
;; Font size, either with ctrl + mouse wheel
(global-set-key (kbd "C-<wheel-up>") 'spacemacs/zoom-frm-in)
(global-set-key (kbd "C-<wheel-down>") 'spacemacs/zoom-frm-out))))
(defun spacemacs/init-emacs-builtin-process-menu () (defun spacemacs/init-emacs-builtin-process-menu ()
(evilify process-menu-mode process-menu-mode-map)) (evilify process-menu-mode process-menu-mode-map))