由正则表达式缩小的Emacs

由正则表达式缩小的Emacs,emacs,narrowing,Emacs,Narrowing,有像M-x窄到行和M-x窄到页这样的函数。哪些例程可以帮助我通过正则表达式实现不存在的M-x窄带的功能 谢谢。这似乎有效。将提示用户输入begin和end正则表达式。(测试不彻底!): 你也可以通过将它放入缓冲区(scratch等)并按CTRL+X,然后按CTRL+E来安装它用正则表达式缩小范围应该做什么我本来打算只显示与正则表达式匹配的行,我应该可以编辑。我发现我可以用M-x和e来编辑文本。这将更新远程缓冲区。 (defun narrow-to-regex () "narrow the b

有像
M-x窄到行
M-x窄到页
这样的函数。哪些例程可以帮助我通过正则表达式实现不存在的M-x窄带的功能


谢谢。

这似乎有效。将提示用户输入begin和end正则表达式。(测试不彻底!):


你也可以通过将它放入缓冲区(scratch等)并按CTRL+X,然后按CTRL+E来安装它

用正则表达式缩小范围应该做什么我本来打算只显示与正则表达式匹配的行,我应该可以编辑。我发现我可以用M-x和e来编辑文本。这将更新远程缓冲区。
(defun narrow-to-regex ()
  "narrow the buffer visibility to the section between two regexes the user provides"
  (interactive)
  (let* ((beginRegex (read-regexp "begin pattern"))
         (endRegex (read-regexp "end pattern"))
         (beg)
         (end))
    (goto-char (point-min)) ;; go to the start of the buffer
    (if (re-search-forward beginRegex nil t nil)
        (setq beg (- (point) (length beginRegex))))
    (if (re-search-forward endRegex nil t nil)
        (setq end (point)))
    (if (and beg end (> end beg))
        (narrow-to-region beg end)
      (message "did not find both instances of the regex, %s %s, no narrow" beg end))))