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.
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?