Function: org-w3m-copy-for-org-mode

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

Signature

(org-w3m-copy-for-org-mode)

Documentation

Copy current buffer content or active region with Org style links.

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

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/ol-w3m.el.gz
(defun org-w3m-copy-for-org-mode ()
  "Copy current buffer content or active region with Org style links.
This will encode `link-title' and `link-location' with
`org-link-make-string', and insert the transformed test into the kill ring,
so that it can be yanked into an Org  buffer with links working correctly."
  (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
                  (not (org-w3m-no-next-link-p))) ; no next link current buffer
        ;; store current point before jump next anchor
        (setq temp-position (point))
        ;; move to next anchor when current point is not at anchor
        (or (get-text-property (point) 'w3m-href-anchor) (org-w3m-get-next-link-start))
        (cond
         ((<= (point) transform-end) ; point is inside transform bound
          ;; get content between two links.
          (when (> (point) temp-position)
            (setq return-content (concat return-content
                                         (buffer-substring
                                          temp-position (point)))))
          (cond
           ((setq link-location (get-text-property (point) 'w3m-href-anchor))
            ;; current point is a link
            ;; (we thus also got link location at current point)
            ;; get link title at current point.
            (setq link-title (buffer-substring (point)
                                               (org-w3m-get-anchor-end)))
            ;; concat Org style url to `return-content'.
            (setq return-content
                  (concat return-content
                          (if (org-string-nw-p link-location)
                              (org-link-make-string link-location link-title)
                            link-title))))
           ((setq link-location (get-text-property (point) 'w3m-image))
            ;; current point is an image
            ;; (we thus also got image link location at current point)
            ;; get link title at current point.
            (setq link-title (buffer-substring (point) (org-w3m-get-image-end)))
            ;; concat Org style url to `return-content'.
            (setq return-content
                  (concat return-content
                          (if (org-string-nw-p link-location)
                              (org-link-make-string link-location link-title)
                            link-title))))
           (t nil))); current point is neither a link nor an image
         (t ; point is NOT inside transform bound
          (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))))
      (org-kill-new return-content)
      (message "Transforming links...done, use C-y to insert text into Org file")
      (message "Copy with link transformation complete."))))