Try M-x org-toggle-link-display
or the menu item Org -> Hyperlinks -> Literal Links
before using isearch
or query-replace
.
The following code does that automagically for you when you use isearch
or query-replace
/query-replace-regexp
. It restores the old state when you are done with searching.
The code is tested with Emacs 25.1.50.2.
EDIT: Added (setq-local search-invisible t)
to search in texts that are hidden by the invisible
text property.
(defvar-local org-descriptive-links-isearch nil
"Backup of the original value `org-descriptive-links' before isearch.")
(defun org-isearch-mode-hook-function ()
"Save value of `org-descriptive-links' before isearch."
(setq org-descriptive-links-isearch org-descriptive-links))
(defun org-isearch-mode-end-hook-function ()
"Restore original value of `org-descriptive-links' after isearch."
(unless (eq org-descriptive-links-isearch org-descriptive-links)
(org-toggle-link-display)))
(defun org-mode-isearch-filter (found)
"Toggle to literal links if match is found within a string that is hidden in the target of descriptive links."
(when (and found
(text-property-any (match-beginning 0) (match-end 0) 'invisible 'org-link)
org-descriptive-links)
(org-toggle-link-display))
found)
(defun org-query-replace-isearch-wrapper (oldfun &rest args)
"Toggle to literal links if match is found within a string that is hidden in the target of descriptive links."
(org-isearch-mode-hook-function)
(prog1 (apply oldfun args)
(org-isearch-mode-end-hook-function)))
(defun org-mode-setup-isearch ()
"Setup some specials for isearch in org-mode.
1. Toggle descriptive links if necessary."
(setq-local search-invisible t)
(add-hook 'isearch-mode-hook 'org-isearch-mode-hook-function)
(add-hook 'isearch-mode-end-hook 'org-isearch-mode-end-hook-function)
(add-function :filter-return (local 'isearch-filter-predicate) #'org-mode-isearch-filter)
(advice-add 'query-replace :around #'org-query-replace-isearch-wrapper)
(advice-add 'query-replace-regexp :around #'org-query-replace-isearch-wrapper))
(add-hook 'org-mode-hook 'org-mode-setup-isearch)
M-s i
causes invisible text to be searched. But, unfortunately it does not make text withinvisible
-text properties visible. This only works for overlays having theinvisible
property. – Tobias Mar 25 '16 at 13:41