help-emacs-windows
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[h-e-w] Re: Resizing a frame's font


From: Henrik Andersson
Subject: [h-e-w] Re: Resizing a frame's font
Date: Wed, 08 Dec 2004 12:12:31 +0100
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

Wow, that's neat.

I love this open-source stuff, where everone contributes their own ideas.

- Henrik

David J. Biesack wrote:
The recent discussion of font choice, coupled with a thread in another forum 
discussing the Mozilla Firefox browser inspired me to write up the following 
Elisp functions.

;; font-resize.el
;; David Biesack address@hidden
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:

;; Functions to change the default font size of the current buffer,
;; similar to how Mozilla Firefox changes the font with C-KP-Add, C-KP-Subtract

;;; Code:

(defun font-increase (arg)
  "Increase the current frame's default font by twice arg. Arg may be negative to 
decrease the font size."
  (interactive "p")
  (font-resize (* 2 arg)))

(defun font-decrease (arg)
  "Decrease the current frame's default font by twice arg. Arg may be negative to 
increase the font size."
  (interactive "p")
  (font-resize (* -2 arg)))

(defun font-resize (arg)
  "Increase the current frame's default font by arg. Arg may be negative to decrease 
the font size."
  (interactive "p")
  (let ((font (cdr (assoc 'font (frame-parameters))))
        size
        new-font
        new-size)
    (string-match "\\(-\\w+-[^-]+-\\w+-.-\\w+-\\w+-\\)\\([0-9]+\\)\\(-.*\\)$" 
font)
    (setq size (string-to-int (substring font (match-beginning 2) (match-end 
2))))
    (setq new-size (+ size arg))
    (setq new-font (concat (substring font (match-beginning 1) (match-end 1))
                       (int-to-string new-size)
                       (substring font (match-beginning 3) (match-end 3))))
    (set-default-font new-font)
    (message "Set default font: %s" new-font)))

;; I bind to Control Keypad Add and Control Keypad Subtract with:

(define-key global-map [C-kp-add]       'font-increase)
(define-key global-map [C-kp-subtract]  'font-decrease)

Now, I can increase or decrease the current frame's font size (in increments of 
two),
just like I can in the Firefox browser. I'm not sure if it works for all fonts;
it is provided as is.



--
---------------------------------------------
Henrik Andersson
Netherlands Institute of Ecology -
Centre for Estuarine and Marine Ecology
P.O. Box 140
4400 AC Yerseke
Phone: +31 113 577473
address@hidden
http://www.nioo.knaw.nl/ppages/handersson





reply via email to

[Prev in Thread] Current Thread [Next in Thread]