Is there quick and dirty way to convert:

[[http://foo.com][everything you need to know about foo]]

to simply:

everything you need to know about foo
  • Your question is formulated rather vaguely. Do you want to replace the link at point with the description or do you want to replace each link in a org file with its description? Do you want to make the replacements interactively or programmatically? Note that you used plural in the heading but just one example link in the body of your question. – Tobias Mar 12 '18 at 1:58

The following elisp-code defines a command org-link-at-point-unlink that replaces the link at point with its contents. Thereby "contents" means the link description.

(require 'subr-x) ;; for `when-let'

(defun org-link-at-point-unlink ()
  "Replace link at point with description."
  (when-let ((el (org-element-context))
         (b (and (eq (org-element-type el) 'link)
             (org-element-property :contents-begin el)))
         (e (org-element-property :contents-end el))
         (contents (buffer-substring-no-properties b e))
         (b (org-element-property :begin el))
         (e (org-element-property :end el)))
    (delete-region b e)
    (insert contents)))
  • it reports replace-region is undefined, what am I missing? – iLemming Mar 12 '18 at 3:47
  • I used (delete-region b e) (insert contents) and that worked. Thank you for that snippet, I learned a few new things. – iLemming Mar 12 '18 at 3:58
  • @Agzam I am sorry about replace-region. That was from my personal configuration. I should have tried the elisp snippet with emacs -Q! I adopted your suggestion now. Thanks. – Tobias Mar 12 '18 at 8:15

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.