   (integerp (string-match "^DONE" result)))
 
 (defun mural-read-tag ()
-  (setq ido-dynamic-match-fn 'mural-query-save-tag)
-  (unwind-protect ;; i have no idea what's going on here
-      (ido-completing-read "tag: " '("nope"))
-    (setq ido-dynamic-match-fn nil)))
-
+  (let ((file-base (buffer-file-name)))
+    (if (not file-base)
+        (error "no file associated with buffer"))
+    (setq mural-current-tagfile (mural-tagfile-for-filename file-base))
+    (if (not mural-current-tagfile)
+        (error "no tagfile associated with %s" file-base))
+    (setq ido-dynamic-match-fn 'mural-query-save-tag)
+    (unwind-protect ;; i have no idea what's going on here
+        (ido-completing-read "tag: " '("nope"))
+      (setq ido-dynamic-match-fn nil))))
+
+(defun mural-tag-tagname (tag)
+  (elt tag 0))
 (defun mural-tag-filename (tag)
   (elt tag 1))
 (defun mural-tag-row (tag)

;;
;; mural does fast, fuzzy tag searching that refines results as you
;; type.
;;
;; To use, put this in your .emacs:
;;
;;   (require 'mural)
;;   ;; not strictly necessary, but avoids slowness on first use
;;   (mural-get-server)
;;   (global-set-key (kbd "C-o") 'mural-find-tag)
;;
;; If it is not already set make sure tags-file-name points at your tags file.
;;
;; To debug launch:
;; (call-process mural-server-path nil t nil tags-file-name)

  (let* ((tag (mural-read-tag))
        (taginfo (assoc tag mural-last-query-result)))
    (progn
      (find-file (mural-abspath-for-tag (file-name-directory mural-current-tagfile) taginfo))
      (goto-line (mural-tag-row taginfo))
      (setq mural-last-query-result nil)
      )))

(defun mural-abspath-for-tag (root taginfo)
  (file-truename (expand-file-name (mural-tag-filename taginfo) root)))

(defvar ido-dynamic-last-query nil)

