rudolfochrist / interleave

Emacs minor mode to interleave notes and text books
329 stars 18 forks source link

Mode hook problem of interleave #40

Closed Yevgnen closed 7 years ago

Yevgnen commented 7 years ago

Hi,

Looking in the definition of interleave-mode, it should be a buffer local minor mode. But if one wants to add hooks for interleave-mode, for example,

    (add-hook 'interleave-mode-hook (lambda () (print (buffer-file-name)))))

can see that when enabling interleave-mode, it prints the pdf buffer file name, while prints the org buffer file name when disabling. That's a bit strange as we enable the mode in an org buffer while disable it by interleave-quit in a pdf buffer. Anyway, shouldn't these two be the same(as the mode is buffer local)? If not, there may be issues when people trying to add hooks for interleave-mode. But personally, I think defining an interleave-mode minor mode maybe is not really necessary. Thanks !

rudolfochrist commented 7 years ago

That's a bit strange as we enable the mode in an org buffer while disable it by interleave-quit in a pdf buffer.

Actually not. In both cases we're switching buffers before run-hooks is called. If you want to reference the buffers, please use interleave-org-buffer and interleave-pdf-buffer. Admittedly, both variables aren't really good documented. I'll fix this soon.

Anyway, shouldn't these two be the same(as the mode is buffer local)? If not, there may be issues when people trying to add hooks for interleave-mode.

The mode is indeed buffer-local, but I'm afraid buffer-file-name doesn't care. It returns the file name for the active buffer, whether this is the one you wanted or not.

But personally, I think defining an interleave-mode minor mode maybe is not really necessary.

OK. This needs some more thinking. How would you define keybindings that doesn't affect other keybindings of other modes?