1

When I've isearched for something in a headline in org-mode, and my cursor is sitting on the headline I want: how do I org-cycle that headline with TAB? Currently I have to first press RET then TAB. I would like to save the RET keystroke if possible. Looking for the Emacs Lisp for configuration.

2
  • C-s is modal: you get into a state where you can use a limited number of keys and stay within that mode (e.g. C-s to go the the next match, C-r to go backwards) - do C-h f isearch-forward and check the isearch-mode-map section to see what those keys are. While in that mode, however, any other keys get added to the search string: you need to exit that mode for keys to be normally interpreted and that's what RET does. IOW, there is no way to do what you want with isearch: it makes iterative, interactive searching easier but the modal nature of it requires a way to exit from it.
    – NickD
    Sep 22, 2022 at 16:23
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Sep 22, 2022 at 16:27

2 Answers 2

1

If you want TAB to exit Isearch and do its regular (non-Isearch) thing, then just bind it in isearch-mode-map to isearch-exit (the same function RET is bound to):

(define-key isearch-mode-map (kbd "TAB") 'isearch-exit)

I don't recommend that, however, as you might want to search for a TAB character by hitting the TAB key...

1
  • 1
    Was not aware of isearch-mode-map and isearch-exit synergy. This is great. I have solved my problem with this. Thank you very much. Regarding your anti-recommendation, I'm not worried. Can bind C-M-TAB to insert TAB into search string if I ever encounter this issue. I've been using Emacs a while and have literally never searched for a TAB character. Sep 22, 2022 at 19:20
0

Instead of isearch, you should be using org-occur. See

(info "(org) Sparse Trees")

or

Sparse Trees (The Org Manual)


org-occur (C-c / r or C-c / /)

Prompts for a regexp (see Regular Expressions) and shows a sparse tree with all matches.

  • If the match is in a headline, the headline is made visible.

  • If the match is in the body of an entry, headline and body are made visible.

In order to provide minimal context, also the full hierarchy of headlines above the match is shown, as well as the headline following the match.

Each match is also highlighted; the highlights disappear when the buffer is changed by an editing command, or by pressing C-c C-c .

When called with a C-u prefix argument, previous highlights are kept, so several calls to this command can be stacked.

1
  • Sparse trees are great, but this answer does not address the specific question that I was asking. Sep 22, 2022 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.