8

Having written a couple of custom comint-derived modes, I often find it tricky to decide how to keep track of buffers and processes: for instance, to associate different source buffers with different interpreters. Is it better to keep a reference to the buffer or the process?

Given a buffer, one can find its associated process using get-buffer-process. Conversely, given a process, process-buffer returns its associated buffer. Both buffers and processes also permit an extra layer of indirection by looking them up by unique name, but this seems fragile compared to just keeping a reference to the object itself.

One possibility seems clearly bad, since it violates the principle of storing data once-and-only-once: namely, keeping references to both the buffer and the process.

Most comint- functions for sending input take a process rather than a buffer as an argument, which argues for hanging on to the process object, not the buffer. On the other hand, buffers tend to stick around longer than processes: a process might finish or be killed and a new process started in the buffer it previously used.

Are there other convincing arguments for referencing the process or its buffer?

6

For the reasons you provided, I generally prefer to hold on to the buffer. Then I write a foo-proc function which returns the corresponding process, potentially re-starting it if needed. And I even sometimes then write a foo-buffer function which calls foo-proc so that not only it gives me the buffer but it also ensures that the process is running.

  • Thanks, this is the kind of guidance I was looking for, and I'm not likely to find a better source! – Jon O. Nov 11 '14 at 1:33

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.