GNU bug report logs -
#49731
28.0.50; Filter xref results by filename
Previous Next
Reported by: Daniel Martín <mardani29 <at> yahoo.es>
Date: Sun, 25 Jul 2021 08:21:02 UTC
Severity: normal
Found in version 28.0.50
Fixed in version 30.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
>> Now pushed to master in the commit 3573ebfa6d (it seems this is
>> backward-compatible since it only sets buffer-local variables).
>
> Nice.
>
> Do you plan on adding an outline-[minor-]mode command to hide/show by
> regexp?
So now here are these two commands:
/ s outline-show-by-heading-regexp
/ h outline-hide-by-heading-regexp
Also there is an additional helper function that is needed
to keep hidden outlines and restore them after reverting the
xref buffer with 'g' (xref-revert-buffer).
This is an example of advice that does this.
Later when xref will use revert-buffer-function,
this advice could be replaced by a simple hook call:
#+begin_src emacs-lisp
(define-advice xref-revert-buffer (:around (ofun &rest args) keep-outlines)
"Keep hidden outlines after xref revert."
(let ((regexp (outline-hidden-headings-regexp))
(value (apply ofun args)))
(outline-hide-by-heading-regexp regexp)
value))
#+end_src
[outline-by-regexp.patch (text/x-diff, inline)]
diff --git a/lisp/outline.el b/lisp/outline.el
index 5ac0f0707f1..d933bd4a444 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -92,6 +92,8 @@ outline-mode-prefix-map
(define-key map "\C-o" 'outline-hide-other)
(define-key map "\C-^" 'outline-move-subtree-up)
(define-key map "\C-v" 'outline-move-subtree-down)
+ (keymap-set map "/ s" #'outline-show-by-heading-regexp)
+ (keymap-set map "/ h" #'outline-hide-by-heading-regexp)
(define-key map [(control ?<)] 'outline-promote)
(define-key map [(control ?>)] 'outline-demote)
(define-key map "\C-m" 'outline-insert-heading)
@@ -1661,6 +1663,42 @@ outline--show-headings-up-to-level
beg end)))
(run-hooks 'outline-view-change-hook)))
+(defun outline-show-by-heading-regexp (regexp)
+ (interactive (list (read-regexp "Regexp to show outlines")))
+ (let (outline-view-change-hook)
+ (outline-map-region
+ (lambda ()
+ (when (string-match-p regexp (buffer-substring (pos-bol) (pos-eol)))
+ (outline-show-branches) ;; To reveal all parent headings
+ (outline-show-entry)))
+ (point-min) (point-max)))
+ (run-hooks 'outline-view-change-hook))
+
+(defun outline-hide-by-heading-regexp (regexp)
+ (interactive (list (read-regexp "Regexp to hide outlines")))
+ (let (outline-view-change-hook)
+ (outline-map-region
+ (lambda ()
+ (when (string-match-p regexp (buffer-substring (pos-bol) (pos-eol)))
+ (outline-hide-subtree)))
+ (point-min) (point-max)))
+ (run-hooks 'outline-view-change-hook))
+
+(defun outline-hidden-headings-regexp ()
+ (let ((headings))
+ (outline-map-region
+ (lambda ()
+ (when (save-excursion
+ (outline-end-of-heading)
+ (seq-some (lambda (o) (eq (overlay-get o 'invisible)
+ 'outline))
+ (overlays-at (point))))
+ (push (buffer-substring (pos-bol) (pos-eol)) headings)))
+ (point-min) (point-max))
+ (mapconcat (lambda (heading)
+ (regexp-quote heading))
+ (nreverse headings) "\\|")))
+
;;; Visibility cycling
This bug report was last modified 1 year and 49 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.