Function: org-activate-links--text-properties

org-activate-links--text-properties is a byte-compiled function defined in org.el.gz.

Signature

(org-activate-links--text-properties LIMIT)

Documentation

Add link properties to links.

This includes angle, plain, and bracket links.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-activate-links--text-properties (limit)
  "Add link properties to links.
This includes angle, plain, and bracket links."
  (catch :exit
    (while (re-search-forward org-link-any-re limit t)
      (let* ((start (match-beginning 0))
	     (end (match-end 0))
	     (visible-start (or (match-beginning 3) (match-beginning 2)))
	     (visible-end (or (match-end 3) (match-end 2)))
	     (style (cond ((eq ?< (char-after start)) 'angle)
			  ((eq ?\[ (char-after (1+ start))) 'bracket)
			  (t 'plain))))
	(when (and (memq style org-highlight-links)
		   ;; Do not span over paragraph boundaries.
		   (not (string-match-p org-element-paragraph-separate
					(match-string 0)))
		   ;; Do not confuse plain links with tags.
		   (not (and (eq style 'plain)
			     (let ((face (get-text-property
					  (max (1- start) (point-min)) 'face)))
			       (if (consp face) (memq 'org-tag face)
				 (eq 'org-tag face))))))
	  (let* ((link-object (save-excursion
				(goto-char start)
				(save-match-data (org-element-link-parser))))
		 (link (org-element-property :raw-link link-object))
		 (type (org-element-property :type link-object))
		 (path (org-element-property :path link-object))
                 (face-property (pcase (org-link-get-parameter type :face)
				  ((and (pred functionp) face) (funcall face path))
				  ((and (pred facep) face) face)
				  ((and (pred consp) face) face) ;anonymous
				  (_ 'org-link)))
		 (properties		;for link's visible part
		  (list 'mouse-face (or (org-link-get-parameter type :mouse-face)
					'highlight)
			'keymap (or (org-link-get-parameter type :keymap)
				    org-mouse-map)
			'help-echo (pcase (org-link-get-parameter type :help-echo)
				     ((and (pred stringp) echo) echo)
				     ((and (pred functionp) echo) echo)
				     (_ (concat "LINK: " link)))
			'htmlize-link (pcase (org-link-get-parameter type
								  :htmlize-link)
					((and (pred functionp) f) (funcall f))
					(_ `(:uri ,link)))
			'font-lock-multiline t)))
	    (org-remove-flyspell-overlays-in start end)
	    (org-rear-nonsticky-at end)
	    (if (not (eq 'bracket style))
		(progn
                  (add-face-text-property start end face-property)
		  (add-text-properties start end properties))
              ;; Initialize folding when used outside org-mode.
              (unless (or (derived-mode-p 'org-mode)
			  (and (org-fold-folding-spec-p 'org-link-description)
                               (org-fold-folding-spec-p 'org-link)))
                (org-fold-initialize (or (and (stringp org-ellipsis) (not (equal "" org-ellipsis)) org-ellipsis)
                                      "...")))
	      ;; Handle invisible parts in bracket links.
	      (let ((spec (or (org-link-get-parameter type :display)
			      'org-link)))
                (unless (org-fold-folding-spec-p spec)
                  (org-fold-add-folding-spec spec
                                          (cdr org-link--link-folding-spec)
                                          nil
                                          'append)
                  (org-fold-core-set-folding-spec-property spec :visible t))
                (org-fold-region start end nil 'org-link)
                (org-fold-region start end nil 'org-link-description)
                ;; We are folding the whole emphasized text with SPEC
                ;; first.  It makes everything invisible (or whatever
                ;; the user wants).
                (org-fold-region start end t spec)
                ;; The visible part of the text is folded using
                ;; 'org-link-description, which is forcing this part of
                ;; the text to be visible.
                (org-fold-region visible-start visible-end t 'org-link-description)
		(add-text-properties start end properties)
                (add-face-text-property start end face-property)
		(org-rear-nonsticky-at visible-start)
		(org-rear-nonsticky-at visible-end)))
	    (let ((f (org-link-get-parameter type :activate-func)))
	      (when (functionp f)
		(funcall f start end path (eq style 'bracket))))
	    (throw :exit t)))))		;signal success
    nil))