Mercurial > emacs
comparison lisp/allout.el @ 7527:1f09079e18c4
(outline-mode): Use outline-this-or-next-heading.
(outline-this-or-next-heading): New function.
(outline-mode): Fixed topic body reindentation scheme
so programming code is not indented unless
`outline-reindent-bodies' has value `force'.
(outline-infer-reindent-bodies): Implement above.
(outline-reindent-bodies): Doc fix.
(outline-init): New user interface for control of
outline-mode session setup. Sets up `outline-find-file-hook',
`outline-layout', and `outline-auto-activation'.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 17 May 1994 09:48:53 +0000 |
parents | d1cbb5dd3434 |
children | 67b7d1ea7b2e |
comparison
equal
deleted
inserted
replaced
7526:bf357bdc648e | 7527:1f09079e18c4 |
---|---|
1 ;;;_* allout.el - Extensive outline mode for use alone and with other modes. | 1 ;;;_* allout.el - Extensive outline mode for use alone and with other modes. |
2 | 2 |
3 ;;;_* Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Ken Manheimer <klm@nist.gov> | 5 ;; Author: Ken Manheimer <klm@nist.gov> |
6 ;; Maintainer: Ken Manheimer <klm@nist.gov> | 6 ;; Maintainer: Ken Manheimer <klm@nist.gov> |
7 ;; Created: Dec 1991 - first release to usenet | 7 ;; Created: Dec 1991 - first release to usenet |
8 ;; Version: $Id: allout.el,v 1.7 1994/05/09 06:36:19 rms Exp rms $|| | 8 ;; Version: Id: allout.el,v 4.3 1994/05/12 17:43:08 klm Exp || |
9 ;; Keywords: outline mode | 9 ;; Keywords: outline mode |
10 | 10 |
11 ;; This file is part of GNU Emacs. | 11 ;; This file is part of GNU Emacs. |
12 | 12 |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | 13 ;; GNU Emacs is free software; you can redistribute it and/or modify |
381 [This feature no longer depends in any way on the 'filladapt.el' | 381 [This feature no longer depends in any way on the 'filladapt.el' |
382 lisp-archive package.]") | 382 lisp-archive package.]") |
383 (make-variable-buffer-local 'outline-use-hanging-indents) | 383 (make-variable-buffer-local 'outline-use-hanging-indents) |
384 | 384 |
385 ;;;_ = outline-reindent-bodies | 385 ;;;_ = outline-reindent-bodies |
386 (defvar outline-reindent-bodies outline-use-hanging-indents | 386 (defvar outline-reindent-bodies (if outline-use-hanging-indents |
387 'text) | |
387 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts. | 388 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts. |
388 | 389 |
389 Indented hanging bodies are adjusted to remain even with \(or | 390 When active, topic body lines that are indented even with or beyond |
390 right-indented from\) the beginning of heading text.") | 391 their topic header are reindented to correspond with depth shifts of |
392 the header. | |
393 | |
394 A value of `t' enables reindent in non-programming-code buffers, ie | |
395 those that do not have the variable `comment-start' set. A value of | |
396 `force' enables reindent whether or not `comment-start' is set.") | |
397 | |
391 (make-variable-buffer-local 'outline-reindent-bodies) | 398 (make-variable-buffer-local 'outline-reindent-bodies) |
392 | 399 |
393 ;;;_ = outline-inhibit-protection | 400 ;;;_ = outline-inhibit-protection |
394 (defvar outline-inhibit-protection nil | 401 (defvar outline-inhibit-protection nil |
395 "*Non-nil disables warnings and confirmation-checks for concealed-text edits. | 402 "*Non-nil disables warnings and confirmation-checks for concealed-text edits. |
406 | 413 |
407 ;;;_ #1 Internal Outline Formatting and Configuration | 414 ;;;_ #1 Internal Outline Formatting and Configuration |
408 ;;;_ - Version | 415 ;;;_ - Version |
409 ;;;_ = outline-version | 416 ;;;_ = outline-version |
410 (defvar outline-version | 417 (defvar outline-version |
411 (let ((rcs-rev "$Revision: 1.7 $")) | 418 (let ((rcs-rev "Revision: 4.3")) |
412 (condition-case err | 419 (condition-case err |
413 (save-match-data | 420 (save-match-data |
414 (string-match "\\$Revision: \\([0-9]+\\.[0-9]+\\)" rcs-rev) | 421 (string-match "Revision: \\([0-9]+\\.[0-9]+\\)" rcs-rev) |
415 (substring rcs-rev (match-beginning 1) (match-end 1))) | 422 (substring rcs-rev (match-beginning 1) (match-end 1))) |
416 (error rcs-rev))) | 423 (error rcs-rev))) |
417 "Revision number of currently loaded outline package. (Currently | 424 "Revision number of currently loaded outline package. \(allout.el)") |
418 specific to allout.el.)") | |
419 ;;;_ > outline-version | 425 ;;;_ > outline-version |
420 (defun outline-version (&optional here) | 426 (defun outline-version (&optional here) |
421 "Return string describing the loaded outline version." | 427 "Return string describing the loaded outline version." |
422 (interactive "P") | 428 (interactive "P") |
423 (let ((msg (concat "Allout Outline Mode v " outline-version))) | 429 (let ((msg (concat "Allout Outline Mode v " outline-version))) |
466 (defvar outline-plain-bullets-string-len (length outline-plain-bullets-string) | 472 (defvar outline-plain-bullets-string-len (length outline-plain-bullets-string) |
467 "Length of outline-plain-bullets-string, updated by set-outline-regexp.") | 473 "Length of outline-plain-bullets-string, updated by set-outline-regexp.") |
468 (make-variable-buffer-local 'outline-plain-bullets-string-len) | 474 (make-variable-buffer-local 'outline-plain-bullets-string-len) |
469 | 475 |
470 | 476 |
471 ;;;_ > outline-reset-header-lead (header-lead) | 477 ;;;_ X outline-reset-header-lead (header-lead) |
472 (defun outline-reset-header-lead (header-lead) | 478 (defun outline-reset-header-lead (header-lead) |
473 "*Reset the leading string used to identify topic headers." | 479 "*Reset the leading string used to identify topic headers." |
474 (interactive "sNew lead string: ") | 480 (interactive "sNew lead string: ") |
475 (setq outline-header-prefix header-lead) | 481 (setq outline-header-prefix header-lead) |
476 (setq outline-header-subtraction (1- (length outline-header-prefix))) | 482 (setq outline-header-subtraction (1- (length outline-header-prefix))) |
477 (set-outline-regexp)) | 483 (set-outline-regexp)) |
478 ;;;_ > outline-lead-with-comment-string (header-lead) | 484 ;;;_ X outline-lead-with-comment-string (header-lead) |
479 (defun outline-lead-with-comment-string (&optional header-lead) | 485 (defun outline-lead-with-comment-string (&optional header-lead) |
480 "*Set the topic-header leading string to specified string. | 486 "*Set the topic-header leading string to specified string. |
481 | 487 |
482 Useful when for encapsulating outline structure in programming | 488 Useful when for encapsulating outline structure in programming |
483 language comments. Returns the leading string." | 489 language comments. Returns the leading string." |
487 (setq header-lead (read-string | 493 (setq header-lead (read-string |
488 "String prefix for topic headers: "))) | 494 "String prefix for topic headers: "))) |
489 (setq outline-reindent-bodies nil) | 495 (setq outline-reindent-bodies nil) |
490 (outline-reset-header-lead header-lead) | 496 (outline-reset-header-lead header-lead) |
491 header-lead) | 497 header-lead) |
492 ;;;_ > outline-infer-header-lead (&optional reset) | 498 ;;;_ > outline-infer-header-lead () |
493 (defun outline-infer-header-lead (&optional set) | 499 (defun outline-infer-header-lead () |
494 "Determine appropriate `outline-header-prefix'. | 500 "Determine appropriate `outline-header-prefix'. |
495 | 501 |
496 Works according to settings of: | 502 Works according to settings of: |
497 | 503 |
504 `comment-start' | |
498 `outline-header-prefix' (default) | 505 `outline-header-prefix' (default) |
499 `outline-use-mode-specific-leader' | 506 `outline-use-mode-specific-leader' |
500 and `outline-mode-leaders'. | 507 and `outline-mode-leaders'. |
501 | 508 |
502 Optional arg SET means to do the processing to establish that prefix | 509 Apply this via \(re\)activation of `outline-mode', rather than |
503 for current outline processing, if it has changed from prior setting." | 510 invoking it directly." |
504 (let* ((use-leader (and (boundp 'outline-use-mode-specific-leader) | 511 (let* ((use-leader (and (boundp 'outline-use-mode-specific-leader) |
505 (if (or (stringp outline-use-mode-specific-leader) | 512 (if (or (stringp outline-use-mode-specific-leader) |
506 (memq outline-use-mode-specific-leader | 513 (memq outline-use-mode-specific-leader |
507 '(outline-mode-leaders | 514 '(outline-mode-leaders |
508 comment-start | 515 comment-start |
535 (if (not leader) | 542 (if (not leader) |
536 nil | 543 nil |
537 (if (string= leader outline-header-prefix) | 544 (if (string= leader outline-header-prefix) |
538 nil ; no change, nothing to do. | 545 nil ; no change, nothing to do. |
539 (setq outline-header-prefix leader) | 546 (setq outline-header-prefix leader) |
540 (if set (outline-reset-header-lead outline-header-prefix)) | |
541 outline-header-prefix)))) | 547 outline-header-prefix)))) |
548 ;;;_ > outline-infer-body-reindent () | |
549 (defun outline-infer-body-reindent () | |
550 "Determine proper setting for `outline-reindent-bodies'. | |
551 | |
552 Depends on default setting of `outline-reindent-bodies' \(which see) | |
553 and presence of setting for `comment-start', to tell whether the | |
554 file is programming code." | |
555 (if (and outline-reindent-bodies | |
556 comment-start | |
557 (not (eq 'force outline-reindent-bodies))) | |
558 (setq outline-reindent-bodies nil))) | |
542 ;;;_ > set-outline-regexp () | 559 ;;;_ > set-outline-regexp () |
543 (defun set-outline-regexp () | 560 (defun set-outline-regexp () |
544 "Generate proper topic-header regexp form for outline functions. | 561 "Generate proper topic-header regexp form for outline functions. |
545 | 562 |
546 Works with respect to `outline-plain-bullets-string' and | 563 Works with respect to `outline-plain-bullets-string' and |
738 ;;;_ = outline-explicitly-deactivated | 755 ;;;_ = outline-explicitly-deactivated |
739 (defvar outline-explicitly-deactivated nil | 756 (defvar outline-explicitly-deactivated nil |
740 "Outline-mode was last deliberately deactived. | 757 "Outline-mode was last deliberately deactived. |
741 So outline-post-command-business should not reactivate it...") | 758 So outline-post-command-business should not reactivate it...") |
742 (make-variable-buffer-local 'outline-explicitly-deactivated) | 759 (make-variable-buffer-local 'outline-explicitly-deactivated) |
743 ;;;_ > outline-init (mode) | 760 ;;;_ > outline-init (&optional mode) |
744 (defun outline-init (mode) | 761 (defun outline-init (&optional mode) |
745 "Prime outline-mode to enable/disable auto-activation, wrt `outline-layout'. | 762 "Prime outline-mode to enable/disable auto-activation, wrt `outline-layout'. |
746 | 763 |
747 MODE is one of: | 764 MODE is one of the following symbols: |
748 | 765 |
749 - nil, for no auto-activation, | 766 - nil \(or no argument) deactivate auto-activation/layou; |
750 - `activation', for auto-activation only, | 767 - 'activate', enable auto-activation only; |
751 - `ask' for auto-activation and auto-layout on confirmation from user, | 768 - 'ask', enable auto-activation, and enable auto-layout but with |
752 - anything else, for auto-activation and auto-layout, without any | 769 confirmation for layout operation solicitated from user each time; |
753 confirmation check. | 770 - 'report', just report and return the current auto-activation state; |
771 - anything else \(eg, t) for auto-activation and auto-layout, without | |
772 any confirmation check. | |
754 | 773 |
755 Use this function to setup your emacs session for automatic activation | 774 Use this function to setup your emacs session for automatic activation |
756 of allout outline mode, contingent to the buffer-specific setting of | 775 of allout outline mode, contingent to the buffer-specific setting of |
757 the `outline-layout' variable. (See `outline-layout' and | 776 the `outline-layout' variable. (See `outline-layout' and |
758 `outline-expose-topic' docstrings for more details on auto layout). | 777 `outline-expose-topic' docstrings for more details on auto layout). |
765 the following two lines in your emacs init file: | 784 the following two lines in your emacs init file: |
766 | 785 |
767 \(require 'allout) | 786 \(require 'allout) |
768 \(outline-init t)" | 787 \(outline-init t)" |
769 | 788 |
770 (if (not mode) | 789 (interactive) |
790 (if (interactive-p) | |
771 (progn | 791 (progn |
772 (setq find-file-hooks (delq 'outline-find-file-hook find-file-hooks)) | 792 (setq mode |
773 (if (interactive-p) | 793 (completing-read |
774 (message "Allout outline mode auto-activation inhibited."))) | 794 (concat "Select outline auto setup mode " |
775 (add-hook 'find-file-hooks 'outline-find-file-hook) | 795 "(empty for report, ? for options) ") |
776 (setq outline-auto-activation | 796 '(("nil")("full")("activate")("deactivate") |
777 (cond ((eq mode 'activation) | 797 ("ask") ("report") ("")) |
778 (message "Allout outline mode auto-activation enabled.") | 798 nil |
779 'activate) | 799 t)) |
780 ((eq mode 'ask) | 800 (if (string= mode "") |
781 (message "Allout outline mode auto-activation enabled.") | 801 (setq mode 'report) |
782 'ask) | 802 (setq mode (intern-soft mode))))) |
783 ((message | 803 (let |
784 "Allout outline mode auto-activation and -layout enabled.") | 804 ;; convenience aliases, for consistent ref to respective vars: |
785 t))))) | 805 ((hook 'outline-find-file-hook) |
806 (curr-mode 'outline-auto-activation)) | |
807 | |
808 (cond ((not mode) | |
809 (setq find-file-hooks (delq hook find-file-hooks)) | |
810 (if (interactive-p) | |
811 (message "Allout outline mode auto-activation inhibited."))) | |
812 ((eq mode 'report) | |
813 (if (not (memq hook find-file-hooks)) | |
814 (outline-init nil) | |
815 ;; Just punt and use the reports from each of the modes: | |
816 (outline-init (symbol-value curr-mode)))) | |
817 (t (add-hook 'find-file-hooks hook) | |
818 (set curr-mode ; 'set', not 'setq'! | |
819 (cond ((eq mode 'activate) | |
820 (message | |
821 "Outline mode auto-activation enabled.") | |
822 'activate) | |
823 ((eq mode 'report) | |
824 ;; Return the current mode setting: | |
825 (outline-init mode)) | |
826 ((eq mode 'ask) | |
827 (message | |
828 (concat "Outline mode auto-activation and " | |
829 "-layout \(upon confirmation) enabled.")) | |
830 'ask) | |
831 ((message | |
832 "Outline mode auto-activation and -layout enabled.") | |
833 'full))))))) | |
834 | |
786 ;;;_ > outline-mode (&optional toggle) | 835 ;;;_ > outline-mode (&optional toggle) |
787 ;;;_ : Defun: | 836 ;;;_ : Defun: |
788 (defun outline-mode (&optional toggle) | 837 (defun outline-mode (&optional toggle) |
789 ;;;_ . Doc string: | 838 ;;;_ . Doc string: |
790 "Toggle minor mode for controlling exposure and editing of text outlines. | 839 "Toggle minor mode for controlling exposure and editing of text outlines. |
1047 (progn ; Inhibit all the fancy formatting: | 1096 (progn ; Inhibit all the fancy formatting: |
1048 (outline-resumptions 'outline-primary-bullet '("*")) | 1097 (outline-resumptions 'outline-primary-bullet '("*")) |
1049 (outline-resumptions 'outline-old-style-prefixes '(())))) | 1098 (outline-resumptions 'outline-old-style-prefixes '(())))) |
1050 | 1099 |
1051 (outline-infer-header-lead) | 1100 (outline-infer-header-lead) |
1101 (outline-infer-body-reindent) | |
1052 | 1102 |
1053 (set-outline-regexp) | 1103 (set-outline-regexp) |
1054 | 1104 |
1055 ; Produce map from current version | 1105 ; Produce map from current version |
1056 ; of outline-keybindings-list: | 1106 ; of outline-keybindings-list: |
1126 | 1176 |
1127 (run-hooks 'outline-mode-hook) | 1177 (run-hooks 'outline-mode-hook) |
1128 (setq outline-mode t)) | 1178 (setq outline-mode t)) |
1129 | 1179 |
1130 ;; Reactivation: | 1180 ;; Reactivation: |
1131 ((setq do-layout t)) | 1181 ((setq do-layout t) |
1182 (outline-infer-body-reindent)) | |
1132 ) ; cond | 1183 ) ; cond |
1133 | 1184 |
1134 (if (and do-layout | 1185 (if (and do-layout |
1135 outline-auto-activation | 1186 outline-auto-activation |
1136 (listp outline-layout) | 1187 (listp outline-layout) |
1138 (if (eq outline-auto-activation 'ask) | 1189 (if (eq outline-auto-activation 'ask) |
1139 (if (y-or-n-p (format "Expose %s with layout '%s'? " | 1190 (if (y-or-n-p (format "Expose %s with layout '%s'? " |
1140 (buffer-name) | 1191 (buffer-name) |
1141 outline-layout)) | 1192 outline-layout)) |
1142 t | 1193 t |
1143 (message "Not doing %s layout.") | 1194 (message "Skipped %s layout." (buffer-name)) |
1144 nil) | 1195 nil) |
1145 t))) | 1196 t))) |
1146 (save-excursion | 1197 (save-excursion |
1147 (message "Adjusting '%s' exposure..." (buffer-name)) | 1198 (message "Adjusting '%s' exposure..." (buffer-name)) |
1148 (goto-char 0) | 1199 (goto-char 0) |
1149 (if (not (outline-goto-prefix)) | 1200 (outline-this-or-next-heading) |
1150 (outline-next-heading)) | 1201 (condition-case err |
1151 (apply 'outline-expose-topic (list outline-layout)) | 1202 (progn |
1152 (message "Adjusting '%s' exposure... done." (buffer-name)))) | 1203 (apply 'outline-expose-topic (list outline-layout)) |
1204 (message "Adjusting '%s' exposure... done." (buffer-name))) | |
1205 ;; Problem applying exposure - notify user, but don't | |
1206 ;; interrupt, eg, file visit: | |
1207 (error (message "%s" (car (cdr err))) | |
1208 (sit-for 1))))) | |
1153 outline-mode | 1209 outline-mode |
1154 ) ; let* | 1210 ) ; let* |
1155 ) ; defun | 1211 ) ; defun |
1156 | 1212 |
1157 ;;;_ #3 Internal Position State-Tracking - "outline-recent-*" funcs | 1213 ;;;_ #3 Internal Position State-Tracking - "outline-recent-*" funcs |
1311 (progn ; Got valid location state - set vars: | 1367 (progn ; Got valid location state - set vars: |
1312 (outline-prefix-data | 1368 (outline-prefix-data |
1313 (goto-char (or (match-beginning 2) | 1369 (goto-char (or (match-beginning 2) |
1314 outline-recent-prefix-beginning)) | 1370 outline-recent-prefix-beginning)) |
1315 (or (match-end 2) outline-recent-prefix-end))))) | 1371 (or (match-end 2) outline-recent-prefix-end))))) |
1372 ;;;_ : outline-this-or-next-heading | |
1373 (defun outline-this-or-next-heading () | |
1374 "Position cursor on current or next heading." | |
1375 ;; A throwaway non-macro that is defined after outline-next-heading | |
1376 ;; and usable by outline-mode. | |
1377 (if (not (outline-goto-prefix)) (outline-next-heading))) | |
1316 ;;;_ > outline-previous-heading () | 1378 ;;;_ > outline-previous-heading () |
1317 (defmacro outline-previous-heading () | 1379 (defmacro outline-previous-heading () |
1318 "Move to the prior \(possibly invisible) heading line. | 1380 "Move to the prior \(possibly invisible) heading line. |
1319 | 1381 |
1320 Return the location of the beginning of the heading, or nil if not found." | 1382 Return the location of the beginning of the heading, or nil if not found." |
4275 ;;;Local variables: | 4337 ;;;Local variables: |
4276 ;;;outline-layout: (0 : -1 -1 0) | 4338 ;;;outline-layout: (0 : -1 -1 0) |
4277 ;;;End: | 4339 ;;;End: |
4278 | 4340 |
4279 ;; allout.el ends here | 4341 ;; allout.el ends here |
4280 |