all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* change font but not frame size?
@ 2007-12-16 12:18 David Reitter
  2007-12-16 15:44 ` Eric Hanchrow
       [not found] ` <mailman.5072.1197820339.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: David Reitter @ 2007-12-16 12:18 UTC (permalink / raw)
  To: gnu emacs-help gnu

Is it possible to change the font in a frame (default face) without  
changing the frame's pixel size?

`set-frame-font' has a `keep-size' argument, which would do the job,  
except that it enlarges/shrinks the frame first before bringing it  
back to the original size. That is a rather ugly effect, and when you  
try to increase font sizes gradually, or switch between different sets  
of faces in a frame, such an animation is very annoying. How can I  
avoid that?

Is there a way to block the screen update and "freeze" the frame until  
it is at its correct size?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: change font but not frame size?
  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>
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Hanchrow @ 2007-12-16 15:44 UTC (permalink / raw)
  To: help-gnu-emacs

I have some absurdly complex code in my .emacs that adjusts the frame
size after setting the font size, in an attempt to make it the same
size it was originally, more or less sorta kinda.  Lemme know if you'd
like to look at it (it isn't pretty).
-- 
The people I know who do great work think that they suck, but
that everyone else sucks even more.

        -- Paul Graham

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: change font but not frame size?
       [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
  0 siblings, 1 reply; 4+ messages in thread
From: David Reitter @ 2007-12-16 16:37 UTC (permalink / raw)
  To: help-gnu-emacs

On Dec 16, 3:44 pm, Eric Hanchrow <off...@blarg.net> wrote:

> I have some absurdly complex code in my .emacs that adjusts the frame
> size after setting the font size, in an attempt to make it the same
> size it was originally, more or less sorta kinda.  Lemme know if you'd
> like to look at it (it isn't pretty).

Sure. I've tried some absurdly complex things as well - such as
creating an invisible frame, setting the font there, reading out the
resulting char-height, and then trying to set the new height of the
frame and its new font in one go with modify-frame-parameters. It
didn't work (on several levels!).

Post the code here - I'm interested!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: change font but not frame size?
  2007-12-16 16:37   ` David Reitter
@ 2007-12-16 17:00     ` Eric Hanchrow
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Hanchrow @ 2007-12-16 17:00 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> "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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-16 17:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.