Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An emacs lisp function to yank visible text from an outline mode buffer so you can paste it somewhere else. Based on org-export-visible.
(defun outline-copy-visible (keepp)
"Create a copy of the visible part of the current buffer and add
it to the kill ring so it can be copied into other buffers or programs.
The copy is created in a temporary buffer and removed after use.
As a special case, if you have a prefix arg KEEPP, the temporary
buffer will not be removed but presented to you so that you can
continue to use it.
This function is derived from org-export-visible."
(interactive "P")
(let* ((file buffer-file-name)
(buffer (get-buffer-create "*Outline Yank Visible*"))
s e)
(with-current-buffer buffer (erase-buffer))
(setq s (goto-char (point-min)))
(while (not (= (point) (point-max)))
(goto-char (outline-find-invisible))
(append-to-buffer buffer s (point))
(setq s (goto-char (outline-find-visible))))
(goto-char (point-min))
(set-buffer buffer)
(kill-new (buffer-substring (point-min) (point-max)))
(if (not keepp)
(kill-buffer buffer)
(switch-to-buffer-other-window buffer)
(goto-char (point-min))))))
(defun outline-find-visible ()
(let ((s (point)))
(while (and (not (= (point-max) (setq s (next-overlay-change s))))
(get-char-property s 'invisible)))
(defun outline-find-invisible ()
(let ((s (point)))
(while (and (not (= (point-max) (setq s (next-overlay-change s))))
(not (get-char-property s 'invisible))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment