3

Currently I have a mode (magit to be precise) when I have clickable text switches buffer to the file. However I'd prefer sometimes to open in new or neighboring window. Is it possible to do it?

PS. By Window I mean Emacs window not Emacs frame.

2 Answers 2

2

In a magit-status buffer you can usually achieve this with C-u RET.
The same usually works for active links in info-mode and help-mode.

But there's no generic way to do this in Emacs. As the document you linked to explains, it's left to the major modes' discretion how they respond to actions on clickable text.
The prescription is:

Implementing a link involves three separate steps: (1) indicating clickability when the mouse moves over the link; (2) making or Mouse-2 on that link do something; and (3) setting up a follow-link condition so that the link obeys mouse-1-click-follows-link.

This however is not a required protocol:

  • Nothing says that it needs to be implemented in full,
  • also it is not mandated to always respond with visiting a buffer upon activation,
  • neither is it mandated to treat all links in a given buffer the same way;
  • hence the "usually" above.

A couple of examples where you can readily observe differences in behavior:

  • magit-status buffers don't respond to mouse clicks at all, only "keyboard clicks" (RETs)
  • info-mode only provides the "open in new window" behavior for "keyboard clicks" but not for mouse clicks.
  • magit-status only provides this behavior when visiting files, but not when "visiting" commits. Also "visiting" (keyboard clicking) commits has a side-effect of checking them out first and then displaying them.
  • In describe-function buffers the links pointing to source files always open new frame, with no option to do otherwise.
  • In describe-function buffers the links pointing to other functions always load the new contents in the current buffer, with no option to do otherwise.
  • In magit history buffers and describe-function's help-mode buffers the [back]' and[forward]` buttons always update the current buffer.
  • In describe-mode buffers the links to "Enabled minor modes" cross-references just scroll down in the current window.
  • dired-mode buffers don't highlight active links.

The implementation details of all this is probably pretty intricate but to illustrate there is no real magic there, compare how info-mode treats mouse clicks and keyboard clicks differently (compare defun Info-mouse-follow-nearest-node (click) and defun Info-follow-nearest-node (&optional fork).

1

Edit: On solution would be to install org-magit package. then, you could use the following command (from OrgMode) to force your link to be open in a new window

Ctrl-u Ctrl-c Ctrl-o

To open files and buffers in new window:

You can open a buffer in a new window with the following command

Ctrl-x 4 b

Note than you can also open a file in a new window with a similar command

Ctrl-x 4 f
4
  • Sorry I have not described it clearly. Neither C-x 4 b not C-x 4 f is what I am looking for. I have an active text 'link' (sorry I don't know emacs-speak for it) like in info page which opens a new buffer with some file or commit or whatever. I want to open this new buffer in new window. I don't seeks how to open a file or an existing file in new window. Sep 24, 2013 at 14:18
  • Hopefully my new answer would help you. Sorry for the misunderstanding of your question.
    – MBR
    Sep 24, 2013 at 14:30
  • No. Magit does not depend on org-mode (and it is not standardized unfortunately) so it results in C--c C-o is undefined. Sep 24, 2013 at 14:39
  • Ok. See my new answer, to be able to use org-mode.
    – MBR
    Sep 24, 2013 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .