Function: org-eww-copy-for-org-mode

org-eww-copy-for-org-mode is an interactive and byte-compiled function defined in ol-eww.el.gz.

Signature

(org-eww-copy-for-org-mode)

Documentation

Copy current buffer content or active region with org-mode style links.

This will encode link-title and link-location with org-link-make-string and insert the transformed text into the kill ring, so that it can be yanked into an Org mode buffer with links working correctly.

Further lines starting with a star get quoted with a comma to keep the structure of the Org file.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/ol-eww.el.gz
(defun org-eww-copy-for-org-mode ()
  "Copy current buffer content or active region with `org-mode' style links.
This will encode `link-title' and `link-location' with
`org-link-make-string' and insert the transformed text into the
kill ring, so that it can be yanked into an Org mode buffer with
links working correctly.

Further lines starting with a star get quoted with a comma to
keep the structure of the Org file."
  (interactive)
  (let* ((regionp (org-region-active-p))
         (transform-start (point-min))
         (transform-end (point-max))
         return-content
         link-location link-title
         temp-position out-bound)
    (when regionp
      (setq transform-start (region-beginning))
      (setq transform-end (region-end))
      ;; Deactivate mark if current mark is activate.
      (deactivate-mark))
    (message "Transforming links...")
    (save-excursion
      (goto-char transform-start)
      (while (and (not out-bound)	; still inside region to copy
                  (org-eww-has-further-url-property-change-p)) ; there is a next link
        ;; Store current point before jump next anchor.
        (setq temp-position (point))
        ;; Move to next anchor when current point is not at anchor.
        (or (org-eww-url-below-point)
	    (org-eww-goto-next-url-property-change))
	(cl-assert
	 (org-eww-url-below-point) t
	 "program logic error: point must have an url below but it hasn't")
	(if (<= (point) transform-end) ; if point is inside transform bound
	    (progn
	      ;; Get content between two links.
	      (when (< temp-position (point))
		(setq return-content (concat return-content
					     (buffer-substring
					      temp-position (point)))))
	      ;; Get link location at current point.
	      (setq link-location (org-eww-url-below-point))
	      ;; Get link title at current point.
	      (setq link-title
		    (buffer-substring
		     (point)
		     (org-eww-goto-next-url-property-change)))
              ;; concat `org-mode' style url to `return-content'.
	      (setq return-content
		    (concat return-content
			    (if (org-string-nw-p link-location)
				;; Hint: link-location is different
				;; for form-elements.
				(org-link-make-string link-location link-title)
			      link-title))))
	  (goto-char temp-position) ; reset point before jump next anchor
	  (setq out-bound t)))	    ; for break out `while' loop
      ;; Add the rest until end of the region to be copied.
      (when (< (point) transform-end)
	(setq return-content
	      (concat return-content
		      (buffer-substring (point) transform-end))))
      ;; Quote lines starting with *.
      (org-kill-new (replace-regexp-in-string "^\\*" ",*" return-content))
      (message "Transforming links...done, use C-y to insert text into Org mode file"))))