3

I've got a weird one for you. When all of the following are true:

  • I'm using org-mode
  • My org-mode file has a code block
  • I export the org file
  • org-src-fontify-natively is true

Then I get a leftover buffer with a name like " org-src-fontification:clojure-mode". It's considered an "invisible" buffer, so it only shows up when listing buffers from Elisp code. It does not appear in the interactive buffer list.

The next time I refresh my magit-status, I get prompted to save a file. There's no option to skip it! If I save the file, it has the contents of the leftover internal buffer.

If I turn off org-src-fontify-natively then this doesn't happen. But my exports also don't get nice fontification either.

Is there some way to either discard that buffer, or convince magit to ignore it?

  • Does C-x s instead of magit-status cause the same prompt? – npostavs Feb 26 '16 at 3:29
  • @npostavs Yes it does. – mtnygard Feb 26 '16 at 13:45
3

One workaround is to advise the functions involved. For example, you could add :after advice to org-src-font-lock-fontify-block to kill the buffer it creates, perhaps like this:

(defun kill-org-src-buffers (&rest args)
  "Kill temporary buffers created by
org-src-font-lock-fontify-block so they don't interfere with
magit-mode."
  (dolist (b (buffer-list))
    (let ((bufname (buffer-name b)))
      (if (string-prefix-p " org-src-fontification:" bufname)
          (kill-buffer b)))))

(advice-add 'org-src-font-lock-fontify-block
            :after #'kill-org-src-buffers)    

The kill-org-src-buffers iterates over all buffers, killing any that match the buffer name prefix that org-src-font-lock-fontify-block uses for its "temporary" buffers. Alternatively, advising magit-save-repository-buffers with :before advice that takes a similar approach would likely work too.

I think it's a bug that org-src-font-lock-fontify-block creates a buffer using get-buffer-create to do work that appears to require only a temporary buffer; it should use with-temp-buffer instead.

  • I think the actual bug is that the "temporary" buffer ends up visiting a file (I guess they're purposely reusing the buffer for efficiency). – npostavs Feb 27 '16 at 14:51
  • Would you consider filing a bug? It sounds like the solution wouldn't be too challenging. – PythonNut Feb 27 '16 at 18:00
  • @PythonNut: normally, yes, I'd submit a patch, especially when the solution is as easy as what's required here: a 3-line change to use with-temp-buffer instead of with-current-buffer and get-buffer-create. But in this case, I'm not an actual user of either org-mode or magit-mode. To report an org-mode bug it appears I'd have to sign up to their mailing list, learn their requirements for how to format the bug report just so they'd even consider it, and actually run org-mode and magit-mode to get the details needed for the report. – Steve Vinoski Feb 28 '16 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.