Function: outline-headers-as-kill

outline-headers-as-kill is an interactive and byte-compiled function defined in outline.el.gz.

Signature

(outline-headers-as-kill BEG END)

Documentation

Save the visible outline headers between BEG and END to the kill ring.

Text shown between the headers isn't copied. Two newlines are inserted between saved headers. Yanking the result may be a convenient way to make a table of contents of the buffer.

Probably introduced at or before Emacs version 21.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/outline.el.gz
(defun outline-headers-as-kill (beg end)
  "Save the visible outline headers between BEG and END to the kill ring.

Text shown between the headers isn't copied.  Two newlines are
inserted between saved headers.  Yanking the result may be a
convenient way to make a table of contents of the buffer."
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (let ((buffer (current-buffer)) start end)
        (with-temp-buffer
          (let ((temp-buffer (current-buffer)))
            (with-current-buffer buffer
              ;; Boundary condition: starting on heading:
              (when (outline-on-heading-p)
                (outline-back-to-heading)
                (setq start (point)
                      end (progn (outline-end-of-heading) (point)))
                (with-current-buffer temp-buffer
                  (insert-buffer-substring buffer start end)
                  (insert "\n\n")))
              (while (outline-next-heading)
                (unless (outline-invisible-p)
                  (setq start (point)
                        end (progn (outline-end-of-heading) (point)))
                  (with-current-buffer temp-buffer
                    (insert-buffer-substring buffer start end)
                    (insert "\n\n"))))))
          (kill-new (buffer-string)))))))