ShingoFukuyama
7/12/2014 - 11:57 PM

emacs font change with overlay

emacs font change with overlay


;; require ov.el (ver 1.0.5)
;; https://github.com/ShingoFukuyama/ov.el
(require 'ov)

(defvar my-ov-font-size nil)

(defun my-ov-font-size-change (ratio &optional update-all-buffer)
  (let ((ov-sticky-rear t)
        (ov-sticky-front t))
    (if update-all-buffer
        (mapc (lambda (buffer)
                (with-current-buffer (get-buffer buffer)
                  (ov-clear 'my-ov-font-size)
                  (ov-set (ov (point-min) (point-max))
                          'face `(:height ,ratio) 'my-ov-font-size t)))
              (buffer-list))
      (ov-clear 'my-ov-font-size)
      (ov-set (ov (point-min) (point-max)) 'face `(:height ,ratio) 'my-ov-font-size t))))

(defun my-ov-font-size-zoom-in (&optional prefix)
  (interactive "P")
  (unless my-ov-font-size
    (setq my-ov-font-size (or (ignore-errors (face-attribute 'default :height)) 120)))
  (my-ov-font-size-change
   (setq my-ov-font-size (+ my-ov-font-size 10))
   (if prefix t nil)))

(defun my-ov-font-size-zoom-out (&optional prefix)
  (interactive "P")
  (unless my-ov-font-size
    (setq my-ov-font-size (or (ignore-errors (face-attribute 'default :height)) 120)))
  (my-ov-font-size-change
   (setq my-ov-font-size (- my-ov-font-size 10))
   (if prefix t nil)))

(defun my-ov-font-size-zoom-for-new-buffer ()
  (unless my-ov-font-size
    (setq my-ov-font-size (or (ignore-errors (face-attribute 'default :height)) 120)))
  (if my-ov-font-size
      (my-ov-font-size-change my-ov-font-size)))

(defun my-ov-font-size-zoom-reset ()
  (interactive)
  (setq my-ov-font-size (or (ignore-errors (face-attribute 'default :height)) 120))
  (mapc (lambda (buffer)
          (with-current-buffer (get-buffer buffer)
            (ov-clear 'my-ov-font-size)))
        (buffer-list)))


(add-hook 'after-change-major-mode-hook 'my-ov-font-size-zoom-for-new-buffer)

(global-set-key (kbd "C-c z i") 'my-ov-font-size-zoom-in)
(global-set-key (kbd "C-c z o") 'my-ov-font-size-zoom-out)
(global-set-key (kbd "C-c z r") 'my-ov-font-size-zoom-reset)
;; `C-u C-c z i' : change font size with all buffers
;; `C-u C-c z o' : change font size with all buffers