Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to: start org outline navigation in special mode #34

Closed
aspiwack opened this issue Apr 25, 2018 · 15 comments
Closed

How to: start org outline navigation in special mode #34

aspiwack opened this issue Apr 25, 2018 · 15 comments

Comments

@aspiwack
Copy link
Collaborator

When using org-goto (traditionally bound to C-c C-j) to navigate an Org document's outline, Boon immediately goes into command mode. However, the org-goto mode rebinds keys, in particular the arrows.

In order for the navigation mode to work well, I need to drop to insert mode. But really, it should open in special mode. Is there a way to make this outline navigation mode use the special mode ? If not, is there at least a way to make it start in insert mode?

@jyp
Copy link
Owner

jyp commented Apr 25, 2018 via email

@aspiwack
Copy link
Collaborator Author

I don't think that it is a major mode, but I don't know how to check. If you can teach me what to look for, I'll do better next time :) .

@aspiwack
Copy link
Collaborator Author

All this is not urgent, of course.

@jyp
Copy link
Owner

jyp commented Apr 25, 2018 via email

@aspiwack
Copy link
Collaborator Author

So. It seems to open a new buffer named org-goto. However, M-x describe-mode just tells me that the major mode is Org mode, and there is nothing specific in the minor mode list either.

@jyp
Copy link
Owner

jyp commented May 5, 2018

org-goto is implemented using recursive edit https://www.gnu.org/software/emacs/manual/html_node/elisp/Recursive-Editing.html --- which is today discouraged. So the "proper" solution would be to reimplement org-goto using a transient keymap as I suggested above. Realistically this will never happen though.

A possible workaround would be to activate insert state whenever a recursive edit takes place. This would be roughly consistent with what happens with minibuffers.

@aspiwack
Copy link
Collaborator Author

aspiwack commented May 6, 2018

Thanks for investigating. It was way over my head.

Going to the special state in recursive editing sounds reasonable in general.

What would be a good approach for it. It may be possible to add an advice to recursive-edit, but it sounds dangerous. Better is probably to check recursion-depth when editing starts, I suppose.

What is the portion of Boon which deals with choosing the mode and should be modified?

@jyp
Copy link
Owner

jyp commented May 6, 2018

I am afraid that advising recursive-edit is the only sensible option. (One could perhaps instead use a post-command hook). In either case, one should call boon-set-state with the appropriate argument at the right places.

@aspiwack
Copy link
Collaborator Author

aspiwack commented May 6, 2018

When entering org-goto from the edit state, we are sent into the command state again. So boon-set-state is called somewhere. Presumably by the function which is called on new buffers. A possibility would be to check recursion-depth there and if its non-zero, to set the state to special instead.

Here's a suggestion along these lines: modify boon-special-mode-p to always be true when recursion-depth is non-zero. Does it sound reasonable?

What is the recommended way to test a custom version of an emacs package. (there must be a way to start emacs with just said package, I just don't know how). So that I can test such change?

@jyp
Copy link
Owner

jyp commented May 7, 2018

I am not sure if we should be using special state or insert state. In this case special state is better probably, but it may not be right in all cases. We could go for this and revisit the decision later (please add a comment to that effect).

Otherwise, I am guessing that this will not work, because the new buffer is probably be created before the recursive edit starts. You can try it, but I am pretty sure. If I am right then an advice or a command hook will be necessary.

To test a modified package, I usually just point use-package to my copy, but you may have to delete the copy in the .emacs.d/elpa directory.

@aspiwack
Copy link
Collaborator Author

Ok. So, I don't get what happens.

Entering org-goto triggers (boon-set-state 'command-state). And conversely exiting the recursive edit started by org-goto restores the state to the value it was before (including if I use exit-recursive-edit to exit).

However, when I call recursive-edit interactively, it doesn't change the state. And if I change the state in the recursive edit, then exit-recursive-edit, then the state isn't restored.

I don't know what can explain this difference.

@aspiwack
Copy link
Collaborator Author

Oh, I think I understand, now: a buffer named *org-goto* is built this way:

(make-indirect-buffer (current-buffer) "*org-goto*")

Is it reasonable to forget about recursive-edit and set it up so buffers name "org-mode" are boon-special-mode-p? (by adding list of buffer-names in addition to the list of modes?)

Otherwise, it's possible to build some trickery using advice on recursive-edit. But it feels a bit arbitrary, considering the fact that recursive-edit is a bit incidental here. I'm not sure what other use of recursive-edit there is out there (hopefully not many, as the manual explicitly says not to use it).

Anyway, I'm not sure which of these two alternatives is preferable. Or if there is a third option. Let me know what you think @jyp . I'll implement it.

@jyp
Copy link
Owner

jyp commented Jun 20, 2018

Using the name of the buffer (with the stars) seems a good enough option. 👍

@jyp
Copy link
Owner

jyp commented Aug 13, 2018

@aspiwack Perhaps you'll be better off simply using something like "counsel-org-goto" or similar.

@jyp
Copy link
Owner

jyp commented Aug 30, 2021

The official way to go is using the 'cmap' package, which provide context-dependent functions, including navigation and tree-editing when on an org-mode heading. https://github.com/jyp/cmap

@jyp jyp closed this as completed Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants