2009-08-29

setting emacs font and the pain

On Aug 28, 5:20 pm, "Drew Adams" wrote:
> > How do i set a font for the current frame?
>
> M-x icicle-font S-TAB
>
> Choose any available font, using completion. Use `M-SPC', if you want to match
> different font parts separately (taking the intersection).
>
> > What i want is a toggle-font code so that i can press a key and have
> > the font set to either a monospaced or variable-spaced one, and just
> > for the current frame. More specifically: what's the elisp function
> > that makes the current frame use Courier New? (i'll also need to
> > know the full string or whatever that emacs uses for what Windows
> > calls the Courier New font.)
>
> (set-frame-parameter nil 'font "-*-Courier
> New-normal-r-*-*-14-112-96-96-c-*-iso8859-1")
>
> or whatever font you want.
>
> M-: (frame-parameters) is your friend.

Thanks Drew & Florian.

Spent another 1 hour on this, didn't want to go further at this moment but wanted to report some findings and reply.

finally was able to get something useful:

(defun cycle-font ()
"Change font in current frame, cycling thru a predefined set of fonts."
(interactive)
(if (not (eq last-command this-command))
(progn
(set-frame-parameter nil 'font "-*-Courier New-normal-r-*-*-14-112-96-96-c-*-iso8859-1")
(put this-command 'state "2"))
(cond
((string= (get this-command 'state) "1")
(set-frame-parameter nil 'font "-*-Courier New-normal-r-*-*-13-112-96-96-c-*-iso8859-1") (put this-command 'state "2"))
((string= (get this-command 'state) "2" )
(set-frame-parameter nil 'font "-outline-Lucida Sans Unicode-normal-normal-normal-sans-13-*-*-*-p-*-iso8859-1") (put this-command 'state "3"))
((string= (get this-command 'state) "3")
(set-frame-parameter nil 'font "-outline-Code2000-normal-normal-normal-*-13-*-*-*-p-*-iso8859-1") (put this-command 'state "1"))
)
)
)


(global-set-key (kbd "") 'cycle-font)

This is for Windows Vista machine. Press a button it'll cycle among 3 fonts. Mostly for the purpose of switching between mono-width courier and variable-width lucida.

The Code2000 is there just for the occation of viewing some unicode. Code2000 is so bad that it renders ascii dash/hyphen as invisible if the font size is not huge.

Code2000 is not part of Windows Vista. You have to downloaded it, i wouldn't recommend it, just that i happened to already did and that seems to be the font containing the most unicode

the elisp dealing is also painful, or, much less than ideal. Here's a outline of my problem.

So, Drew showed me this

(set-frame-parameter nil 'font "-*-Courier New-normal-r-*-*-14-112-96-96-c-*-iso8859-1")

which is great. So, i wanted Lucida. So, logically, i replaced the courier name to lucida like this:

(set-frame-parameter nil 'font "-*-Lucida Sans Unicode-normal-r-*-*-14-112-96-96-c-*-iso8859-1")

but emacs spits out error. I didn't know what those 112, 96, 96 are, so i figured i replace them with asterisk. Tried a few variations, no go. After a while, i found this works:

(set-frame-parameter nil 'font "Lucida Sans Unicode")
(set-frame-parameter nil 'font "courier new")
(set-frame-parameter nil 'font "Fixedsys")
(set-frame-parameter nil 'font "FixedsysTTF")

but i do need to set size because the size spec is not equivalent among fonts. e.g. One font at size 14 will be too large/small for another font at 14.

So i need something like.:

(set-frame-parameter nil 'font "Lucida Sans Unicode" 'size 12)

after looking up some inline doc or elisp doc in few min, i can't find out what's the available parms for set-frame-parameter. But i did find this function:

(frame-parameters)

which gives out all the params/value pairs in a frame. So, after a while finding no easier way, i went thru the rather tedious process of using the menu to set a font, then run the frame-parameters and get the value of the font. So, i get the right font string spec for the fonts i want. e.g.

"-*-Courier New-normal-r-*-*-13-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"

btw, in my haphazard notes i found font-spec, e.g..

(font-spec :family "Unicode Symbols" :size 24)

which turns out not useful here.

now i got cycle-font, next job when i have time would be setting monospaced font whenever dired is opened or calendar (recently someone asked for that, which prob means lots others have the same question)... and also the job of getting all unicode to show...

---------------

ok a question. Is there a doc that list all the params of set-frame-parameter?

i've not attempted to read the elisp doc for the frame section or font/faces section in some cover-to-cover manner... well eventually i'll have to do that.

the cycle-font command above can be improved too... not happy with the state cycle code... hackish.

Xah
∑ http://xahlee.org/

No comments:

Post a Comment