all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Help in querying xlsfonts for a particular font from elisp
@ 2006-08-25 15:41 Andrew M. Scott
  2006-08-25 18:37 ` Peter Dyballa
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andrew M. Scott @ 2006-08-25 15:41 UTC (permalink / raw)


I really like the "vera sans mono" font, but it's only available on
some of the platforms I use. 

My .emacs currently uses the elisp fragment below, with a simple (getenv "PLATFORM")
kludge in the <need-some-help-here> test section; however this fails if I ssh from
a supported platform's xterm onto an unsupported platform.

I'd like help with cleaner solution to test for a supported platform
font.

(when (<need-some-help-here>)
   (set-face-font 'default "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1")
   ;; AMS: Not clear why I need these next two lines
   (add-to-list 'default-frame-alist '(font . "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1"))
   (add-to-list 'initial-frame-alist '(font . "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1"))
   (set-frame-position (selected-frame) -8 -100)
   )

The X11 xlsfonts command seems promising, e.g.

xlsfonts -fn "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1" | wc -l
returns
2 
on a supported platform, and the two lines

xlsfonts: pattern "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1" unmatched
0

I've played with variations of shell-command e.g.
(when (shell-command "xlsfonts -fn '-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1' | wc -l" t)
  (message "font exists")
     (message "font doesn't exist"))
but the shell calling subtleties escape me. Is there a non-interactive
version of shell-command?

Thanks,
Andy Scott

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

* Re: Help in querying xlsfonts for a particular font from elisp
  2006-08-25 15:41 Help in querying xlsfonts for a particular font from elisp Andrew M. Scott
@ 2006-08-25 18:37 ` Peter Dyballa
  2006-08-28 16:09   ` Andrew M. Scott
  2006-08-28 15:16 ` Kevin Rodgers
       [not found] ` <mailman.5816.1156778244.9609.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 5+ messages in thread
From: Peter Dyballa @ 2006-08-25 18:37 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 25.08.2006 um 17:41 schrieb Andrew M. Scott:

> I really like the "vera sans mono" font, but it's only available on
> some of the platforms I use.

The fonts are free. You can easily install them everywhere. If you  
can't because of missing privileges, you could think of setting up a  
font server on your local machine (usually port 7100). This is just a  
piece of software and some configuration. Since the ssh tunnels are  
open to X11 protocol, your remote X clients could use the fonts from  
your font server. When it's running it does not consume much  
resources. The fonts are a few 10 kB, and your font server does not  
need to serve all X11 fonts, just a chosen few.

Instead of complicated Elisp code you could also set up ~/.Xdefaults  
files on your remote computers. Emacs*font and other font resources  
can also name a fontset (Emacs*fontSet, Emacs.Fontset-0), one of a  
few you have set up in the .emacs files.

When you know exactly what each machine offers, you could use Emacs  
invocations (from shell scripts for example) where either X resources  
or fonts or fontsets to use are specified.

--
Greetings

   Pete

There is no national science just as there is no national  
multiplication table; what is national is no longer science.
                                       -- Anton Checov

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

* Re: Help in querying xlsfonts for a particular font from elisp
  2006-08-25 15:41 Help in querying xlsfonts for a particular font from elisp Andrew M. Scott
  2006-08-25 18:37 ` Peter Dyballa
@ 2006-08-28 15:16 ` Kevin Rodgers
       [not found] ` <mailman.5816.1156778244.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2006-08-28 15:16 UTC (permalink / raw)


