all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Mode-specific font setting?
@ 2005-04-25 18:35 David Reitter
  2005-04-26 19:43 ` Kevin Rodgers
  0 siblings, 1 reply; 3+ messages in thread
From: David Reitter @ 2005-04-25 18:35 UTC (permalink / raw)


How do I set a mode-specific font?
I've tried this hack:

  (add-hook 'after-change-major-mode-hook	
  	  (lambda ()
  	  (case major-mode
	  ('text-mode
  		(set-frame-font "fontset-lucida14")
)))
)

Unfortunately it doesn't work, obviously because the selected frame is 
a different one when the hook is called (find-file-other-frame was used 
to open a file), so the font gets set in the wrong frame.

Maybe there is a more elegant way (customization?) than using a hook, 
anyways.

Thanks!

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

* Re: Mode-specific font setting?
@ 2005-04-26  6:42 David Reitter
  0 siblings, 0 replies; 3+ messages in thread
From: David Reitter @ 2005-04-26  6:42 UTC (permalink / raw)


> How do I set a mode-specific font?

To elaborate on this, I want a generic solution that allows me to 
assign special fonts to all major modes.
Another thing I have tried is to find the frame for the current buffer 
(see code below). This doesn't work either, because although the 
current buffer exists, it seems like it doesn't have a window yet (or 
walk-windows ignores it.)

What to do?

---

(defun find-all-frames-internal (buffer)
   (let ((frames nil))
     (walk-windows '(lambda (wind)
                      (if (eq (window-buffer wind) buffer)
                        (let ((frm (window-frame wind)))
                          (unless (memq frm frames)
                            (push frm frames)))))
                   nil t)
     frames))

(add-hook  'after-change-major-mode-hook
           (lambda ()
            ;; this doesn't work yet
;; somehow, the window doesn't exist at this point :(
;; the current-buffer is correct
	    (setq fr (car (find-all-frames-internal (current-buffer))))
	
(if fr	
            (case major-mode
  	  ('text-mode
	     (select-frame fr)
  		(set-frame-font "fontset-lucida14")
)))))

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

* Re: Mode-specific font setting?
  2005-04-25 18:35 Mode-specific font setting? David Reitter
@ 2005-04-26 19:43 ` Kevin Rodgers
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2005-04-26 19:43 UTC (permalink / raw)


David Reitter wrote:
 > How do I set a mode-specific font?

You can't.  Fonts are frame-specific, not window- or mode-specific.

 > I've tried this hack:
 >
 >  (add-hook 'after-change-major-mode-hook
 >        (lambda ()
 >        (case major-mode
 >       ('text-mode
 >          (set-frame-font "fontset-lucida14")
 > )))
 > )
 >
 > Unfortunately it doesn't work, obviously because the selected frame is a
 > different one when the hook is called (find-file-other-frame was used to
 > open a file), so the font gets set in the wrong frame.

It also won't change the font when you select a buffer in a different
mode with `C-x b'.

 > Maybe there is a more elegant way (customization?) than using a hook,
 > anyways.

Use after-make-frame-functions, and make each frame's initial window
dedicated to that buffer for good measure.

-- 
Kevin Rodgers

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

end of thread, other threads:[~2005-04-26 19:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-25 18:35 Mode-specific font setting? David Reitter
2005-04-26 19:43 ` Kevin Rodgers
  -- strict thread matches above, loose matches on Subject: below --
2005-04-26  6:42 David Reitter

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.