 (defvar ectags--fn-name nil
   "Holds the current function name (from where the tag search was initiated).")
 
-
-(defun extract-ectags (tag-buffer obarray-to-use)
-  "Extract a list of tags from a buffer and adds it to \
-the array `obarray-to-use'."
-  (save-excursion
-    (when tag-buffer
-      (set-buffer tag-buffer))
-    (goto-char (point-min))
-
-    (while (= (char-after (point)) ?!)
-      (forward-line))
-
-    (while (/= (point) (point-max))
-      (beginning-of-line)
-
-      (let* ((start (point))
-             (end (progn
-                    (re-search-forward "\t")
-                    (backward-char)
-                    (point))))
-        (intern (buffer-substring-no-properties start end) obarray-to-use))
-
-      (forward-line)
-      ))
-  obarray-to-use)
-
-(defun make-ectags-obarray ()
-  (let ((result (make-vector 65535 0)))
-    (mapc (lambda (b)
-            (when (bufferp b)
-              (save-excursion
-                (extract-ectags b result))))
-            (ectags-table-list))
-    (setq ectags--obarray result)))
 
 (defun ectags-table-list ()
   "Return a list of available tag tables."

  :version "24.4"
  :group 'tools)

(defcustom ectags-big-file-command-format
  "rg --no-heading --no-line-number \"^%s\\b\" %s"
  "The command used to search the tags file when it's too big.  \
The first '%s' is for the tag name, the second '%s' for the tag filename.  \
Will use the following priority (times based on linux kernel's tag \
file of 489 MB):
- rg   0.756s
- grep 1.192s
See `ectags-big-file-size' for when that will happen."
  :group 'ectags
  :type 'string)

(defcustom ectags-big-file-size (* 10 1024 1024)
  "When the tags file is bigger than this, \
will use `ectags-big-file-command-format'
to search the tag."
  :group 'ectags
  :type 'number)

(defcustom ectags-max-candidates 24
  "How many candidates to select between."

another completion system for narrowing down by substring."
  (interactive)
  (ectags-find (completing-read "Tag to find: " ectags--obarray)))

(defun counsel-ectags-function (input)
  (if (not ectags--file-name)
      (ectags-visit-tags-table "tags"))

  (if (< (length input) 3)
      (counsel-more-chars 3)
    (counsel--async-command
     (format "rg -N %s %s" input ectags--file-name))
    '("" "working...")))

(defun counsel-ectags-action (tag-line)
  (ectags-match tag-line)

  (when ectags--matches
    (with-ivy-window
      (xref-push-marker-stack)

      (find-file (file-relative-name (ectags-match-filename (car ectags--matches))))
      (goto-char (point-min))
      (forward-line (1- (ectags-match-linenumber (car ectags--matches))))
      (recenter-top-bottom)
      (unless (eq ivy-exit 'done)
        (swiper--cleanup)
        (swiper--add-overlays (ivy--regex ivy-text))))))

;;;###autoload
(defun counsel-ectags (&optional initial-input)
  (interactive)
  (ectags-visit-tags-table "tags")
  (ivy-read "Find tag: "
            #'counsel-ectags-function
            :initial-input (concat "^" initial-input)
            :dynamic-collection t
            :action #'counsel-ectags-action
            :unwind (lambda ()
                      (counsel-delete-process)
                      (swiper--cleanup))
            :caller 'counsel-ectags))

;;;###autoload
(defun ectags-find-tag ()
