Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use Enter key for different actions (like in emacs) #301

andreadev-it started this conversation in Show and tell
Discussion options

Hello everyone!
Just thought about sharing the code I've written to make some org actions more easily doable. Using this code, you'll be able to do things like toggling checkboxes, advancing headline TODO states, opening links and opening dates inside the agenda just by pressing the "Enter" key.
This better emulates what happens when you press "Enter" on emacs in an org file.

This is a little bit too long to fit inside this post, but I've made a gist about it:
Gist file

Let me know what you think 🙂

You must be logged in to vote

Replies: 2 comments 5 replies

Comment options

I like it :) one thing that comes to mind: what about headlines that have links in them?

You must be logged in to vote
4 replies
Comment options

I'm happy to see that you're enjoining it!
That is indeed a problem with the current script. I'm editing it right now to allow easier customization and help with the problem, but I think that with links, we're out of luck, since treesitter doesn't recognize them 😕

Comment options

Unfortunately I'm not very well versed with the org grammar or treesitter in general (yet). Would it actually make sense to add links to the grammar?

Comment options

I'm not well versed in it too, actually, but I'm having fun doing some of this scripting. I think it does make sense to have it recognized by the treesitter parser, since it already recognizes things like dates, checkboxes (and i mean the actual [ ], not just the whole list item). If links could be recognized by treesitter there could be interesting uses of that feature. However, as first stated, I'm not knowledgable about treesitter, so I could be wrong

Comment options

I've uploaded a new version of this script that fixes that problem. I know I shouldn't, but I used a "private" function that is exported in "orgmode.org.mappings" that checks if the thing under the cursor is a link. It does it through lua patterns (regex).
I decided to do it this way, because treesitter-org thinks that links should not be included inside treesitter grammar: emiasims/tree-sitter-org#25

Comment options

I've improved the script to allow for easier customization. The new "type_to_action" table is in a specific order, the code will execute the action of the first type it can find as ordered inside the list. This means that, if you have multiple possible actions on a specific position, you can decide which one should be executed by putting it higher inside the list. Be aware that this relies on the treesitter parser, which might not always correctly evaluate the syntax.
The gist link is the same as in the first post

You must be logged in to vote
1 reply
Comment options

@andreadev-it same for this feature, feel free to open a PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /