[[search for me]]
最终不会在同一个组织文件(内部链接(中找到文本"搜索我",相反,它总是说"不匹配"并询问我是否要创建一个新标题。如果文本"搜索我"括在双括号中,例如,
<<search for me>>
那么上面的链接就可以了。它不需要双括号即可工作。也许我配置了一些东西来干扰正常行为?不知道如何调试这个。知道发生了什么吗?它对你有用吗?
我创建了几个适合我的版本。希望它能帮助其他人:
(defun my-org-search-link-regexp ()
"Search an org link by text in the same file."
(interactive)
(if (org-in-regexp org-bracket-link-regexp 1)
(let ((link-text (if (match-end 1)
(org-match-string-no-properties 1)
nil)))
(goto-char (point-min))
(re-search-forward link-text nil t))))
或
(defun my-org-search-link-regexp ()
(interactive)
(when (equal major-mode 'org-mode)
(let ((object (org-element-context)))
(when (eq (car object) 'link)
(let ((link (org-element-property :raw-link object)))
(goto-char (point-min))
(re-search-forward link nil t))))))
或
(defun my-org-search-link-regexp ()
"If link under point is org link and of link type `regexp:',
e.g., regexp:search for this text, then search for the regexp supplied,
otherwise invoke org-open-at-point."
(interactive)
(when (equal major-mode 'org-mode)
(let ((link-type "regexp:")
(command-prefix-value)
(object (org-element-context)))
(when (eq (car object) 'link)
(let ((link (org-element-property :raw-link object)))
(when (>= (length link) (length link-type))
(setf command-prefix-value (substring link 0 (length link-type))))
(if (and command-prefix-value
(equal link-type command-prefix-value))
(let ((link-regexp (substring link (1+ (length link-type)) nil)))
(org-mark-ring-push)
(goto-char (point-min))
(re-search-forward link-regexp nil t))
(call-interactively 'org-open-at-point)))))))
(bind-key "C-c C-o" #'my-org-search-link-regexp org-mode-map)
我的偏好是第三个,因为它与键绑定相结合,允许我使用我的常规键绑定进行组织开放点。使用某些东西的实际组织链接类型数据类型可能有一种更好的方法来做到这一点,但它对我来说效果很好。我不希望在我的组织文件中到处都是双括号。我称之为org-mark-ring-push,以便我以后可以调用org-mark-ring-goto,我已经映射到邪恶领袖m B。这样,我可以可靠地跳回到原始链接。