* mode-specific font specifications?
@ 2009-08-24 9:12 Jim McCloskey
0 siblings, 0 replies; 5+ messages in thread
From: Jim McCloskey @ 2009-08-24 9:12 UTC (permalink / raw)
To: help-gnu-emacs
Just getting used to Emacs 23.1, and especially enjoying the improved
font-rendering. Thanks to all who made this possible. It's really great.
There's one thing that I haven't figured out yet, though, so I thought
I might ask for help here. I suspect that I am not alone in wanting to
be able to do this.
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")
)))
or:
(add-hook 'dired-mode-hook
(function
(lambda ()
(font-lock-mode 1)
(require 'dired-x)
(set-default-font "Inconsolata-11")
)))
and that sort of works, in the sense that the first buffer visited is
displayed in the proportional font FONTNAME, and then when you switch
to dired-mode, you get 11pt Inconsolata. However, when you then go
from dired-mode back to the first buffer (in latex-mode, say), the
font used is now Inconsolata. I had hoped to limit the scope of that
second font declaration by putting it inside:
(add-hook 'dired-mode-hook
.... )
but, once called, its effects in fact seem to be global rather than
local to that mode.
Is there a way for me to do what I'd like to be able to do?
Thanks very much for any advice or any pointers to relevant documentation.
Jim
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <mailman.5251.1251123404.2239.help-gnu-emacs@gnu.org>]
* Re: mode-specific font specifications?
[not found] <mailman.5251.1251123404.2239.help-gnu-emacs@gnu.org>
@ 2009-08-24 16:14 ` A.Politz
2009-09-01 17:50 ` Xah Lee
2009-09-01 21:28 ` Oliver Scholz
2 siblings, 0 replies; 5+ messages in thread
From: A.Politz @ 2009-08-24 16:14 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 24, 11:12 am, Jim McCloskey <mccl...@ucsc.edu> wrote:
> Just getting used to Emacs 23.1 [...]
> I'd like to be able to set a default font for text and latex mode [...]
> Jim
It's called face remapping.
(info "(elisp) Face Remapping")
-ap
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: mode-specific font specifications?
[not found] <mailman.5251.1251123404.2239.help-gnu-emacs@gnu.org>
2009-08-24 16:14 ` A.Politz
@ 2009-09-01 17:50 ` Xah Lee
2009-09-01 21:28 ` Oliver Scholz
2 siblings, 0 replies; 5+ messages in thread
From: Xah Lee @ 2009-09-01 17:50 UTC (permalink / raw)
To: help-gnu-emacs
am also interested in this, however, so far i have not been
successful.
here's a work-round command.
(defun cycle-font ()
"Change font in current frame.
When called repeatedly, cycle thru a predefined set of fonts.
Warning: expected to work for Windows only, and you need to install
Code2000 font."
(interactive)
(if (not (eq last-command this-command))
;; correct syntax for some fonts
;; "-*-Courier New-normal-r-*-*-14-112-96-96-c-*-iso8859-1"
;; "-outline-Lucida Sans Unicode-normal-normal-normal-sans-13-*-*-*-p-
*-iso8859-1"
;; "-outline-Code2000-normal-normal-normal-*-15-*-*-*-p-*-iso8859-1"
;; "-raster-Fixedsys-normal-normal-normal-mono-15-*-*-*-c-*-iso8859-1"
;; "-outline-FixedsysTTF-semi-bold-normal-normal-mono-16-*-*-*-c-*-
iso8859-1"
(progn
(set-frame-parameter nil 'font "Courier New-10")
(put this-command 'state "2"))
(cond
((string= (get this-command 'state) "1")
(set-frame-parameter nil 'font "Courier New-10") (put this-
command 'state "2"))
((string= (get this-command 'state) "2" )
(set-frame-parameter nil 'font "Lucida Sans Unicode-10") (put
this-command 'state "1"))
;; ((string= (get this-command 'state) "3")
;; (set-frame-parameter nil 'font "fixedsys-10") (put
;; this-command 'state "1"))
) ) )
to automatically change font by mode, i tried this:
(defun set-font-by-mode ()
"Change font in current frame according to the major mode."
(interactive)
(message (symbol-name major-mode) )
(cond
((equal major-mode 'dired-mode) (set-frame-parameter nil 'font
"Courier New-10") (message "aaaaaa"))
(t (set-frame-parameter nil 'font "Lucida Sans Unicode-10")
(message "bbbbb"))
)
)
(add-hook 'after-change-major-mode-hook 'set-font-by-mode)
it does work when you go into a dired dir first time. However,
switching buffer doesn't work...
might want to try to get the hook to run when buffer is switched, or
attached it to find-file-hook. Or, also try to find a exit-major-mode
hook...
ps: looking at your post, seems you stuck at the same problem as me.
Xah
∑ http://xahlee.org/
☄
On Aug 24, 2:12 am, Jim McCloskey <mccl...@ucsc.edu> wrote:
> Just getting used to Emacs 23.1, and especially enjoying the improved
> font-rendering. Thanks to all who made this possible. It's really great.
>
> There's one thing that I haven't figured out yet, though, so I thought
> I might ask for help here. I suspect that I am not alone in wanting to
> be able to do this.
>
> 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")
> )))
>
> or:
>
> (add-hook 'dired-mode-hook
> (function
> (lambda ()
> (font-lock-mode 1)
> (require 'dired-x)
> (set-default-font "Inconsolata-11")
> )))
>
> and that sort of works, in the sense that the first buffer visited is
> displayed in the proportional font FONTNAME, and then when you switch
> to dired-mode, you get 11pt Inconsolata. However, when you then go
> from dired-mode back to the first buffer (in latex-mode, say), the
> font used is now Inconsolata. I had hoped to limit the scope of that
> second font declaration by putting it inside:
>
> (add-hook 'dired-mode-hook
> .... )
>
> but, once called, its effects in fact seem to be global rather than
> local to that mode.
>
> Is there a way for me to do what I'd like to be able to do?
>
> Thanks very much for any advice or any pointers to relevant documentation.
>
> Jim
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: mode-specific font specifications?
[not found] <mailman.5251.1251123404.2239.help-gnu-emacs@gnu.org>
2009-08-24 16:14 ` A.Politz
2009-09-01 17:50 ` Xah Lee
@ 2009-09-01 21:28 ` Oliver Scholz
2009-09-01 21:38 ` Oliver Scholz
2 siblings, 1 reply; 5+ messages in thread
From: Oliver Scholz @ 2009-09-01 21:28 UTC (permalink / raw)
To: help-gnu-emacs
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é!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-09-01 21:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-24 9:12 mode-specific font specifications? Jim McCloskey
[not found] <mailman.5251.1251123404.2239.help-gnu-emacs@gnu.org>
2009-08-24 16:14 ` A.Politz
2009-09-01 17:50 ` Xah Lee
2009-09-01 21:28 ` Oliver Scholz
2009-09-01 21:38 ` Oliver Scholz
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).