1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-15 09:47:20 +00:00
emacs/lisp/textmodes/page-ext.el

793 lines
29 KiB
EmacsLisp
Raw Normal View History

;;; page-ext.el --- extended page handling commands -*- lexical-binding:t -*-
1991-04-10 16:35:52 +00:00
;; Copyright (C) 1990-1991, 1993-1994, 2001-2020 Free Software
2013-01-01 09:11:05 +00:00
;; Foundation, Inc.
;; Author: Robert J. Chassell <bob@gnu.org>
;; (according to ack.texi)
;; Keywords: wp data
1992-07-22 04:22:30 +00:00
1992-05-31 16:42:19 +00:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
1992-05-31 16:42:19 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
1992-05-31 16:42:19 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
1996-01-14 07:34:30 +00:00
;;; Commentary:
;; You may use these commands to handle an address list or other
;; small data base.
1992-05-31 16:42:19 +00:00
1991-04-10 16:35:52 +00:00
;;; Summary
1991-04-10 16:35:52 +00:00
1996-01-14 07:34:30 +00:00
;; The current page commands are:
;; forward-page C-x ]
;; backward-page C-x [
;; narrow-to-page C-x p
;; count-lines-page C-x l
;; mark-page C-x C-p (change this to C-x C-p C-m)
;; sort-pages not bound
;; what-page not bound
;; The new page handling commands all use `C-x C-p' as a prefix. This
;; means that the key binding for `mark-page' must be changed.
;; Otherwise, no other changes are made to the current commands or
;; their bindings.
;; New page handling commands:
;; pages-next-page C-x C-p C-n
;; pages-previous-page C-x C-p C-p
;; pages-search C-x C-p C-s
;; pages-add-new-page C-x C-p C-a
;; pages-sort-buffer C-x C-p s
;; pages-set-delimiter C-x C-p C-l
2003-02-04 13:30:45 +00:00
;; pages-directory C-x C-p C-d
1996-01-14 07:34:30 +00:00
;; pages-directory-for-addresses C-x C-p d
;; pages-directory-goto C-c C-c
1991-04-10 16:35:52 +00:00
;;; Using the page commands
2003-02-04 13:30:45 +00:00
1996-01-14 07:34:30 +00:00
;; 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 sections.
;; You may change the buffer local value of the `page-delimiter' with
;; the `set-page-delimiter' command. This command is bound to `C-x C-p
;; C-l' The command prompts you for a new value for the page-delimiter.
;; Called with a prefix-arg, the command resets the value of the
;; page-delimiter to its original value.
;; You may set several user options:
;;
;; The `pages-directory-buffer-narrowing-p' variable causes the
;; `pages-directory-goto' command to narrow to the destination page.
;;
;; The `pages-directory-for-adding-page-narrowing-p' variable, causes the
;; `add-new-page' command to narrow to the new entry.
;;
;; The `pages-directory-for-adding-new-page-before-current-page-p' variable
;; causes the `add-new-page' command to insert a new page before current
;; page.
;;
;; These variables are true by default.
;;
;; Additional, addresses-related user options are described in the next page
;; of this file.
1991-04-10 16:35:52 +00:00
;;; Handling an address list or small data base
1991-04-10 16:35:52 +00:00
1996-01-14 07:34:30 +00:00
;; You may use the page commands to handle an address list or other
;; small data base. Put each address or entry on its own page. The
;; first line of text in each page is a `header line' and is listed by
;; the `pages-directory' or `pages-directory-for-addresses' command.
;; Specifically:
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;; 1. Begin each entry with a `page-delimiter' (which is, by default,
;; `^L' at the beginning of the line).
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;; 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.
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;; 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
;; immediately following the line containing page-delimiter.
;;
;; 3. Follow the heading line with the body of the entry. The body
;; extends up to the next `page-delimiter'. The body may be of any
;; length. It is conventional to place a blank line after the last
;; line of the body.
;; For example, a file might look like this:
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;; FSF
;; Free Software Foundation
2005-07-04 23:32:44 +00:00
;; 51 Franklin Street, Fifth Floor
;; Boston, MA 02110-1301 USA.
;; (617) 542-5942
1999-08-16 04:04:27 +00:00
;; gnu@gnu.org
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;;
;; House Subcommittee on Intellectual Property,
;; U.S. House of Representatives,
;; Washington, DC 20515
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;; Congressional committee concerned with permitting or preventing
;; monopolistic restrictions on the use of software technology.
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;;
;; George Lakoff
;; ``Women, Fire, and Dangerous Things:
;; What Categories Reveal about the Mind''
;; 1987, Univ. of Chicago Press
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;; About philosophy, Whorfian effects, and linguistics.
2003-02-04 13:30:45 +00:00
;;
;;
1996-01-14 07:34:30 +00:00
;; OBI (On line text collection.)
;; Open Book Initiative
;; c/o Software Tool & Die
;; 1330 Beacon St, Brookline, MA 02146 USA
2003-02-04 13:30:45 +00:00
;; (617) 739-0202
1996-01-14 07:34:30 +00:00
;; obi@world.std.com
;; In this example, the heading lines are:
;;
;; FSF
;; House Subcommittee on Intellectual Property
;; George Lakoff
;; OBI (On line text collection.)
;; The `C-x C-p s' (pages-sort-buffer) command sorts the entries in the
1996-01-14 07:34:30 +00:00
;; buffer alphabetically.
;; You may use any of the page commands, including the `pages-next-page',
;; `pages-previous-page', `pages-add-new-page', `mark-page', and `pages-search'
1996-01-14 07:34:30 +00:00
;; commands.
;; You may use either the `C-x C-p d' (pages-directory-for-addresses)
;; or the `C-x C-p C-d' (pages-directory) command to construct and
;; display a directory of all the heading lines.
;; In the directory, you may position the cursor over a heading line
;; and type `C-c C-c' (pages-directory-goto) to go to the entry to
;; which it refers in the pages buffer.
;; You can type `C-c C-p C-a' (pages-add-new-page) to add a new entry in the
1996-01-14 07:34:30 +00:00
;; pages buffer or address file. This is the same command you use to
;; add a new entry when you are in the pages buffer or address file.
;; If you wish, you may create several different directories,
;; one for each different buffer.
1991-04-10 16:35:52 +00:00
;; `pages-directory-for-addresses' in detail
1996-01-14 07:34:30 +00:00
;; The `pages-directory-for-addresses' assumes a default addresses
;; file. You do not need to specify the addresses file but merely type
;; `C-x C-p d' from any buffer. The command finds the file, constructs
;; a directory for it, and switches you to the directory. If you call
;; the command with a prefix arg, `C-u C-x C-p d', it prompts you for a
;; file name.
1991-04-10 16:35:52 +00:00
1996-01-14 07:34:30 +00:00
;; You may customize the addresses commands:
1996-01-14 07:34:30 +00:00
;; The `pages-addresses-file-name' variable determines the name of
;; the addresses file; by default it is "~/addresses".
1996-01-14 07:34:30 +00:00
;; The `pages-directory-for-addresses-goto-narrowing-p' variable
;; determines whether `pages-directory-goto' narrows the addresses
;; buffer to the entry, which it does by default.
1996-01-14 07:34:30 +00:00
;; The `pages-directory-for-addresses-buffer-keep-windows-p' variable
;; determines whether `pages-directory-for-addresses' deletes other
;; windows to show as many lines as possible on the screen or works
;; in the usual Emacs manner and keeps other windows. Default is to
;; keep other windows.
1996-01-14 07:34:30 +00:00
;; The `pages-directory-for-adding-addresses-narrowing-p' variable
;; determines whether `pages-directory-for-addresses' narrows the
;; addresses buffer to a new entry when you are adding that entry.
;; Default is to narrow to new entry, which means you see a blank
;; screen before you write the new entry.
1991-04-10 16:35:52 +00:00
;; `pages-directory' in detail
1996-01-14 07:34:30 +00:00
;; Call the `pages-directory' command from the buffer for which you
;; want a directory created; it creates a directory for the buffer and
;; pops you to the directory.
;; The `pages-directory' command has several options:
;; Called with a prefix arg, `C-u C-x C-p C-d', the `pages-directory'
;; prompts you for a regular expression and only lists only those
;; header lines that are part of pages that contain matches to the
;; regexp. In the example above, `C-u C-x C-p C-d 617 RET' would
;; 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.
2003-02-04 13:30:45 +00:00
;;
1996-01-14 07:34:30 +00:00
;; Called with a numeric argument, the `pages-directory' command
;; lists the number of lines in each page. This is helpful when you
2003-02-04 13:30:45 +00:00
;; are printing hardcopy.
1996-01-14 07:34:30 +00:00
;; Called with a negative numeric argument, the `pages-directory'
;; command lists the lengths of pages whose contents match a regexp.
1991-04-10 16:35:52 +00:00
;;; Code:
;;; Customarily customizable variable definitions
(defgroup pages nil
"Extended page-handling commands."
:group 'extensions)
(defcustom pages-directory-buffer-narrowing-p t
"If non-nil, `pages-directory-goto' narrows pages buffer to entry."
:type 'boolean)
(defcustom pages-directory-for-adding-page-narrowing-p t
"If non-nil, `add-new-page' narrows page buffer to new entry."
:type 'boolean)
(defcustom pages-directory-for-adding-new-page-before-current-page-p t
"If non-nil, `add-new-page' inserts new page before current page."
:type 'boolean)
;;; Addresses related variables
(defcustom pages-addresses-file-name "~/addresses"
"Standard name for file of addresses. Entries separated by page-delimiter.
Used by `pages-directory-for-addresses' function."
:type 'file)
(defcustom pages-directory-for-addresses-goto-narrowing-p t
"If non-nil, `pages-directory-goto' narrows addresses buffer to entry."
:type 'boolean)
(defcustom pages-directory-for-addresses-buffer-keep-windows-p t
"If nil, `pages-directory-for-addresses' deletes other windows."
:type 'boolean)
(defcustom pages-directory-for-adding-addresses-narrowing-p t
"If non-nil, `add-new-page' narrows addresses buffer to new entry."
:type 'boolean)
1991-04-10 16:35:52 +00:00
;;; Key bindings for page handling functions
1991-04-10 16:35:52 +00:00
(defvar pages--ctl-x-ctl-p-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-n" #'pages-next-page)
(define-key map "\C-p" #'pages-previous-page)
(define-key map "\C-a" #'pages-add-new-page)
(define-key map "\C-m" #'mark-page)
(define-key map "\C-s" #'pages-search)
(define-key map "s" #'pages-sort-buffer)
(define-key map "\C-l" #'pages-set-delimiter)
(define-key map "\C-d" #'pages-directory)
(define-key map "d" #'pages-directory-for-addresses)
map)
1991-04-10 16:35:52 +00:00
"Keymap for subcommands of C-x C-p, which are for page handling.")
;; FIXME: Merely loading a package shouldn't have this kind of side-effects!
(global-unset-key "\C-x\C-p")
(define-key ctl-x-map "\C-p" #'pages-ctl-x-ctl-p-prefix)
(define-obsolete-function-alias 'ctl-x-ctl-p-prefix 'pages-ctl-x-ctl-p-prefix "27.1")
(defalias 'pages-ctl-x-ctl-p-prefix pages--ctl-x-ctl-p-map)
1991-04-10 16:35:52 +00:00
;;; Page movement function definitions
1991-04-10 16:35:52 +00:00
(define-obsolete-function-alias 'next-page #'pages-next-page "27.1")
(defun pages-next-page (&optional count)
1991-04-10 16:35:52 +00:00
"Move to the next page bounded by the `page-delimiter' variable.
With arg (prefix if interactive), move that many pages."
(interactive "p")
(or count (setq count 1))
(widen)
;; Cannot use forward-page because of problems at page boundaries.
(if (>= count 0)
(while (and (> count 0) (not (eobp)))
(if (re-search-forward page-delimiter nil t)
nil
(goto-char (point-max)))
(setq count (1- count)))
;; If COUNT is negative, we want to go back -COUNT + 1 page boundaries.
;; The first page boundary we reach is the top of the current page,
;; which doesn't count.
(while (and (< count 1) (not (bobp)))
(if (re-search-backward page-delimiter nil t)
(when (= count 0)
(goto-char (match-end 0)))
(goto-char (point-min)))
(setq count (1+ count))))
1991-04-10 16:35:52 +00:00
(narrow-to-page)
(goto-char (point-min))
(recenter 0))
(define-obsolete-function-alias 'previous-page #'pages-previous-page "27.1")
(defun pages-previous-page (&optional count)
1991-04-10 16:35:52 +00:00
"Move to the previous page bounded by the `page-delimiter' variable.
With arg (prefix if interactive), move that many pages."
(interactive "p")
(or count (setq count 1))
(pages-next-page (- count)))
1991-04-10 16:35:52 +00:00
;;; Adding and searching pages
1991-04-10 16:35:52 +00:00
(define-obsolete-function-alias 'add-new-page #'pages-add-new-page "27.1")
(defun pages-add-new-page (header-line)
"Insert new page. Prompt for header line.
If point is in the pages directory buffer, insert the new page in the
buffer associated with the directory.
Insert the new page just before current page if
`pages-directory-for-adding-new-page-before-current-page-p' is non-nil.
Else insert at exact location of point.
Narrow to new page if `pages-directory-for-adding-page-narrowing-p' is
non-nil.
Page begins with a `^L' as the default `page-delimiter'.
Use \\[set-page-delimiter] to change the page-delimiter.
1991-04-10 16:35:52 +00:00
Point is left in the body of page."
(interactive "sHeader line: ")
(widen)
;; If in pages directory buffer
2003-02-04 13:30:45 +00:00
(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
(pages-directory-goto)
(pages-directory-goto)
(forward-page)
(or (eobp) (forward-line -1)))))
(widen)
;; Move point before current delimiter if desired.
(and pages-directory-for-adding-new-page-before-current-page-p
(if (re-search-backward page-delimiter nil t)
(goto-char (match-beginning 0))
;; If going to beginning of file, insert a page-delimiter
;; before current first page.
(goto-char (point-min))
(insert
(format "%s\n"
;; Remove leading `^' from page-delimiter string
(if (eq '^ (car (read-from-string page-delimiter)))
2003-02-04 13:30:45 +00:00
(substring page-delimiter 1))))
(goto-char (point-min))))
;; Insert page delimiter at beginning of line.
(if (not (looking-at "^.")) (forward-line 1))
2003-02-04 13:30:45 +00:00
(insert (format "%s\n%s\n\n\n"
(if (eq '^ (car (read-from-string page-delimiter)))
(substring page-delimiter 1))
header-line))
(forward-line -1)
(and pages-directory-for-adding-page-narrowing-p (narrow-to-page)))
1991-04-10 16:35:52 +00:00
(defvar pages-last-search nil
"Value of last regexp searched for. Initially, nil.")
(define-obsolete-function-alias 'search-pages #'pages-search "27.1")
(defun pages-search (regexp)
1991-04-10 16:35:52 +00:00
"Search for REGEXP, starting from point, and narrow to page it is in."
(interactive (list
(read-string
(format-message "Search for `%s' (end with RET): "
(or pages-last-search "regexp")))))
1991-04-10 16:35:52 +00:00
(if (equal regexp "")
(setq regexp pages-last-search)
(setq pages-last-search regexp))
(widen)
(re-search-forward regexp)
(narrow-to-page))
;;; Sorting pages
1991-04-10 16:35:52 +00:00
(define-obsolete-function-alias 'sort-pages-in-region #'pages-sort-region "27.1")
(defun pages-sort-region (reverse beg end)
2003-02-04 13:30:45 +00:00
"Sort pages in region alphabetically. Prefix arg means reverse order.
1991-04-10 16:35:52 +00:00
Called from a program, there are three arguments:
REVERSE (non-nil means reverse order), BEG and END (region to sort)."
;; This sort function handles ends of pages differently than
;; `sort-pages' and works better with lists of addresses and similar
;; files.
1991-04-10 16:35:52 +00:00
(interactive "P\nr")
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
;;; `sort-subr' takes three arguments
(sort-subr reverse
;; NEXTRECFUN is called with point at the end of the
;; previous record. It moves point to the start of the
;; next record.
(function (lambda ()
(re-search-forward page-delimiter nil t)
(skip-chars-forward " \t\n")
))
2011-11-16 12:34:47 +00:00
;; ENDRECFUN is called with point within the record.
1991-04-10 16:35:52 +00:00
;; It should move point to the end of the record.
(function (lambda ()
(if (re-search-forward
page-delimiter
nil
t)
(goto-char (match-beginning 0))
(goto-char (point-max))))))))
(define-obsolete-function-alias 'sort-pages-buffer #'pages-sort-buffer "27.1")
(defun pages-sort-buffer (&optional reverse)
2003-02-04 13:30:45 +00:00
"Sort pages alphabetically in buffer. Prefix arg means reverse order.
\(Non-nil arg if not interactive.)"
1991-04-10 16:35:52 +00:00
(interactive "P")
(or reverse (setq reverse nil))
(widen)
(let ((beginning (point-min))
(end (point-max)))
(pages-sort-region reverse beginning end)))
1991-04-10 16:35:52 +00:00
;;; Pages directory ancillary definitions
1991-04-10 16:35:52 +00:00
(defvar pages-directory-previous-regexp nil
"Value of previous regexp used by `pages-directory'.
\(This regular expression may be used to select only those pages that
contain matches to the regexp.)")
1991-04-10 16:35:52 +00:00
(defvar-local pages-buffer nil
1991-04-10 16:35:52 +00:00
"The buffer for which the pages-directory function creates the directory.")
(defvar pages-directory-prefix "*Directory for:"
"Prefix of name of temporary buffer for pages-directory.")
(defvar-local pages-pos-list nil
1991-04-10 16:35:52 +00:00
"List containing the positions of the pages in the pages-buffer.")
(defvar pages-target-buffer)
(define-obsolete-variable-alias 'pages-directory-map
'pages-directory-mode-map "26.1")
(defvar pages-directory-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-c" #'pages-directory-goto)
(define-key map "\C-m" #'pages-directory-goto)
(define-key map "\C-c\C-p\C-a" #'pages-add-new-page)
(define-key map [mouse-2] #'pages-directory-goto)
map)
1991-04-10 16:35:52 +00:00
"Keymap for the pages-directory-buffer.")
(defvar pages-original-delimiter "^\f"
"Default page delimiter.")
1991-04-10 16:35:52 +00:00
(define-obsolete-function-alias 'set-page-delimiter #'pages-set-delimiter "27.1")
(defun pages-set-delimiter (regexp reset-p &optional interactively)
1991-04-10 16:35:52 +00:00
"Set buffer local value of page-delimiter to REGEXP.
Called interactively with a prefix argument, reset `page-delimiter' to
its original value.
In a program, non-nil second arg causes first arg to be ignored and
resets the page-delimiter to the original value."
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(interactive
(if current-prefix-arg
(list pages-original-delimiter t t)
(list (read-regexp "Set page-delimiter to regexp: " page-delimiter)
nil t)))
(setq-local pages-original-delimiter
(or pages-original-delimiter page-delimiter))
(setq-local page-delimiter
(if (not reset-p) regexp pages-original-delimiter))
(if interactively
1991-04-10 16:35:52 +00:00
(message "The value of `page-delimiter' is now: %s" page-delimiter)))
;;; Pages directory main definitions
1991-04-10 16:35:52 +00:00
(defvar pages-buffer-original-position)
(defvar pages-buffer-original-page)
1991-04-10 16:35:52 +00:00
(defun pages-directory
(pages-list-all-headers-p count-lines-p &optional regexp)
"Display a directory of the page headers in a temporary buffer.
A header is the first non-blank line after the `page-delimiter'.
1991-04-10 16:35:52 +00:00
\\[pages-directory-mode]
You may move point to one of the lines in the temporary buffer,
then use \\<pages-directory-goto> to go to the same line in the pages buffer.
In interactive use:
1. With no prefix arg, display all headers.
2. With prefix arg, display the headers of only those pages that
contain matches to a regular expression for which you are
prompted.
3. With numeric prefix arg, for every page, print the number of
lines within each page.
4. With negative numeric prefix arg, for only those pages that
match a regular expression, print the number of lines within
each page.
When called from a program, non-nil first arg means list all headers;
non-nil second arg means print numbers of lines in each page; if first
arg is nil, optional third arg is regular expression.
If the buffer is narrowed, the `pages-directory' command creates a
directory for only the accessible portion of the buffer."
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(interactive
(cond ((not current-prefix-arg)
(list t nil nil))
2003-02-04 13:30:45 +00:00
((listp current-prefix-arg)
1991-04-10 16:35:52 +00:00
(list nil
nil
(read-string
(format-message
"Select according to `%s' (end with RET): "
(or pages-directory-previous-regexp "regexp")))))
1991-04-10 16:35:52 +00:00
((> (prefix-numeric-value current-prefix-arg) 0)
(list t t nil))
2003-02-04 13:30:45 +00:00
((< (prefix-numeric-value current-prefix-arg) 0)
1991-04-10 16:35:52 +00:00
(list nil
t
(read-string
(format-message
"Select according to `%s' (end with RET): "
(or pages-directory-previous-regexp "regexp")))))))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(if (equal regexp "")
(setq regexp pages-directory-previous-regexp)
(setq pages-directory-previous-regexp regexp))
2003-02-04 13:30:45 +00:00
(if (called-interactively-p 'interactive)
1991-04-10 16:35:52 +00:00
(message "Creating directory for: %s "
(buffer-name)))
2003-02-04 13:30:45 +00:00
(let ((pages-target-buffer (current-buffer))
1991-04-10 16:35:52 +00:00
(pages-directory-buffer
(concat pages-directory-prefix " " (buffer-name)))
1991-04-10 16:35:52 +00:00
(pages-buffer-original-position (point))
(pages-buffer-original-page 0))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
;; `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.
(with-output-to-temp-buffer pages-directory-buffer
* textmodes/two-column.el (2C-split): * textmodes/texnfo-upd.el (texinfo-multi-file-included-list): * textmodes/tex-mode.el (tex-set-buffer-directory): * textmodes/spell.el (spell-region, spell-string): * textmodes/reftex.el (reftex-erase-buffer): (reftex-get-file-buffer-force, reftex-kill-temporary-buffers): * textmodes/reftex-toc.el (reftex-toc-promote-action): * textmodes/reftex-sel.el (reftex-get-offset, reftex-insert-docstruct) (reftex-select-item): * textmodes/reftex-ref.el (reftex-label-info-update) (reftex-offer-label-menu): * textmodes/reftex-index.el (reftex-index-change-entry) (reftex-index-phrases-info): * textmodes/reftex-global.el (reftex-create-tags-file) (reftex-save-all-document-buffers, reftex-ensure-write-access): * textmodes/reftex-dcr.el (reftex-echo-ref, reftex-echo-cite) (reftex-view-crossref-from-bibtex): * textmodes/reftex-cite.el (reftex-bibtex-selection-callback) (reftex-extract-bib-entries-from-thebibliography) (reftex-all-used-citation-keys, reftex-create-bibtex-file): * textmodes/refbib.el (r2b-capitalize-title): (r2b-convert-buffer, r2b-help): * textmodes/page-ext.el (pages-directory) (pages-directory-goto-with-mouse): * textmodes/bibtex.el (bibtex-validate-globally): * textmodes/bib-mode.el (bib-capitalize-title): * textmodes/artist.el (artist-clear-buffer, artist-system): * progmodes/xscheme.el (global-set-scheme-interaction-buffer): (local-set-scheme-interaction-buffer, xscheme-process-filter) (verify-xscheme-buffer, xscheme-enter-interaction-mode) (xscheme-enter-debugger-mode, xscheme-debugger-mode-p) (xscheme-send-control-g-interrupt, xscheme-start-process) (xscheme-process-sentinel, xscheme-cd): * progmodes/verilog-mode.el (verilog-read-always-signals) (verilog-set-define, verilog-getopt-file) (verilog-module-inside-filename-p): * progmodes/sh-script.el: * progmodes/python.el (python-pdbtrack-get-source-buffer) (python-pdbtrack-grub-for-buffer, python-execute-file): * progmodes/octave-inf.el (inferior-octave): * progmodes/idlwave.el (idlwave-scan-user-lib-files) (idlwave-shell-compile-helper-routines, idlwave-set-local) (idlwave-display-completion-list-xemacs, idlwave-list-abbrevs) (idlwave-display-completion-list-emacs, idlwave-list-load-path-shadows) (idlwave-completion-fontify-classes, idlwave-display-calling-sequence): * progmodes/idlw-shell.el (idlwave-shell-examine-display-clear) (idlwave-shell-filter, idlwave-shell-examine-highlight) (idlwave-shell-sentinel, idlwave-shell-filter-directory) (idlwave-shell-display-line, idlwave-shell-set-bp-in-module) (idlwave-shell-examine-display, idlwave-shell-run-region) (idlwave-shell-filter-bp, idlwave-shell-save-and-action) (idlwave-shell-sources-filter, idlwave-shell-goto-next-error): * progmodes/idlw-help.el (idlwave-help-get-special-help) (idlwave-help-get-help-buffer): * progmodes/gud.el (gud-basic-call, gud-find-class) (gud-tooltip-activate-mouse-motions-if-enabled): * progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe): * progmodes/ebrowse.el (ebrowse-member-table, ebrowse-save-tree-as) (ebrowse-view-exit-fn, ebrowse-tags-list-members-in-file) (ebrowse-tags-next-file): * progmodes/ebnf2ps.el (ebnf-generate-eps, ebnf-generate-eps) (ebnf-eps-production-list, ebnf-begin-file, ebnf-log) (ebnf-eps-finish-and-write): * progmodes/cpp.el (cpp-edit-save): * progmodes/cperl-mode.el (cperl-pod-to-manpage): * progmodes/cc-defs.el (c-emacs-features): * progmodes/antlr-mode.el (antlr-invalidate-context-cache) (antlr-directory-dependencies): * progmodes/ada-xref.el (ada-gnat-parse-gpr, ada-get-ali-file-name) (ada-run-application, ada-find-in-src-path, ada-goto-parent) (ada-find-any-references, ada-make-filename-from-adaname) (ada-make-body-gnatstub): * obsolete/rnews.el (news-list-news-groups): * obsolete/resume.el (resume-suspend-hook,resume-write-buffer-to-file): * obsolete/iso-acc.el (iso-acc-minibuf-setup): * net/rcirc.el (rcirc-debug): * net/newst-treeview.el (newsticker--treeview-list-add-item) (newsticker--treeview-list-clear, newsticker-treeview-browse-url) (newsticker--treeview-list-update-faces, newsticker-treeview-save) (newsticker--treeview-item-show-text, newsticker--treeview-item-show) (newsticker--treeview-tree-update-tag,newsticker--treeview-buffer-init) (newsticker-treeview-show-item, newsticker--treeview-unfold-node) (newsticker--treeview-list-clear-highlight) (newsticker--treeview-list-update-highlight) (newsticker--treeview-list-highlight-start) (newsticker--treeview-tree-update-highlight) (newsticker--treeview-get-selected-item) (newsticker-treeview-mark-list-items-old) (newsticker--treeview-set-current-node): * net/newst-plainview.el (newsticker--buffer-set-uptodate): * net/newst-backend.el (newsticker--get-news-by-funcall) (newsticker--get-news-by-wget, newsticker--image-get) (newsticker--image-sentinel): * net/mairix.el (mairix-rmail-fetch-field, mairix-gnus-fetch-field): * net/eudcb-ph.el (eudc-ph-do-request, eudc-ph-open-session): (eudc-ph-close-session): * net/eudc.el (eudc-save-options): * language/thai-word.el (thai-update-word-table): * language/japan-util.el (japanese-string-conversion): * international/titdic-cnv.el (tsang-quick-converter) (ziranma-converter, ctlau-converter): * international/mule-cmds.el (describe-language-environment): * international/ja-dic-cnv.el (skkdic-convert-okuri-ari) (skkdic-convert-postfix, skkdic-convert-prefix): (skkdic-convert-okuri-nasi, skkdic-convert): * emacs-lisp/re-builder.el (reb-update-overlays): * emacs-lisp/pp.el (pp-to-string, pp-display-expression): * emacs-lisp/gulp.el (gulp-send-requests): * emacs-lisp/find-gc.el (trace-call-tree): * emacs-lisp/eieio-opt.el (eieio-browse, eieio-describe-class) (eieio-describe-generic): * emacs-lisp/eieio-base.el (eieio-persistent-read): * emacs-lisp/edebug.el (edebug-outside-excursion): * emacs-lisp/debug.el (debugger-make-xrefs): * emacs-lisp/cust-print.el (custom-prin1-to-string): * emacs-lisp/chart.el (chart-new-buffer): * emacs-lisp/authors.el (authors-scan-el, authors-scan-change-log): Use with-current-buffer. * textmodes/artist.el (artist-system): Don't call copy-sequence on a fresh string. * progmodes/idlw-shell.el (easymenu setup): Use dolist.
2009-10-31 02:38:34 +00:00
(with-current-buffer standard-output
1991-04-10 16:35:52 +00:00
(pages-directory-mode)
(setq buffer-read-only nil)
1991-04-10 16:35:52 +00:00
(insert
"==== Pages Directory: use `C-c C-c' to go to page under cursor. ====" ?\n)
(setq pages-buffer pages-target-buffer)
1991-04-10 16:35:52 +00:00
(setq pages-pos-list nil))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(if pages-list-all-headers-p
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
;; 1. If no prefix argument, list all headers
(save-excursion
(goto-char (point-min))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
;; (a) Point is at beginning of buffer; but the first
;; page may not begin with a page-delimiter
(save-restriction
;; If page delimiter is at beginning of buffer, skip it
(if (and (save-excursion
(re-search-forward page-delimiter nil t))
(= 1 (match-beginning 0)))
(goto-char (match-end 0)))
(narrow-to-page)
(pages-copy-header-and-position count-lines-p))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
;; (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)))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
;; 2. Else list headers whose pages match regexp.
(save-excursion
;; REMOVED save-restriction AND widen FROM HERE
(goto-char (point-min))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
;; (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)))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
;; (b) Search for next page-delimiter
(while (re-search-forward page-delimiter nil t)
(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)
)))))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(set-buffer standard-output)
(setq buffer-read-only t)
1991-04-10 16:35:52 +00:00
;; Put positions in increasing order to go with buffer.
(setq pages-pos-list (nreverse pages-pos-list))
(if (called-interactively-p 'interactive)
1991-04-10 16:35:52 +00:00
(message "%d matching lines in: %s"
(length pages-pos-list) (buffer-name pages-target-buffer))))
1991-04-10 16:35:52 +00:00
(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)
1
pages-buffer-original-page))))
2008-06-07 02:37:56 +00:00
1991-04-10 16:35:52 +00:00
(defun pages-copy-header-and-position (count-lines-p)
"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."
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(let (position line-count)
(if count-lines-p
(save-excursion
(save-restriction
(narrow-to-page)
(setq line-count (count-lines (point-min) (point-max))))))
;; Keep track of page for later cursor positioning
(if (<= (point) pages-buffer-original-position)
(setq pages-buffer-original-page
(1+ pages-buffer-original-page)))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(save-excursion
;; go to first non-blank char after the page-delimiter
2003-02-04 13:30:45 +00:00
(skip-chars-forward " \t\n")
1991-04-10 16:35:52 +00:00
;; set the marker here; this the place to which the
2003-02-04 13:30:45 +00:00
;; `pages-directory-goto' command will go
1991-04-10 16:35:52 +00:00
(setq position (make-marker))
(set-marker position (point))
(let ((start (point))
Use line-end-position rather than end-of-line, etc. * textmodes/texnfo-upd.el (texinfo-start-menu-description) (texinfo-update-menu-region-beginning, texinfo-menu-first-node) (texinfo-delete-existing-pointers, texinfo-find-pointer) (texinfo-clean-up-node-line, texinfo-insert-node-lines) (texinfo-multiple-files-update): * textmodes/table.el (table--probe-cell-left-up) (table--probe-cell-right-bottom): * textmodes/picture.el (picture-tab-search): * textmodes/page-ext.el (pages-copy-header-and-position) (pages-directory-for-addresses): * progmodes/vera-mode.el (vera-get-offset): * progmodes/simula.el (simula-calculate-indent): * progmodes/python.el (python-pdbtrack-overlay-arrow): * progmodes/prolog.el (end-of-prolog-clause): * progmodes/perl-mode.el (perl-calculate-indent, perl-indent-exp): * progmodes/icon.el (indent-icon-exp): * progmodes/etags.el (tag-re-match-p): * progmodes/ebrowse.el (ebrowse-show-file-name-at-point): * progmodes/ebnf2ps.el (ebnf-begin-file): * progmodes/dcl-mode.el (dcl-back-to-indentation-1) (dcl-save-local-variable): * play/life.el (life-setup): * play/gametree.el (gametree-looking-at-ply): * nxml/nxml-maint.el (nxml-insert-target-repertoire-glyph-set): * mail/sendmail.el (mail-mode-auto-fill): * emacs-lisp/lisp-mode.el (calculate-lisp-indent): * emacs-lisp/edebug.el (edebug-overlay-arrow): * emacs-lisp/checkdoc.el (checkdoc-this-string-valid): * woman.el (woman-parse-numeric-value, woman2-TH, woman2-SH) (woman-tab-to-tab-stop, WoMan-warn-ignored): * type-break.el (type-break-file-keystroke-count): * term.el (term-replace-by-expanded-history-before-point) (term-skip-prompt, term-extract-string): * speedbar.el (speedbar-edit-line, speedbar-expand-line) (speedbar-contract-line, speedbar-toggle-line-expansion) (speedbar-parse-c-or-c++tag, speedbar-parse-tex-string) (speedbar-buffer-revert-buffer, speedbar-highlight-one-tag-line): * sort.el (sort-skip-fields): * skeleton.el (skeleton-internal-list): * simple.el (line-move-finish, line-move-to-column): * shell.el (shell-forward-command): * misc.el (copy-from-above-command): * makesum.el (double-column): * ebuff-menu.el (electric-buffer-update-highlight): * dired.el (dired-move-to-end-of-filename): * dframe.el (dframe-popup-kludge): * bookmark.el (bookmark-kill-line, bookmark-bmenu-show-filenames): * arc-mode.el (archive-get-lineno): Use line-end-position and line-beginning-position. * net/ange-ftp.el, progmodes/hideif.el, reposition.el: Same, but only in comments.
2010-11-06 20:23:42 +00:00
(end (line-end-position))
inserted-at)
1991-04-10 16:35:52 +00:00
;; change to directory buffer
(set-buffer standard-output)
2003-02-04 13:30:45 +00:00
;; record page position
1991-04-10 16:35:52 +00:00
(setq pages-pos-list (cons position pages-pos-list))
;; insert page header
(setq inserted-at (point))
(insert-buffer-substring pages-target-buffer start end)
2003-02-04 13:30:45 +00:00
(add-text-properties inserted-at (point)
'(mouse-face highlight
help-echo "mouse-2: go to this page"))
1998-12-31 01:49:11 +00:00
(put-text-property inserted-at (point) 'rear-nonsticky 'highlight))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(if count-lines-p
(save-excursion
(beginning-of-line)
(insert (format "%3d: " line-count))))
2003-02-04 13:30:45 +00:00
1991-04-10 16:35:52 +00:00
(terpri))
(end-of-line 1)))
1991-04-10 16:35:52 +00:00
(define-derived-mode pages-directory-mode special-mode "Pages-Directory"
1991-04-10 16:35:52 +00:00
"Mode for handling the pages-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."
)
1991-04-10 16:35:52 +00:00
(defun pages-directory-goto (&optional event)
1991-04-10 16:35:52 +00:00
"Go to the corresponding line in the pages buffer."
;; This function is mostly a copy of `occur-mode-goto-occurrence'
(interactive (list last-nonmenu-event))
(if event (mouse-set-point event))
1991-04-10 16:35:52 +00:00
(if (or (not pages-buffer)
(not (buffer-name pages-buffer)))
(progn
(setq pages-buffer nil
pages-pos-list nil)
(error "Buffer in which pages were found is deleted")))
1991-04-10 16:35:52 +00:00
(beginning-of-line)
(let* ((pages-number (1- (count-lines (point-min) (point))))
(pos (nth pages-number pages-pos-list))
(end-of-directory-p (eobp))
(narrowing-p pages-directory-buffer-narrowing-p))
2003-02-04 13:30:45 +00:00
(pop-to-buffer pages-buffer)
1991-04-10 16:35:52 +00:00
(widen)
(goto-char (if end-of-directory-p
(point-max)
(marker-position pos)))
1991-04-10 16:35:52 +00:00
(if narrowing-p (narrow-to-page))))
(define-obsolete-function-alias 'pages-directory-goto-with-mouse
#'pages-directory-goto "26.1")
1991-04-10 16:35:52 +00:00
;;; The `pages-directory-for-addresses' function and ancillary code
1991-04-10 16:35:52 +00:00
(defun pages-directory-for-addresses (&optional filename)
"Find addresses file and display its directory.
By default, create and display directory of `pages-addresses-file-name'.
Optional argument is FILENAME. In interactive use, with prefix
argument, prompt for file name and provide completion.
Move point to one of the lines in the displayed directory,
then use \\[pages-directory-goto] to go to the same line
in the addresses buffer.
If `pages-directory-for-addresses-goto-narrowing-p' is non-nil,
`pages-directory-goto' narrows addresses buffer to entry.
If `pages-directory-for-addresses-buffer-keep-windows-p' is nil,
2003-02-04 13:30:45 +00:00
this command deletes other windows when it displays the addresses
directory."
1991-04-10 16:35:52 +00:00
(interactive
(list (if current-prefix-arg
(read-file-name "Filename: " pages-addresses-file-name))))
(if (called-interactively-p 'interactive)
1991-04-10 16:35:52 +00:00
(message "Creating directory for: %s "
(or filename pages-addresses-file-name)))
(if (file-exists-p (or filename pages-addresses-file-name))
(progn
(set-buffer
(find-file-noselect
(expand-file-name
(or filename pages-addresses-file-name))))
(widen)
(pages-directory t nil nil)
;; by RJC, 2006 Jun 11: including this causes failure; it results in
;; the message "Buffer in which pages were found is deleted"
;; (pages-directory-address-mode)
(setq-local pages-directory-buffer-narrowing-p
pages-directory-for-addresses-goto-narrowing-p)
(or pages-directory-for-addresses-buffer-keep-windows-p
(delete-other-windows))
1991-04-10 16:35:52 +00:00
(save-excursion
(goto-char (point-min))
Use line-end-position rather than end-of-line, etc. * textmodes/texnfo-upd.el (texinfo-start-menu-description) (texinfo-update-menu-region-beginning, texinfo-menu-first-node) (texinfo-delete-existing-pointers, texinfo-find-pointer) (texinfo-clean-up-node-line, texinfo-insert-node-lines) (texinfo-multiple-files-update): * textmodes/table.el (table--probe-cell-left-up) (table--probe-cell-right-bottom): * textmodes/picture.el (picture-tab-search): * textmodes/page-ext.el (pages-copy-header-and-position) (pages-directory-for-addresses): * progmodes/vera-mode.el (vera-get-offset): * progmodes/simula.el (simula-calculate-indent): * progmodes/python.el (python-pdbtrack-overlay-arrow): * progmodes/prolog.el (end-of-prolog-clause): * progmodes/perl-mode.el (perl-calculate-indent, perl-indent-exp): * progmodes/icon.el (indent-icon-exp): * progmodes/etags.el (tag-re-match-p): * progmodes/ebrowse.el (ebrowse-show-file-name-at-point): * progmodes/ebnf2ps.el (ebnf-begin-file): * progmodes/dcl-mode.el (dcl-back-to-indentation-1) (dcl-save-local-variable): * play/life.el (life-setup): * play/gametree.el (gametree-looking-at-ply): * nxml/nxml-maint.el (nxml-insert-target-repertoire-glyph-set): * mail/sendmail.el (mail-mode-auto-fill): * emacs-lisp/lisp-mode.el (calculate-lisp-indent): * emacs-lisp/edebug.el (edebug-overlay-arrow): * emacs-lisp/checkdoc.el (checkdoc-this-string-valid): * woman.el (woman-parse-numeric-value, woman2-TH, woman2-SH) (woman-tab-to-tab-stop, WoMan-warn-ignored): * type-break.el (type-break-file-keystroke-count): * term.el (term-replace-by-expanded-history-before-point) (term-skip-prompt, term-extract-string): * speedbar.el (speedbar-edit-line, speedbar-expand-line) (speedbar-contract-line, speedbar-toggle-line-expansion) (speedbar-parse-c-or-c++tag, speedbar-parse-tex-string) (speedbar-buffer-revert-buffer, speedbar-highlight-one-tag-line): * sort.el (sort-skip-fields): * skeleton.el (skeleton-internal-list): * simple.el (line-move-finish, line-move-to-column): * shell.el (shell-forward-command): * misc.el (copy-from-above-command): * makesum.el (double-column): * ebuff-menu.el (electric-buffer-update-highlight): * dired.el (dired-move-to-end-of-filename): * dframe.el (dframe-popup-kludge): * bookmark.el (bookmark-kill-line, bookmark-bmenu-show-filenames): * arc-mode.el (archive-get-lineno): Use line-end-position and line-beginning-position. * net/ange-ftp.el, progmodes/hideif.el, reposition.el: Same, but only in comments.
2010-11-06 20:23:42 +00:00
(delete-region (point) (line-end-position))
1991-04-10 16:35:52 +00:00
(insert
"=== Address List Directory: use `C-c C-c' to go to page under cursor. ===")
(set-buffer-modified-p nil)
))
(error "No addresses file found!")))
(define-derived-mode pages-directory-address-mode pages-directory-mode
"Addresses Directory"
1991-04-10 16:35:52 +00:00
"Mode for handling the Addresses Directory buffer.
Move point to one of the lines in this buffer,
then use \\[pages-directory-goto] to go
1991-04-10 16:35:52 +00:00
to the same line in the pages buffer."
:syntax-table nil)
1991-04-10 16:35:52 +00:00
(provide 'page-ext)
2003-09-01 15:45:59 +00:00
;;; page-ext.el ends here