Dimitar Panayotov shares experience

Everything which eases programmer’s life and satisfies the clients

Archive for the 'kde' Category


GNU Emacs: Use TTF font even if it is looks like not installed

Posted by Dimitar Panayotov on 30 November 2006, 2:48

Since I switched to KDE 3.5.5 (on Debian 4.0, othewise known as “Etch”), I have been trying to use DejaVu Sans Mono font in Emacs — it is a TTF font, it is beautiful, and supports many more encodings than everyday monospace fonts around.

Just for your information, If you want to install those fonts on Debian, do this:

# login as root before executing this command.
apt-get install ttf-dejavu

If you downloaded your fonts other way, you should install them in subdirectory into /usr/share/fonts/truetype (at least in KDE 3.5.5), like this:

/usr/share/fonts/truetype/ttf-dejavu
/usr/share/fonts/truetype/your-fonts

So, for the example how to make Emacs to use TTF font which you cannot see in set-default-font possible choices, I will use ttf-dejavu font name.

# login as root before executing those commands.
cd /usr/share/fonts/truetype/ttf-dejavu
mkfontscale
mkfontdir
fc-cache -fv

Now you should edit your Xorg configuration file (/etc/X11/xorg.conf) like this:

Section "Files"
  ...
  FontPath  "/usr/share/fonts/truetype/ttf-dejavu"
  ...
EndSection

Section "Module"
  ...
  Load  "freetype"
  ...
EndSection

Now restart the X server (in this case Xorg). I do it this way:

# go to the text console — for example with CTRL+ALT+F1
# login as root
/etc/init.d/kdm stop
/etc/init.d/kdm start

Now you should look as to how will your desired font name look like. Open the file "/usr/share/fonts/truetype/ttf-dejavu/fonts.dir“. It should look like that:

425 # some count

DejaVuSans-Bold.ttf -misc-dejavu sans-bold-r-normal--0-0-0-0-p-0-adobe-standard
DejaVuSans-Bold.ttf -misc-dejavu sans-bold-r-normal–0-0-0-0-p-0-adobe-symbol
DejaVuSans-Bold.ttf -misc-dejavu sans-bold-r-normal–0-0-0-0-p-0-ascii-0
DejaVuSans-Bold.ttf -misc-dejavu sans-bold-r-normal–0-0-0-0-p-0-iso10646-1
DejaVuSans-Bold.ttf -misc-dejavu sans-bold-r-normal–0-0-0-0-p-0-iso8859-10
DejaVuSans-Bold.ttf -misc-dejavu sans-bold-r-normal–0-0-0-0-p-0-iso8859-13
DejaVuSans-Bold.ttf -misc-dejavu sans-bold-r-normal–0-0-0-0-p-0-iso8859-15

Pick one from there, for example I picked this:

-misc-dejavu sans mono-medium-r-normal–0-0-0-0-m-0-iso10646-1

There are two ways to proceed ahead: “dialogous” and “copy-paste in your .emacs file”.

Dialogous way:

In Emacs do this:

M-x set-default-font RET
[copy and paste your selected font PostScript name here] RET

(Clarification: press ALT+X, then type “set-default-font”, then press Enter/Return key. Then paste the PostScript name of the font, copied earlier, then press Enter/Return key. Same rules apply for all Emacs instructions.)

If you choose this way (the dialogous), you are in trouble — now the font is too big. But fear not, do this:

M-x customize-face RET
default RET

Go to “height” field. Now change the value and press “Set for Current Session” after every change; do it as many times as necessary to pick up a good font size for your taste. Afterward, if you press “Save for Future Sessions”, changes in font face and font size will be written to your .emacs file and thus kept for future use.

Copy-paste in your .emacs file:

Copy and paste this (or your font PostScript name choice):

(custom-set-faces
‘(default ((t (:stipple nil :background “#ffffff” :foreground “#000000″ :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 80 :width normal :family “misc-dejavu sans mono”)))))

Of course, the second approach requires either restarting of Emacs or Lisp-evaluating the line in place (with C-x C-e).

And that’s it. I have still not figured out a way to make Emacs show the names of all TTF fonts in set-default-font command’s possible choices. But since the scenarios described here are working, it is not a big concern. Yes, I would like to know, since the choosing from a visible list seems more clean and right for me; it means that you have done all the things properly and thus Emacs sees your fonts. If somebody knows how to do this on Emacs 21.4a, please tell me.

EDIT (2007-Mar-06; my birthday, by the way):

On Emacs 22.0.95 (got from CVS) invoking set-default-font and pressing TAB/Space to show possible choices, the fonts in the new directory actually appear. So, it seems that Emacs is doing what it should: get the available fonts from the underlying desktop/windowing system.

Posted in debian, emacs, gnu, kde | 1 Comment »

GNU Emacs: Universal way to put text in clipboard

Posted by Dimitar Panayotov on 29 November 2006, 2:04

Many time I have been using copy-region-as-kill Emacs function (with shortcut keys, of course) on Windows XP without a problem. However, I recently switched to Debian 4.0 + KDE 3.5.5, only to discover that it does not work!

I was sure that the KDE was blocking something and I was right: it has an option in its “Privacy” settings which, when enabled, does not allow transfer of data in clipboard between applications. However, even with this option disabled (and KDE restarted) it still does not work. I quickly found the right function to be called:

clipboard-kill-ring-save

Of course, to be more convenient, you should call it with a shortcut keys combination, put this in your “.emacs” file:

(global-set-key [f10] ‘clipboard-kill-ring-save)

If you want help about how exactly you should formulate your shortcut keys combination, see this:

Key Bindings - GNU Emacs Tutorial

Yes, I know it is not an easy to read documentation, and I know that we are all sick of loooooong looooong manuals, but what could we do? Read if you want.

Posted in emacs, gnu, kde | 5 Comments »