comparison lisp/textmodes/ooutline.el @ 6175:340f5eb2e8b6

(outline-on-heading-p): Use bolp. (show-children): Use outline-back-to-heading. (outline-next-preface): Don't retreat over \n or ^M if no more headers.
author Richard M. Stallman <rms@gnu.org>
date Thu, 03 Mar 1994 19:17:47 +0000
parents 2f02deab5b9e
children ec7e22ebd6b3
comparison
equal deleted inserted replaced
6174:3902f1241d1c 6175:340f5eb2e8b6
232 232
233 (defun outline-next-preface () 233 (defun outline-next-preface ()
234 "Skip forward to just before the next heading line." 234 "Skip forward to just before the next heading line."
235 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)") 235 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
236 nil 'move) 236 nil 'move)
237 (goto-char (match-beginning 0))) 237 (progn
238 (if (memq (preceding-char) '(?\n ?\^M)) 238 (goto-char (match-beginning 0))
239 (forward-char -1))) 239 (if (memq (preceding-char) '(?\n ?\^M))
240 (forward-char -1)))))
240 241
241 (defun outline-next-heading () 242 (defun outline-next-heading ()
242 "Move to the next (possibly invisible) heading line." 243 "Move to the next (possibly invisible) heading line."
243 (interactive) 244 (interactive)
244 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)") 245 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
245 nil 'move) 246 nil 'move)
246 (goto-char (1+ (match-beginning 0))))) 247 (goto-char (1+ (match-beginning 0)))))
247 248
248 (defun outline-back-to-heading () 249 (defun outline-back-to-heading ()
249 "Move to previous (possibly invisible) heading line, 250 "Move to previous heading line, or beg of this line if it's a heading.
250 or to the beginning of this line if it is a heading line." 251 Only visible heading lines are considered."
251 (beginning-of-line) 252 (beginning-of-line)
252 (or (outline-on-heading-p) 253 (or (outline-on-heading-p)
253 (re-search-backward (concat "^\\(" outline-regexp "\\)") nil 'move))) 254 (re-search-backward (concat "^\\(" outline-regexp "\\)") nil 'move)))
254 255
255 (defun outline-on-heading-p () 256 (defun outline-on-heading-p ()
256 "Return T if point is on a header line." 257 "Return T if point is on a (visible) heading line."
257 (save-excursion 258 (save-excursion
258 (beginning-of-line) 259 (beginning-of-line)
259 (and (eq (preceding-char) ?\n) 260 (and (bobp)
260 (looking-at outline-regexp)))) 261 (looking-at outline-regexp))))
261 262
262 (defun outline-end-of-heading () 263 (defun outline-end-of-heading ()
263 (if (re-search-forward outline-heading-end-regexp nil 'move) 264 (if (re-search-forward outline-heading-end-regexp nil 'move)
264 (forward-char -1))) 265 (forward-char -1)))
421 Default is enough to cause the following heading to appear." 422 Default is enough to cause the following heading to appear."
422 (interactive "P") 423 (interactive "P")
423 (setq level 424 (setq level
424 (if level (prefix-numeric-value level) 425 (if level (prefix-numeric-value level)
425 (save-excursion 426 (save-excursion
426 (beginning-of-line) 427 (outline-back-to-heading)
427 (let ((start-level (funcall outline-level))) 428 (let ((start-level (funcall outline-level)))
428 (outline-next-heading) 429 (outline-next-heading)
429 (if (eobp) 430 (if (eobp)
430 1 431 1
431 (max 1 (- (funcall outline-level) start-level))))))) 432 (max 1 (- (funcall outline-level) start-level)))))))
432 (save-excursion 433 (save-excursion
433 (save-restriction 434 (save-restriction
434 (beginning-of-line) 435 (outline-back-to-heading)
435 (setq level (+ level (funcall outline-level))) 436 (setq level (+ level (funcall outline-level)))
436 (narrow-to-region (point) 437 (narrow-to-region (point)
437 (progn (outline-end-of-subtree) 438 (progn (outline-end-of-subtree)
438 (if (eobp) (point-max) (1+ (point))))) 439 (if (eobp) (point-max) (1+ (point)))))
439 (goto-char (point-min)) 440 (goto-char (point-min))
440 (while (and (not (eobp)) 441 (while (and (not (eobp))
441 (progn 442 (progn
442 (outline-next-heading) 443 (outline-next-heading)
443 (not (eobp)))) 444 (not (eobp))))
444 (if (<= (funcall outline-level) level) 445 (if (<= (funcall outline-level) level)
445 (save-excursion 446 (save-excursion
446 (outline-flag-region (save-excursion 447 (outline-flag-region (save-excursion
447 (forward-char -1) 448 (forward-char -1)
448 (if (memq (preceding-char) '(?\n ?\^M)) 449 (if (memq (preceding-char) '(?\n ?\^M))
449 (forward-char -1)) 450 (forward-char -1))
450 (point)) 451 (point))
451 (progn (outline-end-of-heading) (point)) 452 (progn (outline-end-of-heading) (point))
452 ?\n))))))) 453 ?\n)))))))
453 454
454 (defun outline-up-heading (arg) 455 (defun outline-up-heading (arg)
455 "Move to the heading line of which the present line is a subheading. 456 "Move to the heading line of which the present line is a subheading.
456 With argument, move up ARG levels." 457 With argument, move up ARG levels."
457 (interactive "p") 458 (interactive "p")