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: Xah Lee
Subject: Re: mode-specific font specifications?
Date: Tue, 1 Sep 2009 10:50:25 -0700 (PDT)
User-agent: G2/1.0

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



reply via email to

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