outline.el 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. ;;; outline.el --- outline mode commands for Emacs
  2. ;; Copyright (C) 1986, 1993-1995, 1997, 2000-2015 Free Software
  3. ;; Foundation, Inc.
  4. ;; Maintainer: emacs-devel@gnu.org
  5. ;; Keywords: outlines
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This package is a major mode for editing outline-format documents.
  19. ;; An outline can be `abstracted' to show headers at any given level,
  20. ;; with all stuff below hidden. See the Emacs manual for details.
  21. ;;; Todo:
  22. ;; - subtree-terminators
  23. ;; - better handle comments before function bodies (i.e. heading)
  24. ;; - don't bother hiding whitespace
  25. ;;; Code:
  26. (defgroup outlines nil
  27. "Support for hierarchical outlining."
  28. :prefix "outline-"
  29. :group 'wp)
  30. (defvar outline-regexp "[*\^L]+"
  31. "Regular expression to match the beginning of a heading.
  32. Any line whose beginning matches this regexp is considered to start a heading.
  33. Note that Outline mode only checks this regexp at the start of a line,
  34. so the regexp need not (and usually does not) start with `^'.
  35. The recommended way to set this is with a Local Variables: list
  36. in the file it applies to. See also `outline-heading-end-regexp'.")
  37. ;;;###autoload(put 'outline-regexp 'safe-local-variable 'stringp)
  38. (defvar outline-heading-end-regexp "\n"
  39. "Regular expression to match the end of a heading line.
  40. You can assume that point is at the beginning of a heading when this
  41. regexp is searched for. The heading ends at the end of the match.
  42. The recommended way to set this is with a `Local Variables:' list
  43. in the file it applies to.")
  44. ;;;###autoload(put 'outline-heading-end-regexp 'safe-local-variable 'stringp)
  45. (defvar outline-mode-prefix-map
  46. (let ((map (make-sparse-keymap)))
  47. (define-key map "@" 'outline-mark-subtree)
  48. (define-key map "\C-n" 'outline-next-visible-heading)
  49. (define-key map "\C-p" 'outline-previous-visible-heading)
  50. (define-key map "\C-i" 'outline-show-children)
  51. (define-key map "\C-s" 'outline-show-subtree)
  52. (define-key map "\C-d" 'outline-hide-subtree)
  53. (define-key map "\C-u" 'outline-up-heading)
  54. (define-key map "\C-f" 'outline-forward-same-level)
  55. (define-key map "\C-b" 'outline-backward-same-level)
  56. (define-key map "\C-t" 'outline-hide-body)
  57. (define-key map "\C-a" 'outline-show-all)
  58. (define-key map "\C-c" 'outline-hide-entry)
  59. (define-key map "\C-e" 'outline-show-entry)
  60. (define-key map "\C-l" 'outline-hide-leaves)
  61. (define-key map "\C-k" 'outline-show-branches)
  62. (define-key map "\C-q" 'outline-hide-sublevels)
  63. (define-key map "\C-o" 'outline-hide-other)
  64. (define-key map "\C-^" 'outline-move-subtree-up)
  65. (define-key map "\C-v" 'outline-move-subtree-down)
  66. (define-key map [(control ?<)] 'outline-promote)
  67. (define-key map [(control ?>)] 'outline-demote)
  68. (define-key map "\C-m" 'outline-insert-heading)
  69. map))
  70. (defvar outline-mode-menu-bar-map
  71. (let ((map (make-sparse-keymap)))
  72. (define-key map [hide] (cons "Hide" (make-sparse-keymap "Hide")))
  73. (define-key map [hide outline-hide-other]
  74. '(menu-item "Hide Other" outline-hide-other
  75. :help "Hide everything except current body and parent and top-level headings"))
  76. (define-key map [hide outline-hide-sublevels]
  77. '(menu-item "Hide Sublevels" outline-hide-sublevels
  78. :help "Hide everything but the top LEVELS levels of headers, in whole buffer"))
  79. (define-key map [hide outline-hide-subtree]
  80. '(menu-item "Hide Subtree" outline-hide-subtree
  81. :help "Hide everything after this heading at deeper levels"))
  82. (define-key map [hide outline-hide-entry]
  83. '(menu-item "Hide Entry" outline-hide-entry
  84. :help "Hide the body directly following this heading"))
  85. (define-key map [hide outline-hide-body]
  86. '(menu-item "Hide Body" outline-hide-body
  87. :help "Hide all body lines in buffer, leaving all headings visible"))
  88. (define-key map [hide outline-hide-leaves]
  89. '(menu-item "Hide Leaves" outline-hide-leaves
  90. :help "Hide the body after this heading and at deeper levels"))
  91. (define-key map [show] (cons "Show" (make-sparse-keymap "Show")))
  92. (define-key map [show outline-show-subtree]
  93. '(menu-item "Show Subtree" outline-show-subtree
  94. :help "Show everything after this heading at deeper levels"))
  95. (define-key map [show outline-show-children]
  96. '(menu-item "Show Children" outline-show-children
  97. :help "Show all direct subheadings of this heading"))
  98. (define-key map [show outline-show-branches]
  99. '(menu-item "Show Branches" outline-show-branches
  100. :help "Show all subheadings of this heading, but not their bodies"))
  101. (define-key map [show outline-show-entry]
  102. '(menu-item "Show Entry" outline-show-entry
  103. :help "Show the body directly following this heading"))
  104. (define-key map [show outline-show-all]
  105. '(menu-item "Show All" outline-show-all
  106. :help "Show all of the text in the buffer"))
  107. (define-key map [headings]
  108. (cons "Headings" (make-sparse-keymap "Headings")))
  109. (define-key map [headings demote-subtree]
  110. '(menu-item "Demote Subtree" outline-demote
  111. :help "Demote headings lower down the tree"))
  112. (define-key map [headings promote-subtree]
  113. '(menu-item "Promote Subtree" outline-promote
  114. :help "Promote headings higher up the tree"))
  115. (define-key map [headings move-subtree-down]
  116. '(menu-item "Move Subtree Down" outline-move-subtree-down
  117. :help "Move the current subtree down past arg headlines of the same level"))
  118. (define-key map [headings move-subtree-up]
  119. '(menu-item "Move Subtree Up" outline-move-subtree-up
  120. :help "Move the current subtree up past arg headlines of the same level"))
  121. (define-key map [headings copy]
  122. '(menu-item "Copy to Kill Ring" outline-headers-as-kill
  123. :enable mark-active
  124. :help "Save the visible outline headers in region at the start of the kill ring"))
  125. (define-key map [headings outline-insert-heading]
  126. '(menu-item "New Heading" outline-insert-heading
  127. :help "Insert a new heading at same depth at point"))
  128. (define-key map [headings outline-backward-same-level]
  129. '(menu-item "Previous Same Level" outline-backward-same-level
  130. :help "Move backward to the arg'th subheading at same level as this one."))
  131. (define-key map [headings outline-forward-same-level]
  132. '(menu-item "Next Same Level" outline-forward-same-level
  133. :help "Move forward to the arg'th subheading at same level as this one"))
  134. (define-key map [headings outline-previous-visible-heading]
  135. '(menu-item "Previous" outline-previous-visible-heading
  136. :help "Move to the previous heading line"))
  137. (define-key map [headings outline-next-visible-heading]
  138. '(menu-item "Next" outline-next-visible-heading
  139. :help "Move to the next visible heading line"))
  140. (define-key map [headings outline-up-heading]
  141. '(menu-item "Up" outline-up-heading
  142. :help "Move to the visible heading line of which the present line is a subheading"))
  143. map))
  144. (defvar outline-minor-mode-menu-bar-map
  145. (let ((map (make-sparse-keymap)))
  146. (define-key map [outline]
  147. (cons "Outline"
  148. (nconc (make-sparse-keymap "Outline")
  149. ;; Remove extra separator
  150. (cdr
  151. ;; Flatten the major mode's menus into a single menu.
  152. (apply 'append
  153. (mapcar (lambda (x)
  154. (if (consp x)
  155. ;; Add a separator between each
  156. ;; part of the unified menu.
  157. (cons '(--- "---") (cdr x))))
  158. outline-mode-menu-bar-map))))))
  159. map))
  160. (defvar outline-mode-map
  161. (let ((map (make-sparse-keymap)))
  162. (define-key map "\C-c" outline-mode-prefix-map)
  163. (define-key map [menu-bar] outline-mode-menu-bar-map)
  164. map))
  165. (defvar outline-font-lock-keywords
  166. '(
  167. ;; Highlight headings according to the level.
  168. (eval . (list (concat "^\\(?:" outline-regexp "\\).+")
  169. 0 '(outline-font-lock-face) nil t)))
  170. "Additional expressions to highlight in Outline mode.")
  171. (defface outline-1
  172. '((t :inherit font-lock-function-name-face))
  173. "Level 1."
  174. :group 'outlines)
  175. (defface outline-2
  176. '((t :inherit font-lock-variable-name-face))
  177. "Level 2."
  178. :group 'outlines)
  179. (defface outline-3
  180. '((t :inherit font-lock-keyword-face))
  181. "Level 3."
  182. :group 'outlines)
  183. (defface outline-4
  184. '((t :inherit font-lock-comment-face))
  185. "Level 4."
  186. :group 'outlines)
  187. (defface outline-5
  188. '((t :inherit font-lock-type-face))
  189. "Level 5."
  190. :group 'outlines)
  191. (defface outline-6
  192. '((t :inherit font-lock-constant-face))
  193. "Level 6."
  194. :group 'outlines)
  195. (defface outline-7
  196. '((t :inherit font-lock-builtin-face))
  197. "Level 7."
  198. :group 'outlines)
  199. (defface outline-8
  200. '((t :inherit font-lock-string-face))
  201. "Level 8."
  202. :group 'outlines)
  203. (defvar outline-font-lock-faces
  204. [outline-1 outline-2 outline-3 outline-4
  205. outline-5 outline-6 outline-7 outline-8])
  206. (defun outline-font-lock-face ()
  207. "Return one of `outline-font-lock-faces' for current level."
  208. (save-excursion
  209. (goto-char (match-beginning 0))
  210. (looking-at outline-regexp)
  211. (aref outline-font-lock-faces
  212. (% (1- (funcall outline-level))
  213. (length outline-font-lock-faces)))))
  214. (defvar outline-view-change-hook nil
  215. "Normal hook to be run after outline visibility changes.")
  216. (defvar outline-mode-hook nil
  217. "This hook is run when outline mode starts.")
  218. (defvar outline-blank-line nil
  219. "Non-nil means to leave unhidden blank line before heading.")
  220. ;;;###autoload
  221. (define-derived-mode outline-mode text-mode "Outline"
  222. "Set major mode for editing outlines with selective display.
  223. Headings are lines which start with asterisks: one for major headings,
  224. two for subheadings, etc. Lines not starting with asterisks are body lines.
  225. Body text or subheadings under a heading can be made temporarily
  226. invisible, or visible again. Invisible lines are attached to the end
  227. of the heading, so they move with it, if the line is killed and yanked
  228. back. A heading with text hidden under it is marked with an ellipsis (...).
  229. \\{outline-mode-map}
  230. The commands `outline-hide-subtree', `outline-show-subtree',
  231. `outline-show-children', `outline-hide-entry',
  232. `outline-show-entry', `outline-hide-leaves', and `outline-show-branches'
  233. are used when point is on a heading line.
  234. The variable `outline-regexp' can be changed to control what is a heading.
  235. A line is a heading if `outline-regexp' matches something at the
  236. beginning of the line. The longer the match, the deeper the level.
  237. Turning on outline mode calls the value of `text-mode-hook' and then of
  238. `outline-mode-hook', if they are non-nil."
  239. (make-local-variable 'line-move-ignore-invisible)
  240. (setq line-move-ignore-invisible t)
  241. ;; Cause use of ellipses for invisible text.
  242. (add-to-invisibility-spec '(outline . t))
  243. (set (make-local-variable 'paragraph-start)
  244. (concat paragraph-start "\\|\\(?:" outline-regexp "\\)"))
  245. ;; Inhibit auto-filling of header lines.
  246. (set (make-local-variable 'auto-fill-inhibit-regexp) outline-regexp)
  247. (set (make-local-variable 'paragraph-separate)
  248. (concat paragraph-separate "\\|\\(?:" outline-regexp "\\)"))
  249. (set (make-local-variable 'font-lock-defaults)
  250. '(outline-font-lock-keywords t nil nil backward-paragraph))
  251. (setq imenu-generic-expression
  252. (list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
  253. (add-hook 'change-major-mode-hook 'outline-show-all nil t))
  254. (defcustom outline-minor-mode-prefix "\C-c@"
  255. "Prefix key to use for Outline commands in Outline minor mode.
  256. The value of this variable is checked as part of loading Outline mode.
  257. After that, changing the prefix key requires manipulating keymaps."
  258. :type 'string
  259. :group 'outlines)
  260. ;;;###autoload
  261. (define-minor-mode outline-minor-mode
  262. "Toggle Outline minor mode.
  263. With a prefix argument ARG, enable Outline minor mode if ARG is
  264. positive, and disable it otherwise. If called from Lisp, enable
  265. the mode if ARG is omitted or nil.
  266. See the command `outline-mode' for more information on this mode."
  267. nil " Outl" (list (cons [menu-bar] outline-minor-mode-menu-bar-map)
  268. (cons outline-minor-mode-prefix outline-mode-prefix-map))
  269. :group 'outlines
  270. (if outline-minor-mode
  271. (progn
  272. ;; Turn off this mode if we change major modes.
  273. (add-hook 'change-major-mode-hook
  274. (lambda () (outline-minor-mode -1))
  275. nil t)
  276. (set (make-local-variable 'line-move-ignore-invisible) t)
  277. ;; Cause use of ellipses for invisible text.
  278. (add-to-invisibility-spec '(outline . t)))
  279. (setq line-move-ignore-invisible nil)
  280. ;; Cause use of ellipses for invisible text.
  281. (remove-from-invisibility-spec '(outline . t))
  282. ;; When turning off outline mode, get rid of any outline hiding.
  283. (outline-show-all)))
  284. (defvar outline-level 'outline-level
  285. "Function of no args to compute a header's nesting level in an outline.
  286. It can assume point is at the beginning of a header line and that the match
  287. data reflects the `outline-regexp'.")
  288. ;;;###autoload(put 'outline-level 'risky-local-variable t)
  289. (defvar outline-heading-alist ()
  290. "Alist associating a heading for every possible level.
  291. Each entry is of the form (HEADING . LEVEL).
  292. This alist is used two ways: to find the heading corresponding to
  293. a given level and to find the level of a given heading.
  294. If a mode or document needs several sets of outline headings (for example
  295. numbered and unnumbered sections), list them set by set and sorted by level
  296. within each set. For example in texinfo mode:
  297. (setq outline-heading-alist
  298. \\='((\"@chapter\" . 2) (\"@section\" . 3) (\"@subsection\" . 4)
  299. (\"@subsubsection\" . 5)
  300. (\"@unnumbered\" . 2) (\"@unnumberedsec\" . 3)
  301. (\"@unnumberedsubsec\" . 4) (\"@unnumberedsubsubsec\" . 5)
  302. (\"@appendix\" . 2) (\"@appendixsec\" . 3)...
  303. (\"@appendixsubsec\" . 4) (\"@appendixsubsubsec\" . 5) ..))
  304. Instead of sorting the entries in each set, you can also separate the
  305. sets with nil.")
  306. (make-variable-buffer-local 'outline-heading-alist)
  307. ;; This used to count columns rather than characters, but that made ^L
  308. ;; appear to be at level 2 instead of 1. Columns would be better for
  309. ;; tab handling, but the default regexp doesn't use tabs, and anyone
  310. ;; who changes the regexp can also redefine the outline-level variable
  311. ;; as appropriate.
  312. (defun outline-level ()
  313. "Return the depth to which a statement is nested in the outline.
  314. Point must be at the beginning of a header line.
  315. This is actually either the level specified in `outline-heading-alist'
  316. or else the number of characters matched by `outline-regexp'."
  317. (or (cdr (assoc (match-string 0) outline-heading-alist))
  318. (- (match-end 0) (match-beginning 0))))
  319. (defun outline-next-preface ()
  320. "Skip forward to just before the next heading line.
  321. If there's no following heading line, stop before the newline
  322. at the end of the buffer."
  323. (if (re-search-forward (concat "\n\\(?:" outline-regexp "\\)")
  324. nil 'move)
  325. (goto-char (match-beginning 0)))
  326. (if (and (bolp) (or outline-blank-line (eobp)) (not (bobp)))
  327. (forward-char -1)))
  328. (defun outline-next-heading ()
  329. "Move to the next (possibly invisible) heading line."
  330. (interactive)
  331. ;; Make sure we don't match the heading we're at.
  332. (if (and (bolp) (not (eobp))) (forward-char 1))
  333. (if (re-search-forward (concat "^\\(?:" outline-regexp "\\)")
  334. nil 'move)
  335. (goto-char (match-beginning 0))))
  336. (defun outline-previous-heading ()
  337. "Move to the previous (possibly invisible) heading line."
  338. (interactive)
  339. (re-search-backward (concat "^\\(?:" outline-regexp "\\)")
  340. nil 'move))
  341. (defsubst outline-invisible-p (&optional pos)
  342. "Non-nil if the character after POS is invisible.
  343. If POS is nil, use `point' instead."
  344. (get-char-property (or pos (point)) 'invisible))
  345. (defun outline-back-to-heading (&optional invisible-ok)
  346. "Move to previous heading line, or beg of this line if it's a heading.
  347. Only visible heading lines are considered, unless INVISIBLE-OK is non-nil."
  348. (beginning-of-line)
  349. (or (outline-on-heading-p invisible-ok)
  350. (let (found)
  351. (save-excursion
  352. (while (not found)
  353. (or (re-search-backward (concat "^\\(?:" outline-regexp "\\)")
  354. nil t)
  355. (error "Before first heading"))
  356. (setq found (and (or invisible-ok (not (outline-invisible-p)))
  357. (point)))))
  358. (goto-char found)
  359. found)))
  360. (defun outline-on-heading-p (&optional invisible-ok)
  361. "Return t if point is on a (visible) heading line.
  362. If INVISIBLE-OK is non-nil, an invisible heading line is ok too."
  363. (save-excursion
  364. (beginning-of-line)
  365. (and (bolp) (or invisible-ok (not (outline-invisible-p)))
  366. (looking-at outline-regexp))))
  367. (defun outline-insert-heading ()
  368. "Insert a new heading at same depth at point."
  369. (interactive)
  370. (let ((head (save-excursion
  371. (condition-case nil
  372. (outline-back-to-heading)
  373. (error (outline-next-heading)))
  374. (if (eobp)
  375. (or (caar outline-heading-alist) "")
  376. (match-string 0)))))
  377. (unless (or (string-match "[ \t]\\'" head)
  378. (not (string-match (concat "\\`\\(?:" outline-regexp "\\)")
  379. (concat head " "))))
  380. (setq head (concat head " ")))
  381. (unless (bolp) (end-of-line) (newline))
  382. (insert head)
  383. (unless (eolp)
  384. (save-excursion (newline-and-indent)))
  385. (run-hooks 'outline-insert-heading-hook)))
  386. (defun outline-invent-heading (head up)
  387. "Create a heading by using heading HEAD as a template.
  388. When UP is non-nil, the created heading will be one level above.
  389. Otherwise, it will be one level below."
  390. (save-match-data
  391. ;; Let's try to invent one by repeating or deleting the last char.
  392. (let ((new-head (if up (substring head 0 -1)
  393. (concat head (substring head -1)))))
  394. (if (string-match (concat "\\`\\(?:" outline-regexp "\\)")
  395. new-head)
  396. ;; Why bother checking that it is indeed higher/lower level ?
  397. new-head
  398. ;; Didn't work, so ask what to do.
  399. (read-string (format-message "%s heading for `%s': "
  400. (if up "Parent" "Demoted") head)
  401. head nil nil t)))))
  402. (defun outline-promote (&optional which)
  403. "Promote headings higher up the tree.
  404. If `transient-mark-mode' is on, and mark is active, promote headings in
  405. the region (from a Lisp program, pass `region' for WHICH). Otherwise:
  406. without prefix argument, promote current heading and all headings in the
  407. subtree (from a Lisp program, pass `subtree' for WHICH); with prefix
  408. argument, promote just the current heading (from a Lisp program, pass
  409. nil for WHICH, or do not pass any argument)."
  410. (interactive
  411. (list (if (and transient-mark-mode mark-active) 'region
  412. (outline-back-to-heading)
  413. (if current-prefix-arg nil 'subtree))))
  414. (cond
  415. ((eq which 'region)
  416. (outline-map-region 'outline-promote (region-beginning) (region-end)))
  417. (which
  418. (outline-map-region 'outline-promote
  419. (point)
  420. (save-excursion (outline-get-next-sibling) (point))))
  421. (t
  422. (outline-back-to-heading t)
  423. (let* ((head (match-string-no-properties 0))
  424. (level (save-match-data (funcall outline-level)))
  425. (up-head (or (outline-head-from-level (1- level) head)
  426. ;; Use the parent heading, if it is really
  427. ;; one level less.
  428. (save-excursion
  429. (save-match-data
  430. (outline-up-heading 1 t)
  431. (and (= (1- level) (funcall outline-level))
  432. (match-string-no-properties 0))))
  433. ;; Bummer!! There is no lower level heading.
  434. (outline-invent-heading head 'up))))
  435. (unless (rassoc level outline-heading-alist)
  436. (push (cons head level) outline-heading-alist))
  437. (replace-match up-head nil t)))))
  438. (defun outline-demote (&optional which)
  439. "Demote headings lower down the tree.
  440. If `transient-mark-mode' is on, and mark is active, demote headings in
  441. the region (from a Lisp program, pass `region' for WHICH). Otherwise:
  442. without prefix argument, demote current heading and all headings in the
  443. subtree (from a Lisp program, pass `subtree' for WHICH); with prefix
  444. argument, demote just the current heading (from a Lisp program, pass
  445. nil for WHICH, or do not pass any argument)."
  446. (interactive
  447. (list (if (and transient-mark-mode mark-active) 'region
  448. (outline-back-to-heading)
  449. (if current-prefix-arg nil 'subtree))))
  450. (cond
  451. ((eq which 'region)
  452. (outline-map-region 'outline-demote (region-beginning) (region-end)))
  453. (which
  454. (outline-map-region 'outline-demote
  455. (point)
  456. (save-excursion (outline-get-next-sibling) (point))))
  457. (t
  458. (let* ((head (match-string-no-properties 0))
  459. (level (save-match-data (funcall outline-level)))
  460. (down-head
  461. (or (outline-head-from-level (1+ level) head)
  462. (save-excursion
  463. (save-match-data
  464. (while (and (progn (outline-next-heading) (not (eobp)))
  465. (<= (funcall outline-level) level)))
  466. (when (eobp)
  467. ;; Try again from the beginning of the buffer.
  468. (goto-char (point-min))
  469. (while (and (progn (outline-next-heading) (not (eobp)))
  470. (<= (funcall outline-level) level))))
  471. (unless (eobp)
  472. (looking-at outline-regexp)
  473. (match-string-no-properties 0))))
  474. ;; Bummer!! There is no higher-level heading in the buffer.
  475. (outline-invent-heading head nil))))
  476. (unless (rassoc level outline-heading-alist)
  477. (push (cons head level) outline-heading-alist))
  478. (replace-match down-head nil t)))))
  479. (defun outline-head-from-level (level head &optional alist)
  480. "Get new heading with level LEVEL, closest to HEAD, from ALIST.
  481. If there are no such entries, return nil.
  482. ALIST defaults to `outline-heading-alist'.
  483. Similar to (car (rassoc LEVEL ALIST)).
  484. If there are several different entries with same new level, choose
  485. the one with the smallest distance to the association of HEAD in the alist.
  486. This makes it possible for promotion to work in modes with several
  487. independent sets of headings (numbered, unnumbered, appendix...)"
  488. (unless alist (setq alist outline-heading-alist))
  489. (let ((l (rassoc level alist))
  490. ll h hl l2 l2l)
  491. (cond
  492. ((null l) nil)
  493. ;; If there's no HEAD after L, any other entry for LEVEL after L
  494. ;; can't be much better than L.
  495. ((null (setq h (assoc head (setq ll (memq l alist))))) (car l))
  496. ;; If there's no other entry for LEVEL, just keep L.
  497. ((null (setq l2 (rassoc level (cdr ll)))) (car l))
  498. ;; Now we have L, L2, and H: see if L2 seems better than L.
  499. ;; If H is after L2, L2 is better.
  500. ((memq h (setq l2l (memq l2 (cdr ll))))
  501. (outline-head-from-level level head l2l))
  502. ;; Now we have H between L and L2.
  503. ;; If there's a separator between L and H, prefer L2.
  504. ((memq h (memq nil ll))
  505. (outline-head-from-level level head l2l))
  506. ;; If there's a separator between L2 and H, prefer L.
  507. ((memq l2 (memq nil (setq hl (memq h ll)))) (car l))
  508. ;; No separator between L and L2, check the distance.
  509. ((< (* 2 (length hl)) (+ (length ll) (length l2l)))
  510. (outline-head-from-level level head l2l))
  511. ;; If all else fails, just keep L.
  512. (t (car l)))))
  513. (defun outline-map-region (fun beg end)
  514. "Call FUN for every heading between BEG and END.
  515. When FUN is called, point is at the beginning of the heading and
  516. the match data is set appropriately."
  517. (save-excursion
  518. (setq end (copy-marker end))
  519. (goto-char beg)
  520. (when (re-search-forward (concat "^\\(?:" outline-regexp "\\)") end t)
  521. (goto-char (match-beginning 0))
  522. (funcall fun)
  523. (while (and (progn
  524. (outline-next-heading)
  525. (< (point) end))
  526. (not (eobp)))
  527. (funcall fun)))))
  528. ;; Vertical tree motion
  529. (defun outline-move-subtree-up (&optional arg)
  530. "Move the current subtree up past ARG headlines of the same level."
  531. (interactive "p")
  532. (outline-move-subtree-down (- arg)))
  533. (defun outline-move-subtree-down (&optional arg)
  534. "Move the current subtree down past ARG headlines of the same level."
  535. (interactive "p")
  536. (outline-back-to-heading)
  537. (let* ((movfunc (if (> arg 0) 'outline-get-next-sibling
  538. 'outline-get-last-sibling))
  539. ;; Find the end of the subtree to be moved as well as the point to
  540. ;; move it to, adding a newline if necessary, to ensure these points
  541. ;; are at bol on the line below the subtree.
  542. (end-point-func (lambda ()
  543. (outline-end-of-subtree)
  544. (if (eq (char-after) ?\n) (forward-char 1)
  545. (if (and (eobp) (not (bolp))) (insert "\n")))
  546. (point)))
  547. (beg (point))
  548. (folded (save-match-data
  549. (outline-end-of-heading)
  550. (outline-invisible-p)))
  551. (end (save-match-data
  552. (funcall end-point-func)))
  553. (ins-point (make-marker))
  554. (cnt (abs arg)))
  555. ;; Find insertion point, with error handling.
  556. (goto-char beg)
  557. (while (> cnt 0)
  558. (or (funcall movfunc)
  559. (progn (goto-char beg)
  560. (user-error "Cannot move past superior level")))
  561. (setq cnt (1- cnt)))
  562. (if (> arg 0)
  563. ;; Moving forward - still need to move over subtree.
  564. (funcall end-point-func))
  565. (move-marker ins-point (point))
  566. (insert (delete-and-extract-region beg end))
  567. (goto-char ins-point)
  568. (if folded (outline-hide-subtree))
  569. (move-marker ins-point nil)))
  570. (defun outline-end-of-heading ()
  571. "Move to one char before the next `outline-heading-end-regexp'."
  572. (if (re-search-forward outline-heading-end-regexp nil 'move)
  573. (forward-char -1)))
  574. (defun outline-next-visible-heading (arg)
  575. "Move to the next visible heading line.
  576. With ARG, repeats or can move backward if negative.
  577. A heading line is one that starts with a `*' (or that
  578. `outline-regexp' matches)."
  579. (interactive "p")
  580. (if (< arg 0)
  581. (beginning-of-line)
  582. (end-of-line))
  583. (let (found-heading-p)
  584. (while (and (not (bobp)) (< arg 0))
  585. (while (and (not (bobp))
  586. (setq found-heading-p
  587. (re-search-backward
  588. (concat "^\\(?:" outline-regexp "\\)")
  589. nil 'move))
  590. (outline-invisible-p)))
  591. (setq arg (1+ arg)))
  592. (while (and (not (eobp)) (> arg 0))
  593. (while (and (not (eobp))
  594. (setq found-heading-p
  595. (re-search-forward
  596. (concat "^\\(?:" outline-regexp "\\)")
  597. nil 'move))
  598. (outline-invisible-p (match-beginning 0))))
  599. (setq arg (1- arg)))
  600. (if found-heading-p (beginning-of-line))))
  601. (defun outline-previous-visible-heading (arg)
  602. "Move to the previous heading line.
  603. With ARG, repeats or can move forward if negative.
  604. A heading line is one that starts with a `*' (or that
  605. `outline-regexp' matches)."
  606. (interactive "p")
  607. (outline-next-visible-heading (- arg)))
  608. (defun outline-mark-subtree ()
  609. "Mark the current subtree in an outlined document.
  610. This puts point at the start of the current subtree, and mark at the end."
  611. (interactive)
  612. (let ((beg))
  613. (if (outline-on-heading-p)
  614. ;; we are already looking at a heading
  615. (beginning-of-line)
  616. ;; else go back to previous heading
  617. (outline-previous-visible-heading 1))
  618. (setq beg (point))
  619. (outline-end-of-subtree)
  620. (push-mark (point) nil t)
  621. (goto-char beg)))
  622. (defvar outline-isearch-open-invisible-function nil
  623. "Function called if `isearch' finishes in an invisible overlay.
  624. The function is called with the overlay as its only argument.
  625. If nil, `outline-show-entry' is called to reveal the invisible text.")
  626. (put 'outline 'reveal-toggle-invisible 'outline-reveal-toggle-invisible)
  627. (defun outline-flag-region (from to flag)
  628. "Hide or show lines from FROM to TO, according to FLAG.
  629. If FLAG is nil then text is shown, while if FLAG is t the text is hidden."
  630. (remove-overlays from to 'invisible 'outline)
  631. (when flag
  632. ;; We use `front-advance' here because the invisible text begins at the
  633. ;; very end of the heading, before the newline, so text inserted at FROM
  634. ;; belongs to the heading rather than to the entry.
  635. (let ((o (make-overlay from to nil 'front-advance)))
  636. (overlay-put o 'evaporate t)
  637. (overlay-put o 'invisible 'outline)
  638. (overlay-put o 'isearch-open-invisible
  639. (or outline-isearch-open-invisible-function
  640. 'outline-isearch-open-invisible))))
  641. ;; Seems only used by lazy-lock. I.e. obsolete.
  642. (run-hooks 'outline-view-change-hook))
  643. (defun outline-reveal-toggle-invisible (o hidep)
  644. (save-excursion
  645. (goto-char (overlay-start o))
  646. (if hidep
  647. ;; When hiding the area again, we could just clean it up and let
  648. ;; reveal do the rest, by simply doing:
  649. ;; (remove-overlays (overlay-start o) (overlay-end o)
  650. ;; 'invisible 'outline)
  651. ;;
  652. ;; That works fine as long as everything is in sync, but if the
  653. ;; structure of the document is changed while revealing parts of it,
  654. ;; the resulting behavior can be ugly. I.e. we need to make
  655. ;; sure that we hide exactly a subtree.
  656. (progn
  657. (let ((end (overlay-end o)))
  658. (delete-overlay o)
  659. (while (progn
  660. (outline-hide-subtree)
  661. (outline-next-visible-heading 1)
  662. (and (not (eobp)) (< (point) end))))))
  663. ;; When revealing, we just need to reveal sublevels. If point is
  664. ;; inside one of the sublevels, reveal will call us again.
  665. ;; But we need to preserve the original overlay.
  666. (let ((o1 (copy-overlay o)))
  667. (overlay-put o 'invisible nil) ;Show (most of) the text.
  668. (while (progn
  669. (outline-show-entry)
  670. (outline-show-children)
  671. ;; Normally just the above is needed.
  672. ;; But in odd cases, the above might fail to show anything.
  673. ;; To avoid an infinite loop, we have to make sure that
  674. ;; *something* gets shown.
  675. (and (equal (overlay-start o) (overlay-start o1))
  676. (< (point) (overlay-end o))
  677. (= 0 (forward-line 1)))))
  678. ;; If still nothing was shown, just kill the damn thing.
  679. (when (equal (overlay-start o) (overlay-start o1))
  680. ;; I've seen it happen at the end of buffer.
  681. (delete-overlay o1))))))
  682. ;; Function to be set as an outline-isearch-open-invisible' property
  683. ;; to the overlay that makes the outline invisible (see
  684. ;; `outline-flag-region').
  685. (defun outline-isearch-open-invisible (_overlay)
  686. ;; We rely on the fact that isearch places point on the matched text.
  687. (outline-show-entry))
  688. (defun outline-hide-entry ()
  689. "Hide the body directly following this heading."
  690. (interactive)
  691. (save-excursion
  692. (outline-back-to-heading)
  693. (outline-end-of-heading)
  694. (outline-flag-region (point) (progn (outline-next-preface) (point)) t)))
  695. (define-obsolete-function-alias
  696. 'hide-entry 'outline-hide-entry "25.1")
  697. (defun outline-show-entry ()
  698. "Show the body directly following this heading.
  699. Show the heading too, if it is currently invisible."
  700. (interactive)
  701. (save-excursion
  702. (outline-back-to-heading t)
  703. (outline-flag-region (1- (point))
  704. (progn
  705. (outline-next-preface)
  706. (if (= 1 (- (point-max) (point)))
  707. (point-max)
  708. (point)))
  709. nil)))
  710. (define-obsolete-function-alias
  711. 'show-entry 'outline-show-entry "25.1")
  712. (defun outline-hide-body ()
  713. "Hide all body lines in buffer, leaving all headings visible."
  714. (interactive)
  715. (outline-hide-region-body (point-min) (point-max)))
  716. (define-obsolete-function-alias
  717. 'hide-body 'outline-hide-body "25.1")
  718. (defun outline-hide-region-body (start end)
  719. "Hide all body lines between START and END, but not headings."
  720. ;; Nullify the hook to avoid repeated calls to `outline-flag-region'
  721. ;; wasting lots of time running `lazy-lock-fontify-after-outline'
  722. ;; and run the hook finally.
  723. (let (outline-view-change-hook)
  724. (save-excursion
  725. (save-restriction
  726. (narrow-to-region start end)
  727. (goto-char (point-min))
  728. (if (outline-on-heading-p)
  729. (outline-end-of-heading)
  730. (outline-next-preface))
  731. (while (not (eobp))
  732. (outline-flag-region (point)
  733. (progn (outline-next-preface) (point)) t)
  734. (unless (eobp)
  735. (forward-char (if (looking-at "\n\n") 2 1))
  736. (outline-end-of-heading))))))
  737. (run-hooks 'outline-view-change-hook))
  738. (define-obsolete-function-alias
  739. 'hide-region-body 'outline-hide-region-body "25.1")
  740. (defun outline-show-all ()
  741. "Show all of the text in the buffer."
  742. (interactive)
  743. (outline-flag-region (point-min) (point-max) nil))
  744. (define-obsolete-function-alias
  745. 'show-all 'outline-show-all "25.1")
  746. (defun outline-hide-subtree ()
  747. "Hide everything after this heading at deeper levels."
  748. (interactive)
  749. (outline-flag-subtree t))
  750. (define-obsolete-function-alias
  751. 'hide-subtree 'outline-hide-subtree "25.1")
  752. (defun outline-hide-leaves ()
  753. "Hide the body after this heading and at deeper levels."
  754. (interactive)
  755. (save-excursion
  756. (outline-back-to-heading)
  757. ;; Turned off to fix bug reported by Otto Maddox on 22 Nov 2005.
  758. ;; (outline-end-of-heading)
  759. (outline-hide-region-body
  760. (point)
  761. (progn (outline-end-of-subtree) (point)))))
  762. (define-obsolete-function-alias
  763. 'hide-leaves 'outline-hide-leaves "25.1")
  764. (defun outline-show-subtree ()
  765. "Show everything after this heading at deeper levels."
  766. (interactive)
  767. (outline-flag-subtree nil))
  768. (define-obsolete-function-alias
  769. 'show-subtree 'outline-show-subtree "25.1")
  770. (defun outline-show-heading ()
  771. "Show the current heading and move to its end."
  772. (outline-flag-region (- (point)
  773. (if (bobp) 0
  774. (if (and outline-blank-line
  775. (eq (char-before (1- (point))) ?\n))
  776. 2 1)))
  777. (progn (outline-end-of-heading) (point))
  778. nil))
  779. (defun outline-hide-sublevels (levels)
  780. "Hide everything but the top LEVELS levels of headers, in whole buffer."
  781. (interactive (list
  782. (cond
  783. (current-prefix-arg (prefix-numeric-value current-prefix-arg))
  784. ((save-excursion (beginning-of-line)
  785. (looking-at outline-regexp))
  786. (funcall outline-level))
  787. (t 1))))
  788. (if (< levels 1)
  789. (error "Must keep at least one level of headers"))
  790. (save-excursion
  791. (let* (outline-view-change-hook
  792. (beg (progn
  793. (goto-char (point-min))
  794. ;; Skip the prelude, if any.
  795. (unless (outline-on-heading-p t) (outline-next-heading))
  796. (point)))
  797. (end (progn
  798. (goto-char (point-max))
  799. ;; Keep empty last line, if available.
  800. (if (bolp) (1- (point)) (point)))))
  801. (if (< end beg)
  802. (setq beg (prog1 end (setq end beg))))
  803. ;; First hide everything.
  804. (outline-flag-region beg end t)
  805. ;; Then unhide the top level headers.
  806. (outline-map-region
  807. (lambda ()
  808. (if (<= (funcall outline-level) levels)
  809. (outline-show-heading)))
  810. beg end)
  811. ;; Finally unhide any trailing newline.
  812. (goto-char (point-max))
  813. (if (and (bolp) (not (bobp)) (outline-invisible-p (1- (point))))
  814. (outline-flag-region (1- (point)) (point) nil))))
  815. (run-hooks 'outline-view-change-hook))
  816. (define-obsolete-function-alias
  817. 'hide-sublevels 'outline-hide-sublevels "25.1")
  818. (defun outline-hide-other ()
  819. "Hide everything except current body and parent and top-level headings."
  820. (interactive)
  821. (outline-hide-sublevels 1)
  822. (let (outline-view-change-hook)
  823. (save-excursion
  824. (outline-back-to-heading t)
  825. (outline-show-entry)
  826. (while (condition-case nil (progn (outline-up-heading 1 t) (not (bobp)))
  827. (error nil))
  828. (outline-flag-region (1- (point))
  829. (save-excursion (forward-line 1) (point))
  830. nil))))
  831. (run-hooks 'outline-view-change-hook))
  832. (define-obsolete-function-alias
  833. 'hide-other 'outline-hide-other "25.1")
  834. (defun outline-toggle-children ()
  835. "Show or hide the current subtree depending on its current state."
  836. (interactive)
  837. (save-excursion
  838. (outline-back-to-heading)
  839. (if (not (outline-invisible-p (line-end-position)))
  840. (outline-hide-subtree)
  841. (outline-show-children)
  842. (outline-show-entry))))
  843. (defun outline-flag-subtree (flag)
  844. "Assign FLAG to the current subtree."
  845. (save-excursion
  846. (outline-back-to-heading)
  847. (outline-end-of-heading)
  848. (outline-flag-region (point)
  849. (progn (outline-end-of-subtree) (point))
  850. flag)))
  851. (defun outline-end-of-subtree ()
  852. "Move to the end of the current subtree."
  853. (outline-back-to-heading)
  854. (let ((first t)
  855. (level (funcall outline-level)))
  856. (while (and (not (eobp))
  857. (or first (> (funcall outline-level) level)))
  858. (setq first nil)
  859. (outline-next-heading))
  860. (if (and (bolp) (not (eolp)))
  861. ;; We stopped at a nonempty line (the next heading).
  862. (progn
  863. ;; Go to end of line before heading
  864. (forward-char -1)
  865. (if (and outline-blank-line (bolp))
  866. ;; leave blank line before heading
  867. (forward-char -1))))))
  868. (defun outline-show-branches ()
  869. "Show all subheadings of this heading, but not their bodies."
  870. (interactive)
  871. (outline-show-children 1000))
  872. (define-obsolete-function-alias
  873. 'show-branches 'outline-show-branches "25.1")
  874. (defun outline-show-children (&optional level)
  875. "Show all direct subheadings of this heading.
  876. Prefix arg LEVEL is how many levels below the current level should be shown.
  877. Default is enough to cause the following heading to appear."
  878. (interactive "P")
  879. (setq level
  880. (if level (prefix-numeric-value level)
  881. (save-excursion
  882. (outline-back-to-heading)
  883. (let ((start-level (funcall outline-level)))
  884. (outline-next-heading)
  885. (if (eobp)
  886. 1
  887. (max 1 (- (funcall outline-level) start-level)))))))
  888. (let (outline-view-change-hook)
  889. (save-excursion
  890. (outline-back-to-heading)
  891. (setq level (+ level (funcall outline-level)))
  892. (outline-map-region
  893. (lambda ()
  894. (if (<= (funcall outline-level) level)
  895. (outline-show-heading)))
  896. (point)
  897. (progn (outline-end-of-subtree)
  898. (if (eobp) (point-max) (1+ (point)))))))
  899. (run-hooks 'outline-view-change-hook))
  900. (define-obsolete-function-alias
  901. 'show-children 'outline-show-children "25.1")
  902. (defun outline-up-heading (arg &optional invisible-ok)
  903. "Move to the visible heading line of which the present line is a subheading.
  904. With argument, move up ARG levels.
  905. If INVISIBLE-OK is non-nil, also consider invisible lines."
  906. (interactive "p")
  907. (and (eq this-command 'outline-up-heading)
  908. (or (eq last-command 'outline-up-heading) (push-mark)))
  909. (outline-back-to-heading invisible-ok)
  910. (let ((start-level (funcall outline-level)))
  911. (when (<= start-level 1)
  912. (error "Already at top level of the outline"))
  913. (while (and (> start-level 1) (> arg 0) (not (bobp)))
  914. (let ((level start-level))
  915. (while (not (or (< level start-level) (bobp)))
  916. (if invisible-ok
  917. (outline-previous-heading)
  918. (outline-previous-visible-heading 1))
  919. (setq level (funcall outline-level)))
  920. (setq start-level level))
  921. (setq arg (- arg 1))))
  922. (looking-at outline-regexp))
  923. (defun outline-forward-same-level (arg)
  924. "Move forward to the ARG'th subheading at same level as this one.
  925. Stop at the first and last subheadings of a superior heading."
  926. (interactive "p")
  927. (outline-back-to-heading)
  928. (while (> arg 0)
  929. (let ((point-to-move-to (save-excursion
  930. (outline-get-next-sibling))))
  931. (if point-to-move-to
  932. (progn
  933. (goto-char point-to-move-to)
  934. (setq arg (1- arg)))
  935. (progn
  936. (setq arg 0)
  937. (error "No following same-level heading"))))))
  938. (defun outline-get-next-sibling ()
  939. "Move to next heading of the same level, and return point.
  940. If there is no such heading, return nil."
  941. (let ((level (funcall outline-level)))
  942. (outline-next-visible-heading 1)
  943. (while (and (not (eobp)) (> (funcall outline-level) level))
  944. (outline-next-visible-heading 1))
  945. (if (or (eobp) (< (funcall outline-level) level))
  946. nil
  947. (point))))
  948. (defun outline-backward-same-level (arg)
  949. "Move backward to the ARG'th subheading at same level as this one.
  950. Stop at the first and last subheadings of a superior heading."
  951. (interactive "p")
  952. (outline-back-to-heading)
  953. (while (> arg 0)
  954. (let ((point-to-move-to (save-excursion
  955. (outline-get-last-sibling))))
  956. (if point-to-move-to
  957. (progn
  958. (goto-char point-to-move-to)
  959. (setq arg (1- arg)))
  960. (progn
  961. (setq arg 0)
  962. (error "No previous same-level heading"))))))
  963. (defun outline-get-last-sibling ()
  964. "Move to previous heading of the same level, and return point.
  965. If there is no such heading, return nil."
  966. (let ((opoint (point))
  967. (level (funcall outline-level)))
  968. (outline-previous-visible-heading 1)
  969. (when (and (/= (point) opoint) (outline-on-heading-p))
  970. (while (and (> (funcall outline-level) level)
  971. (not (bobp)))
  972. (outline-previous-visible-heading 1))
  973. (if (< (funcall outline-level) level)
  974. nil
  975. (point)))))
  976. (defun outline-headers-as-kill (beg end)
  977. "Save the visible outline headers between BEG and END to the kill ring.
  978. Text shown between the headers isn't copied. Two newlines are
  979. inserted between saved headers. Yanking the result may be a
  980. convenient way to make a table of contents of the buffer."
  981. (interactive "r")
  982. (save-excursion
  983. (save-restriction
  984. (narrow-to-region beg end)
  985. (goto-char (point-min))
  986. (let ((buffer (current-buffer))
  987. start end)
  988. (with-temp-buffer
  989. (with-current-buffer buffer
  990. ;; Boundary condition: starting on heading:
  991. (when (outline-on-heading-p)
  992. (outline-back-to-heading)
  993. (setq start (point)
  994. end (progn (outline-end-of-heading)
  995. (point)))
  996. (insert-buffer-substring buffer start end)
  997. (insert "\n\n")))
  998. (let ((temp-buffer (current-buffer)))
  999. (with-current-buffer buffer
  1000. (while (outline-next-heading)
  1001. (unless (outline-invisible-p)
  1002. (setq start (point)
  1003. end (progn (outline-end-of-heading) (point)))
  1004. (with-current-buffer temp-buffer
  1005. (insert-buffer-substring buffer start end)
  1006. (insert "\n\n"))))))
  1007. (kill-new (buffer-string)))))))
  1008. (provide 'outline)
  1009. (provide 'noutline)
  1010. ;;; outline.el ends here