             nextlinesafter
               (if (> (:linesafter settings) 0)
                 (concat (rest linesafter) (take 1 lines))
-                [])
-            ]
-          ; (if (not (empty? nextresults))
-          ;   (do
-          ;     (log-msg "nextresults:")
-          ;     (log-msg nextresults)))
+                [])]
           (search-lines nextlinenum nextline (rest lines) nextlinesbefore
-            nextlinesafter (concat results nextresults) settings)
-      )
-      results
-    )
-  )
-)
+            nextlinesafter (concat results nextresults) settings))
+      (if
+        (and
+          (> (count results) 0)
+          (:firstmatch settings))
+        (take 1 results)
+        results))))
 
 (defn search-text-file-lines [f settings]
   (with-open [rdr (reader f)]

    (if (empty? errs)
      (do
        (search-dirs (get-search-dirs settings) settings)
        []
      )
      errs
    )
  )
)


  (:use [cljsearch.common])
  (:use [cljsearch.filetypes])
  (:use [cljsearch.fileutil])
  (:use [cljsearch.searchresult]))

; ref to contain the seq of SearchResult records
(def search-results (ref []))
