Subject: 27.0.50; which-function reports wrong imenu information

From: Alex Branham <[email-masked]>
Date: Mon, 10 Dec 2018 12:58:25 -0600

(which-function) can report outdated information because it relies on
imenu--index-alist. To see what I'm talking about, from emacs -q:

M-x which-function-mode RET

type:
    (defun test () "foo" (ignore))

M-x imenu *Rescan* RET C-g

type:
    (defun test2 () "bar" (ignore))

With point inside test2, (which-function) reports test (you'll see this
in the modeline) because it uses the (outdated) information in
`imenu--index-alist'.

I see a few potential fixes:

- Check `add-log-current-defun' before checking `imenu--index-alist' in
  `which-function' (easy, but falling back on imenu--index-alist could
  still report old info)

- Have `which-function' update `imenu--index-alist' before checking it
  (also easy to implement, but updating the index could be slow in large
  buffers)

- Something else

I'm happy to write up a patch, just let me know what solution is best.

Thanks,
Alex