From: Eric Hanchrow <offby1@blarg.net>
To: help-gnu-emacs@gnu.org
Subject: Re: change font but not frame size?
Date: Sun, 16 Dec 2007 09:00:46 -0800 [thread overview]
Message-ID: <87mysa377l.fsf@offby1.atm01.sea.blarg.net> (raw)
In-Reply-To: ea52eb53-2a7a-45ea-8e56-c7912017485c@18g2000hsf.googlegroups.com
>>>>> "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
prev parent reply other threads:[~2007-12-16 17:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-16 12:18 change font but not frame size? David Reitter
2007-12-16 15:44 ` Eric Hanchrow
[not found] ` <mailman.5072.1197820339.18990.help-gnu-emacs@gnu.org>
2007-12-16 16:37 ` David Reitter
2007-12-16 17:00 ` Eric Hanchrow [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mysa377l.fsf@offby1.atm01.sea.blarg.net \
--to=offby1@blarg.net \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).