有M-x narrow-to-line
和M-x narrow-to-page
之类的功能。哪些例程可以帮助我实现不存在的M-xarrow-by-regex功能?
谢谢。
答案 0 :(得分:0)
这似乎有效。将提示用户输入开始和结束正则表达式。 (未经非常彻底的测试!):
(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))))
您也可以通过将其放入缓冲区(刮擦等)并先按CTRL + X,再按CTRL + E来安装它