Andrew M. Scott wrote:
> I really like the "vera sans mono" font, but it's only available on
> some of the platforms I use. 
> 
> My .emacs currently uses the elisp fragment below, with a simple (getenv "PLATFORM")
> kludge in the <need-some-help-here> test section; however this fails if I ssh from
> a supported platform's xterm onto an unsupported platform.
> 
> I'd like help with cleaner solution to test for a supported platform
> font.
> 
> (when (<need-some-help-here>)
>    (set-face-font 'default "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1")
>    ;; AMS: Not clear why I need these next two lines
>    (add-to-list 'default-frame-alist '(font . "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1"))
>    (add-to-list 'initial-frame-alist '(font . "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1"))
>    (set-frame-position (selected-frame) -8 -100)
>    )
> 
> The X11 xlsfonts command seems promising, e.g.
> 
> xlsfonts -fn "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1" | wc -l
> returns
> 2 
> on a supported platform, and the two lines
> 
> xlsfonts: pattern "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1" unmatched
> 0
> 
> I've played with variations of shell-command e.g.
> (when (shell-command "xlsfonts -fn '-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1' | wc -l" t)
>   (message "font exists")
>      (message "font doesn't exist"))

You need `if', not `when' there.

> but the shell calling subtleties escape me. Is there a non-interactive
> version of shell-command?

First, does (x-list-fonts ""-bitstream-bitstream vera sans 
mono-medium-r-*-*-16-120-*-*-*-*-*-1") work?

If not, try calling the xlsfonts command with `shell-command-to-string'
instead of `shell'.

-- 
Kevin

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

* Re: Help in querying xlsfonts for a particular font from elisp
  2006-08-25 18:37 ` Peter Dyballa
@ 2006-08-28 16:09   ` Andrew M. Scott
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew M. Scott @ 2006-08-28 16:09 UTC (permalink / raw)
  Cc: Andrew M. Scott, help-gnu-emacs

>>>>> "Peter" == Peter Dyballa <Peter_Dyballa@Web.DE> writes:

    Peter> Am 25.08.2006 um 17:41 schrieb Andrew M. Scott:

    >> I really like the "vera sans mono" font, but it's only
    >> available on some of the platforms I use.

    Peter> The fonts are free. You can easily install them everywhere.
    Peter> If you can't because of missing privileges, you could think
    Peter> of setting up a font server on your local machine (usually
    Peter> port 7100). This is just a piece of software and some
    Peter> configuration. Since the ssh tunnels are open to X11
    Peter> protocol, your remote X clients could use the fonts from
    Peter> your font server. When it's running it does not consume
    Peter> much resources. The fonts are a few 10 kB, and your font
    Peter> server does not need to serve all X11 fonts, just a chosen
    Peter> few.

    Peter> Instead of complicated Elisp code you could also set up
    Peter> ~/.Xdefaults files on your remote computers. Emacs*font and
    Peter> other font resources can also name a fontset
    Peter> (Emacs*fontSet, Emacs.Fontset-0), one of a few you have set
    Peter> up in the .emacs files.

    Peter> When you know exactly what each machine offers, you could
    Peter> use Emacs invocations (from shell scripts for example)
    Peter> where either X resources or fonts or fontsets to use are
    Peter> specified.

Peter,

My work/home laptops are often disconnected from a network, so I was
looking for a self-contained solution, though I like your font-server
suggestion! Thank you!!

As background, my desire is to "take my Emacs customizations" with me;
I have a master gnu/linux .emacs and a personal site-lisp area which I
replicate to other gnu/linux and Windows XP machines. The handy
color-theme.el package allows me to take my color scheme with me, and
I was wondering if a few more lines of .emacs elisp could let me
conditionally use my favorite font per platform (that is already
installed by default.)

There appears to be a whole spectrum of where to put "conditionals"
like this. On one side, in the ~/.Xdefaults or ~/.Xresources, either
supported with ancillary scripts or m4 macros, or in a .emacs or
equivalent elisp file. I was trying the elisp route.

Also, one of my motivations for my question is to better understand
(in general) how to call native commands on my gnu/linux system
from elisp and process its return information. For example, my .emacs
currently has some code to customize the grep-command strings for the
platforms which supported it, based on a "grep --version" query:

--- .emacs snippet (It works, even if not pretty) ----
;; AMS: I prefer M-x grep ignoring case; otherwise default is "grep -n -e "
;; AMS: If grep 2.5 is available, ignore GNUS files prefixed with .newsrc,
;; because it is slow to parse with font-lock mode enabled.

;; Futures:
;; 1. Is there a way to do this that is directory-specific, like the
;;    .cvsignore command. Maybe a combination of skip_directories and
;;    excludes?
;; 2. GREP_OPTIONS breaks older grep's, so probably it's a portability
;;    barrier, e.g. leave it out of my .tcshrc
;; 3. Better: set GREP_OPTIONS conditionally (upon grep >= v2.5) in
;;    .tcshrc, e.g. setenv GREP_OPTIONS "-nH -i --color=always
;;    --exclude='\.newsrc.*'"
;;     setenv GREP_COLOR red (red is the default)

(defvar my-grep-version nil
      "*Version of grep that is foremost in my exec-path.")

;; nth split-string idea courtesy of Thien-Thi Nguyen <ttn@glug.org>
;; AMS: Discern best available grep for WinXP, Unix
(setq my-grep-version
   (nth 3 (split-string (shell-command-to-string
                         (concat
                           (or (executable-find "ggrep")
                               (executable-find "grep"))
                           " --version")
                         ))))

;; Courtesy of Kevin Rodgers <ihs_4664@yahoo.com>
;; (setq my-grep-version
;;    (shell-command-to-string "grep --version | awk '{printf(\"%s\", $NF); exit}'"))

  (if (string-lessp "2.5" my-grep-version)
    (progn
      ;; GNU grep 2.5+
      ;; (setq grep-command "grep -nH -i --color=always --exclude='\.newsrc.*' ")
      (setq grep-command (concat
                           (or (executable-find "ggrep")
                               (executable-find "grep"))
                            " -nH -i --exclude='\.newsrc.*' --exclude='.fonts.cache-1' ")))
      ;; GNU grep 2.4 or earlier
      (setq grep-command (concat
                           (or (executable-find "ggrep")
                               (executable-find "grep"))
                             " -nH -i ")))


Andy Scott

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

* Re: Help in querying xlsfonts for a particular font from elisp
       [not found] ` <mailman.5816.1156778244.9609.help-gnu-emacs@gnu.org>
@ 2006-08-28 17:24   ` Andrew M. Scott
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew M. Scott @ 2006-08-28 17:24 UTC (permalink / raw)


>>>>> "Kevin" == Kevin Rodgers <ihs_4664@yahoo.com> writes:

    Kevin> Andrew M. Scott wrote:
    >> I'd like help with cleaner solution to test for a supported
    >> platform font.
    >> 
    >> (when (<need-some-help-here>) (set-face-font 'default
    >> "-bitstream-bitstream vera sans
    >> mono-medium-r-*-*-16-120-*-*-*-*-*-1")
    >> ;; AMS: Not clear why I need these next two lines
    >> (add-to-list 'default-frame-alist '(font .
    >> "-bitstream-bitstream vera sans
    >> mono-medium-r-*-*-16-120-*-*-*-*-*-1")) (add-to-list
    >> 'initial-frame-alist '(font . "-bitstream-bitstream vera sans
    >> mono-medium-r-*-*-16-120-*-*-*-*-*-1")) (set-frame-position
    >> (selected-frame) -8 -100) )

    Kevin> You need `if', not `when' there.

Yup. My error.

    >> but the shell calling subtleties escape me. Is there a
    >> non-interactive version of shell-command?

    Kevin> First, does (x-list-fonts "-bitstream-bitstream vera sans
    Kevin> mono-medium-r-*-*-16-120-*-*-*-*-*-1") work?

Returns nil (=> Emacs doesn't know about it).

    Kevin> If not, try calling the xlsfonts command with
    Kevin> `shell-command-to-string' instead of `shell'.

Thanks for the pointer, Kevin! 

Here's my .updated emacs fragment, which is working for me. I'm
depending on xlsfonts returning "unmatched" if the 'vera sans mono'
doesn't exist on that platform.

;; Use the bitstream vera sans mono font if available
(when (executable-find "xlsfonts")
 (unless (string-match "unmatched"
   (shell-command-to-string "xlsfonts -fn '-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1'"))
   (set-face-font 'default "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1")
   (add-to-list 'default-frame-alist '(font . "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1"))
   (add-to-list 'initial-frame-alist '(font . "-bitstream-bitstream vera sans mono-medium-r-*-*-16-120-*-*-*-*-*-1"))
   (set-frame-position (selected-frame) -8 -100)
   ))

Thanks again!
Andy Scott

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

end of thread, other threads:[~2006-08-28 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-25 15:41 Help in querying xlsfonts for a particular font from elisp Andrew M. Scott
2006-08-25 18:37 ` Peter Dyballa
2006-08-28 16:09   ` Andrew M. Scott
2006-08-28 15:16 ` Kevin Rodgers
     [not found] ` <mailman.5816.1156778244.9609.help-gnu-emacs@gnu.org>
2006-08-28 17:24   ` Andrew M. Scott

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.