emacs组织模式,仅搜索标头

Leo*_*sev 8 regex emacs search header org-mode

在emacs中,我希望只能搜索组织模式文件中的"标题".

想法1:仅搜索可见
我可以通过隐藏所有内容来实现这一点,然后只显示轮廓(S-TAB,S-TAB),然后可以搜索所有可见的内容.(在这种情况下,它将是整个内容表) .但是,我如何只搜索可见内容?Cs搜索一切.

想法2:使用
我可以做的正则表达式:

C-c / /             //opens regex search
\*.*heading        //start with * (escaped), followed by any chars, then heading.
Run Code Online (Sandbox Code Playgroud)

但目前输入所有这些都很麻烦.考虑到我已经开始学习像3小时前的emacs,我能以某种方式自动化吗?
例如,我可以编写一个函数来搜索"*.*ARGUMENT"并将其绑定为热键吗?但仍然有能力像'下一个找到,下一个找到'等...?

用例就是搜索我的笔记.有些像〜7000 +行长,我通常只搜索标题.

[编辑解决方案1]
@ abo-abo的回答对我来说很有用.我现在用helm-org-in-buffer-headings

即,我安装了Melpa:https: //github.com/milkypostman/melpa#usage

然后我从包列表中安装了helm: M-x package-list-packages

然后我编辑了我的.emacs并绑定了一个热键:
(global-set-key (kbd "C-=") 'helm-org-in-buffer-headings) ;Outline search.

我重新加载了emacs,现在当按下Ctrl + =时会弹出一个可搜索的轮廓,当我输入其他字符时会自动缩小.通常的Cn,Cp按钮用于导航.

谢谢!

[编辑解决方案2] 好奇心得到了我的好处.在享受了头盔搜索之后,我也和worf一起搞砸了.它就像helm(它使用helm)但看起来更好,我可以通过按数字键来选择轮廓的"级别".如果使用的话,我只删除了标题搜索所需的位:

;; ——— 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)))))
Run Code Online (Sandbox Code Playgroud)

然后将其绑定到热键:

(global-set-key (kbd "<f3>") 'worf-goto)
Run Code Online (Sandbox Code Playgroud)

abo*_*abo 7

worf-gotoWORF可以做到这一点,这样可以helm-org-in-buffer-headings掌舵

worf-goto实际上helm用作后端。除了helm-org-in-buffer-headings,您还可以获得:

  • 标题以与原始缓冲区相同的方式着色
  • 您可以使用适当的数字选择具有相同级别的所有标题