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

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

Re: mode-specific font specifications?


From: Oliver Scholz
Subject: Re: mode-specific font specifications?
Date: Tue, 01 Sep 2009 23:28:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

I have a similar problem. But I use muse for my prose and verse, rather
than text mode.

Jim McCloskey <mcclosk@ucsc.edu> writes:

[...]

> I'd like to be able to set a default font for text and latex mode (for
> prose composition essentially) and to have a nice proportional font
> for that context (Linux Libertine or something). But such a font makes
> little or no sense for dired-mode, for example, where you really want
> a monospace font like Inconsolata (so that the alignment looks right).
>
> I thought I could do what I wanted by setting a default font in the
> init file with (set-default-font "FONTNAME") and then:
>
>     (add-hook 'dired-mode-hook
>       (function
>          (lambda ()
>                 (font-lock-mode 1)
>                 (require 'dired-x)
>                   (set-frame-font "Inconsolata-11")
>                                 )))
>

[...]

This changes the font of the frame's default face, only when you
activate dired-mode. What you probably want, instead of changing the
default face globally or for the frame, is specifying the font only for
the specific buffer.

Unfortunately, as far as I know, Gnu Emacs provides no means to make a
face buffer-local. There is the variable `default-text-properties',
though, which provides something close, but not quite close. Something
like ....

(add-hook 'text-mode-hook
          (lambda ()
            (set (make-local-variable 'default-text-properties)
                 '(face variable-pitch))))

... would probably do the job for text-mode. It has, however, no
effect on text that is already fontified (for instance, because
it is italic.)

I use overlays:

(defface egoge-proportional
  '((((type x))
     (:family "monotype-Garamond" :height 1.4))
    (((type w32))
      (:family "Sylfaen" :height 1.4)))
  "Basic face with variable width font.")

(defvar egoge-font-overlay nil)

(defun egoge-add-font-overlay ()
  (interactive)
  (let ((from (point-min))
        (to (point-max)))
      (when (eq major-mode 'message-mode)
        (save-excursion
          (message-goto-body)
          (setq from (point)
                to   (if (message-goto-signature)
                         (progn (forward-line -1)
                                (point))
                       (point-max)))))
      (let ((overlay (make-overlay from to)))
        (overlay-put overlay 'face 'egoge-proportional)
        (set (make-local-variable 'egoge-font-overlay)
             overlay))))

(add-hook 'muse-mode-hook
          #'egoge-add-font-overlay)




    Oliver
-- 
15 Fructidor an 217 de la Révolution
Liberté, Egalité, Fraternité!


reply via email to

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