            (setq mural-server-output (concat mural-server-output output))))))
      proc))
 
-(defun mural-query (query)
+;; I can't believe I have to write this function
+(defun filter (pred lst)
+  (if (eq 0 (length lst))
+      '()
+    (let ((fst (car lst))
+          (rst (filter pred (cdr lst))))
+      (if (funcall pred fst)
+        (cons fst rst)
+        rst))))
+
+(defun mural-tagfile-for-filename (filename)
+  (let ((resolved-fname (file-truename filename)))
+    (car (filter
+          (lambda (tagfile)
+            ;; file-truename resolves symlinks so we make sure to compare the same thing
+            (eq 0 (string-match
+                   (file-truename (file-name-directory tagfile))
+                   resolved-fname)))
+          (mapcar 'car mural-tagfile-to-process)))))
+
+(defun mural-query (query tagfile)
   (if (equal "" query)
       '()
-    (progn
+    (let ((proc (mural-get-server tagfile)))
       (setq mural-server-output "")
-      (process-send-string (process-name (mural-get-server))
+      (process-send-string (process-name proc)
                            (concat query "\n"))
 
       ;; Wait up to 1/2 second
       (loop for i from 1 to 10
             until (mural-response-complete mural-server-output)
-            do (accept-process-output mural-server-process .05))
+            do (accept-process-output proc .05))
       (if (mural-response-complete mural-server-output)
           (mural-parse-response mural-server-output)
         (progn

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

(defun mural-abspath-for-tag (taginfo)
  (expand-file-name
   (mural-tag-filename taginfo)
   ;; need to make this conditional on the tag file to support multiple repos
   (file-name-directory (directory-file-name tags-file-name))))

;; (mural-abspath-for-tag '("hi" "flib/core/preparable/Preparer.php" 1))

(defvar ido-dynamic-last-query nil)


        ))))

(defun mural-query-save-tag (query)
  (let ((qresult (mural-query query mural-current-tagfile)))
    (setq mural-last-query-result qresult)
    (mapcar 'mural-tag-tagname qresult)))

;;(mural-parse-response "MATCH foo bar 1\nMATCH hi bye 2\nDONE hi hi")
;; returns '((tag file row) ...)
