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)