comparison lisp/textmodes/outline.el @ 20062:bf3f4dc09cc0

(outline-back-to-heading): New arg INVISIBLE-OK. (outline-on-heading-p): (show-entry): If the heading is invisible, show it too. (hide-other):
author Karl Heuer <kwzh@gnu.org>
date Wed, 15 Oct 1997 23:48:01 +0000
parents d6e501bdc16a
children ea977d99058b
comparison
equal deleted inserted replaced
20061:fb0d3082b28c 20062:bf3f4dc09cc0
318 318
319 (defsubst outline-visible () 319 (defsubst outline-visible ()
320 "Non-nil if the character after point is visible." 320 "Non-nil if the character after point is visible."
321 (not (get-char-property (point) 'invisible))) 321 (not (get-char-property (point) 'invisible)))
322 322
323 (defun outline-back-to-heading () 323 (defun outline-back-to-heading (&optional invisible-ok)
324 "Move to previous heading line, or beg of this line if it's a heading. 324 "Move to previous heading line, or beg of this line if it's a heading.
325 Only visible heading lines are considered." 325 Only visible heading lines are considered, unless INVISIBLE-OK is non-nil."
326 (beginning-of-line) 326 (beginning-of-line)
327 (or (outline-on-heading-p) 327 (or (outline-on-heading-p t)
328 (let (found) 328 (let (found)
329 (save-excursion 329 (save-excursion
330 (while (not found) 330 (while (not found)
331 (or (re-search-backward (concat "^\\(" outline-regexp "\\)") 331 (or (re-search-backward (concat "^\\(" outline-regexp "\\)")
332 nil t) 332 nil t)
333 (error "before first heading")) 333 (error "before first heading"))
334 (setq found (and (outline-visible) (point))))) 334 (setq found (and (or invisible-ok (outline-visible)) (point)))))
335 (goto-char found) 335 (goto-char found)
336 found))) 336 found)))
337 337
338 (defun outline-on-heading-p () 338 (defun outline-on-heading-p (&optional invisible-ok)
339 "Return t if point is on a (visible) heading line." 339 "Return t if point is on a (visible) heading line.
340 If INVISIBLE-OK is non-nil, an invisible heading line is ok too."
340 (save-excursion 341 (save-excursion
341 (beginning-of-line) 342 (beginning-of-line)
342 (and (bolp) (outline-visible) 343 (and (bolp) (or invisible-ok (outline-visible))
343 (looking-at outline-regexp)))) 344 (looking-at outline-regexp))))
344 345
345 (defun outline-end-of-heading () 346 (defun outline-end-of-heading ()
346 (if (re-search-forward outline-heading-end-regexp nil 'move) 347 (if (re-search-forward outline-heading-end-regexp nil 'move)
347 (forward-char -1))) 348 (forward-char -1)))
453 (outline-end-of-heading) 454 (outline-end-of-heading)
454 (save-excursion 455 (save-excursion
455 (outline-flag-region (point) (progn (outline-next-preface) (point)) t))) 456 (outline-flag-region (point) (progn (outline-next-preface) (point)) t)))
456 457
457 (defun show-entry () 458 (defun show-entry ()
458 "Show the body directly following this heading." 459 "Show the body directly following this heading.
459 (interactive) 460 Show the heading too, if it is currently invisible."
460 (save-excursion 461 (interactive)
461 (outline-flag-region (point) (progn (outline-next-preface) (point)) nil))) 462 (save-excursion
463 (outline-back-to-heading t)
464 (outline-flag-region (1- (point))
465 (progn (outline-next-preface) (point)) nil)))
462 466
463 (defun hide-body () 467 (defun hide-body ()
464 "Hide all of buffer except headings." 468 "Hide all of buffer except headings."
465 (interactive) 469 (interactive)
466 (hide-region-body (point-min) (point-max))) 470 (hide-region-body (point-min) (point-max)))
524 (show-children levels)) 528 (show-children levels))
525 ;; Move to the next, since we already found it. 529 ;; Move to the next, since we already found it.
526 (goto-char end))))) 530 (goto-char end)))))
527 531
528 (defun hide-other () 532 (defun hide-other ()
529 "Hide everything except for the current body and the parent headings." 533 "Hide everything except current body and parent and top-level headings."
530 (interactive) 534 (interactive)
531 (hide-sublevels 1) 535 (hide-sublevels 1)
532 (let ((last (point)) 536 (save-excursion
533 (pos (point))) 537 (outline-back-to-heading t)
534 (while (save-excursion 538 (show-entry)
535 (and (end-of-line 0) 539 (while (condition-case nil (progn (outline-up-heading 1) t) (error nil))
536 (not (outline-visible)))) 540 (outline-flag-region (1- (point))
537 (save-excursion 541 (save-excursion (forward-line 1) (point))
538 (beginning-of-line) 542 nil))))
539 (if (eq last (point))
540 (progn
541 (outline-next-heading)
542 (outline-flag-region last (point) nil))
543 (show-children)
544 (setq last (point)))))))
545 543
546 (defun outline-flag-subtree (flag) 544 (defun outline-flag-subtree (flag)
547 (save-excursion 545 (save-excursion
548 (outline-back-to-heading) 546 (outline-back-to-heading)
549 (outline-end-of-heading) 547 (outline-end-of-heading)