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

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

Re: change font but not frame size?


From: Eric Hanchrow
Subject: Re: change font but not frame size?
Date: Sun, 16 Dec 2007 09:00:46 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

>>>>> "David" == David Reitter <david.reitter@gmail.com> writes:

    David> Post the code here - I'm interested!

I'm not certain that this is all of it; there may be some bits
scattered throughout my .emacs that this stuff requires, but that I've
overlooked.

(defun current-font-size (frame)
  (let ((fontname (cdr (assq 'font (frame-parameters frame)))))

    (string-match
     ;; todo -- figure out how to factor out the common
     ;; subexpression.  rx is a macro.
     (rx (and
          (repeat 6 (and "-" (zero-or-more (not (any "-")))))
          "-"
          (submatch (+ (any "0123456789")))
          (repeat 7   (and "-" (zero-or-more (not (any "-"))))))
         )
     fontname)
    (let ((size (match-string 1 fontname)))

      ;; sometimes, on OS X, fontname will be something silly like
      ;; "fontset-mac", which has no size field.  Thus "size" will be
      ;; nil, and "read"  will prompt in the minibuffer, which is
      ;; annoying.  So we just pick a reasonable default value.
      (when (not size)
        (setq size "12"))

      (read size))))

(defun enlarge-font (frame ratio)
  (set-font-size (round (* ratio (current-font-size frame)))))

(let ((bigger  (lambda () "Enlarge the font by 20%." (interactive) 
(enlarge-font (selected-frame) 1.2)))
      (smaller (lambda () "Reduce the font by 17%."  (interactive) 
(enlarge-font (selected-frame) (/ 1 1.2)))))
  (global-set-key (kbd "C--") smaller)
  (global-set-key (kbd "C-+") bigger)
  (case system-type
    ((windows-nt darwin)
     (global-set-key (kbd "<C-wheel-up>"  ) smaller)
     (global-set-key (kbd "<C-wheel-down>") bigger))
    (t

     (global-set-key (kbd "<C-mouse-4>"   ) smaller)
     (global-set-key (kbd "<C-mouse-5>"   ) bigger))))

(defun set-font-size (desired-size)
  "Use Bitstream Vera Sans if we can, and try to preserve the
frame size in pixels (which probably only works on GNU Emacs 22
and later), regardless of the current screen resolution."
  (interactive "NHeight in pixels: ")
  (when (eq system-type 'berkeley-unix)
    (error "Alas, I don't know how to set the font on BSD"))
  (let* ((fn (format

              (cond
               ((eq window-system 'mac)
                "-*-courier-medium-r-normal--%d-*-*-*-*-*-*-*")
               ((featurep 'gtk)
                "Bitstream Vera Sans Mono-%d")
               (t
                "-*-Bitstream Vera Sans Mono-Medium-r-*-*-%d-*-*-*-*-*-*-*"))
              desired-size))
         (args (append (list fn)
                       (if (< 21 emacs-major-version)
                           (list t)
                         nil))))
    (apply 'set-frame-font args)))

-- 
It has been suggested that this article or section be merged
into Fried dough. (Discuss)
        -- Seen on Wikipedia





reply via email to

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