Quantcast
Channel: Planet Apache
Viewing all articles
Browse latest Browse all 9364

Rodent of Unusual Size (Ken Coar): Emacs and terminal fonting

$
0
0

My new work environment (contracting at Red Hat) has resulted in a number of changes in how I do things, including:

  1. Using a second monitor on my laptop;
  2. Switching from Enlightenment E16 to E17 so I can use the second monitor;
  3. Enhancing my Emacs and urxvt configurations so I can change the typeface so others can read stuff on my screen (i.e., make the windows and typefaces larger);
  4. Switch to using NetworkManager to handle my networking setups;
  5. And many more, I'm sure.

Here's how I change the fonts in Emacs. I add these to my ~/.emacs file:

 ;;
 ;; Keybindings of the form C-c  are supposedly reserved
 ;; for user bindings.
 ;;
 ;; Set up CTRL/C-r to reset
    to the startup font
 ;;
 (global-set-key (concat (kbd "C-c") "r") 'RoUS/reset-font)
 ;;
 ;; And CTRL/C-n to move to the 'next' font, cycling through
 ;; our list
 ;;
 (global-set-key (concat (kbd
    "C-c") "n") 'RoUS/cycle-fonts)
 ;;
 ;; Here's the list of fonts I've chosen, based on trial and
 ;; error on multiple monitors at multiple resolutions
 ;;
 (setq RoUS/default-font
    (frame-parameter (car (frame-list)) 'font)
 )
 (setq RoUS/font-list (append (list RoUS/default-font)
 '("fixed-18"
 "courier-18"
 "courier-20"
 "courier-25"
 "LucidaTypewriter-18"
    "LucidaTypewriter-20"
 "LucidaTypewriter-24"
 "terminal-14"
 )
 )
 )
 ;;
 ;; And here are the functions to reset and cycle the font
 ;;
 (defun RoUS/reset-font ()
 (interactive)
    (set-default-font RoUS/default-font)
 )
 (defun RoUS/cycle-fonts ()
 (interactive)
 (let (next-font)
 (setq next-font (pop RoUS/font-list))
 (cdr (nconc RoUS/font-list (list next-font)))
    (message (concat "Font is now: " next-font))
 (set-default-font next-font)
 )
 )
 

The font cycling for my urxvt (also known as rxvt-unicode) terminal windows takes advantage of the Perl extension functionality. I wrote a little Perl snippet to handle the fonts (in the file ~/.urxvt-ext.d/cycle-fonts):

 #! perl
 use List::MoreUtils qw(uniq);
 
 my @preferred_fonts = ();
 
 sub on_init {
    my $self = $_[0];
 my $term = $self->{term};
 push(@preferred_fonts, $term->resource('font'));
 if (my $fonts = $term->x_resource('fonts2cycle')) {
 push(@preferred_fonts,
    split(/\s*,\s*/, $fonts));
 @preferred_fonts = uniq(@preferred_fonts);
 }
 return ();
 }
 
 sub on_user_command {
 my ($self, $cmd) = @_;
 if (($cmd eq 'cycle-fonts') && (@preferred_fonts
    >= 1)) {
 my $fontwas = $self->resource('font');
 my $newfont;
 while (($newfont = $preferred_fonts[0]) eq $fontwas) {
 @preferred_fonts = @preferred_fonts[ 1 .. $#preferred_fonts, 0 ];
 }
    $self->cmd_parse("\033]50;$newfont\007");
 }
 ()
 }
 

This is enabled (and controlled) through X resources. In my .Xresources file, I have the following:

 URxvt.perl-ext-common: default,cycle-fonts
 URxvt.perl-lib: ~/.urxvt-ext.d:$HOME/.urxvt-ext.d:/home/coar/.urxvt-ext.d
 URxvt.fonts2cycle: fixed, \
    lucidasanstypewriter-18, \
 lucidasanstypewriter-24, \
 -*-lucidatypewriter-medium-r-normal-sans-26-190-100-100-m-159-*-*, \
 -*-lucidatypewriter-medium-r-normal-sans-34-240-100-100-m-200-*-*
    URxvt.keysym.C-equal: perl:cycle-fonts
 URxvt.keysym.C-minus: command:\033]710;fixed\007
 

Again, the list of fonts was determined by trial and error.


Viewing all articles
Browse latest Browse all 9364

Trending Articles