+ (interactive "r")
+ (save-excursion
+ (let*
+ ;; state vars:
+ (strings prefix pad result depth new-depth out gone-out bullet beg
+ next done)
+
+ (goto-char start)
+ (beginning-of-line)
+ ;; Goto initial topic, and register preceeding stuff, if any:
+ (if (> (allout-goto-prefix) start)
+ ;; First topic follows beginning point - register preliminary stuff:
+ (setq result (list (list 0 "" nil
+ (buffer-substring start (1- (point)))))))
+ (while (and (not done)
+ (not (eobp)) ; Loop until we've covered the region.
+ (not (> (point) end)))
+ (setq depth (allout-recent-depth) ; Current topics depth,
+ bullet (allout-recent-bullet) ; ... bullet,
+ prefix (allout-recent-prefix)
+ beg (progn (allout-end-of-prefix t) (point))) ; and beginning.
+ (setq done ; The boundary for the current topic:
+ (not (allout-next-visible-heading 1)))
+ (setq new-depth (allout-recent-depth))
+ (setq gone-out out
+ out (< new-depth depth))
+ (beginning-of-line)
+ (setq next (point))
+ (goto-char beg)
+ (setq strings nil)
+ (while (> next (point)) ; Get all the exposed text in
+ (setq strings
+ (cons (buffer-substring
+ beg
+ ;To hidden text or end of line:
+ (progn
+ (search-forward "\r"
+ (save-excursion (end-of-line)
+ (point))
+ 1)
+ (if (= (preceding-char) ?\r)
+ (1- (point))
+ (point))))
+ strings))
+ (if (< (point) next) ; Resume from after hid text, if any.
+ (forward-line 1))
+ (setq beg (point)))
+ ;; Accumulate list for this topic:
+ (setq strings (nreverse strings))
+ (setq result
+ (cons
+ (if format
+ (let ((special (if (string-match
+ (regexp-quote bullet)
+ allout-distinctive-bullets-string)
+ bullet)))
+ (cond ((listp format)
+ (list depth
+ (if allout-abbreviate-flattened-numbering
+ (allout-stringify-flat-index format
+ gone-out)
+ (allout-stringify-flat-index-plain
+ format))
+ strings
+ special))
+ ((eq format 'indent)
+ (if special
+ (list depth
+ (concat (make-string (1+ depth) ? )
+ (substring prefix -1))
+ strings)
+ (list depth
+ (make-string depth ? )
+ strings)))
+ (t (error "allout-listify-exposed: %s %s"
+ "invalid format" format))))
+ (list depth prefix strings))
+ result))
+ ;; Reasses format, if any:
+ (if (and format (listp format))
+ (cond ((= new-depth depth)
+ (setq format (cons (1+ (car format))
+ (cdr format))))
+ ((> new-depth depth) ; descending - assume by 1:
+ (setq format (cons 1 format)))
+ (t
+ ; Pop the residue:
+ (while (< new-depth depth)
+ (setq format (cdr format))
+ (setq depth (1- depth)))
+ ; And increment the current one:
+ (setq format
+ (cons (1+ (or (car format)
+ -1))
+ (cdr format)))))))
+ ;; Put the list with first at front, to last at back:
+ (nreverse result))))
+;;;_ > allout-process-exposed (&optional func from to frombuf
+;;; tobuf format)
+(defun allout-process-exposed (&optional func from to frombuf tobuf
+ format &optional start-num)
+ "Map function on exposed parts of current topic; results to another buffer.
+
+All args are options; default values itemized below.
+
+Apply FUNCTION to exposed portions FROM position TO position in buffer
+FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
+alternate presentation form:
+
+ `flat' - Present prefix as numeric section.subsection..., starting with
+ section indicated by the start-num, innermost nesting first.
+ X`flat-indented' - Prefix is like `flat' for first topic at each
+ X level, but subsequent topics have only leaf topic
+ X number, padded with blanks to line up with first.
+ `indent' \(symbol) - Convert header prefixes to all white space,
+ except for distinctive bullets.
+
+Defaults:
+ FUNCTION: `allout-insert-listified'
+ FROM: region start, if region active, else start of buffer
+ TO: region end, if region active, else end of buffer
+ FROMBUF: current buffer
+ TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
+ FORMAT: nil"
+
+ ; Resolve arguments,
+ ; defaulting if necessary:
+ (if (not func) (setq func 'allout-insert-listified))
+ (if (not (and from to))
+ (if (my-region-active-p)
+ (setq from (region-beginning) to (region-end))
+ (setq from (point-min) to (point-max))))
+ (if frombuf
+ (if (not (bufferp frombuf))
+ ;; Specified but not a buffer - get it:
+ (let ((got (get-buffer frombuf)))
+ (if (not got)
+ (error (concat "allout-process-exposed: source buffer "
+ frombuf
+ " not found."))
+ (setq frombuf got))))
+ ;; not specified - default it:
+ (setq frombuf (current-buffer)))
+ (if tobuf
+ (if (not (bufferp tobuf))
+ (setq tobuf (get-buffer-create tobuf)))
+ ;; not specified - default it:
+ (setq tobuf (concat "*" (buffer-name frombuf) " exposed*")))
+ (if (listp format)
+ (nreverse format))
+
+ (let* ((listified
+ (progn (set-buffer frombuf)
+ (allout-listify-exposed from to format))))
+ (set-buffer tobuf)
+ (mapcar func listified)
+ (pop-to-buffer tobuf)))
+
+;;;_ - Copy exposed
+;;;_ > allout-insert-listified (listified)
+(defun allout-insert-listified (listified)
+ "Insert contents of listified outline portion in current buffer.
+
+Listified is a list representing each topic header and body:
+
+ \`(depth prefix text)'
+
+or \`(depth prefix text bullet-plus)'
+
+If `bullet-plus' is specified, it is inserted just after the entire prefix."
+ (setq listified (cdr listified))
+ (let ((prefix (prog1
+ (car listified)
+ (setq listified (cdr listified))))
+ (text (prog1
+ (car listified)
+ (setq listified (cdr listified))))
+ (bullet-plus (car listified)))
+ (insert prefix)
+ (if bullet-plus (insert (concat " " bullet-plus)))
+ (while text
+ (insert (car text))
+ (if (setq text (cdr text))
+ (insert "\n")))
+ (insert "\n")))
+;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
+(defun allout-copy-exposed-to-buffer (&optional arg tobuf format)
+ "Duplicate exposed portions of current outline to another buffer.
+
+Other buffer has current buffers name with \" exposed\" appended to it.
+
+With repeat count, copy the exposed parts of only the current topic.
+
+Optional second arg TOBUF is target buffer name.
+
+Optional third arg FORMAT, if non-nil, symbolically designates an
+alternate presentation format for the outline:
+
+ `flat' - Convert topic header prefixes to numeric
+ section.subsection... identifiers.
+ `indent' - Convert header prefixes to all white space, except for
+ distinctive bullets.
+ `indent-flat' - The best of both - only the first of each level has
+ the full path, the rest have only the section number
+ of the leaf, preceded by the right amount of indentation."