;; previous-page C-x C-p C-p
;; search-pages C-x C-p C-s
;; add-new-page C-x C-p C-a
-;; sort-pages-buffer C-x C-p s
+;; sort-pages-buffer C-x C-p s
;; set-page-delimiter C-x C-p C-l
-;; pages-directory C-x C-p C-d
+;; pages-directory C-x C-p C-d
;; pages-directory-for-addresses C-x C-p d
;; pages-directory-goto C-c C-c
\f
;;; Using the page commands
-
+
;; The page commands are helpful in several different contexts. For
;; example, programmers often divide source files into sections using the
;; `page-delimiter'; you can use the `pages-directory' command to list
;; the `pages-directory' or `pages-directory-for-addresses' command.
;; Specifically:
-;;
+;;
;; 1. Begin each entry with a `page-delimiter' (which is, by default,
;; `^L' at the beginning of the line).
-;;
+;;
;; 2. The first line of text in each entry is the `heading line'; it
;; will appear in the pages-directory-buffer which is constructed
;; using the `C-x C-p C-d' (pages-directory) command or the `C-x
;; C-p d' (pages-directory-for-addresses) command.
-;;
+;;
;; The heading line may be on the same line as the page-delimiter
;; or it may follow after. It is the first non-blank line on the
;; page. Conventionally, the heading line is placed on the line
;; line of the body.
;; For example, a file might look like this:
-;;
+;;
;; FSF
;; Free Software Foundation
;; 59 Temple Place - Suite 330
;; Boston, MA 02111-1307 USA.
;; (617) 542-5942
;; gnu@gnu.org
-;;
+;;
;; \f
;; House Subcommittee on Intellectual Property,
;; U.S. House of Representatives,
;; Washington, DC 20515
-;;
+;;
;; Congressional committee concerned with permitting or preventing
;; monopolistic restrictions on the use of software technology.
-;;
+;;
;; \f
;; George Lakoff
;; ``Women, Fire, and Dangerous Things:
;; What Categories Reveal about the Mind''
;; 1987, Univ. of Chicago Press
-;;
+;;
;; About philosophy, Whorfian effects, and linguistics.
-;;
-;; \f
+;;
+;; \f
;; OBI (On line text collection.)
;; Open Book Initiative
;; c/o Software Tool & Die
;; 1330 Beacon St, Brookline, MA 02146 USA
-;; (617) 739-0202
+;; (617) 739-0202
;; obi@world.std.com
;; In this example, the heading lines are:
;; match the telephone area code of the first and fourth entries, so
;; only the header lines of those two entries would appear in the
;; pages-directory-buffer.
-;;
+;;
;; Called with a numeric argument, the `pages-directory' command
;; lists the number of lines in each page. This is helpful when you
-;; are printing hardcopy.
+;; are printing hardcopy.
;; Called with a negative numeric argument, the `pages-directory'
;; command lists the lengths of pages whose contents match a regexp.
pages-directory-for-adding-page-narrowing-p variable
is non-nil.
-Page begins with a `^L' as the default page-delimiter.
+Page begins with a `^L' as the default page-delimiter.
Use \\[set-page-delimiter] to change the page-delimiter.
Point is left in the body of page."
(interactive "sHeader line: ")
(widen)
;; If in pages directory buffer
- (if (eq major-mode 'pages-directory-mode)
+ (if (eq major-mode 'pages-directory-mode)
(progn
;; Add new page before or after current page?
(if pages-directory-for-adding-new-page-before-current-page-p
(format "%s\n"
;; Remove leading `^' from page-delimiter string
(if (eq '^ (car (read-from-string page-delimiter)))
- (substring page-delimiter 1))))
+ (substring page-delimiter 1))))
(goto-char (point-min))))
;; Insert page delimiter at beginning of line.
(if (not (looking-at "^.")) (forward-line 1))
- (insert (format "%s\n%s\n\n\n"
+ (insert (format "%s\n%s\n\n\n"
(if (eq '^ (car (read-from-string page-delimiter)))
(substring page-delimiter 1))
header-line))
(autoload 'sort-subr "sort" "Primary function for sorting." t nil)
(defun sort-pages-in-region (reverse beg end)
- "Sort pages in region alphabetically. Prefix arg means reverse order.
+ "Sort pages in region alphabetically. Prefix arg means reverse order.
Called from a program, there are three arguments:
REVERSE (non-nil means reverse order), BEG and END (region to sort)."
(goto-char (point-max))))))))
(defun sort-pages-buffer (&optional reverse)
- "Sort pages alphabetically in buffer. Prefix arg means reverse order.
+ "Sort pages alphabetically in buffer. Prefix arg means reverse order.
\(Non-nil arg if not interactive.\)"
(interactive "P")
(defvar pages-pos-list nil
"List containing the positions of the pages in the pages-buffer.")
-(defvar pages-directory-map nil
- "Keymap for the pages-directory-buffer.")
+(defvar pages-target-buffer)
-(if pages-directory-map
- ()
- (setq pages-directory-map (make-sparse-keymap))
- (define-key pages-directory-map "\C-c\C-c"
- 'pages-directory-goto)
- (define-key pages-directory-map "\C-c\C-p\C-a" 'add-new-page)
- (define-key pages-directory-map [mouse-2] 'pages-directory-goto-with-mouse))
+(defvar pages-directory-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\C-c\C-c" 'pages-directory-goto)
+ (define-key map "\C-c\C-p\C-a" 'add-new-page)
+ (define-key map [mouse-2] 'pages-directory-goto-with-mouse)
+ map)
+ "Keymap for the pages-directory-buffer.")
+(defvaralias 'pages-directory-map 'pages-directory-mode-map)
(defvar original-page-delimiter "^\f"
"Default page delimiter.")
In a program, non-nil second arg causes first arg to be ignored and
resets the page-delimiter to the original value."
-
+
(interactive
(if current-prefix-arg
(list original-page-delimiter "^\f")
If the buffer is narrowed, the `pages-directory' command creates a
directory for only the accessible portion of the buffer."
-
+
(interactive
(cond ((not current-prefix-arg)
(list t nil nil))
- ((listp current-prefix-arg)
+ ((listp current-prefix-arg)
(list nil
nil
(read-string
(or pages-directory-previous-regexp "regexp")))))
((> (prefix-numeric-value current-prefix-arg) 0)
(list t t nil))
- ((< (prefix-numeric-value current-prefix-arg) 0)
+ ((< (prefix-numeric-value current-prefix-arg) 0)
(list nil
t
(read-string
(format "Select according to `%s' (end with RET): "
(or pages-directory-previous-regexp "regexp")))))))
-
+
(if (equal regexp "")
(setq regexp pages-directory-previous-regexp)
(setq pages-directory-previous-regexp regexp))
-
+
(if (interactive-p)
(message "Creating directory for: %s "
(buffer-name)))
-
- (let ((target-buffer (current-buffer))
+
+ (let ((pages-target-buffer (current-buffer))
(pages-directory-buffer
(concat pages-directory-prefix " " (buffer-name)))
(linenum 1)
(pages-buffer-original-position (point))
(pages-buffer-original-page 0))
-
+
;; `with-output-to-temp-buffer' binds the value of the variable
;; `standard-output' to the buffer named as its first argument,
;; but does not switch to that buffer.
(pages-directory-mode)
(insert
"==== Pages Directory: use `C-c C-c' to go to page under cursor. ====" ?\n)
- (setq pages-buffer target-buffer)
+ (setq pages-buffer pages-target-buffer)
(setq pages-pos-list nil))
-
+
(if pages-list-all-headers-p
-
+
;; 1. If no prefix argument, list all headers
(save-excursion
(goto-char (point-min))
-
+
;; (a) Point is at beginning of buffer; but the first
;; page may not begin with a page-delimiter
(save-restriction
(goto-char (match-end 0)))
(narrow-to-page)
(pages-copy-header-and-position count-lines-p))
-
+
;; (b) Search within pages buffer for next page-delimiter
(while (re-search-forward page-delimiter nil t)
(pages-copy-header-and-position count-lines-p)))
-
+
;; 2. Else list headers whose pages match regexp.
(save-excursion
;; REMOVED save-restriction AND widen FROM HERE
(goto-char (point-min))
-
+
;; (a) Handle first page
(save-restriction
(narrow-to-page)
;; search for selection regexp
(if (save-excursion (re-search-forward regexp nil t))
(pages-copy-header-and-position count-lines-p)))
-
+
;; (b) Search for next page-delimiter
(while (re-search-forward page-delimiter nil t)
(save-restriction
(if (save-excursion (re-search-forward regexp nil t))
(pages-copy-header-and-position count-lines-p)
)))))
-
+
(set-buffer standard-output)
;; Put positions in increasing order to go with buffer.
(setq pages-pos-list (nreverse pages-pos-list))
(if (interactive-p)
(message "%d matching lines in: %s"
- (length pages-pos-list) (buffer-name target-buffer))))
+ (length pages-pos-list) (buffer-name pages-target-buffer))))
(pop-to-buffer pages-directory-buffer)
(sit-for 0) ; otherwise forward-line fails if N > window height.
(forward-line (if (= 0 pages-buffer-original-page)
"Copy page header and its position to the Pages Directory.
Only arg non-nil, count lines in page and insert before header.
Used by `pages-directory' function."
-
+
(let (position line-count)
(if count-lines-p
(if (<= (point) pages-buffer-original-position)
(setq pages-buffer-original-page
(1+ pages-buffer-original-page)))
-
+
(save-excursion
;; go to first non-blank char after the page-delimiter
- (skip-chars-forward " \t\n")
+ (skip-chars-forward " \t\n")
;; set the marker here; this the place to which the
- ;; `pages-directory-goto' command will go
+ ;; `pages-directory-goto' command will go
(setq position (make-marker))
(set-marker position (point))
(let ((start (point))
inserted-at)
;; change to directory buffer
(set-buffer standard-output)
- ;; record page position
+ ;; record page position
(setq pages-pos-list (cons position pages-pos-list))
;; insert page header
(setq inserted-at (point))
- (insert-buffer-substring target-buffer start end)
- (add-text-properties inserted-at (point)
+ (insert-buffer-substring pages-target-buffer start end)
+ (add-text-properties inserted-at (point)
'(mouse-face highlight
help-echo "mouse-2: go to this page"))
(put-text-property inserted-at (point) 'rear-nonsticky 'highlight))
-
+
(if count-lines-p
(save-excursion
(beginning-of-line)
(insert (format "%3d: " line-count))))
-
+
(terpri))
(end-of-line 1)))
to the same line in the pages buffer."
(kill-all-local-variables)
- (use-local-map pages-directory-map)
+ (use-local-map pages-directory-mode-map)
(setq major-mode 'pages-directory-mode)
(setq mode-name "Pages-Directory")
(make-local-variable 'pages-buffer)
(make-local-variable 'pages-pos-list)
- (make-local-variable 'pages-directory-buffer-narrowing-p))
+ (make-local-variable 'pages-directory-buffer-narrowing-p)
+ (run-mode-hooks 'pages-directory-mode-hook))
(defun pages-directory-goto ()
"Go to the corresponding line in the pages buffer."
(pos (nth pages-number pages-pos-list))
(end-of-directory-p (eobp))
(narrowing-p pages-directory-buffer-narrowing-p))
- (pop-to-buffer pages-buffer)
+ (pop-to-buffer pages-buffer)
(widen)
(if end-of-directory-p
(goto-char (point-max))
`pages-directory-goto' narrows addresses buffer to entry.
If pages-directory-for-addresses-buffer-keep-windows-p is nil,
-this command deletes other windows when it displays the addresses
+this command deletes other windows when it displays the addresses
directory."
(interactive
))
(error "No addresses file found!")))
-(defun pages-directory-address-mode ()
+(define-derived-mode pages-directory-address-mode pages-directory-mode
+ "Addresses Directory"
"Mode for handling the Addresses Directory buffer.
Move point to one of the lines in this buffer,
then use \\[pages-directory-goto] to go
to the same line in the pages buffer."
+ :syntax-table nil)
- (use-local-map pages-directory-map)
- (setq major-mode 'pages-directory-address-mode)
- (setq mode-name "Addresses Directory")
- (make-local-variable 'pages-buffer)
- (make-local-variable 'pages-pos-list)
- (make-local-variable 'pages-directory-buffer-narrowing-p))
-
-\f
-;;; Place `provide' at end of file.
(provide 'page-ext)
+;;; arch-tag: 2f311550-c6e0-4458-9c12-7f039c058bdb
;;; page-ext.el ends here