Function: org-link-make-string-for-buffer
org-link-make-string-for-buffer is a byte-compiled function defined in
ol.el.gz.
Signature
(org-link-make-string-for-buffer LINK &optional DESCRIPTION INTERACTIVE-P)
Documentation
Format LINK with DESCRIPTION for current buffer.
When BUFFER is nil, format LINK for current buffer.
When DESCRIPTION is nil, set it according to :insert-description link
parameter or org-link-make-description-function.
When current buffer is a file buffer and link points to that file,
strip the file name from the link.
Make sure that file: link follows org-link-file-path-type.
Strip <..> brackets from LINK, if it is a plain link.
When INTERACTIVE-P is non-nil, prompt user for description.
Return link with description, as a string.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ol.el.gz
(defun org-link-make-string-for-buffer (link &optional description interactive-p)
"Format LINK with DESCRIPTION for current buffer.
When BUFFER is nil, format LINK for current buffer.
When DESCRIPTION is nil, set it according to :insert-description link
parameter or `org-link-make-description-function'.
When current buffer is a file buffer and link points to that file,
strip the file name from the link.
Make sure that file: link follows `org-link-file-path-type'.
Strip <..> brackets from LINK, if it is a plain link.
When INTERACTIVE-P is non-nil, prompt user for description.
Return link with description, as a string."
(when (and (string-match org-link-plain-re link)
(not (string-match org-ts-regexp link)))
;; URL-like link, normalize the use of angular brackets.
(setq link (org-unbracket-string "<" ">" link)))
;; Check if we are linking to the current file with a search
;; option If yes, simplify the link by using only the search
;; option.
(when (and (buffer-file-name (buffer-base-buffer))
(let ((case-fold-search nil))
(string-match "\\`file:\\(.+?\\)::" link)))
(let ((path (match-string-no-properties 1 link))
(search (substring-no-properties link (match-end 0))))
(save-match-data
(when (equal (file-truename (buffer-file-name (buffer-base-buffer)))
(file-truename path))
;; We are linking to this same file, with a search option
(setq link search)))))
;; Check if we can/should use a relative path. If yes, simplify
;; the link.
(let ((case-fold-search nil))
(when (string-match "\\`\\(file\\|docview\\):" link)
(let* ((type (match-string-no-properties 0 link))
(path-start (match-end 0))
(search (and (string-match "::\\(.*\\)\\'" link path-start)
(match-string 1 link)))
(path
(if search
(substring-no-properties
link path-start (match-beginning 0))
(substring-no-properties link (match-end 0))))
;; file:::search
(path (if (org-string-nw-p path) path (buffer-file-name)))
(origpath path))
(setq path (org-link--normalize-filename path org-link-file-path-type))
(setq link (concat type path (and search (concat "::" search))))
(when (equal description origpath)
(setq description path)))))
(unless description
(setq description (org-link-get-description link)))
(when interactive-p
(setq description (read-string "Description: " description)))
(unless (org-string-nw-p description)
(setq description nil))
(org-link-make-string link description))