Mercurial > hg > xemacs-beta
view lisp/paragraphs.el @ 826:6728e641994e
[xemacs-hg @ 2002-05-05 11:30:15 by ben]
syntax cache, 8-bit-format, lots of code cleanup
README.packages: Update info about --package-path.
i.c: Create an inheritable event and pass it on to XEmacs, so that ^C
can be handled properly. Intercept ^C and signal the event.
"Stop Build" in VC++ now works.
bytecomp-runtime.el: Doc string changes.
compat.el: Some attempts to redo this to
make it truly useful and fix the "multiple versions interacting
with each other" problem. Not yet done. Currently doesn't work.
files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code.
xemacs.mak: Split up CFLAGS into a version without flags specifying the C
library. The problem seems to be that minitar depends on zlib,
which depends specifically on libc.lib, not on any of the other C
libraries. Unless you compile with libc.lib, you get errors --
specifically, no _errno in the other libraries, which must make it
something other than an int. (#### But this doesn't seem to obtain
in XEmacs, which also uses zlib, and can be linked with any of the
C libraries. Maybe zlib is used differently and doesn't need
errno, or maybe XEmacs provides an int errno; ... I don't
understand.
Makefile.in.in: Fix so that packages are around when testing.
abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch.
-- FUNCTIONALITY CHANGES:
add partial support for 8-bit-fixed, 16-bit-fixed, and
32-bit-fixed formats. not quite done yet. (in particular, needs
functions to actually convert the buffer.) NOTE: lots of changes
to regex.c here. also, many new *_fmt() inline funs that take an
Internal_Format argument.
redo syntax cache code. make the cache per-buffer; keep the cache
valid across calls to functions that use it. also keep it valid
across insertions/deletions and extent changes, as much as is
possible. eliminate the junky regex-reentrancy code by passing in
the relevant lisp info to the regex routines as local vars.
add general mechanism in extents code for signalling extent changes.
fix numerous problems with the case-table implementation; yoshiki
never properly transferred many algorithms from old-style to
new-style case tables.
redo char tables to support a default argument, so that mapping
only occurs over changed args. change many chartab functions to
accept Lisp_Object instead of Lisp_Char_Table *.
comment out the code in font-lock.c by default, because
font-lock.el no longer uses it. we should consider eliminating it
entirely.
Don't output bell as ^G in console-stream when not a TTY.
add -mswindows-termination-handle to interface with i.c, so we can
properly kill a build.
add more error-checking to buffer/string macros.
add some additional buffer_or_string_() funs.
-- INTERFACE CHANGES AFFECTING MORE CODE:
switch the arguments of write_c_string and friends to be
consistent with write_fmt_string, which must have printcharfun
first.
change BI_* macros to BYTE_* for increased clarity; similarly for
bi_* local vars.
change VOID_TO_LISP to be a one-argument function. eliminate
no-longer-needed CVOID_TO_LISP.
-- char/string macro changes:
rename MAKE_CHAR() to make_emchar() for slightly less confusion
with make_char(). (The former generates an Emchar, the latter a
Lisp object. Conceivably we should rename make_char() -> wrap_char()
and similarly for make_int(), make_float().)
Similar changes for other *CHAR* macros -- we now consistently use
names with `emchar' whenever we are working with Emchars. Any
remaining name with just `char' always refers to a Lisp object.
rename macros with XSTRING_* to string_* except for those that
reference actual fields in the Lisp_String object, following
conventions used elsewhere.
rename set_string_{data,length} macros (the only ones to work with
a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_*
to make the difference clear.
try to be consistent about caps vs. lowercase in macro/inline-fun
names for chars and such, which wasn't the case before. we now
reserve caps either for XFOO_ macros that reference object fields
(e.g. XSTRING_DATA) or for things that have non-function semantics,
e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an
arg (any arg) more than once. otherwise, use lowercase.
here is a summary of most of the macros/inline funs changed by all
of the above changes:
BYTE_*_P -> byte_*_p
XSTRING_BYTE -> string_byte
set_string_data/length -> set_lispstringp_data/length
XSTRING_CHAR_LENGTH -> string_char_length
XSTRING_CHAR -> string_emchar
INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p
INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p
charptr_copy_char -> charptr_copy_emchar
LEADING_BYTE_* -> leading_byte_*
CHAR_* -> EMCHAR_*
*_CHAR_* -> *_EMCHAR_*
*_CHAR -> *_EMCHAR
CHARSET_BY_ -> charset_by_*
BYTE_SHIFT_JIS* -> byte_shift_jis*
BYTE_BIG5* -> byte_big5*
REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte
char_to_unicode -> emchar_to_unicode
valid_char_p -> valid_emchar_p
Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality).
-- INTERFACE CHANGES AFFECTING LESS CODE:
use DECLARE_INLINE_HEADER in various places.
remove '#ifdef emacs' from XEmacs-only files.
eliminate CHAR_TABLE_VALUE(), which duplicated the functionality
of get_char_table().
add BUFFER_TEXT_LOOP to simplify iterations over buffer text.
define typedefs for signed and unsigned types of fixed sizes
(INT_32_BIT, UINT_32_BIT, etc.).
create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE;
fix code to use it.
add charptr_emchar_len to return the text length of the character
pointed to by a ptr; use it in place of
charcount_to_bytecount(..., 1). add emchar_len to return the text
length of a given character.
add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount
and Charbpos/Charcount, in code (particularly, the extents code
and redisplay code) that works with either kind of index. rename
redisplay struct params with names such as `charbpos' to
e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos.
eliminate xxDEFUN in place of DEFUN; no longer necessary with
changes awhile back to doc.c.
split up big ugly combined list of EXFUNs in lisp.h on a
file-by-file basis, since other prototypes are similarly split.
rewrite some "*_UNSAFE" macros as inline funs and eliminate the
_UNSAFE suffix.
move most string code from lisp.h to text.h; the string code and
text.h code is now intertwined in such a fashion that they need
to be in the same place and partially interleaved. (you can't
create forward references for inline funs)
automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in
batch mode.
Fix up some problems in lisp-tests/symbol-tests that were
causing spurious failures.
author | ben |
---|---|
date | Sun, 05 May 2002 11:33:57 +0000 |
parents | d8c768dcca7a |
children | 9ec13301bb30 |
line wrap: on
line source
;;; paragraphs.el --- paragraph and sentence parsing. ;; Copyright (C) 1985, 86, 87, 91, 94, 95, 97, 2001 ;; Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: wp, dumped ;; This file is part of XEmacs. ;; XEmacs is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; XEmacs 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 XEmacs; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ;; 02111-1307, USA. ;;; Synched up with: FSF 19.34. ;;; Commentary: ;; This file is dumped with XEmacs. ;; This package provides the paragraph-oriented commands documented in the ;; XEmacs Reference Manual. ;; 06/11/1997 - Use char-(after|before) instead of ;; (following|preceding)-char. -slb ;;; Code: (defvar use-hard-newlines nil "Non-nil means to distinguish hard and soft newlines. When this is non-nil, the functions `newline' and `open-line' add the text-property `hard' to newlines that they insert. Also, a line is only considered as a candidate to match `paragraph-start' or `paragraph-separate' if it follows a hard newline. Newlines not marked hard are called \"soft\", and are always internal to paragraphs. The fill functions always insert soft newlines. Each buffer has its own value of this variable.") (make-variable-buffer-local 'use-hard-newlines) (defun use-hard-newlines (&optional arg insert) "Minor mode to distinguish hard and soft newlines. When active, the functions `newline' and `open-line' add the text-property `hard' to newlines that they insert, and a line is only considered as a candidate to match `paragraph-start' or `paragraph-separate' if it follows a hard newline. Prefix argument says to turn mode on if positive, off if negative. When the mode is turned on, if there are newlines in the buffer but no hard newlines, ask the user whether to mark as hard any newlines preceding a `paragraph-start' line. From a program, second arg INSERT specifies whether to do this; it can be `never' to change nothing, t or `always' to force marking, `guess' to try to do the right thing with no questions, nil or anything else to ask the user. Newlines not marked hard are called \"soft\", and are always internal to paragraphs. The fill functions insert and delete only soft newlines." (interactive (list current-prefix-arg nil)) (if (or (<= (prefix-numeric-value arg) 0) (and use-hard-newlines (null arg))) ;; Turn mode off (setq use-hard-newlines nil) ;; Turn mode on ;; Intuit hard newlines -- ;; mark as hard any newlines preceding a paragraph-start line. (if (or (eq insert t) (eq insert 'always) (and (not (eq 'never insert)) (not use-hard-newlines) (not (text-property-any (point-min) (point-max) 'hard t)) (save-excursion (goto-char (point-min)) (search-forward "\n" nil t)) (or (eq insert 'guess) (y-or-n-p "Make newlines between paragraphs hard? ")))) (save-excursion (goto-char (point-min)) (while (search-forward "\n" nil t) (let ((pos (point))) (move-to-left-margin) (if (looking-at paragraph-start) (progn (set-hard-newline-properties (1- pos) pos) ;; If paragraph-separate, newline after it is hard too. (if (looking-at paragraph-separate) (progn (end-of-line) (if (not (eobp)) (set-hard-newline-properties (point) (1+ (point)))))))))))) (setq use-hard-newlines t))) (defconst paragraph-start "[ \t\n\f]" "\ *Regexp for beginning of a line that starts OR separates paragraphs. This regexp should match lines that separate paragraphs and should also match lines that start a paragraph \(and are part of that paragraph). This is matched against the text at the left margin, which is not necessarily the beginning of the line, so it should never use \"^\" as an anchor. This ensures that the paragraph functions will work equally well within a region of text indented by a margin setting. The variable `paragraph-separate' specifies how to distinguish lines that start paragraphs from lines that separate them. If the variable `use-hard-newlines' is non-nil, then only lines following a hard newline are considered to match.") ;; paragraph-start requires a hard newline, but paragraph-separate does not: ;; It is assumed that paragraph-separate is distinctive enough to be believed ;; whenever it occurs, while it is reasonable to set paragraph-start to ;; something very minimal, even including "." (which makes every hard newline ;; start a new paragraph). (defconst paragraph-separate "[ \t\f]*$" "\ *Regexp for beginning of a line that separates paragraphs. If you change this, you may have to change `paragraph-start' also. A line matching this is not part of any paragraph. This is matched against the text at the left margin, which is not necessarily the beginning of the line, so it should not use \"^\" as an anchor. This ensures that the paragraph functions will work equally within a region of text indented by a margin setting.") (defconst sentence-end "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*" "\ *Regexp describing the end of a sentence. All paragraph boundaries also end sentences, regardless. In order to be recognized as the end of a sentence, the ending period, question mark, or exclamation point must be followed by two spaces, unless it's inside some sort of quotes or parenthesis.") (defconst page-delimiter "^\014" "\ *Regexp describing line-beginnings that separate pages.") (defvar paragraph-ignore-fill-prefix nil "\ Non-nil means the paragraph commands are not affected by `fill-prefix'. This is desirable in modes where blank lines are the paragraph delimiters.") (defun forward-paragraph (&optional arg) "Move forward to end of paragraph. With arg N, do it N times; negative arg -N means move backward N paragraphs. A line which `paragraph-start' matches either separates paragraphs \(if `paragraph-separate' matches it also) or is the first line of a paragraph. A paragraph end is the beginning of a line which is not part of the paragraph to which the end of the previous line belongs, or the end of the buffer." (interactive "_p") ; XEmacs (or arg (setq arg 1)) (let* ((fill-prefix-regexp (and fill-prefix (not (equal fill-prefix "")) (not paragraph-ignore-fill-prefix) (regexp-quote fill-prefix))) ;; Remove ^ from paragraph-start and paragraph-sep if they are there. ;; These regexps shouldn't be anchored, because we look for them ;; starting at the left-margin. This allows paragraph commands to ;; work normally with indented text. ;; This hack will not find problem cases like "whatever\\|^something". (paragraph-start (if (and (not (equal "" paragraph-start)) (equal ?^ (aref paragraph-start 0))) (substring paragraph-start 1) paragraph-start)) (paragraph-separate (if (and (not (equal "" paragraph-start)) (equal ?^ (aref paragraph-separate 0))) (substring paragraph-separate 1) paragraph-separate)) (paragraph-separate (if fill-prefix-regexp (concat paragraph-separate "\\|" fill-prefix-regexp "[ \t]*$") paragraph-separate)) ;; This is used for searching. (sp-paragraph-start (concat "^[ \t]*\\(" paragraph-start "\\)")) start) (while (and (< arg 0) (not (bobp))) (if (and (not (looking-at paragraph-separate)) (re-search-backward "^\n" (max (1- (point)) (point-min)) t) (looking-at paragraph-separate)) nil (setq start (point)) ;; Move back over paragraph-separating lines. (backward-char 1) (beginning-of-line) (while (and (not (bobp)) (progn (move-to-left-margin) (looking-at paragraph-separate))) (forward-line -1)) (if (bobp) nil ;; Go to end of the previous (non-separating) line. (end-of-line) ;; Search back for line that starts or separates paragraphs. (if (if fill-prefix-regexp ;; There is a fill prefix; it overrides paragraph-start. (let (multiple-lines) (while (and (progn (beginning-of-line) (not (bobp))) (progn (move-to-left-margin) (not (looking-at paragraph-separate))) (looking-at fill-prefix-regexp)) (if (not (= (point) start)) (setq multiple-lines t)) (forward-line -1)) (move-to-left-margin) ;; Don't move back over a line before the paragraph ;; which doesn't start with fill-prefix ;; unless that is the only line we've moved over. (and (not (looking-at fill-prefix-regexp)) multiple-lines (forward-line 1)) (not (bobp))) (while (and (re-search-backward sp-paragraph-start nil 1) ;; Found a candidate, but need to check if it is a ;; REAL paragraph-start. (not (bobp)) (progn (setq start (point)) (move-to-left-margin) (not (looking-at paragraph-separate))) (or (not (looking-at paragraph-start)) (and use-hard-newlines (not (get-text-property (1- start) 'hard))))) (goto-char start)) (> (point) (point-min))) ;; Found one. (progn ;; Move forward over paragraph separators. ;; We know this cannot reach the place we started ;; because we know we moved back over a non-separator. (while (and (not (eobp)) (progn (move-to-left-margin) (looking-at paragraph-separate))) (forward-line 1)) ;; If line before paragraph is just margin, back up to there. (end-of-line 0) (if (> (current-column) (current-left-margin)) (forward-char 1) (skip-chars-backward " \t") (if (not (bolp)) (forward-line 1)))) ;; No starter or separator line => use buffer beg. (goto-char (point-min))))) (setq arg (1+ arg))) (while (and (> arg 0) (not (eobp))) ;; Move forward over separator lines, and one more line. (while (prog1 (and (not (eobp)) (progn (move-to-left-margin) (not (eobp))) (looking-at paragraph-separate)) (forward-line 1))) (if fill-prefix-regexp ;; There is a fill prefix; it overrides paragraph-start. (while (and (not (eobp)) (progn (move-to-left-margin) (not (eobp))) (not (looking-at paragraph-separate)) (looking-at fill-prefix-regexp)) (forward-line 1)) (while (and (re-search-forward sp-paragraph-start nil 1) (progn (setq start (match-beginning 0)) (goto-char start) (not (eobp))) (progn (move-to-left-margin) (not (looking-at paragraph-separate))) (or (not (looking-at paragraph-start)) (and use-hard-newlines (not (get-text-property (1- start) 'hard))))) (forward-char 1)) (if (< (point) (point-max)) (goto-char start))) (setq arg (1- arg))))) (defun backward-paragraph (&optional arg) "Move backward to start of paragraph. With arg N, do it N times; negative arg -N means move forward N paragraphs. A paragraph start is the beginning of a line which is a `first-line-of-paragraph' or which is ordinary text and follows a paragraph-separating line; except: if the first real line of a paragraph is preceded by a blank line, the paragraph starts at that blank line. See `forward-paragraph' for more information." (interactive "_p") ; XEmacs (or arg (setq arg 1)) (forward-paragraph (- arg))) (defun mark-paragraph (&optional arg) "Put point at beginning of this paragraph, mark at end. The paragraph marked is the one that contains point or follows point. With arg N, puts mark at end of following N paragraphs; negative arg -N means point is put at end of this paragraph, mark is put at beginning of this or a previous paragraph." (interactive "p") (unless arg (setq arg 1)) (when (zerop arg) (error "Cannot mark zero paragraphs")) (forward-paragraph arg) (push-mark nil t t) (backward-paragraph arg)) (defun kill-paragraph (arg) "Kill forward to end of paragraph. With arg N, kill forward to Nth end of paragraph; negative arg -N means kill backward to Nth start of paragraph." (interactive "*p") ; XEmacs (kill-region (point) (progn (forward-paragraph arg) (point)))) (defun backward-kill-paragraph (arg) "Kill back to start of paragraph. With arg N, kill back to Nth start of paragraph; negative arg -N means kill forward to Nth end of paragraph." (interactive "*p") ; XEmacs (kill-region (point) (progn (backward-paragraph arg) (point)))) (defun transpose-paragraphs (arg) "Interchange this (or next) paragraph with previous one." (interactive "*p") (transpose-subr 'forward-paragraph arg)) (defun start-of-paragraph-text () (let ((opoint (point)) npoint) (forward-paragraph -1) (setq npoint (point)) (skip-chars-forward " \t\n") ;; If the range of blank lines found spans the original start point, ;; try again from the beginning of it. ;; Must be careful to avoid infinite loop ;; when following a single return at start of buffer. (if (and (>= (point) opoint) (< npoint opoint)) (progn (goto-char npoint) (if (> npoint (point-min)) (start-of-paragraph-text)))))) (defun end-of-paragraph-text () (let ((opoint (point))) (forward-paragraph 1) (if (eq (char-before (point)) ?\n) (backward-char 1)) (if (<= (point) opoint) (progn (forward-char 1) (if (< (point) (point-max)) (end-of-paragraph-text)))))) (defun forward-sentence (&optional arg) "Move forward to next `sentence-end'. With argument, repeat. With negative argument, move backward repeatedly to `sentence-beginning'. The variable `sentence-end' is a regular expression that matches ends of sentences. A paragraph boundary also terminates a sentence." (interactive "_p") ; XEmacs (or arg (setq arg 1)) (while (< arg 0) (let ((par-beg (save-excursion (start-of-paragraph-text) (point)))) (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t) (goto-char (1- (match-end 0))) (goto-char par-beg))) (setq arg (1+ arg))) (while (> arg 0) (let ((par-end (save-excursion (end-of-paragraph-text) (point)))) (if (re-search-forward sentence-end par-end t) (skip-chars-backward " \t\n") (goto-char par-end))) (setq arg (1- arg)))) (defun backward-sentence (&optional arg) "Move backward to start of sentence. With arg, do it arg times. See `forward-sentence' for more information." (interactive "_p") ; XEmacs (or arg (setq arg 1)) (forward-sentence (- arg))) (defun kill-sentence (&optional arg) "Kill from point to end of sentence. With arg, repeat; negative arg -N means kill back to Nth start of sentence." (interactive "*p") ; XEmacs (kill-region (point) (progn (forward-sentence arg) (point)))) (defun backward-kill-sentence (&optional arg) "Kill back from point to start of sentence. With arg, repeat, or kill forward to Nth end of sentence if negative arg -N." (interactive "*p") ; XEmacs (kill-region (point) (progn (backward-sentence arg) (point)))) (defun mark-end-of-sentence (arg) "Put mark at end of sentence. Arg works as in `forward-sentence'." (interactive "p") ;; FSF Version: ; (push-mark ; (save-excursion ; (forward-sentence arg) ; (point)) ; nil t)) (mark-something 'mark-end-of-sentence 'forward-sentence arg)) (defun mark-end-of-line (arg) "Put mark at end of line. Arg works as in `end-of-line'." (interactive "p") (mark-something 'mark-end-of-line 'end-of-line arg)) (defun transpose-sentences (arg) "Interchange this (next) and previous sentence." (interactive "*p") (transpose-subr 'forward-sentence arg)) ;;; paragraphs.el ends here