Function: klink:yank-handler

klink:yank-handler is a byte-compiled function defined in klink.el.

Signature

(klink:yank-handler KLINK)

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/klink.el
(defun klink:yank-handler (klink)
  (if (string-match "<\\([^,]+\\)?[#,][ \t]*\\(.+\\)" klink)
      (let* ((file (or (match-string 1 klink)
		       (get-text-property 0 'file-name klink)))
	     (rest (match-string 2 klink))
	     (dir (file-name-directory file))
	     (buf-file (hypb:buffer-file-name)))
	(cond ((equal file buf-file)
	       ;; Remove the klink filename since yanking into the
	       ;; same file
	       (insert (format "<#%s" rest)))
	      ((and buf-file (equal dir (file-name-directory buf-file)))
	       ;; Use filename without dir since yanking into same directory
	       (insert (format "<%s#%s" (file-name-nondirectory file) rest)))
	      (t (if (or (not file)
			 (and file (string-prefix-p file (substring klink 1))))
		     (insert klink)
		   (insert (format "<%s#%s" file rest))))))
    (insert klink)))