FFAP and Ruby in Emacs

If you want to use FFAP (find-file-at-point) in ruby-mode you can add this to your .emacs

(defvar ruby-program-name "ruby")
(defun ruby-module-path(module)
      ruby-program-name " -e "
      "\"ret='()';$LOAD_PATH.each{|p| "
      "x=p+'/'+ARGV[0].gsub('.rb', '')+'.rb';"
      "if(File.exist?(x))};printf ret\" "

(eval-after-load "ffap"
  '(push '(ruby-mode . ruby-module-path) ffap-alist))

When you do ffap (i bind it to C-x f) near a require ‘PP’ for example it will find it in your ruby path.

Always search before coding

This is a annoying, even if it take 5mn to code thing like that :

(defun my-dired-rm-rf()
  "Rm -rf directories"
  (let ((sel (selected-window)))
	(dolist (curFile (dired-get-marked-files))
	  (if (yes-or-no-p (concat "Do you want to remove \"" (file-name-nondirectory curFile) "\" ? "))
			(shell-command (concat "rm -rvf " curFile) 
"*Removing Directories*")
			(kill-buffer "*Removing Directories*")
			(select-window sel)

you discover after a litlle while that if you have did a lilt bit of searching before, you will have discovered a variable call `dired-recursive-deletes` that would do the thing in a much better way.

Emacs nighly cvs snapshot with xft on Ubuntu Edgy

I wanted to try the latest cvs snapshot with XFT support, since i did not want to screw up more my workstation i have used packages instead of make install blindy.

Basically i have a script called ./build.sh

set -e

d=$(date '+%Y%m%d')

mkdir -p cvs

pushd cvs >/dev/null && {
cvs -Q -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs co -r emacs-unicode-2 emacs
} && popd >/dev/null

mkdir -p build
[[ -d build/emacs-${d} ]] && rm -rf build/emacs-${d}
cp -al cvs/emacs build/emacs-${d}

zcat patches/emacs-snapshot_${debpatch}.diff.gz|patch -p1 -d build/emacs-${d}
cat patches/with-font.patch|patch --silent -p1 -d build/emacs-${d}

pushd build/emacs-${d} >/dev/null && {
    chmod +x debian/rules
    dch -v "1:${d}-1" "New snapshot."
    dch "Build with xft."
    fakeroot dpkg-buildpackage -b
} && popd >/dev/null

in patches/with-font.patch i have :

--- c/debian/rules.chmou        2007-01-21 23:21:09.486353750 +1100
+++ c/debian/rules      2007-01-21 23:21:13.914630500 +1100
@@ -393,7 +393,7 @@
 # Emacs-gtk confflags
 emacs_gtk_confflags := ${confflags}
 emacs_gtk_confflags += --with-x=yes
-emacs_gtk_confflags += --with-x-toolkit=gtk
+emacs_gtk_confflags += --with-x-toolkit=gtk  --enable-font-backend --with-xft

 # Emacs-nox confflags
 emacs_nox_confflags := ${confflags}
--- c/src/emacs.c.chmou 2007-01-21 23:21:09.486353750 +1100
+++ c/src/emacs.c       2007-01-21 23:22:18.430662500 +1100
@@ -1408,10 +1408,10 @@
     = argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args);

-  enable_font_backend = 0;
-  if (argmatch (argv, argc, "-enable-font-backend", "--enable-font-backend",
-               4, NULL, &skip_args))
     enable_font_backend = 1;
+  if (argmatch (argv, argc, "-disable-font-backend", "--disable-font-backend",
+               4, NULL, &skip_args))
+    enable_font_backend = 0;
 #endif /* USE_FONT_BACKEND */

@@ -1816,7 +1816,7 @@
   { "-unibyte", "--unibyte", 81, 0 },
   { "-no-multibyte", "--no-multibyte", 80, 0 },
   { "-nl", "--no-loadup", 70, 0 },
-  { "-enable-font-backend", "--enable-font-backend", 65, 0 },
+  { "-disable-font-backend", "--disable-font-backend", 65, 0 },
   /* -d must come last before the options handled in startup.el.  */
   { "-d", "--display", 60, 1 },
   { "-display", 0, 60, 1 },

i have as well in patches/ the ubuntu (or could be debian) patch downloaded from the ubuntu (or debian archive) archive which is for ubuntu on


If there is a new version you will need to increase the version in build.sh to match the patch downloaded.

When running build.sh it should produce binary in build/* with xft enabled by default. Make sure to have all the dependencies (dpkg-buildpackages should tell you if there is unresovled one).

One screenshot :

Screenshot of Emacs snapshot with XFT

Xterm like Control-L in Eshell

If you want to emulate Control-L in Eshell (the Emacs Shell) like in Xterm, you can use this :

(defun eshell-show-minimum-output ()
  (goto-char (eshell-beginning-of-output))
  (set-window-start (selected-window)
		      (goto-char (point-max))

And add a key bind to it in your custom hook :

  (local-set-key "\C-l" 'eshell-show-minimum-output)

Cheetah Mode for Emacs

Here is a simple html derived mode for Cheetah templates files. The font-locking regexp can be improved thought but that’s a start.

(define-derived-mode cheetah-mode html-mode "Cheetah"
  (make-face 'cheetah-variable-face)
     ("\(#\(from\|else\|include\|set\|import\|for\|if\|end\)+\)\>" 1 font-lock-type-face)
     ("\(#\(from\|for\|end\)\).*\<\(for\|import\|if\|in\)\>" 3 font-lock-type-face)
     ("\(\$\(?:\sw\|}\|{\|\s_\)+\)" 1 font-lock-variable-name-face))
  (font-lock-mode 1)
(setq auto-mode-alist (cons '( "\.tmpl\'" . cheetah-mode ) auto-mode-alist ))

Access Gajim within Emacs

Here is some function to launch a gajim window from Emacs :

(defvar gajim-remote "/usr/bin/gajim-remote")
(defvar gajim-user-list ())

(defun my-gajim-get-list()
      (call-process gajim-remote nil t nil "list_contacts")
      (goto-char (point-min))
      (while (re-search-forward "^jid[ ]*:[ ]*\(.*\)$" (point-max) t )
        (setq gajim-user-list (append gajim-user-list (list (match-string-no-properties 1)))))))

(defun my-gajim-talk()
  (let* ((ff (if (not gajim-user-list)(my-gajim-get-list) gajim-user-list))
         (answer (completing-read "Jabber: " (mapcar (lambda (tt)(list tt)) ff))))
    (message answer)
    (start-process "*GAJIM*" nil gajim-remote "open_chat" answer)
(global-set-key '[(control x)(j)] 'my-gajim-talk)

If Emacs had a dbus support that would have been cool.