unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 49731@debbugs.gnu.org, "Daniel Martín" <mardani29@yahoo.es>
Subject: bug#49731: 28.0.50; Filter xref results by filename
Date: Tue, 13 Feb 2024 18:52:29 +0200	[thread overview]
Message-ID: <86v86s4dsi.fsf@mail.linkov.net> (raw)
In-Reply-To: <16f2a5d7-fb89-5e8c-71b7-c9f9ddc5d4e3@yandex.ru> (Dmitry Gutov's message of "Wed, 23 Nov 2022 16:19:47 +0200")

[-- Attachment #1: Type: text/plain, Size: 951 bytes --]

>> 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: outline-by-regexp.patch --]
[-- Type: text/x-diff, Size: 2155 bytes --]

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) "\\|")))
+
 \f
 ;;; Visibility cycling
 

  parent reply	other threads:[~2024-02-13 16:52 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <m1pmv6iz4n.fsf.ref@yahoo.es>
2021-07-25  8:19 ` bug#49731: 28.0.50; Filter xref results by filename Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-25  8:32   ` Lars Ingebrigtsen
2021-07-25  8:33     ` Lars Ingebrigtsen
2021-07-26 23:16       ` Dmitry Gutov
2021-07-25  9:10   ` Eli Zaretskii
2021-07-25 14:58     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-25 20:43   ` Juri Linkov
2021-07-26 11:49     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-26 22:53       ` Juri Linkov
2022-01-16 18:52       ` Juri Linkov
2022-11-21  7:58         ` Juri Linkov
2022-11-23  8:39           ` Juri Linkov
2022-11-23 14:19             ` Dmitry Gutov
2022-11-23 17:50               ` Juri Linkov
2022-11-23 18:08                 ` Dmitry Gutov
2022-11-23 18:20                   ` Juri Linkov
2022-11-23 18:47                     ` Dmitry Gutov
2022-11-24  7:48                       ` Juri Linkov
2022-11-25  7:35                         ` Kévin Le Gouguec
2024-02-13 16:52               ` Juri Linkov [this message]
2024-02-14  9:25                 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-15  7:23                   ` Juri Linkov
2021-07-26 23:28   ` Dmitry Gutov
2021-07-27 17:08     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-27 20:51       ` Juri Linkov
2021-07-27 23:11         ` Dmitry Gutov
2021-07-28  0:08       ` Dmitry Gutov
2021-07-28 16:12         ` Juri Linkov
2021-07-29  2:02           ` Dmitry Gutov
2021-07-29 17:43             ` Juri Linkov
2021-08-02  2:09               ` Dmitry Gutov
2021-08-02 20:58                 ` Juri Linkov
2021-08-06  0:03                   ` Dmitry Gutov
2021-07-31 16:45         ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-31 17:06           ` Eli Zaretskii
2022-11-23 18:48       ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86v86s4dsi.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=49731@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=mardani29@yahoo.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).