[OS X Emacs] "with-current-buffer" issues

James Harkins jamshark70 at gmail.com
Thu Jun 24 02:28:07 EDT 2010


I am using Aquamacs to run supercollider 
(http://supercollider.sourceforge.net) via sclang-mode. One of the 
features is rudimentary document integration. When a buffer is opened 
for a supercollider code file, it gets registered with a sclang-document 
object on the Lisp side, and functions are called in the supercollider 
interpreter to create a Document object pointing to it.

The problem is when a buffer gets killed. There's a hook to close the 
document:

(defun sclang-document-kill-buffer-hook-function ()
   (sclang-close-document (current-buffer)))

(defun sclang-close-document (buffer)
   (with-sclang-document
    buffer
    (message "closing buf id %d" sclang-document-id)
    (setq sclang-document-list (delq buffer sclang-document-list))
    (sclang-perform-command-no-result
     'documentClosed sclang-document-id)))

(defmacro with-sclang-document (buffer &rest body)
   `(when (sclang-document-p buffer)
      (with-current-buffer buffer
        , at body)))

I'm observing that the main body of sclang-close-document is running 
every time a buffer is killed, even if the buffer should not be 
associated with a sclang-document. The result is that Document objects 
are being closed in the sclang interpreter even though their buffers 
still exist in Emacs.

But, for instance, if I open a class library file, I can see on the 
interpreter side that it gets ID 3. But when I kill that buffer, 
supercollider closes the document for ID 2. So now I have a Document 
object in the interpreter for a buffer that is gone, and another buffer 
that is still open in Emacs has no Document object in the interpreter.

It sounds like with-current-buffer is operating on the wrong buffer.

I've been discussing this with the sclang-mode developers and they are 
convinced that the code is fine. Moreover, /this behavior is not 
reproducible in Emacs on Linux/. So it suggests that Aquamacs is 
evaluating the Lisp function(s) in this case differently from standard 
Emacs.

Any ideas? If there is a discrepancy (I know, I know, "Aquamacs is not 
Emacs!"), how could the sclang-mode functions be modified to be safe for 
both standard Emacs and Aquamacs?

hjh


-- 

James Harkins /// dewdrop world
jamshark70 at dewdrop-world.net
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman

blog: http://www.dewdrop-world.net/words
audio clips: http://www.dewdrop-world.net/audio
more audio: http://soundcloud.com/dewdrop_world/tracks

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://email.esm.psu.edu/pipermail/macosx-emacs/attachments/20100624/0afb9e63/attachment.html>


More information about the MacOSX-Emacs mailing list