Comment 2 for bug 1922146

Revision history for this message
Ergus (ergus) wrote :

Or maybe better this if you don't want to use the `--result \"grep\"`:

(defun my/global-imeny-action (tag line regex)
   (goto-line line)
   (search-forward regex)
   (search-backward regex))

(defun myparse (str)
  (when (string-match "\\(^[^ ]+\\)[[:blank:]]+\\([[:digit:]]+\\) [^ ]+[[:blank:]]\\{2,\\}\\(.+\\)" str)
    (list (match-string-no-properties 1 str)
   (string-to-number (match-string-no-properties 2 str))
   #'my/global-imeny-action
   (match-string-no-properties 3 str))))

(defun my/imenu-create-index-function ()
  (let ((file (buffer-file-name)))
    (when file
      (mapcar #'myparse
       (with-temp-buffer
  (shell-command (concat "global -f " file) t)

  (split-string (buffer-string) "\n" t)
  )))))

(setq imenu-create-index-function
      #'my/imenu-create-index-function)