Skip to main content
Code fix
Source Link
Melioratus
  • 4.8k
  • 1
  • 27
  • 49

@Juancho correctly suggested to use occur to provide the functionality you desire.

Use add-hook on the occur-mode-find-occurrence-hook.

  • To see how occur-mode-find-occurrence-hook works, try this:
  1. Add the code blocks below into your large org-mode file.

       >  This code block adds the functionality to `occur`. 
    
         #+BEGIN_SRC elisp :results none :exports none 
         (defun my/occur-org-cycle ()
           (outline-hide-sublevels 1)
           (org-cycle) 
           (org-switch-to-buffer-other-window "*Occur*")
          )
    
         (add-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
       >  This code block removes the functionality from `occur`  
    
         #+BEGIN_SRC elisp :results none :exports none 
          (remove-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
  2. Click inside the first code block and press C-c C-c to add a hook to occur. Answer yes if prompted.

  3. Call occur using M-s o ^*

  4. Navigate your headlines from the new *Occur* buffer and they should expand and collapse as you described.

  5. To revert back to the default behavior, click inside the second code block and execute by pressing C-c C-c. Answer yes if prompted.


To add this functionality permanently, you will need modify and add the code into your emacs configuration file. Unfortunately, I'm still working that step out.

Thanks for asking a great question!


This code was tested using
GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
Org mode version 9.0.9

@Juancho correctly suggested to use occur to provide the functionality you desire.

Use add-hook on the occur-mode-find-occurrence-hook.

  • To see how occur-mode-find-occurrence-hook works, try this:
  1. Add the code blocks below into your large org-mode file.

       >  This code block adds the functionality to `occur`. 
    
         #+BEGIN_SRC elisp :results none :exports none 
         (defun my/occur-org-cycle ()
           (outline-hide-sublevels 1)
           (org-cycle) 
          )
    
         (add-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
       >  This code block removes the functionality from `occur`  
    
         #+BEGIN_SRC elisp :results none :exports none 
          (remove-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
  2. Click inside the first code block and press C-c C-c to add a hook to occur. Answer yes if prompted.

  3. Call occur using M-s o ^*

  4. Navigate your headlines from the new *Occur* buffer and they should expand and collapse as you described.

  5. To revert back to the default behavior, click inside the second code block and execute by pressing C-c C-c. Answer yes if prompted.


To add this functionality permanently, you will need modify and add the code into your emacs configuration file. Unfortunately, I'm still working that step out.

Thanks for asking a great question!


This code was tested using
GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
Org mode version 9.0.9

@Juancho correctly suggested to use occur to provide the functionality you desire.

Use add-hook on the occur-mode-find-occurrence-hook.

  • To see how occur-mode-find-occurrence-hook works, try this:
  1. Add the code blocks below into your large org-mode file.

       >  This code block adds the functionality to `occur`. 
    
         #+BEGIN_SRC elisp :results none :exports none 
         (defun my/occur-org-cycle ()
           (outline-hide-sublevels 1)
           (org-cycle) 
           (org-switch-to-buffer-other-window "*Occur*")
          )
    
         (add-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
       >  This code block removes the functionality from `occur`  
    
         #+BEGIN_SRC elisp :results none :exports none 
          (remove-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
  2. Click inside the first code block and press C-c C-c to add a hook to occur. Answer yes if prompted.

  3. Call occur using M-s o ^*

  4. Navigate your headlines from the new *Occur* buffer and they should expand and collapse as you described.

  5. To revert back to the default behavior, click inside the second code block and execute by pressing C-c C-c. Answer yes if prompted.


To add this functionality permanently, you will need modify and add the code into your emacs configuration file. Unfortunately, I'm still working that step out.

Thanks for asking a great question!


This code was tested using
GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
Org mode version 9.0.9

Source Link
Melioratus
  • 4.8k
  • 1
  • 27
  • 49

@Juancho correctly suggested to use occur to provide the functionality you desire.

Use add-hook on the occur-mode-find-occurrence-hook.

  • To see how occur-mode-find-occurrence-hook works, try this:
  1. Add the code blocks below into your large org-mode file.

       >  This code block adds the functionality to `occur`. 
    
         #+BEGIN_SRC elisp :results none :exports none 
         (defun my/occur-org-cycle ()
           (outline-hide-sublevels 1)
           (org-cycle) 
          )
    
         (add-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
       >  This code block removes the functionality from `occur`  
    
         #+BEGIN_SRC elisp :results none :exports none 
          (remove-hook 'occur-mode-find-occurrence-hook 'my/occur-org-cycle)
         #+END_SRC
    
  2. Click inside the first code block and press C-c C-c to add a hook to occur. Answer yes if prompted.

  3. Call occur using M-s o ^*

  4. Navigate your headlines from the new *Occur* buffer and they should expand and collapse as you described.

  5. To revert back to the default behavior, click inside the second code block and execute by pressing C-c C-c. Answer yes if prompted.


To add this functionality permanently, you will need modify and add the code into your emacs configuration file. Unfortunately, I'm still working that step out.

Thanks for asking a great question!


This code was tested using
GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
Org mode version 9.0.9