The dedicated buffers you are talking about in your question are
Those are filled by
Only the default directory and the buffer name containing the search words are needed for
That information must be present in the links to
The following lisp code defines a new org link type
councelrg with the corresponding functions for following and storing the link.
Links of that type consist of a elisp cons with the
default-directory in the
car and the buffer name in the
Those links are read by
(defconst org+-counselrg-link-type "counselrg"
"String for identifying counsel-rg links.")
(defun org+-buffer-base-name (buffer-name)
"Remove trailing <.*> in BUFFER-NAME."
(when (string-match "<[^<>]+>\\'" buffer-name)
(setq buffer-name (substring buffer-name nil (match-beginning 0)))))
(defun org+-counselrg-store ()
"Store links of type counselrg:LINK-PATH."
(when (derived-mode-p 'ivy-occur-grep-mode)
(org-store-link-props :type org+-counselrg-link-type
:link (format "%s:%S" org+-counselrg-link-type (cons default-directory (org+-buffer-base-name (buffer-name))))
:description (format "%s in %s" (buffer-name) default-directory))
(defun org+-counselrg-follow (link-path)
"Follow org-links of type counselrg:LINK-PATH."
(let* ((caller-window (get-buffer-window))
(dir-buf (read link-path))
(dir-name (car dir-buf))
(buf-name (cdr dir-buf))
;; First try to re-use already existing buffer.
(cl-loop for buf in (buffer-list)
if (with-current-buffer buf
(file-equal-p default-directory dir-name)
do (with-current-buffer buf (ivy-occur-revert-buffer))
and return buf
;; if there is no buffer for re-use:
(with-current-buffer (generate-new-buffer buf-name)
(setq default-directory dir-name)
(let ((inhibit-read-only t)
If you like to try the code put it into your
*scratch* buffer and evaluate the buffer with
If you even want to install the code put it into your init file and restart emacs.