# HG changeset patch # User Dave Love # Date 947112478 0 # Node ID ce06277761dc37051b8afe7d4c9408587bd7bfb0 # Parent 7811b5b4d905170da35a933d7a1bfaab4a60780c (outline-mode-menu-bar-map): Add outline-headers-as-kill. (outline-mode): Define imenu-generic-expression. (outline-headers-as-kill): New command. diff -r 7811b5b4d905 -r ce06277761dc lisp/textmodes/outline.el --- a/lisp/textmodes/outline.el Wed Jan 05 22:39:30 2000 +0000 +++ b/lisp/textmodes/outline.el Wed Jan 05 22:47:58 2000 +0000 @@ -118,6 +118,9 @@ (define-key outline-mode-menu-bar-map [headings] (cons "Headings" (make-sparse-keymap "Headings"))) + (define-key outline-mode-menu-bar-map [headings copy] + '(menu-item "Copy to kill ring" outline-headers-as-kill + :enable mark-active)) (define-key outline-mode-menu-bar-map [headings outline-backward-same-level] '("Previous Same Level" . outline-backward-same-level)) (define-key outline-mode-menu-bar-map [headings outline-forward-same-level] @@ -241,6 +244,8 @@ (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '(outline-font-lock-keywords t)) (make-local-variable 'change-major-mode-hook) + (setq imenu-generic-expression + (list (list nil (concat outline-regexp ".*$") 0))) (add-hook 'change-major-mode-hook 'show-all) (run-hooks 'text-mode-hook 'outline-mode-hook)) @@ -735,6 +740,40 @@ (if (< (funcall outline-level) level) nil (point)))) + +(defun outline-headers-as-kill (beg end) + "Save the visible outline headers in region at the start of 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 + (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))) + (insert-buffer-substring buffer start end) + (insert "\n\n"))) + (let ((temp-buffer (current-buffer))) + (with-current-buffer buffer + (while (outline-next-heading) + (when (outline-visible) + (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))))))) (provide 'outline) (provide 'noutline)