Emacs org mode, search headers only

In emacs, I want to be able to search only "headers" in the org mode file.

Idea 1: search only visible
I could achieve this by hiding everything, then showing only the circuit (S-TAB, S-TAB), and then, perhaps, will look for everything that is visible (in this case it will be the entire table of contents). But how can I search only visible content? Cs is looking for everything.

Idea 2: use regex
I can potentially do:

Cc / / //opens regex search \*.*heading //start with * (escaped), followed by any chars, then heading. 

But at the moment it is cumbersome to print all of this. Given that I started learning emacs like 3 hours ago, can I somehow automate this?
For example, can I write a search function using "*. ARGUMENT" and bind it to a hotkey? but still have the ability to go, like "next find, next find", etc.?

A use case for this is to search for my notes. Some of them look like ~ 7000+ lines long, and I usually only look for headings.

[EDIT Solution 1]
@ Abo-abo's answer worked well for me. Now i am using helm-org-in-buffer-headings

Ie I installed Melpa: https://github.com/milkypostman/melpa#usage

Then I installed a loop from the package list: Mx package-list-packages

Then I edited my .emacs and associated a hotkey with it:
(global-set-key (kbd "C-=") 'helm-org-in-buffer-headings) ;Outline search.

I reloaded emacs, and now when you press Ctrl + = a tooltip appears that automatically narrows when you type extra characters. The usual buttons Cn, Cp work for navigation.

Thanks!

[Change Decision 2] I got better curiosity. After enjoying the helm search, I also fiddled with worf. This is similar to the helmsman (he uses a helmet), but it looks better, and I can select the β€œlevel” of the circuit by pressing a number key. I hacked only the bit needed to search in the header, if used:

 ;; β€”β€”β€” WORF Utilities β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” ;; https://github.com/abo-abo/worf/blob/master/worf.el (defun worf--pretty-heading (str lvl) "Prettify heading STR or level LVL." (setq str (or str "")) (setq str (propertize str 'face (nth (1- lvl) org-level-faces))) (let (desc) (while (and (string-match org-bracket-link-regexp str) (stringp (setq desc (match-string 3 str)))) (setq str (replace-match (propertize desc 'face 'org-link) nil nil str))) str)) (defun worf--pattern-transformer (x) "Transform X to make 1-9 select the heading level in `worf-goto'." (if (string-match "^[1-9]" x) (setq x (format "^%s" x)) x)) (defun worf-goto () "Jump to a heading with `helm'." (interactive) (require 'helm-match-plugin) (let ((candidates (org-map-entries (lambda () (let ((comp (org-heading-components)) (h (org-get-heading))) (cons (format "%d%s%s" (car comp) (make-string (1+ (* 2 (1- (car comp)))) ?\ ) (if (get-text-property 0 'fontified h) h (worf--pretty-heading (nth 4 comp) (car comp)))) (point)))))) helm-update-blacklist-regexps helm-candidate-number-limit) (helm :sources `((name . "Headings") (candidates . ,candidates) (action . (lambda (x) (goto-char x) (call-interactively 'show-branches) (worf-more))) (pattern-transformer . worf--pattern-transformer))))) 

And then tied it to a hot key:

 (global-set-key (kbd "<f3>") 'worf-goto) 
+8
source share
3 answers

worf-goto from worf can do this, so helm-org-in-buffer-headings from helm .

worf-goto actually uses helm as the back end. In addition to helm-org-in-buffer-headings you get:

  • Headings
  • painted the same way as in the original buffer
  • you can select all headings with the same level using the corresponding number
+4
source

If you have ivy installed, you can use counsel-org-goto to search for headers in the current buffer or counsel-org-goto-all to search for headers in all open org-mode buffers.

This is a good option if you do not want to install other things that come with worf.

+2
source

If you don't want to rely on external packages, org, in fact, already offers this feature: the org-goto function.

If you want it to behave similarly to helm-org-in-buffer-headings , you need to set org-goto-interface to outline-path-completion , for example by adding to the initialization file:

 (setq org-goto-interface (quote outline-path-completion)) 
0
source

Source: https://habr.com/ru/post/1211434/


All Articles