 (defvar ido-dynamic-match-fn nil)
 (defvar mural-tagfile-to-process '()
   "alist from tagfile name to a mural_server process that handles this tagfile")
+
+(defvar mural-current-tagfile nil)
 
 (defun mural-add-tagfile (tagfile)
   "Register tagfile and make it available for queries"

  "Returns t if RESULT is a complete response from the server"
  (integerp (string-match "^DONE" result)))

(defun mural-read-tag (file-base)
  "Run the typeahead in the minibuffer against a tagset
appropriate for FILE-BASE.  Return a taginfo list which can be
accessed through the mural-tag-* functions"
  (if (not file-base)
      (error "no file associated with buffer"))
  (let ((mural-current-tagfile (mural-tagfile-for-filename file-base)))
    (if (not mural-current-tagfile)
        (error "no tagfile associated with %s" file-base))
    (let ((ido-dynamic-match-fn 'mural-query-save-tag)
          (mural-last-query-result nil)) ;; set by mural-query-save-tag
      (assoc
       (ido-completing-read "tag: " '("nope"))
       mural-last-query-result))))

;; Tags are lists like '(tag filename row tagfile)
(defun mural-tag-tagname (tag)

  "Interactively search for a tag in the current repository and
open it in a new buffer"
  (interactive)
  (let ((taginfo (mural-read-tag (mural-infer-tagfile))))
    (find-file (mural-tag-filename taginfo))
    (goto-line (mural-tag-row taginfo))))

