加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – emacs组织模式,仅搜索标题

发布时间:2020-12-13 21:53:49 所属栏目:百科 来源:网络整理
导读:在emacs中,我希望只能搜索组织模式文件中的“标题”. 想法1:仅搜索可见 我可以通过隐藏所有内容来实现这一点,然后只显示轮廓(S-TAB,S-TAB),然后搜索所有可见的内容.(在这种情况下,它将是整个内容表). 但是,我如何只搜索可见内容? C-s搜索所有内容. 想法2:
在emacs中,我希望只能搜索组织模式文件中的“标题”.

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

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

C-c / /             //opens regex search
*.*heading        //start with * (escaped),followed by any chars,then heading.

但目前输入所有这些都很麻烦.考虑到我已经开始学习像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);大纲搜索.

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

谢谢!

[编辑解决方案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)))))

然后将其绑定到热键:

(global-set-key (kbd "<f3>") 'worf-goto)
来自 worf的worf-goto可以做到这一点,
从 helm起,也可以使用helm-org-in-buffer-headings.

worf-goto实际上使用helm作为后端.除了helm-org-in-buffer-headings之外,您还可以:

>标题的颜色与原始缓冲区中的颜色相同>您可以使用相应的数字选择具有相同级别的所有标题

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读