From 3edf542762fa44416b5edaa9ad5065bcb04ef91d Mon Sep 17 00:00:00 2001 From: Rich Alesi Date: Wed, 25 Mar 2015 22:53:57 -0700 Subject: [PATCH] Refactor zoom-frame microstate to use spacemacs microstate macro. Modify zoom in and out to keep frame the same size. --- spacemacs/extensions.el | 86 +++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/spacemacs/extensions.el b/spacemacs/extensions.el index c817f8556..0970b7312 100644 --- a/spacemacs/extensions.el +++ b/spacemacs/extensions.el @@ -130,55 +130,49 @@ zoom-frm-in) :init (progn - (defun spacemacs/zoom-frame-overlay-map () - "Set a temporary overlay map to easily change the font size." - (set-temporary-overlay-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "+") 'spacemacs/zoom-in-frame) - (define-key map (kbd "-") 'spacemacs/zoom-out-frame) - (define-key map (kbd "=") 'spacemacs/reset-zoom) - map) t)) + (spacemacs|define-micro-state zoom-frm + :doc "Zoom Frame [+] zoom frame in [-] zoom frame out [=] reset zoom" + :evil-leader "zf" + :use-minibuffer t + :bindings + ("+" spacemacs/zoom-frm-in :post 'spacemacs//powerline-calc) + ("-" spacemacs/zoom-frm-out :post 'spacemacs//powerline-calc) + ("=" spacemacs/zoom-frm-unzoom :post 'spacemacs//powerline-calc)) - (defun spacemacs/zoom-frame-micro-state-doc () - "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))) + (defun spacemacs//powerline-calc () (when (fboundp 'powerline-reset) (setq-default powerline-height (spacemacs/compute-powerline-height)) - (powerline-reset)) - (spacemacs/zoom-frame-overlay-map) - (spacemacs/zoom-frame-micro-state-doc)) - (evil-leader/set-key - "zf+" 'spacemacs/zoom-in-frame - "zf-" 'spacemacs/zoom-out-frame - "zf=" 'spacemacs/reset-zoom)))) + (powerline-reset))) + + (defun spacemacs/zoom-frm-in () + "zoom in frame, but keep the same pixel size" + (interactive) + (let ((fwp (* (frame-char-width) (frame-width))) + (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-") 'spacemacs/zoom-frm-in) + (global-set-key (kbd "C-") 'spacemacs/zoom-frm-out)))) (defun spacemacs/init-emacs-builtin-process-menu () (evilify process-menu-mode process-menu-mode-map))