Mercurial > hg > xemacs-beta
comparison man/lispref/positions.texi @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | 3ecd8885ac67 |
children | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
2 @c This is part of the XEmacs Lisp Reference Manual. | 2 @c This is part of the XEmacs Lisp Reference Manual. |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
4 @c See the file lispref.texi for copying conditions. | 4 @c See the file lispref.texi for copying conditions. |
5 @setfilename ../../info/positions.info | 5 @setfilename ../../info/positions.info |
6 @node Positions, Markers, Consoles and Devices, Top | 6 @node Positions, Markers, Consoles and Devices, Top |
7 @chapter Positions | 7 @chapter Positions |
8 @cindex position (in buffer) | 8 @cindex position (in buffer) |
247 | 247 |
248 Here are two commands that users use to do these things. They are | 248 Here are two commands that users use to do these things. They are |
249 documented here to warn you not to use them in Lisp programs, because | 249 documented here to warn you not to use them in Lisp programs, because |
250 they set the mark and display messages in the echo area. | 250 they set the mark and display messages in the echo area. |
251 | 251 |
252 @deffn Command beginning-of-buffer &optional n | 252 @deffn Command beginning-of-buffer &optional count |
253 This function moves point to the beginning of the buffer (or the limits | 253 This function moves point to the beginning of the buffer (or the limits |
254 of the accessible portion, when narrowing is in effect), setting the | 254 of the accessible portion, when narrowing is in effect), setting the |
255 mark at the previous position. If @var{n} is non-@code{nil}, then it | 255 mark at the previous position. If @var{count} is non-@code{nil}, then it |
256 puts point @var{n} tenths of the way from the beginning of the buffer. | 256 puts point @var{count} tenths of the way from the beginning of the buffer. |
257 | 257 |
258 In an interactive call, @var{n} is the numeric prefix argument, | 258 In an interactive call, @var{count} is the numeric prefix argument, |
259 if provided; otherwise @var{n} defaults to @code{nil}. | 259 if provided; otherwise @var{count} defaults to @code{nil}. |
260 | 260 |
261 Don't use this function in Lisp programs! | 261 Don't use this function in Lisp programs! |
262 @end deffn | 262 @end deffn |
263 | 263 |
264 @deffn Command end-of-buffer &optional n | 264 @deffn Command end-of-buffer &optional count |
265 This function moves point to the end of the buffer (or the limits of | 265 This function moves point to the end of the buffer (or the limits of |
266 the accessible portion, when narrowing is in effect), setting the mark | 266 the accessible portion, when narrowing is in effect), setting the mark |
267 at the previous position. If @var{n} is non-@code{nil}, then it puts | 267 at the previous position. If @var{count} is non-@code{nil}, then it puts |
268 point @var{n} tenths of the way from the end of the buffer. | 268 point @var{count} tenths of the way from the end of the buffer. |
269 | 269 |
270 In an interactive call, @var{n} is the numeric prefix argument, | 270 In an interactive call, @var{count} is the numeric prefix argument, |
271 if provided; otherwise @var{n} defaults to @code{nil}. | 271 if provided; otherwise @var{count} defaults to @code{nil}. |
272 | 272 |
273 Don't use this function in Lisp programs! | 273 Don't use this function in Lisp programs! |
274 @end deffn | 274 @end deffn |
275 | 275 |
276 @node Text Lines | 276 @node Text Lines |
351 the end of the last line, and the value will be 2. | 351 the end of the last line, and the value will be 2. |
352 | 352 |
353 In an interactive call, @var{count} is the numeric prefix argument. | 353 In an interactive call, @var{count} is the numeric prefix argument. |
354 @end deffn | 354 @end deffn |
355 | 355 |
356 @defun count-lines start end | 356 @defun count-lines start end &optional ignore-invisible-lines-flag |
357 @cindex lines in region | 357 @cindex lines in region |
358 This function returns the number of lines between the positions | 358 This function returns the number of lines between the positions |
359 @var{start} and @var{end} in the current buffer. If @var{start} and | 359 @var{start} and @var{end} in the current buffer. If @var{start} and |
360 @var{end} are equal, then it returns 0. Otherwise it returns at least | 360 @var{end} are equal, then it returns 0. Otherwise it returns at least |
361 1, even if @var{start} and @var{end} are on the same line. This is | 361 1, even if @var{start} and @var{end} are on the same line. This is |
362 because the text between them, considered in isolation, must contain at | 362 because the text between them, considered in isolation, must contain at |
363 least one line unless it is empty. | 363 least one line unless it is empty. |
364 | 364 |
365 With optional @var{ignore-invisible-lines-flag} non-@code{nil}, lines | |
366 collapsed with selective-display are excluded from the line count. | |
367 | |
368 @strong{Note:} The expression to return the current line number is not | |
369 obvious: | |
370 | |
371 @example | |
372 (1+ (count-lines 1 (point-at-bol))) | |
373 @end example | |
374 | |
365 Here is an example of using @code{count-lines}: | 375 Here is an example of using @code{count-lines}: |
366 | 376 |
367 @example | 377 @example |
368 @group | 378 @group |
369 (defun current-line () | 379 (defun current-line () |
473 | 483 |
474 @defun vertical-motion count &optional window pixels | 484 @defun vertical-motion count &optional window pixels |
475 This function moves point to the start of the frame line @var{count} | 485 This function moves point to the start of the frame line @var{count} |
476 frame lines down from the frame line containing point. If @var{count} | 486 frame lines down from the frame line containing point. If @var{count} |
477 is negative, it moves up instead. The optional second argument | 487 is negative, it moves up instead. The optional second argument |
478 @var{window} may be used to specify a window other than the | 488 @var{window} may be used to specify a window other than the |
479 selected window in which to perform the motion. | 489 selected window in which to perform the motion. |
480 | 490 |
481 Normally, @code{vertical-motion} returns the number of lines moved. The | 491 Normally, @code{vertical-motion} returns the number of lines moved. The |
482 value may be less in absolute value than @var{count} if the beginning or | 492 value may be less in absolute value than @var{count} if the beginning or |
483 end of the buffer was reached. If the optional third argument, | 493 end of the buffer was reached. If the optional third argument, |
590 beginning of the first screen line. @xref{Minibuffer Misc}. | 600 beginning of the first screen line. @xref{Minibuffer Misc}. |
591 @end defun | 601 @end defun |
592 @end ignore | 602 @end ignore |
593 | 603 |
594 @node List Motion | 604 @node List Motion |
595 @subsection Moving over Balanced Expressions | 605 @subsection Moving over Balanced Expressions |
596 @cindex sexp motion | 606 @cindex sexp motion |
597 @cindex Lisp expression motion | 607 @cindex Lisp expression motion |
598 @cindex list motion | 608 @cindex list motion |
599 | 609 |
600 Here are several functions concerned with balanced-parenthesis | 610 Here are several functions concerned with balanced-parenthesis |
610 parentheses. (Other syntactic entities such as words or paired string | 620 parentheses. (Other syntactic entities such as words or paired string |
611 quotes are ignored.) @var{arg} defaults to 1 if omitted. If @var{arg} | 621 quotes are ignored.) @var{arg} defaults to 1 if omitted. If @var{arg} |
612 is negative, move backward across that many groups of parentheses. | 622 is negative, move backward across that many groups of parentheses. |
613 @end deffn | 623 @end deffn |
614 | 624 |
615 @deffn Command backward-list &optional arg | 625 @deffn Command backward-list &optional count |
616 This function moves backward across @var{arg} balanced groups of | 626 This function moves backward across @var{count} balanced groups of |
617 parentheses. (Other syntactic entities such as words or paired string | 627 parentheses. (Other syntactic entities such as words or paired string |
618 quotes are ignored.) @var{arg} defaults to 1 if omitted. If @var{arg} | 628 quotes are ignored.) @var{count} defaults to 1 if omitted. If |
619 is negative, move forward across that many groups of parentheses. | 629 @var{count} is negative, move forward across that many groups of |
620 @end deffn | 630 parentheses. |
621 | 631 @end deffn |
622 @deffn Command up-list arg | 632 |
623 This function moves forward out of @var{arg} levels of parentheses. | 633 @deffn Command up-list &optional count |
634 This function moves forward out of @var{count} levels of parentheses. | |
624 A negative argument means move backward but still to a less deep spot. | 635 A negative argument means move backward but still to a less deep spot. |
625 @end deffn | 636 @end deffn |
626 | 637 |
627 @deffn Command down-list arg | 638 @deffn Command down-list &optional count |
628 This function moves forward into @var{arg} levels of parentheses. A | 639 This function moves forward into @var{count} levels of parentheses. |
629 negative argument means move backward but still go | 640 A negative argument means move backward but still go deeper in |
630 deeper in parentheses (@minus{}@var{arg} levels). | 641 parentheses (@minus{}@var{count} levels). |
631 @end deffn | 642 @end deffn |
632 | 643 |
633 @deffn Command forward-sexp &optional arg | 644 @deffn Command forward-sexp &optional count |
634 This function moves forward across @var{arg} balanced expressions. | 645 This function moves forward across @var{count} balanced expressions. |
635 Balanced expressions include both those delimited by parentheses and | 646 Balanced expressions include both those delimited by parentheses and |
636 other kinds, such as words and string constants. @var{arg} defaults to | 647 other kinds, such as words and string constants. @var{count} defaults to |
637 1 if omitted. If @var{arg} is negative, move backward across that many | 648 1 if omitted. If @var{count} is negative, move backward across that many |
638 balanced expressions. For example, | 649 balanced expressions. For example, |
639 | 650 |
640 @example | 651 @example |
641 @group | 652 @group |
642 ---------- Buffer: foo ---------- | 653 ---------- Buffer: foo ---------- |
653 ---------- Buffer: foo ---------- | 664 ---------- Buffer: foo ---------- |
654 @end group | 665 @end group |
655 @end example | 666 @end example |
656 @end deffn | 667 @end deffn |
657 | 668 |
658 @deffn Command backward-sexp &optional arg | 669 @deffn Command backward-sexp &optional count |
659 This function moves backward across @var{arg} balanced expressions. | 670 This function moves backward across @var{count} balanced expressions. |
660 @var{arg} defaults to 1 if omitted. If @var{arg} is negative, move | 671 @var{count} defaults to 1 if omitted. If @var{count} is negative, move |
661 forward across that many balanced expressions. | 672 forward across that many balanced expressions. |
662 @end deffn | 673 @end deffn |
663 | 674 |
664 @deffn Command beginning-of-defun &optional arg | 675 @deffn Command beginning-of-defun &optional count |
665 This function moves back to the @var{arg}th beginning of a defun. If | 676 This function moves back to the @var{count}th beginning of a defun. |
666 @var{arg} is negative, this actually moves forward, but it still moves | 677 If @var{count} is negative, this actually moves forward, but it still |
667 to the beginning of a defun, not to the end of one. @var{arg} defaults | 678 moves to the beginning of a defun, not to the end of one. @var{count} |
668 to 1 if omitted. | 679 defaults to 1 if omitted. |
669 @end deffn | 680 @end deffn |
670 | 681 |
671 @deffn Command end-of-defun &optional arg | 682 @deffn Command end-of-defun &optional count |
672 This function moves forward to the @var{arg}th end of a defun. If | 683 This function moves forward to the @var{count}th end of a defun. |
673 @var{arg} is negative, this actually moves backward, but it still moves | 684 If @var{count} is negative, this actually moves backward, but it still |
674 to the end of a defun, not to the beginning of one. @var{arg} defaults | 685 moves to the end of a defun, not to the beginning of one. @var{count} |
675 to 1 if omitted. | 686 defaults to 1 if omitted. |
676 @end deffn | 687 @end deffn |
677 | 688 |
678 @defopt defun-prompt-regexp | 689 @defopt defun-prompt-regexp |
679 If non-@code{nil}, this variable holds a regular expression that | 690 If non-@code{nil}, this variable holds a regular expression that |
680 specifies what text can appear before the open-parenthesis that starts a | 691 specifies what text can appear before the open-parenthesis that starts a |
811 @defspec with-current-buffer buffer forms@dots{} | 822 @defspec with-current-buffer buffer forms@dots{} |
812 This special form evaluates @var{forms} with @var{buffer} as the current | 823 This special form evaluates @var{forms} with @var{buffer} as the current |
813 buffer. It returns the value of the last form. | 824 buffer. It returns the value of the last form. |
814 @end defspec | 825 @end defspec |
815 | 826 |
816 @defspec with-temp-file file forms@dots{} | 827 @defspec with-temp-file filename forms@dots{} |
817 This special form creates a new buffer, evaluates @var{forms} there, and | 828 This special form creates a new buffer, evaluates @var{forms} there, and |
818 writes the buffer to @var{file}. It returns the value of the last form | 829 writes the buffer to @var{filename}. It returns the value of the last form |
819 evaluated. | 830 evaluated. |
820 @end defspec | 831 @end defspec |
821 | 832 |
822 @defspec save-selected-window forms@dots{} | 833 @defspec save-selected-window forms@dots{} |
823 This special form is similar to @code{save-excursion} but it saves and | 834 This special form is similar to @code{save-excursion} but it saves and |
923 this is what you want to do, @code{save-restriction} is not the right | 934 this is what you want to do, @code{save-restriction} is not the right |
924 tool for the job. Here is what you must use instead: | 935 tool for the job. Here is what you must use instead: |
925 | 936 |
926 @example | 937 @example |
927 @group | 938 @group |
928 (let ((beg (point-min-marker)) | 939 (let ((start (point-min-marker)) |
929 (end (point-max-marker))) | 940 (end (point-max-marker))) |
930 (unwind-protect | 941 (unwind-protect |
931 (progn @var{body}) | 942 (progn @var{body}) |
932 (save-excursion | 943 (save-excursion |
933 (set-buffer (marker-buffer beg)) | 944 (set-buffer (marker-buffer start)) |
934 (narrow-to-region beg end)))) | 945 (narrow-to-region start end)))) |
935 @end group | 946 @end group |
936 @end example | 947 @end example |
937 | 948 |
938 Here is a simple example of correct use of @code{save-restriction}: | 949 Here is a simple example of correct use of @code{save-restriction}: |
939 | 950 |