Saturday, August 19, 2006

Instantly search all the documents you ever printed

Ever wanted to be able to quickly search through all the pdf documents/papers you have printed from the Internet? Here's how: modify your printer command/driver to save all printed documents on the disk, and then let Beagle index them.

For Linux users, here's a simple hack that does it by redefining the lpr command. Create a directory ~/printed, and save this script somewhere in your PATH before /usr/bin.


# if lpr is invoked with filenames
for file in "$@" ; do
if test -f "$file" ; then
basename=$(basename $file)
tempname=$(tempfile -d ~/printed -s "-$basename.pdf")
echo "Converting $file to $tempname"
nice ps2pdf $file $tempname

# if lpr reads its data from the standard input
if test -z "$@" ; then
tempname=$(tempfile -d ~/printed)
tee $tempname | /usr/bin/lpr "$@"
nice ps2pdf $tempname $tempname.pdf
rm $tempname
exec /usr/bin/lpr "$@"

I want to emphasize that this script is a hack, and the proper way of doing this is probably by modifying /etc/printcap or whatever CUPS uses instead. Tell me if you know how to do it.

Friday, May 26, 2006

Org-mouse 0.15: Agenda buffer support

Org-mouse.el 0.15 includes support for the Agenda buffer: it has the same context-sensitive menus (tags, timestamps, etc) as in normal org-mode buffers, so that you can now modify the entries directly from the Agenda buffer.

Thursday, May 11, 2006

Org-mouse for emacs, new version (0.14)

A new version of org-mouse.el is out. I added a menu entry that converts a plain list to an outline. Also, "Insert Heading"
now inserts a sibling heading if the point is on "***" and a child heading otherwise.

Org-mouse.el is an Emacs mode that provides a better mouse support for org-mode, a versatile Emacs mode for note taking and project planning (illustrated tutorial). It implements mouse-controlled subtree expansion/collapse and context menus.

Monday, May 08, 2006

Recent documents: Emacs and GNOME integration

Script described in the previous post, can be used to put files opened in Emacs on GNOME's recently used document list. Put somewhere in your PATH, and add this to your .emacs file:

(defun local-add-file-to-recent ()
(when buffer-file-name
(start-process "" nil ""
(concat "file://" buffer-file-name)

(add-hook 'find-file-hook 'local-add-file-to-recent)

Hopefully, GNOME Deskbar Applet will soon be able to use the recent documents list, giving you something close to a system-wide equivalent of the excellent iswitchb mode.

This complements recently-used.el, which works in the opposite direction: it makes the system-wide list of recently used files available to Emacs.

Recent documents script for GNOME

Script is a simple command-line tool that adds a given filename (URI) to the list of recently used files. It will work for systems using Recent File Storage Specification, such as GNOME. This script can be useful for integrating applications such as Emacs with your desktop.

I wrote this script because I couldn't find anything similar. Please tell me if there is a known command-line tool that I could use instead.

Friday, April 28, 2006

Autocollapse mode for emacs

Users of various emacs outline modes, especially org-mode might find this piece of code useful. It periodically collapses all outline headlines (trees) which are structurally far away from the current cursor position. The purpose is to automatically collapse nodes which you are no longer working on, thereby preventing uncontrolled growth of the visible size of your .org buffer as the day progresses.

This version should work correctly even if you have many windows with the same buffer.

(defun local-fold-from-level (beg end level)
(hide-region-body beg end)
(goto-char beg)
(unless (looking-at outline-regexp)
(outline-next-visible-heading 1))
(while (and (<= (point) end) (not (eobp)))
(when (> (outline-level) level)
(outline-next-visible-heading 1)))

(defun local-contains-point (beg end pointlist)
(let ((result))
(dolist (point pointlist result)
(setq result (or result (and (>= point beg) (<= point end)))))))

(defun local-auto-fold ()
(let ((pointlist (mapcar 'window-point
(get-buffer-window-list (current-buffer) nil t))))
(unless (looking-at outline-regexp)
(outline-next-visible-heading 1))
(while (not (eobp))
(let ((end (save-excursion (outline-end-of-subtree) (point))))
(if (local-contains-point (point) end pointlist)
(outline-next-visible-heading 1)
(local-fold-from-level (point) end (outline-level))))))))

(defun local-auto-fold-all ()
(dolist (buffer (buffer-list))
(set-buffer buffer)
(when (eq major-mode 'org-mode)

(run-with-idle-timer 60 t 'local-auto-fold-all)

Welcome to Zero Tau

The purpose of this blog is simple: to distribute half-baked marginally useful pieces of code I've written, which are not flexible enough and too "under development" to publish elsewhere. On the other hand, I find them useful enough to let others suffer from using them. Enjoy!