Subject: bug#36877: 25.3; uniquify renaway uniquify-managed list

From: Noam Postavsky <[email-masked]>
Date: Thu, 15 Aug 2019 13:20:13 -0400

David Biesack <[email-masked]> writes:

>   uniquify-rationalize-file-buffer-names("index.html" "/Users/david.biesack/dev/developer.apiture.com/_site/docs/apis/workflow/v0.13.0/" #<buffer index.html>)
>   uniquify--create-file-buffer-advice(#[257 "\301!\211\302\230\203\f

Ah right, Emacs 25 still has that thing where it cuts off nthe pasted
text after NUL bytes.  For next time, saving the backtrace to a file and
attaching it should work better.

Looking at the fix-list in the backtrace, we have:

  [cl-struct-uniquify-item "index.html" "/Users/david.biesack/dev/developer.apiture.com/_site/docs/apis/workflow/v0.13.0" #<buffer index.html> nil]
  { ;; repeated 5 times...
  [cl-struct-uniquify-item "index.html" "/Users/david.biesack/dev/developer.apiture.com/_site/docs/apis/sample" #<buffer index.html<docs/apis/sample>> "index.html<docs/apis/sample>"]
  [cl-struct-uniquify-item "index.html" "/Users/david.biesack/dev/developer.apiture.com/_site/doc/apis/sample" #<buffer index.html<doc/apis/sample>> "index.html<doc/apis/sample>"]
  [cl-struct-uniquify-item "index.html" "/Users/david.biesack/dev/developer.apiture.com/_site/docs/apis/sample/sample" #<buffer index.html<sample/sample>> "index.html<sample/sample>"]
  [cl-struct-uniquify-item "index.html" "/Users/david.biesack/dev/developer.apiture.com" #<buffer index.html<developer.apiture.com>> "index.html<developer.apiture.com>"]
  [cl-struct-uniquify-item "index.html" "/Users/david.biesack/dev/developer.apiture.com/_site/docs/concepts" #<buffer index.html<concepts>> "index.html<concepts>"]
  }

I think that means the (dolist (buffer (buffer-list))...) somehow went
over #<buffer index.html<docs/apis/sample>> 5 times, or else that buffer
already had duplicates in its uniquify-managed list (i.e., this
backtrace triggerred "too late").

Did you add the advice in an ongoing session?  If yes, then it you
should clear out existing duplicates first, so we can catch a "fresh"
instance.  Evaluating the below should do:

    (let ((htable (make-hash-table :test 'equal)))
      (save-current-buffer
        (dolist (buf (buffer-list))
          (set-buffer buf)
          (when (cdr uniquify-managed)
            (clrhash htable)
            (dolist (item (cdr uniquify-managed))
              (puthash item t htable))
            (let ((managed nil))
              (maphash (lambda (k _v)
                         (push k managed))
                       htable)
              (push (car uniquify-managed) managed)
              (setq uniquify-managed managed))))))

If that backtrace was actually from a new session (that is, the advice
was added at the beginning of the session), then it means the problem is
coming from some other unexpected spot.