aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2012-03-28 12:30:12 -0700
committerGlenn Morris2012-03-28 12:30:12 -0700
commitfee88ca0e8777476ea411d666bed8ac9fc4c8e20 (patch)
treea904f18fd4695c7b09699c76ea26dbc34cb27c81
parente8fc049ff7ed71d570f320d9a90d8b2546db5de2 (diff)
downloademacs-fee88ca0e8777476ea411d666bed8ac9fc4c8e20.tar.gz
emacs-fee88ca0e8777476ea411d666bed8ac9fc4c8e20.zip
Doc and lispref updates related to searching
* doc/lispref/searching.texi (Regexp Functions, Regexp Search): (Simple Match Data, Saving Match Data, Standard Regexps): Copyedits. (Regexp Functions): Mention regexp-opt is not guaranteed. Mention regexp-opt-charset. (Regexp Search): Recommend against looking-back. (Search and Replace): Use Texinfo recommended quote convention. Add more query-replace-map items. List multi-query-replace-map items. * lisp/replace.el (query-replace-map): Doc fix. * admin/FOR-RELEASE: Related markup.
-rw-r--r--admin/FOR-RELEASE2
-rw-r--r--doc/lispref/ChangeLog8
-rw-r--r--doc/lispref/searching.texi108
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/replace.el4
5 files changed, 90 insertions, 36 deletions
diff --git a/admin/FOR-RELEASE b/admin/FOR-RELEASE
index 73ff5ab7810..10e589371c4 100644
--- a/admin/FOR-RELEASE
+++ b/admin/FOR-RELEASE
@@ -220,7 +220,7 @@ os.texi cyd
220package.texi rgm 220package.texi rgm
221positions.texi cyd 221positions.texi cyd
222processes.texi 222processes.texi
223searching.texi 223searching.texi rgm
224sequences.texi cyd 224sequences.texi cyd
225streams.texi cyd 225streams.texi cyd
226strings.texi cyd 226strings.texi cyd
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index ca3b61d897e..dfd1180b556 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,9 +1,15 @@
12012-03-28 Glenn Morris <rgm@gnu.org> 12012-03-28 Glenn Morris <rgm@gnu.org>
2 2
3 * searching.texi (Regular Expressions, Regexp Special): 3 * searching.texi (Regular Expressions, Regexp Special):
4 (Regexp Backslash, Regexp Example): Copyedits. 4 (Regexp Backslash, Regexp Example, Regexp Functions, Regexp Search):
5 (Simple Match Data, Saving Match Data, Standard Regexps): Copyedits.
5 (Regexp Special): Mention collation. 6 (Regexp Special): Mention collation.
6 Clarify char classes with an example. 7 Clarify char classes with an example.
8 (Regexp Functions): Mention regexp-opt is not guaranteed.
9 Mention regexp-opt-charset.
10 (Regexp Search): Recommend against looking-back.
11 (Search and Replace): Use Texinfo recommended quote convention.
12 Add more query-replace-map items. List multi-query-replace-map items.
7 13
82012-03-27 Martin Rudalics <rudalics@gmx.at> 142012-03-27 Martin Rudalics <rudalics@gmx.at>
9 15
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi
index a248932b51d..e79d361bfeb 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -902,7 +902,7 @@ This function returns a regular expression whose only exact match is
902@var{string}. Using this regular expression in @code{looking-at} will 902@var{string}. Using this regular expression in @code{looking-at} will
903succeed only if the next characters in the buffer are @var{string}; 903succeed only if the next characters in the buffer are @var{string};
904using it in a search function will succeed if the text being searched 904using it in a search function will succeed if the text being searched
905contains @var{string}. 905contains @var{string}. @xref{Regexp Search}.
906 906
907This allows you to request an exact string match or search when calling 907This allows you to request an exact string match or search when calling
908a function that wants a regular expression. 908a function that wants a regular expression.
@@ -931,7 +931,11 @@ whitespace:
931This function returns an efficient regular expression that will match 931This function returns an efficient regular expression that will match
932any of the strings in the list @var{strings}. This is useful when you 932any of the strings in the list @var{strings}. This is useful when you
933need to make matching or searching as fast as possible---for example, 933need to make matching or searching as fast as possible---for example,
934for Font Lock mode. 934for Font Lock mode@footnote{Note that @code{regexp-opt} does not
935guarantee that its result is absolutely the most efficient form
936possible. A hand-tuned regular expression can sometimes be slightly
937more efficient, but is almost never worth the effort.}.
938@c See eg http://debbugs.gnu.org/2816
935 939
936If the optional argument @var{paren} is non-@code{nil}, then the 940If the optional argument @var{paren} is non-@code{nil}, then the
937returned regular expression is always enclosed by at least one 941returned regular expression is always enclosed by at least one
@@ -947,7 +951,7 @@ regular expression which is equivalent to the actual value
947(but not as efficient): 951(but not as efficient):
948 952
949@example 953@example
950(defun regexp-opt (strings paren) 954(defun regexp-opt (strings &optional paren)
951 (let ((open-paren (if paren "\\(" "")) 955 (let ((open-paren (if paren "\\(" ""))
952 (close-paren (if paren "\\)" ""))) 956 (close-paren (if paren "\\)" "")))
953 (concat open-paren 957 (concat open-paren
@@ -962,6 +966,19 @@ This function returns the total number of grouping constructs
962shy groups (@pxref{Regexp Backslash}). 966shy groups (@pxref{Regexp Backslash}).
963@end defun 967@end defun
964 968
969@c Supposedly an internal regexp-opt function, but table.el uses it at least.
970@defun regexp-opt-charset chars
971This function returns a regular expression matching a character in the
972list of characters @var{chars}.
973
974@example
975(regexp-opt-charset '(?a ?b ?c ?d ?e))
976 @result{} "[a-e]"
977@end example
978@end defun
979
980@c Internal functions: regexp-opt-group
981
965@node Regexp Search 982@node Regexp Search
966@section Regular Expression Searching 983@section Regular Expression Searching
967@cindex regular expression searching 984@cindex regular expression searching
@@ -1104,8 +1121,7 @@ following'' means precisely that: the search is ``anchored'' and it can
1104succeed only starting with the first character following point. The 1121succeed only starting with the first character following point. The
1105result is @code{t} if so, @code{nil} otherwise. 1122result is @code{t} if so, @code{nil} otherwise.
1106 1123
1107This function does not move point, but it updates the match data, which 1124This function does not move point, but it does update the match data.
1108you can access using @code{match-beginning} and @code{match-end}.
1109@xref{Match Data}. If you need to test for a match without modifying 1125@xref{Match Data}. If you need to test for a match without modifying
1110the match data, use @code{looking-at-p}, described below. 1126the match data, use @code{looking-at-p}, described below.
1111 1127
@@ -1126,8 +1142,8 @@ comes back" twice.
1126@end defun 1142@end defun
1127 1143
1128@defun looking-back regexp &optional limit greedy 1144@defun looking-back regexp &optional limit greedy
1129This function returns @code{t} if @var{regexp} matches text before 1145This function returns @code{t} if @var{regexp} matches the text
1130point, ending at point, and @code{nil} otherwise. 1146immediately before point (i.e., ending at point), and @code{nil} otherwise.
1131 1147
1132Because regular expression matching works only going forward, this is 1148Because regular expression matching works only going forward, this is
1133implemented by searching backwards from point for a match that ends at 1149implemented by searching backwards from point for a match that ends at
@@ -1155,6 +1171,11 @@ comes back" twice.
1155 @result{} nil 1171 @result{} nil
1156@end group 1172@end group
1157@end example 1173@end example
1174
1175@c http://debbugs.gnu.org/5689
1176As a general recommendation, try to avoid using @code{looking-back}
1177wherever possible, since it is slow. For this reason, there are no
1178plans to add a @code{looking-back-p} function.
1158@end defun 1179@end defun
1159 1180
1160@defun looking-at-p regexp 1181@defun looking-at-p regexp
@@ -1178,6 +1199,7 @@ a part of the code.
1178@node POSIX Regexps 1199@node POSIX Regexps
1179@section POSIX Regular Expression Searching 1200@section POSIX Regular Expression Searching
1180 1201
1202@cindex backtracking and POSIX regular expressions
1181 The usual regular expression functions do backtracking when necessary 1203 The usual regular expression functions do backtracking when necessary
1182to handle the @samp{\|} and repetition constructs, but they continue 1204to handle the @samp{\|} and repetition constructs, but they continue
1183this only until they find @emph{some} match. Then they succeed and 1205this only until they find @emph{some} match. Then they succeed and
@@ -1350,12 +1372,16 @@ only information available is about the entire match.
1350query the match data immediately after searching, before calling any 1372query the match data immediately after searching, before calling any
1351other function that might perform another search. Alternatively, you 1373other function that might perform another search. Alternatively, you
1352may save and restore the match data (@pxref{Saving Match Data}) around 1374may save and restore the match data (@pxref{Saving Match Data}) around
1353the call to functions that could perform another search. 1375the call to functions that could perform another search. Or use the
1376functions that explicitly do not modify the match data;
1377e.g. @code{string-match-p}.
1354 1378
1379@c This is an old comment and presumably there is no prospect of this
1380@c changing now. But still the advice stands.
1355 A search which fails may or may not alter the match data. In the 1381 A search which fails may or may not alter the match data. In the
1356past, a failing search did not do this, but we may change it in the 1382current implementation, it does not, but we may change it in the
1357future. So don't try to rely on the value of the match data after 1383future. Don't try to rely on the value of the match data after a
1358a failing search. 1384failing search.
1359 1385
1360@defun match-string count &optional in-string 1386@defun match-string count &optional in-string
1361This function returns, as a string, the text matched in the last search 1387This function returns, as a string, the text matched in the last search
@@ -1369,7 +1395,7 @@ argument @var{in-string}. After a buffer search or match,
1369you should omit @var{in-string} or pass @code{nil} for it; but you 1395you should omit @var{in-string} or pass @code{nil} for it; but you
1370should make sure that the current buffer when you call 1396should make sure that the current buffer when you call
1371@code{match-string} is the one in which you did the searching or 1397@code{match-string} is the one in which you did the searching or
1372matching. 1398matching. Failure to follow this advice will lead to incorrect results.
1373 1399
1374The value is @code{nil} if @var{count} is out of range, or for a 1400The value is @code{nil} if @var{count} is out of range, or for a
1375subexpression inside a @samp{\|} alternative that wasn't used or a 1401subexpression inside a @samp{\|} alternative that wasn't used or a
@@ -1382,7 +1408,7 @@ has no text properties.
1382@end defun 1408@end defun
1383 1409
1384@defun match-beginning count 1410@defun match-beginning count
1385This function returns the position of the start of text matched by the 1411This function returns the position of the start of the text matched by the
1386last regular expression searched for, or a subexpression of it. 1412last regular expression searched for, or a subexpression of it.
1387 1413
1388If @var{count} is zero, then the value is the position of the start of 1414If @var{count} is zero, then the value is the position of the start of
@@ -1475,7 +1501,7 @@ write the entire match data, all at once.
1475 1501
1476@defun match-data &optional integers reuse reseat 1502@defun match-data &optional integers reuse reseat
1477This function returns a list of positions (markers or integers) that 1503This function returns a list of positions (markers or integers) that
1478record all the information on what text the last search matched. 1504record all the information on the text that the last search matched.
1479Element zero is the position of the beginning of the match for the 1505Element zero is the position of the beginning of the match for the
1480whole expression; element one is the position of the end of the match 1506whole expression; element one is the position of the end of the match
1481for the expression. The next two elements are the positions of the 1507for the expression. The next two elements are the positions of the
@@ -1544,6 +1570,7 @@ an error; that sets the match data in a meaningless but harmless way.
1544If @var{reseat} is non-@code{nil}, all markers on the @var{match-list} list 1570If @var{reseat} is non-@code{nil}, all markers on the @var{match-list} list
1545are reseated to point to nowhere. 1571are reseated to point to nowhere.
1546 1572
1573@c TODO Make it properly obsolete.
1547@findex store-match-data 1574@findex store-match-data
1548@code{store-match-data} is a semi-obsolete alias for @code{set-match-data}. 1575@code{store-match-data} is a semi-obsolete alias for @code{set-match-data}.
1549@end defun 1576@end defun
@@ -1551,7 +1578,7 @@ are reseated to point to nowhere.
1551@node Saving Match Data 1578@node Saving Match Data
1552@subsection Saving and Restoring the Match Data 1579@subsection Saving and Restoring the Match Data
1553 1580
1554 When you call a function that may do a search, you may need to save 1581 When you call a function that may search, you may need to save
1555and restore the match data around that call, if you want to preserve the 1582and restore the match data around that call, if you want to preserve the
1556match data from an earlier search for later use. Here is an example 1583match data from an earlier search for later use. Here is an example
1557that shows the problem that arises if you fail to save the match data: 1584that shows the problem that arises if you fail to save the match data:
@@ -1560,8 +1587,7 @@ that shows the problem that arises if you fail to save the match data:
1560@group 1587@group
1561(re-search-forward "The \\(cat \\)") 1588(re-search-forward "The \\(cat \\)")
1562 @result{} 48 1589 @result{} 48
1563(foo) ; @r{Perhaps @code{foo} does} 1590(foo) ; @r{@code{foo} does more searching.}
1564 ; @r{more searching.}
1565(match-end 0) 1591(match-end 0)
1566 @result{} 61 ; @r{Unexpected result---not 48!} 1592 @result{} 61 ; @r{Unexpected result---not 48!}
1567@end group 1593@end group
@@ -1654,7 +1680,7 @@ Instead of a string, @var{rep} can be a function. In that case,
1654@code{replace-regexp-in-string} calls @var{rep} for each match, 1680@code{replace-regexp-in-string} calls @var{rep} for each match,
1655passing the text of the match as its sole argument. It collects the 1681passing the text of the match as its sole argument. It collects the
1656value @var{rep} returns and passes that to @code{replace-match} as the 1682value @var{rep} returns and passes that to @code{replace-match} as the
1657replacement string. The match-data at this point are the result 1683replacement string. The match data at this point are the result
1658of matching @var{regexp} against a substring of @var{string}. 1684of matching @var{regexp} against a substring of @var{string}.
1659@end defun 1685@end defun
1660 1686
@@ -1692,7 +1718,7 @@ it specifies how many times to use each of the strings in the
1692 1718
1693If @var{from-string} contains upper-case letters, then 1719If @var{from-string} contains upper-case letters, then
1694@code{perform-replace} binds @code{case-fold-search} to @code{nil}, and 1720@code{perform-replace} binds @code{case-fold-search} to @code{nil}, and
1695it uses the @code{replacements} without altering the case of them. 1721it uses the @var{replacements} without altering their case.
1696 1722
1697Normally, the keymap @code{query-replace-map} defines the possible 1723Normally, the keymap @code{query-replace-map} defines the possible
1698user responses for queries. The argument @var{map}, if 1724user responses for queries. The argument @var{map}, if
@@ -1722,7 +1748,7 @@ to the functions that use this map.
1722Prefix keys are not supported; each key binding must be for a 1748Prefix keys are not supported; each key binding must be for a
1723single-event key sequence. This is because the functions don't use 1749single-event key sequence. This is because the functions don't use
1724@code{read-key-sequence} to get the input; instead, they read a single 1750@code{read-key-sequence} to get the input; instead, they read a single
1725event and look it up ``by hand.'' 1751event and look it up ``by hand''.
1726@end itemize 1752@end itemize
1727@end defvar 1753@end defvar
1728 1754
@@ -1732,26 +1758,30 @@ friends.
1732 1758
1733@table @code 1759@table @code
1734@item act 1760@item act
1735Do take the action being considered---in other words, ``yes.'' 1761Do take the action being considered---in other words, ``yes''.
1736 1762
1737@item skip 1763@item skip
1738Do not take action for this question---in other words, ``no.'' 1764Do not take action for this question---in other words, ``no''.
1739 1765
1740@item exit 1766@item exit
1741Answer this question ``no,'' and give up on the entire series of 1767Answer this question ``no'', and give up on the entire series of
1742questions, assuming that the answers will be ``no.'' 1768questions, assuming that the answers will be ``no''.
1769
1770@item exit-prefix
1771Like @code{exit}, but add the key that was pressed to
1772@code{unread-comment-events}.
1743 1773
1744@item act-and-exit 1774@item act-and-exit
1745Answer this question ``yes,'' and give up on the entire series of 1775Answer this question ``yes'', and give up on the entire series of
1746questions, assuming that subsequent answers will be ``no.'' 1776questions, assuming that subsequent answers will be ``no''.
1747 1777
1748@item act-and-show 1778@item act-and-show
1749Answer this question ``yes,'' but show the results---don't advance yet 1779Answer this question ``yes'', but show the results---don't advance yet
1750to the next question. 1780to the next question.
1751 1781
1752@item automatic 1782@item automatic
1753Answer this question and all subsequent questions in the series with 1783Answer this question and all subsequent questions in the series with
1754``yes,'' without further user interaction. 1784``yes'', without further user interaction.
1755 1785
1756@item backup 1786@item backup
1757Move back to the previous place that a question was asked about. 1787Move back to the previous place that a question was asked about.
@@ -1760,6 +1790,9 @@ Move back to the previous place that a question was asked about.
1760Enter a recursive edit to deal with this question---instead of any 1790Enter a recursive edit to deal with this question---instead of any
1761other action that would normally be taken. 1791other action that would normally be taken.
1762 1792
1793@item edit-replacement
1794Edit the replacement for this question in the minibuffer.
1795
1763@item delete-and-edit 1796@item delete-and-edit
1764Delete the text being considered, then enter a recursive edit to replace 1797Delete the text being considered, then enter a recursive edit to replace
1765it. 1798it.
@@ -1778,7 +1811,18 @@ Display some help, then ask again.
1778@defvar multi-query-replace-map 1811@defvar multi-query-replace-map
1779This variable holds a keymap that extends @code{query-replace-map} by 1812This variable holds a keymap that extends @code{query-replace-map} by
1780providing additional keybindings that are useful in multi-buffer 1813providing additional keybindings that are useful in multi-buffer
1781replacements. 1814replacements. The additional ``bindings'' are:
1815
1816@table @code
1817@item automatic-all
1818Answer this question and all subsequent questions in the series with
1819``yes'', without further user interaction, for all remaining buffers.
1820
1821@item exit-current
1822Answer this question ``no'', and give up on the entire series of
1823questions for the current buffer. Continue to the next buffer in the
1824sequence.
1825@end table
1782@end defvar 1826@end defvar
1783 1827
1784@defvar replace-search-function 1828@defvar replace-search-function
@@ -1841,8 +1885,8 @@ If non-@code{nil}, the value should be a regular expression describing
1841the end of a sentence, including the whitespace following the 1885the end of a sentence, including the whitespace following the
1842sentence. (All paragraph boundaries also end sentences, regardless.) 1886sentence. (All paragraph boundaries also end sentences, regardless.)
1843 1887
1844If the value is @code{nil}, the default, then the function 1888If the value is @code{nil}, as it is by default, then the function
1845@code{sentence-end} has to construct the regexp. That is why you 1889@code{sentence-end} constructs the regexp. That is why you
1846should always call the function @code{sentence-end} to obtain the 1890should always call the function @code{sentence-end} to obtain the
1847regexp to be used to recognize the end of a sentence. 1891regexp to be used to recognize the end of a sentence.
1848@end defopt 1892@end defopt
@@ -1852,6 +1896,6 @@ This function returns the value of the variable @code{sentence-end},
1852if non-@code{nil}. Otherwise it returns a default value based on the 1896if non-@code{nil}. Otherwise it returns a default value based on the
1853values of the variables @code{sentence-end-double-space} 1897values of the variables @code{sentence-end-double-space}
1854(@pxref{Definition of sentence-end-double-space}), 1898(@pxref{Definition of sentence-end-double-space}),
1855@code{sentence-end-without-period} and 1899@code{sentence-end-without-period}, and
1856@code{sentence-end-without-space}. 1900@code{sentence-end-without-space}.
1857@end defun 1901@end defun
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 57c2edcbb28..d7e436d2e05 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12012-03-28 Glenn Morris <rgm@gnu.org>
2
3 * replace.el (query-replace-map): Doc fix.
4
12012-03-28 Andreas Schwab <schwab@linux-m68k.org> 52012-03-28 Andreas Schwab <schwab@linux-m68k.org>
2 6
3 * vc/vc-git.el (vc-git-state): Don't try to match all of the diff 7 * vc/vc-git.el (vc-git-state): Don't try to match all of the diff
diff --git a/lisp/replace.el b/lisp/replace.el
index 9fbaa279079..ad87d474b8b 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1594,8 +1594,8 @@ E to edit the replacement string"
1594 "Keymap that defines the responses to questions in `query-replace'. 1594 "Keymap that defines the responses to questions in `query-replace'.
1595The \"bindings\" in this map are not commands; they are answers. 1595The \"bindings\" in this map are not commands; they are answers.
1596The valid answers include `act', `skip', `act-and-show', 1596The valid answers include `act', `skip', `act-and-show',
1597`exit', `act-and-exit', `edit', `delete-and-edit', `recenter', 1597`exit', `act-and-exit', `edit', `edit-replacement', `delete-and-edit',
1598`automatic', `backup', `exit-prefix', and `help'.") 1598`recenter', `automatic', `backup', `exit-prefix', `quit', and `help'.")
1599 1599
1600(defvar multi-query-replace-map 1600(defvar multi-query-replace-map
1601 (let ((map (make-sparse-keymap))) 1601 (let ((map (make-sparse-keymap)))