diff --git a/doc/emacs/abbrevs.texi b/doc/emacs/abbrevs.texi index 23d7e28f4e39..695ffa8d1cd5 100644 --- a/doc/emacs/abbrevs.texi +++ b/doc/emacs/abbrevs.texi @@ -407,7 +407,7 @@ you are expanding. in this search; if it is @code{nil}, the word and the expansion must match in case. If the value is @code{case-fold-search} (the default), then the variable @code{case-fold-search} controls whether to ignore -case while searching for expansions (@pxref{Search Case}). +case while searching for expansions (@pxref{Lax Search}). @vindex dabbrev-case-replace Normally, dynamic abbrev expansion preserves the case pattern @@ -421,7 +421,7 @@ the dynamic abbrev's case pattern is preserved in most cases; if it is @code{nil}, the expansion is always copied verbatim. If the value is @code{case-replace} (the default), then the variable @code{case-replace} controls whether to copy the expansion verbatim -(@pxref{Replacement and Case}). +(@pxref{Replacement and Lax Matches}). However, if the expansion contains a complex mixed case pattern, and the dynamic abbrev matches this pattern as far as it goes, then the diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi index 27bb77d5cacc..2877be9c6b7f 100644 --- a/doc/emacs/emacs.texi +++ b/doc/emacs/emacs.texi @@ -392,18 +392,20 @@ Searching and Replacement * Regexps:: Syntax of regular expressions. * Regexp Backslash:: Regular expression constructs starting with `\'. * Regexp Example:: A complex regular expression explained. -* Search Case:: To ignore case while searching, or not. +* Lax Search:: Search ignores some distinctions between + similar characters, like letter-case. * Replace:: Search, and replace some or all matches. * Other Repeating Search:: Operating on all matches for some regexp. +* Search Customizations:: Various search customizations. Incremental Search * Basic Isearch:: Basic incremental search commands. * Repeat Isearch:: Searching for the same string again. -* Error in Isearch:: When your string is not found. -* Special Isearch:: Special input in incremental search. * Isearch Yank:: Commands that grab text into the search string or else edit the search string. +* Error in Isearch:: When your string is not found. +* Special Isearch:: Special input in incremental search. * Not Exiting Isearch:: Prefix argument and scrolling commands. * Isearch Minibuffer:: Incremental search of the minibuffer history. @@ -411,7 +413,8 @@ Replacement Commands * Unconditional Replace:: Replacing all matches for a string. * Regexp Replace:: Replacing all matches for a regexp. -* Replacement and Case:: How replacements preserve case of letters. +* Replacement and Lax Matches:: + Lax searching for text to replace. * Query Replace:: How to use querying. Commands for Fixing Typos diff --git a/doc/emacs/glossary.texi b/doc/emacs/glossary.texi index e66cd79e7409..cc81101d67af 100644 --- a/doc/emacs/glossary.texi +++ b/doc/emacs/glossary.texi @@ -175,11 +175,22 @@ corresponding Control character. @xref{User Input,C-M-}. Case conversion means changing text from upper case to lower case or vice versa. @xref{Case}. +@item Case Folding +Case folding means ignoring the differences between case variants of +the same letter: upper-case, lower-case, and title-case. Emacs +performs case folding by default in text search. @xref{Lax Search}. + @item Character Characters form the contents of an Emacs buffer. Also, key sequences (q.v.@:) are usually made up of characters (though they may include other input events as well). @xref{User Input}. +@item Character Folding +Character folding means ignoring differences between similarly looking +characters, such as between @code{a}, and @code{@:a} and @code{@'a}. +Emacs performs character folding by default in text search. @xref{Lax +Search}. + @item Character Set Emacs supports a number of character sets, each of which represents a particular alphabet or script. @xref{International}. diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index a571ea7ed67a..f1a59f843515 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -2285,7 +2285,7 @@ input. @xref{Query Replace}, for more information on query replace. You can control the case-sensitivity of tags search commands by customizing the value of the variable @code{tags-case-fold-search}. The default is to use the same setting as the value of -@code{case-fold-search} (@pxref{Search Case}). +@code{case-fold-search} (@pxref{Lax Search}). It is possible to get through all the files in the tags table with a single invocation of @kbd{M-x tags-query-replace}. But often it is diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi index 2493fdadf37c..ed339a967a48 100644 --- a/doc/emacs/mini.texi +++ b/doc/emacs/mini.texi @@ -642,8 +642,8 @@ expressions. A numeric prefix argument @var{n} means to fetch the @var{n}th matching entry. These commands are unusual, in that they use the minibuffer to read the regular expression argument, even though they are invoked from the minibuffer. An upper-case letter in -the regular expression makes the search case-sensitive (@pxref{Search -Case}). +the regular expression makes the search case-sensitive (@pxref{Lax +Search}). You can also search through the history using an incremental search. @xref{Isearch Minibuffer}. diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index ae275d1ca67a..9da9226d3bfb 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -26,9 +26,11 @@ thing, but search for patterns instead of fixed strings. * Regexps:: Syntax of regular expressions. * Regexp Backslash:: Regular expression constructs starting with `\'. * Regexp Example:: A complex regular expression explained. -* Search Case:: To ignore case while searching, or not. +* Lax Search:: Search ignores some distinctions between + similar characters, like letter-case. * Replace:: Search, and replace some or all matches. * Other Repeating Search:: Operating on all matches for some regexp. +* Search Customizations:: Various search customizations. @end menu @node Incremental Search @@ -54,10 +56,10 @@ Incremental search backward (@code{isearch-backward}). @menu * Basic Isearch:: Basic incremental search commands. * Repeat Isearch:: Searching for the same string again. -* Error in Isearch:: When your string is not found. -* Special Isearch:: Special input in incremental search. * Isearch Yank:: Commands that grab text into the search string or else edit the search string. +* Error in Isearch:: When your string is not found. +* Special Isearch:: Special input in incremental search. * Not Exiting Isearch:: Prefix argument and scrolling commands. * Isearch Minibuffer:: Incremental search of the minibuffer history. @end menu @@ -89,31 +91,46 @@ cursor moves to just after the first @samp{FOO}. @cindex isearch face At each step, Emacs highlights the @dfn{current match}---the buffer text that matches the search string---using the @code{isearch} face -(@pxref{Faces}). The current search string is also displayed in the -echo area. +(@pxref{Faces}). @xref{Search Customizations}, for various options +that customize this highlighting. The current search string is also +displayed in the echo area. If you make a mistake typing the search string, type @key{DEL}. Each @key{DEL} cancels the last character of the search string. +@xref{Error in Isearch}, for more about dealing with unsuccessful +search. +@cindex exit incremental search +@cindex incremental search, exiting When you are satisfied with the place you have reached, type @key{RET}. This stops searching, leaving the cursor where the search brought it. Also, any command not specially meaningful in searches stops the searching and is then executed. Thus, typing @kbd{C-a} -exits the search and then moves to the beginning of the line. -@key{RET} is necessary only if the next command you want to type is a -printing character, @key{DEL}, @key{RET}, or another character that is -special within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, -@kbd{C-y}, @kbd{M-y}, @kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some others -described below). +exits the search and then moves to the beginning of the line; typing +one of the arrow keys exits the search and performs the respective +movement command; etc. @key{RET} is necessary only if the next +command you want to type is a printing character, @key{DEL}, +@key{RET}, or another character that is special within searches +(@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, @kbd{C-y}, @kbd{M-y}, +@kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some others described below). +You can fine-tune the commands that exit the search; see @ref{Not +Exiting Isearch}. As a special exception, entering @key{RET} when the search string is empty launches nonincremental search (@pxref{Nonincremental Search}). +(This can be customized; see @ref{Search Customizations}.) + + To abandon the search and return to the place where you started, +type @kbd{@key{ESC} @key{ESC} @key{ESC}} (@code{isearch-cancel}) or +@kbd{C-g C-g} (@code{isearch-abort}). When you exit the incremental search, it adds the original value of point to the mark ring, without activating the mark; you can thus use -@kbd{C-u C-@key{SPC}} to return to where you were before beginning the -search. @xref{Mark Ring}. It only does this if the mark was not -already active. +@kbd{C-u C-@key{SPC}} or @kbd{C-x C-x} to return to where you were +before beginning the search. @xref{Mark Ring}. (Emacs only does this +if the mark was not already active; if the mark was active when you +started the search, both @kbd{C-u C-@key{SPC}} and @kbd{C-x C-x} will +go to the mark.) @kindex C-r @findex isearch-backward @@ -134,7 +151,6 @@ characters with @key{DEL}. Similarly, each @kbd{C-r} in a backward incremental search repeats the backward search. @cindex lazy search highlighting -@vindex isearch-lazy-highlight If you pause for a little while during incremental search, Emacs highlights all the other possible matches for the search string that are present on the screen. This helps you anticipate where you can @@ -142,21 +158,26 @@ get to by typing @kbd{C-s} or @kbd{C-r} to repeat the search. The other matches are highlighted differently from the current match, using the customizable face @code{lazy-highlight} (@pxref{Faces}). If you don't like this feature, you can disable it by setting -@code{isearch-lazy-highlight} to @code{nil}. +@code{isearch-lazy-highlight} to @code{nil}. For other customizations +related to highlighting matches, see @ref{Search Customizations}. After exiting a search, you can search for the same string again by typing just @kbd{C-s C-s}. The first @kbd{C-s} is the key that invokes incremental search, and the second @kbd{C-s} means to search -again. Similarly, @kbd{C-r C-r} searches backward for the last -search string. In determining the last search string, it doesn't -matter whether the string was searched for with @kbd{C-s} or -@kbd{C-r}. +again for the last search string. Similarly, @kbd{C-r C-r} searches +backward for the last search string. In determining the last search +string, it doesn't matter whether that string was searched for with +@kbd{C-s} or @kbd{C-r}. If you are searching forward but you realize you were looking for something before the starting point, type @kbd{C-r} to switch to a backward search, leaving the search string unchanged. Similarly, @kbd{C-s} in a backward search switches to a forward search. +@cindex search, wrapping around +@cindex search, overwrapped +@cindex wrapped search +@cindex overwrapped search If a search is failing and you ask to repeat it by typing another @kbd{C-s}, it starts again from the beginning of the buffer. Repeating a failing reverse search with @kbd{C-r} starts again from @@ -169,19 +190,86 @@ you have already seen. @cindex search ring @kindex M-n @r{(Incremental search)} @kindex M-p @r{(Incremental search)} +@vindex search-ring-max To reuse earlier search strings, use the @dfn{search ring}. The commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a search string to reuse. These commands leave the selected search ring -element in the minibuffer, where you can edit it. - +element in the minibuffer, where you can edit it. Type +@kbd{C-s}/@kbd{C-r} or @key{RET} to accept the string and start +searching for it. The number of most recently used search strings +saved in the search ring is specified by the variable +@code{search-ring-max}, 16 by default. + +@cindex incremental search, edit search string +@cindex interactively edit search string @kindex M-e @r{(Incremental search)} +@kindex Mouse-1 @r{in the minibuffer (Incremental Search)} To edit the current search string in the minibuffer without -replacing it with items from the search ring, type @kbd{M-e}. Type @key{RET}, -@kbd{C-s} or @kbd{C-r} to finish editing the string and search for it. +replacing it with items from the search ring, type @kbd{M-e} or click +@kbd{Mouse-1} in the minibuffer. Type @key{RET}, @kbd{C-s} or +@kbd{C-r} to finish editing the string and search for it. Type +@kbd{C-f} or @kbd{@key{RIGHT}} to add to the search string characters +following point from the buffer from which you started the search. + +@node Isearch Yank +@subsection Isearch Yanking + + In many cases, you will want to use text at or near point as your +search string. The commands described in this subsection let you do +that conveniently. + +@kindex C-w @r{(Incremental search)} +@findex isearch-yank-word-or-char + @kbd{C-w} (@code{isearch-yank-word-or-char}) appends the next +character or word at point to the search string. This is an easy way +to search for another occurrence of the text at point. (The decision +of whether to copy a character or a word is heuristic.) + +@kindex M-s C-e @r{(Incremental search)} +@findex isearch-yank-line + Similarly, @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest +of the current line to the search string. If point is already at the +end of a line, it appends the next line. With a prefix argument +@var{n}, it appends the next @var{n} lines. + +@kindex C-y @r{(Incremental search)} +@kindex M-y @r{(Incremental search)} +@kindex Mouse-2 @r{in the minibuffer (Incremental search)} +@findex isearch-yank-kill +@findex isearch-yank-pop +@findex isearch-yank-x-selection + Within incremental search, @kbd{C-y} (@code{isearch-yank-kill}) +appends the current kill to the search string. @kbd{M-y} +(@code{isearch-yank-pop}), if called after @kbd{C-y}, replaces that +appended text with an earlier kill, similar to the usual @kbd{M-y} +(@code{yank-pop}) command (@pxref{Yanking}). Clicking @kbd{Mouse-2} +in the echo area appends the current X selection (@pxref{Primary +Selection}) to the search string (@code{isearch-yank-x-selection}). + +@kindex C-M-w @r{(Incremental search)} +@kindex C-M-y @r{(Incremental search)} +@findex isearch-del-char +@findex isearch-yank-char + @kbd{C-M-w} (@code{isearch-del-char}) deletes the last character +from the search string, and @kbd{C-M-y} (@code{isearch-yank-char}) +appends the character after point to the search string. An +alternative method to add the character after point is to enter the +minibuffer with @kbd{M-e} (@pxref{Repeat Isearch}) and type @kbd{C-f} +or @kbd{@key{RIGHT}} at the end of the search string in the +minibuffer. Each @kbd{C-f} or @kbd{@key{RIGHT}} you type adds another +character following point to the search string. + + Normally, when the search is case-insensitive, text yanked into the +search string is converted to lower case, so that the search remains +case-insensitive (@pxref{Lax Search, case folding}). However, if the +value of the variable @code{search-upper-case} (@pxref{Lax Search, +search-upper-case}) is other than @code{not-yanks}, that disables this +down-casing. @node Error in Isearch @subsection Errors in Incremental Search +@cindex isearch-fail face If your string is not found at all, the echo area says @samp{Failing I-Search}, and the cursor moves past the place where Emacs found as much of your string as it could. Thus, if you search for @samp{FOOT}, @@ -192,12 +280,13 @@ string that failed to match is highlighted using the face At this point, there are several things you can do. If your string was mistyped, you can use @key{DEL} to erase some of it and correct -it. If you like the place you have found, you can type @key{RET} to -remain there. Or you can type @kbd{C-g}, which removes from the -search string the characters that could not be found (the @samp{T} in -@samp{FOOT}), leaving those that were found (the @samp{FOO} in -@samp{FOOT}). A second @kbd{C-g} at that point cancels the search -entirely, returning point to where it was when the search started. +it, or you can type @kbd{M-e} and edit it. If you like the place you +have found, you can type @key{RET} to remain there. Or you can type +@kbd{C-g}, which removes from the search string the characters that +could not be found (the @samp{T} in @samp{FOOT}), leaving those that +were found (the @samp{FOO} in @samp{FOOT}). A second @kbd{C-g} at +that point cancels the search entirely, returning point to where it +was when the search started. @cindex quitting (in search) @kindex C-g @r{(Incremental search)} @@ -216,34 +305,21 @@ search. @node Special Isearch @subsection Special Input for Incremental Search - Some of the characters you type during incremental search have -special effects. + In addition to characters described in the previous subsections, +some of the other characters you type during incremental search have +special effects. They are described here. -@cindex lax space matching -@kindex M-s SPC @r{(Incremental search)} -@kindex SPC @r{(Incremental search)} -@findex isearch-toggle-lax-whitespace -@vindex search-whitespace-regexp - By default, incremental search performs @dfn{lax space matching}: -each space, or sequence of spaces, matches any sequence of one or more -spaces in the text. Hence, @samp{foo bar} matches @samp{foo bar}, -@samp{foo@w{ }bar}, @samp{foo@w{ }bar}, and so on (but not -@samp{foobar}). More precisely, Emacs matches each sequence of space -characters in the search string to a regular expression specified by -the variable @code{search-whitespace-regexp}. For example, to make -spaces match sequences of newlines as well as spaces, set it to -@samp{"[[:space:]\n]+"}. - - To toggle lax space matching, type @kbd{M-s @key{SPC}} -(@code{isearch-toggle-lax-whitespace}). To disable this feature -entirely, change @code{search-whitespace-regexp} to @code{nil}; then -each space in the search string matches exactly one space. - - If the search string you entered contains only lower-case letters, -the search is case-insensitive; as long as an upper-case letter exists -in the search string, the search becomes case-sensitive. If you -delete the upper-case character from the search string, it ceases to -have this effect. @xref{Search Case}. + To toggle lax space matching (@pxref{Lax Search, lax space +matching}), type @kbd{M-s @key{SPC}}. + + To toggle case sensitivity of the search, type @kbd{M-c} or +@kbd{M-s c}. @xref{Lax Search, case folding}. If the search string +includes upper-case letters, the search is case-sensitive by default. + + To toggle whether or not the search will consider similar and +equivalent characters as a match, type @kbd{M-s '}. @xref{Lax Search, +character folding}. If the search string includes accented +characters, that disables character folding during that search. @cindex invisible text, searching for @kindex M-s i @r{(Incremental search)} @@ -251,7 +327,17 @@ have this effect. @xref{Search Case}. To toggle whether or not invisible text is searched, type @kbd{M-s i} (@code{isearch-toggle-invisible}). @xref{Outline Search}. - To search for a newline character, type @kbd{C-j}. +@kindex M-r @r{(Incremental Search)} +@kindex M-s r @r{(Incremental Search)} +@findex isearch-toggle-regexp + To toggle between non-regexp and regexp incremental search, type +@kbd{M-r} or @kbd{M-s r} (@code{isearch-toggle-regexp}). +@xref{Regexp Search}. + + To toggle symbol mode, type @kbd{M-s _}. @xref{Symbol Search}. + + To search for a newline character, type @kbd{C-j} as part of the +search string. To search for non-@acronym{ASCII} characters, use one of the following methods: @@ -265,17 +351,21 @@ example, @kbd{C-q C-s} during incremental search adds the @samp{control-S} character to the search string. @item -Type @kbd{C-x 8 @key{RET}}, followed by a Unicode name or code-point. -This adds the specified character into the search string, similar to -the usual @code{insert-char} command (@pxref{Inserting Text}). +Type @kbd{C-x 8 @key{RET}}, followed by a Unicode name or code-point +in hex. This adds the specified character into the search string, +similar to the usual @code{insert-char} command (@pxref{Inserting +Text}). @item +@kindex C-^ @r{(Incremental Search)} +@findex isearch-toggle-input-method +@findex isearch-toggle-specified-input-method Use an input method (@pxref{Input Methods}). If an input method is -enabled in the current buffer when you start the search, you can use -it in the search string also. While typing the search string, you can -toggle the input method with @kbd{C-\} -(@code{isearch-toggle-input-method}). You can also turn on a -non-default input method with @kbd{C-^} +enabled in the current buffer when you start the search, the same +method will be active in the minibuffer when you type the search +string. While typing the search string, you can toggle the input +method with @kbd{C-\} (@code{isearch-toggle-input-method}). You can +also turn on a non-default input method with @kbd{C-^} (@code{isearch-toggle-specified-input-method}), which prompts for the name of the input method. When an input method is active during incremental search, the search prompt includes the input method @@ -286,13 +376,17 @@ I-search [@var{im}]: @end example @noindent -@findex isearch-toggle-input-method -@findex isearch-toggle-specified-input-method where @var{im} is the mnemonic of the active input method. Any input method you enable during incremental search remains enabled in the current buffer afterwards. @end itemize +@kindex M-s o @r{(Incremental Search)} +@findex isearch-occur + Typing @kbd{M-s o} in incremental search invokes +@code{isearch-occur}, which runs @code{occur} with the current search +string. @xref{Other Repeating Search, occur}. + @kindex M-% @r{(Incremental search)} Typing @kbd{M-%} in incremental search invokes @code{query-replace} or @code{query-replace-regexp} (depending on search mode) with the @@ -302,83 +396,72 @@ prefix argument means to replace backward. @xref{Query Replace}. @kindex M-TAB @r{(Incremental search)} Typing @kbd{M-@key{TAB}} in incremental search invokes @code{isearch-complete}, which attempts to complete the search string -using the search ring as a list of completion alternatives. -@xref{Completion}. In many operating systems, the @kbd{M-@key{TAB}} -key sequence is captured by the window manager; you then need to -rebind @code{isearch-complete} to another key sequence if you want to -use it (@pxref{Rebinding}). - +using the search ring (the previous search strings you used) as a list +of completion alternatives. @xref{Completion}. In many operating +systems, the @kbd{M-@key{TAB}} key sequence is captured by the window +manager; you then need to rebind @code{isearch-complete} to another +key sequence if you want to use it (@pxref{Rebinding}). + +@kindex M-s h r @r{(Incremental Search)} +@findex isearch-highlight-regexp + You can exit the search while leaving the matches for the last +search string highlighted on display. To this end, type @kbd{M-s h r} +(@code{isearch-highlight-regexp}), which will run +@code{highlight-regexp} (@pxref{Highlight Interactively}) passing +it the regexp derived from the last search string and prompting you +for the face to use for highlighting. To remove the highlighting, +type @kbd{M-s h u} (@code{unhighlight-regexp}). + +@cindex incremental search, help on special keys +@kindex C-h C-h @r{(Incremental Search)} +@findex isearch-help-map @vindex isearch-mode-map - When incremental search is active, you can type @kbd{C-h C-h} to -access interactive help options, including a list of special key -bindings. These key bindings are part of the keymap -@code{isearch-mode-map} (@pxref{Keymaps}). - -@node Isearch Yank -@subsection Isearch Yanking - -@kindex C-y @r{(Incremental search)} -@kindex M-y @r{(Incremental search)} -@findex isearch-yank-kill -@findex isearch-yank-pop - Within incremental search, @kbd{C-y} (@code{isearch-yank-kill}) -appends the current kill to the search string. @kbd{M-y} -(@code{isearch-yank-pop}), if called after @kbd{C-y}, replaces that -appended text with an earlier kill, similar to the usual @kbd{M-y} -(@code{yank-pop}) command (@pxref{Yanking}). @kbd{Mouse-2} appends -the current X selection (@pxref{Primary Selection}). - -@kindex C-w @r{(Incremental search)} -@findex isearch-yank-word-or-char - @kbd{C-w} (@code{isearch-yank-word-or-char}) appends the next -character or word at point to the search string. This is an easy way -to search for another occurrence of the text at point. (The decision -of whether to copy a character or a word is heuristic.) - -@kindex M-s C-e @r{(Incremental search)} -@findex isearch-yank-line - Similarly, @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest -of the current line to the search string. If point is already at the -end of a line, it appends the next line. With a prefix argument -@var{n}, it appends the next @var{n} lines. - - If the search is currently case-insensitive, both @kbd{C-w} and -@kbd{M-s C-e} convert the text they copy to lower case, so that the -search remains case-insensitive. - -@kindex C-M-w @r{(Incremental search)} -@kindex C-M-y @r{(Incremental search)} -@findex isearch-del-char -@findex isearch-yank-char - @kbd{C-M-w} (@code{isearch-del-char}) deletes the last character -from the search string, and @kbd{C-M-y} (@code{isearch-yank-char}) -appends the character after point to the search string. An -alternative method to add the character after point is to enter the -minibuffer with @kbd{M-e} (@pxref{Repeat Isearch}) and type @kbd{C-f} -at the end of the search string in the minibuffer. + When incremental search is active, you can type @kbd{C-h C-h} +(@code{isearch-help-map}) to access interactive help options, +including a list of special key bindings. These key bindings are part +of the keymap @code{isearch-mode-map} (@pxref{Keymaps}). @node Not Exiting Isearch @subsection Not Exiting Incremental Search -This subsection describes two categories of commands which you can -type without exiting the current incremental search, even though they -are not themselves part of incremental search. +This subsection describes how to control whether typing a command not +specifically meaningful is searches exits the search before executing +the command. It also describes two categories of commands which you +can type without exiting the current incremental search, even though +they are not themselves part of incremental search. + +@vindex search-exit-option + Normally, typing a command that is not bound by the incremental +search exits the search before executing the command. Thus, the +command operates on the buffer from which you invoked the search. +However, if you customize the variable @code{search-exit-option} to a +@code{nil} value, the characters which you type that are not +interpreted by the incremental search are simply appended to the +search string. This is so you could include in the search string +control characters, such as @kbd{C-a}, that would normally exit the +search and invoke the command bound to them on the buffer. @table @asis @item Prefix Arguments +@cindex prefix argument commands, during incremental search @vindex isearch-allow-prefix - In incremental search, when you enter a prefix argument -(@pxref{Arguments}), by default it will apply either to the next -action in the search or to the command that exits the search. + In incremental search, when you type a command that specifies a +prefix argument (@pxref{Arguments}), by default it will apply either +to the next action in the search or to the command that exits the +search. In other words, entering a prefix argument will not by itself +terminate the search. In previous versions of Emacs, entering a prefix argument always terminated the search. You can revert to this behavior by setting the variable @code{isearch-allow-prefix} to @code{nil}. When @code{isearch-allow-scroll} is non-@code{nil} (see below), -prefix arguments always have the default behavior described above. +prefix arguments always have the default behavior described above, +i.e., they don't terminate the search, even if +@code{isearch-allow-prefix} is @code{nil}. @item Scrolling Commands +@cindex scrolling commands, during incremental search @vindex isearch-allow-scroll Normally, scrolling commands exit incremental search. If you change the variable @code{isearch-allow-scroll} to a non-@code{nil} value, @@ -390,12 +473,14 @@ prefix arguments to these commands in the usual way. This feature won't let you scroll the current match out of visibility, however. The @code{isearch-allow-scroll} feature also affects some other -commands, such as @kbd{C-x 2} (@code{split-window-below}) and @kbd{C-x -^} (@code{enlarge-window}), which don't exactly scroll but do affect -where the text appears on the screen. It applies to any command whose -name has a non-@code{nil} @code{isearch-scroll} property. So you can -control which commands are affected by changing these properties. - +commands, such as @kbd{C-x 2} (@code{split-window-below}) and +@kbd{C-x ^} (@code{enlarge-window}), which don't exactly scroll but do +affect where the text appears on the screen. It applies to any +command whose name has a non-@code{nil} @code{isearch-scroll} +property. So you can control which commands are affected by changing +these properties. + +@cindex prevent commands from exiting incremental search For example, to make @kbd{C-h l} usable within an incremental search in all future Emacs sessions, use @kbd{C-h c} to find what command it runs (@pxref{Key Help}), which is @code{view-lossage}. Then you can @@ -409,7 +494,8 @@ put the following line in your init file (@pxref{Init File}): This feature can be applied to any command that doesn't permanently change point, the buffer contents, the match data, the current buffer, or the selected window and frame. The command must not itself attempt -an incremental search. +an incremental search. This feature is disabled if +@code{isearch-allow-scroll} is @code{nil} (which it is by default). @end table @node Isearch Minibuffer @@ -475,11 +561,13 @@ search matches any sequence of those two words separated by one or more spaces, newlines, or other punctuation characters. This is particularly useful for searching text documents, because you don't have to worry whether the words you are looking for are separated by -newlines or spaces. +newlines or spaces. Note that major modes for programming languages +or other specialized modes can modify the definition of a word to suit +their syntactic needs. @table @kbd @item M-s w -If incremental search is active, toggle word search mode + If incremental search is active, toggle word search mode (@code{isearch-toggle-word}); otherwise, begin an incremental forward word search (@code{isearch-forward-word}). @item M-s w @key{RET} @var{words} @key{RET} @@ -514,6 +602,14 @@ so that the matching can proceed incrementally as you type. This additional laxity does not apply to the lazy highlight (@pxref{Incremental Search}), which always matches whole words. +@kindex M-s M-w +@findex eww-search-word +@vindex eww-search-prefix + Search the Web for the text in region. This command performs an +Internet search for the words in region using the search engine whose +@acronym{URL} is specified by the variable @code{eww-search-prefix}. +@xref{Basics, EWW, , eww, The Emacs Web Wowser Manual}. + @node Symbol Search @section Symbol Search @cindex symbol search @@ -529,6 +625,7 @@ searching source code. @table @kbd @item M-s _ +@findex isearch-toggle-symbol If incremental search is active, toggle symbol search mode (@code{isearch-toggle-symbol}); otherwise, begin an incremental forward symbol search (@code{isearch-forward-symbol}). @@ -595,13 +692,16 @@ for. To search backward for a regexp, use @kbd{C-M-r} (@code{isearch-backward-regexp}), @kbd{C-r} with a prefix argument, or @kbd{M-r} within a backward incremental search. +@vindex regexp-search-ring-max All of the special key sequences in an ordinary incremental search -do similar things in an incremental regexp search. For instance, -typing @kbd{C-s} immediately after starting the search retrieves the -last incremental search regexp used and searches forward for it. -Incremental regexp and non-regexp searches have independent defaults. -They also have separate search rings, which you can access with -@kbd{M-p} and @kbd{M-n}. +(@pxref{Special Isearch}) do similar things in an incremental regexp +search. For instance, typing @kbd{C-s} immediately after starting the +search retrieves the last incremental search regexp used and searches +forward for it. Incremental regexp and non-regexp searches have +independent defaults. They also have separate search rings, which you +can access with @kbd{M-p} and @kbd{M-n}. The maximum number of search +regexps saved in the search ring is determined by the value of +@code{regexp-search-ring-max}, 16 by default. Unlike ordinary incremental search, incremental regexp search do not use lax space matching by default. To toggle this feature @@ -1030,21 +1130,67 @@ This contains two parts in succession: a character set matching period, @samp{?}, or @samp{!}, and a character set matching close-brackets, quotes, or parentheses, repeated zero or more times. -@node Search Case -@section Searching and Case +@node Lax Search +@section Lax Matching During Searching + +@cindex lax search +@cindex character equivalence in search + Normally, you'd want search commands to disregard certain minor +differences between the search string you types and the text being +searched. For example, sequences of whitespace characters of +different length are normally perceived as equivalent; letter-case +differences usually don't matter; etc. This is known as +@dfn{character equivalence}. + + This section describes the Emacs lax search features, and how to +tailor them to your needs. +@cindex lax space matching in search +@kindex M-s SPC @r{(Incremental search)} +@kindex SPC @r{(Incremental search)} +@findex isearch-toggle-lax-whitespace +@vindex search-whitespace-regexp + By default, search commands perform @dfn{lax space matching}: +each space, or sequence of spaces, matches any sequence of one or more +whitespace characters in the text. (Incremental regexp search has a +separate default; see @ref{Regexp Search}.) Hence, @samp{foo bar} +matches @samp{foo bar}, @samp{foo@w{ }bar}, @samp{foo@w{ }bar}, and so +on (but not @samp{foobar}). More precisely, Emacs matches each +sequence of space characters in the search string to a regular +expression specified by the variable @code{search-whitespace-regexp}. +For example, to make spaces match sequences of newlines as well as +spaces, set it to @samp{"[[:space:]\n]+"}. The default value of this +variable depends on the buffer's major mode; most major modes classify +spaces, tabs, and formfeed characters as whitespace. + + If you want whitespace characters to match exactly, you can turn lax +space matching by typing @kbd{M-s @key{SPC}} +(@code{isearch-toggle-lax-whitespace}) within an incremental search. +Another @kbd{M-s @key{SPC}} turns lax space matching back on. To +disable this feature entirely, change @code{search-whitespace-regexp} +to @code{nil}; then each space in the search string matches exactly +one space. + +@cindex case folding in search +@cindex case-sensitivity and search Searches in Emacs normally ignore the case of the text they are -searching through, if you specify the text in lower case. Thus, if -you specify searching for @samp{foo}, then @samp{Foo} and @samp{foo} -also match. Regexps, and in particular character sets, behave -likewise: @samp{[ab]} matches @samp{a} or @samp{A} or @samp{b} or -@samp{B}. - - An upper-case letter anywhere in the incremental search string makes -the search case-sensitive. Thus, searching for @samp{Foo} does not find -@samp{foo} or @samp{FOO}. This applies to regular expression search as -well as to string search. The effect ceases if you delete the -upper-case letter from the search string. +searching through, if you specify the search string in lower case. +Thus, if you specify searching for @samp{foo}, then @samp{Foo} and +@samp{foo} also match. Regexps, and in particular character sets, +behave likewise: @samp{[ab]} matches @samp{a} or @samp{A} or @samp{b} +or @samp{B}. This feature is known as @dfn{case folding}, and it is +supported in both incremental and non-incremental search modes. + +@vindex search-upper-case + An upper-case letter anywhere in the search string makes the search +case-sensitive. Thus, searching for @samp{Foo} does not find +@samp{foo} or @samp{FOO}. This applies to regular expression search +as well as to string search. The effect ceases if you delete the +upper-case letter from the search string. The variable +@code{search-upper-case} controls this: if it is non-@code{nil} (the +default), an upper-case character in the search string make the search +case-sensitive; setting it to @code{nil} disables this effect of +upper-case characters. @vindex case-fold-search If you set the variable @code{case-fold-search} to @code{nil}, then @@ -1055,12 +1201,14 @@ This variable applies to nonincremental searches also, including those performed by the replace commands (@pxref{Replace}) and the minibuffer history matching commands (@pxref{Minibuffer History}). -@c isearch-toggle-case-fold - Typing @kbd{M-c} within an incremental search toggles the case -sensitivity of that search. The effect does not extend beyond the -current incremental search to the next one, but it does override the -effect of adding or removing an upper-case letter in the current -search. +@kindex M-c @r{(Incremental search)} +@kindex M-s c @r{(Incremental search)} +@findex isearch-toggle-case-fold + Typing @kbd{M-c} or @kbd{M-s c} (@code{isearch-toggle-case-fold}) +within an incremental search toggles the case sensitivity of that +search. The effect does not extend beyond the current incremental +search to the next one, but it does override the effect of adding or +removing an upper-case letter in the current search. Several related variables control case-sensitivity of searching and matching for specific commands or activities. For instance, @@ -1068,6 +1216,46 @@ matching for specific commands or activities. For instance, @code{find-tag}. To find these variables, do @kbd{M-x apropos-variable @key{RET} case-fold-search @key{RET}}. +@cindex character folding in search +@cindex equivalent character sequences + Case folding disregards case distinctions between characters, making +upper-case characters match lower-case variants, and vice versa. A +generalization of case folding is @dfn{character folding}, which +disregards wider classes of distinctions between similar characters. +For instance, under character folding the letter @code{a} will match +all of its accented cousins like @code{@"a} and @code{@'a}, i.e., the +match disregards the diacriticals that distinguish between these +variants. In addition, @code{a} will match other characters that +resemble it, or have it as part of their graphical representation, +such as @sc{u+249c parenthesized latin small letter a} and @sc{u+2100 +account of} (which looks like a small @code{a} over @code{c}). +Similarly, the @acronym{ASCII} double-quote character @code{"} will +match all the other variants of double quotes defined by the Unicode +standard. +@ignore @c FIXME: This doesn't work. Should it? +Finally, character folding can make a sequence of one or +more characters match another sequence of a different length: for +example, the sequence of two characters @code{ae} matches the ligature +@code{@ae{}}. +@end ignore +Character sequences that match under character folding are called +@dfn{equivalent}. + +@kindex M-s ' @r{(Incremental Search)} +@findex isearch-toggle-character-fold + Searches in Emacs normally perform character folding, thus matching +equivalent character sequences. You can disable this behavior by +customizing the variable @code{search-default-regexp-mode} to the +@code{nil} value. @xref{Search Customizations}. Within an +incremental search, typing @kbd{M-s '} +(@code{isearch-toggle-character-fold}) toggles character folding, but +only for that search. + + Like with case folding, typing an explicit variant of a character, +such as @code{@"a}, as part of the search string disables character +folding for that search. If you delete such a character from the +search string, this effect ceases. + @node Replace @section Replacement Commands @cindex replacement @@ -1078,7 +1266,8 @@ apropos-variable @key{RET} case-fold-search @key{RET}}. Emacs provides several commands for performing search-and-replace operations. In addition to the simple @kbd{M-x replace-string} command, there is @kbd{M-%} (@code{query-replace}), which presents -each occurrence of the pattern and asks you whether to replace it. +each occurrence of the search pattern and asks you whether to replace +it. The replace commands normally operate on the text from point to the end of the buffer. When the region is active, they operate on it @@ -1087,17 +1276,11 @@ instead (@pxref{Mark}). The basic replace commands replace one is possible to perform several replacements in parallel, using the command @code{expand-region-abbrevs} (@pxref{Expanding Abbrevs}). -@vindex replace-lax-whitespace - Unlike incremental search, the replacement commands do not use lax -space matching (@pxref{Special Isearch}) by default. To enable lax -space matching for replacement, change the variable -@code{replace-lax-whitespace} to @code{t}. (This only affects how -Emacs finds the text to replace, not the replacement text.) - @menu * Unconditional Replace:: Replacing all matches for a string. * Regexp Replace:: Replacing all matches for a regexp. -* Replacement and Case:: How replacements preserve case of letters. +* Replacement and Lax Matches:: + Lax searching for text to replace. * Query Replace:: How to use querying. @end menu @@ -1128,8 +1311,8 @@ activating the mark; use @kbd{C-u C-@key{SPC}} to move back there. A prefix argument restricts replacement to matches that are surrounded by word boundaries. - @xref{Replacement and Case}, for details about case-sensitivity in -replace commands. + @xref{Replacement and Lax Matches}, for details about +case-sensitivity in replace commands. @node Regexp Replace @subsection Regexp Replacement @@ -1137,7 +1320,7 @@ replace commands. The @kbd{M-x replace-string} command replaces exact matches for a single string. The similar command @kbd{M-x replace-regexp} replaces -any match for a specified pattern. +any match for a specified regular expression pattern (@pxref{Regexps}). @table @kbd @item M-x replace-regexp @key{RET} @var{regexp} @key{RET} @var{newstring} @key{RET} @@ -1218,9 +1401,28 @@ M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET} \,(format "%-72sABC%05d" \& \#) @key{RET} @end example -@node Replacement and Case -@subsection Replace Commands and Case +@node Replacement and Lax Matches +@subsection Replace Commands and Lax Matches + + This subsection describes the behavior of replace commands with +respect to lax matches (@pxref{Lax Search}) and how to customize it. +In general, replace commands mostly default to stricter matching than +their search counterparts. +@cindex lax space matching in replace commands +@vindex replace-lax-whitespace + Unlike incremental search, the replacement commands do not use lax +space matching (@pxref{Lax Search, lax space matching}) by default. +To enable lax space matching for replacement, change the variable +@code{replace-lax-whitespace} to non-@code{nil}. (This only affects +how Emacs finds the text to replace, not the replacement text.) + +@vindex replace-regexp-lax-whitespace + A companion variable @code{replace-regexp-lax-whitespace} controls +whether @code{query-replace-regexp} uses lax whitespace matching when +searching for patterns. + +@cindex case folding in replace commands If the first argument of a replace command is all lower case, the command ignores case while searching for occurrences to replace---provided @code{case-fold-search} is non-@code{nil}. If @@ -1250,6 +1452,14 @@ exactly as given, with no case conversion. Likewise, if either @code{case-replace} or @code{case-fold-search} is set to @code{nil}, replacement is done without case conversion. +@cindex character folding in replace commands + The replacement commands by default do not use character folding +(@pxref{Lax Search, character folding}) when looking for the text to +replace. To enable character folding for matching, set the variable +@code{replace-character-fold} to a non-@code{nil} value. (This +setting does not affect the replacement text, only how Emacs finds the +text to replace.) + @node Query Replace @subsection Query Replace @cindex query replace @@ -1270,9 +1480,9 @@ occurrence and asks you whether to replace it. Aside from querying, @code{query-replace} works just like @code{replace-string} (@pxref{Unconditional Replace}). In particular, it preserves case provided @code{case-replace} is non-@code{nil}, as it normally is -(@pxref{Replacement and Case}). A numeric argument means to consider -only occurrences that are bounded by word-delimiter characters. A -negative prefix argument replaces backward. +(@pxref{Replacement and Lax Matches}). A numeric argument means to +consider only occurrences that are bounded by word-delimiter +characters. A negative prefix argument replaces backward. @kindex C-M-% @findex query-replace-regexp @@ -1280,18 +1490,38 @@ negative prefix argument replaces backward. It works like @code{replace-regexp} except that it queries like @code{query-replace}. +@vindex query-replace-from-to-separator + You can reuse earlier replacements with these commands. When +@code{query-replace} or @code{query-replace-regexp} prompts for the +search string, use @kbd{M-p} and @kbd{M-n} to show previous +replacements in the form @samp{@var{from} -> @var{to}}, where +@var{from} is the search pattern, @var{to} is its replacement, and the +separator between them is determined by the value of the variable +@code{query-replace-from-to-separator}. Type @key{RET} to select the +desired replacement. + @cindex faces for highlighting query replace @cindex query-replace face -@cindex lazy-highlight face +@cindex lazy-highlight face, in replace +@vindex query-replace-highlight +@vindex query-replace-lazy-highlight +@vindex query-replace-show-replacement These commands highlight the current match using the face -@code{query-replace}. They highlight other matches using -@code{lazy-highlight} just like incremental search (@pxref{Incremental -Search}). By default, @code{query-replace-regexp} will show the -substituted replacement string for the current match in the -minibuffer. If you want to keep special sequences @samp{\&} and -@samp{\@var{n}} unexpanded, customize +@code{query-replace}. You can disable this highlight by setting the +variable @code{query-replace-highlight} to @code{nil}. They highlight +other matches using @code{lazy-highlight} just like incremental search +(@pxref{Incremental Search}); this can be disabled by setting +@code{query-replace-lazy-highlight} to @code{nil}. By default, +@code{query-replace-regexp} will show the substituted replacement +string for the current match in the minibuffer. If you want to keep +special sequences @samp{\&} and @samp{\@var{n}} unexpanded, customize @code{query-replace-show-replacement} variable. +@vindex query-replace-skip-read-only + The variable @code{query-replace-skip-read-only}, if set +non-@code{nil}, will cause replacement commands to ignore matches in +read-only text. The default is not to ignore them. + The characters you can type when you are shown a match for the string or regexp are: @@ -1311,9 +1541,13 @@ or regexp are: @c WideCommands @table @kbd @item @key{SPC} +@itemx y to replace the occurrence with @var{newstring}. @item @key{DEL} +@itemx @key{Delete} +@itemx @key{BACKSPACE} +@itemx n to skip to the next occurrence without replacing this one. @item , @r{(Comma)} @@ -1329,6 +1563,7 @@ must use @kbd{C-x @key{ESC} @key{ESC} @key{RET}} to restart (@pxref{Repetition}). @item @key{RET} +@itemx q to exit without doing any more replacements. @item .@: @r{(Period)} @@ -1338,19 +1573,6 @@ occurrences. @item ! to replace all remaining occurrences without asking again. -@item Y @r{(Upper-case)} -to replace all remaining occurrences in all remaining buffers in -multi-buffer replacements (like the Dired @key{Q} command that performs -query replace on selected files). It answers this question and all -subsequent questions in the series with ``yes'', without further -user interaction. - -@item N @r{(Upper-case)} -to skip to the next buffer in multi-buffer replacements without -replacing remaining occurrences in the current buffer. It answers -this question ``no'', gives up on the questions for the current buffer, -and continues to the next buffer in the sequence. - @item ^ to go back to the position of the previous occurrence (or what used to be an occurrence), in case you changed it by mistake or want to @@ -1378,19 +1600,30 @@ replacement string for any further occurrences. to redisplay the screen. Then you must type another character to specify what to do with this occurrence. +@item Y @r{(Upper-case)} +to replace all remaining occurrences in all remaining buffers in +multi-buffer replacements (like the Dired @key{Q} command that performs +query replace on selected files). It answers this question and all +subsequent questions in the series with ``yes'', without further +user interaction. + +@item N @r{(Upper-case)} +to skip to the next buffer in multi-buffer replacements without +replacing remaining occurrences in the current buffer. It answers +this question ``no'', gives up on the questions for the current buffer, +and continues to the next buffer in the sequence. + @item C-h +@itemx ? +@itemx @key{F1} to display a message summarizing these options. Then you must type another character to specify what to do with this occurrence. @end table - Some other characters are aliases for the ones listed above: @kbd{y}, -@kbd{n} and @kbd{q} are equivalent to @key{SPC}, @key{DEL} and -@key{RET}. - Aside from this, any other character exits the @code{query-replace}, and is then reread as part of a key sequence. Thus, if you type @kbd{C-k}, it exits the @code{query-replace} and then kills to end of -line. +line. In particular, @kbd{C-g} simply exits the @code{query-replace}. To restart a @code{query-replace} once it is exited, use @kbd{C-x @key{ESC} @key{ESC}}, which repeats the @code{query-replace} because it @@ -1454,12 +1687,17 @@ a multi-file incremental search is activated automatically. @cindex Occur mode @cindex mode, Occur +@cindex match (face name) +@vindex list-matching-lines-default-context-lines @item M-x occur Prompt for a regexp, and display a list showing each line in the -buffer that contains a match for it. To limit the search to part of -the buffer, narrow to that part (@pxref{Narrowing}). A numeric +buffer that contains a match for it. The text that matched is +highlighted using the @code{match} face. To limit the search to part +of the buffer, narrow to that part (@pxref{Narrowing}). A numeric argument @var{n} specifies that @var{n} lines of context are to be -displayed before and after each matching line. +displayed before and after each matching line. The default number of +context lines is specified by the variable +@code{list-matching-lines-default-context-lines}. @kindex RET @r{(Occur mode)} @kindex o @r{(Occur mode)} @@ -1526,3 +1764,89 @@ it never deletes lines that are only partially contained in the region If a match is split across lines, this command keeps all those lines. @end table + +@node Search Customizations +@section Tailoring Search to Your Needs +@cindex search customizations + + This section describes miscellaneous search-related customizations +not described elsewhere. + +@cindex default search mode +@cindex search mode, default + The default search mode for the incremental search is specified by +the variable @code{search-default-regexp-mode}. It can be @code{nil}, +@code{t}, or a function. If it is @code{nil}, the default mode is to +do literal searches without character folding, but with case folding +and lax-whitespace matches as determined by @code{case-fold-search} +and @code{search-whitespace-regexp}, respectively (@pxref{Lax +Search}). If the value is @code{t}, incremental search defaults to +regexp searches. The default value specifies a function that causes +the default search mode to perform character folding in addition to +case folding and lax-whitespace matching. + +@vindex search-highlight + The current match of an on-going incremental search is highlighted +using the @code{isearch} face. This highlighting can be disabled by +setting the variable @code{search-highlight} to a @code{nil} value. + +@cindex lazy highlighting customizations +@vindex isearch-lazy-highlight +@cindex lazy-highlight face + The other matches for the search string that are visible on display +are highlighted using the @code{lazy-highlight} face. Setting the +variable @code{isearch-lazy-highlight} to a @code{nil} value disables +this highlighting. Here are some other variables that customize the +lazy highlighting: + +@table @code +@item lazy-highlight-initial-delay +Time in seconds to wait before highlighting visible matches. + +@item lazy-highlight-interval +Time in seconds between highlighting successive matches. + +@item lazy-highlight-max-at-a-time +The maximum number of matches to highlight before checking for input. +A large number can take some time to highlight, so if you want to +continue searching and type @kbd{C-s} or @kbd{C-r} during that time, +Emacs will not respond until it finishes highlighting all those +matches. Thus, smaller values make Emacs more responsive. +@end table + +@vindex search-nonincremental-instead + Normally, entering @key{RET} within incremental search when the +search string is empty launches a nonincremental search. (Actually, +it lets you edit the search string, and the next @key{RET} does the +search.) However, if you customize the variable +@code{search-nonincremental-instead} to a @code{nil} value, typing +@key{RET} will always exit the incremental search, even if the search +string is empty. + +@vindex isearch-hide-immediately + By default, incremental search and query-replace commands match +invisible text, but hide any such matches as soon as the current match +moves off the invisible text. If you customize the variable +@code{isearch-hide-immediately} to a @code{nil} value, any invisible +text where matches were found stays on display until the search or the +replace command exits. + +@cindex search display on slow terminals +@vindex search-slow-speed +@vindex search-slow-window-lines + Searching incrementally on slow terminals, such as displays +connected to remote machines over slow connection, could be annoying +due to the need to redraw large portions of the display as the search +proceeds. Emacs provides a special display mode for slow terminals, +whereby search pops up a separate small window and displays the text +surrounding the match in that window. Small windows display faster, +so the annoying effect of slow speed is alleviated. The variable +@code{search-slow-speed} determines the baud rate threshold below +which Emacs will use this display mode. The variable +@code{search-slow-window-lines} controls the number of lines in the +window Emacs pops up for displaying the search results; the default is +1 line. Normally, this window will pop up at the bottom of the window +that displays the buffer where you start searching, bit if the value +of @code{search-slow-window-lines} is negative, that means to put the +window at the top and give it the number of lines that is the absolute +value of that value. diff --git a/etc/NEWS b/etc/NEWS index 1a381ecfbdd5..daa5003fb816 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -135,25 +135,6 @@ frames. Works for functions, variables, faces, etc. It is bound to `C-h o' by default. -** New user option `search-default-regexp-mode' -specifies the default mode for I-search. - -** `isearch' and `query-replace' now perform character folding in matches. -This is analogous to case folding, but instead of disregarding case -variants, it disregards wider classes of distinctions between similar -characters. (Case folding is a special case of character folding.) -This means many characters in the search string will match entire -groups of characters instead of just themselves. - -For instance, the " will match all variants of double quotes (like “ -and ”), and the letter a will match all of its accented cousins, even -those composed of multiple characters, as well as many other symbols -like ℀, ℁, ⒜, and ⓐ. - -** New function `character-fold-to-regexp' can be used -by searching commands to produce a regexp matching anything that -character-folds into STRING. - ** New command `checkdoc-package-keywords' checks if the current package keywords are recognized. Set the new option `checkdoc-package-keywords-flag' to non-nil to make @@ -175,10 +156,6 @@ the `network-security-level' variable. ** C-h l now also lists the commands that were run. ---- -** The new M-s M-w key binding uses eww to search the web for the -text in the region. - ** M-x suggests shorthands and ignores obsolete commands for completion. ** x-select-enable-clipboard is renamed select-enable-clipboard. x-select-enable-primary and renamed select-enable-primary. @@ -532,6 +509,36 @@ element. The new commands bound to and in the minibuffer: ** Search and Replace ++++ +*** New user option `search-default-regexp-mode' +specifies the default mode for I-search. + ++++ +*** `isearch' and `query-replace' can now perform character folding in matches. +Isearch does that by default, while `query-replace' will do that if +the new variable `replace-character-fold' is customized to a non-nil +value. This is analogous to case folding, but instead of disregarding +case variants, it disregards wider classes of distinctions between +similar characters. (Case folding is a special case of character +folding.) This means many characters in the search string will match +entire groups of characters instead of just themselves. + +For instance, the " will match all variants of double quotes (like “ +and ”), and the letter a will match all of its accented cousins, even +those composed of multiple characters, as well as many other symbols +like ℀, ℁, ⒜, and ⓐ. + ++++ +*** New function `character-fold-to-regexp' can be used +by searching commands to produce a regexp matching anything that +character-folds into STRING. + ++++ +*** The new M-s M-w key binding uses eww to search the web for the +text in the region. The search engine to use for this is specified by +the customizable variable `eww-search-prefix'. + ++++ *** Query-replace history is enhanced. When query-replace reads the FROM string from the minibuffer, typing `M-p' will now show previous replacements as "FROM SEP TO", where FROM diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 58cce67598c4..8fd2594fec80 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3741,20 +3741,25 @@ discarding." (byte-defop-compiler-1 quote) (defun byte-compile-setq (form) - (let ((args (cdr form))) - (if args - (while args - (if (eq (length args) 1) - (byte-compile-log-warning - (format "missing value for `%S' at end of setq" (car args)) - nil :error)) - (byte-compile-form (car (cdr args))) - (or byte-compile--for-effect (cdr (cdr args)) - (byte-compile-out 'byte-dup 0)) - (byte-compile-variable-set (car args)) - (setq args (cdr (cdr args)))) - ;; (setq), with no arguments. - (byte-compile-form nil byte-compile--for-effect)) + (let* ((args (cdr form)) + (len (length args))) + (if (= (logand len 1) 1) + (progn + (byte-compile-log-warning + (format "missing value for `%S' at end of setq" (car (last args))) + nil :error) + (byte-compile-form + `(signal 'wrong-number-of-arguments '(setq ,len)) + byte-compile--for-effect)) + (if args + (while args + (byte-compile-form (car (cdr args))) + (or byte-compile--for-effect (cdr (cdr args)) + (byte-compile-out 'byte-dup 0)) + (byte-compile-variable-set (car args)) + (setq args (cdr (cdr args)))) + ;; (setq), with no arguments. + (byte-compile-form nil byte-compile--for-effect))) (setq byte-compile--for-effect nil))) (defun byte-compile-setq-default (form) diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el index 4a3c273bc84e..355913acbedf 100644 --- a/lisp/emacs-lisp/cconv.el +++ b/lisp/emacs-lisp/cconv.el @@ -473,27 +473,28 @@ places where they originally did not directly appear." :fun-body ,(cconv--convert-function () body env form))) (`(setq . ,forms) ; setq special form - (let ((prognlist ())) - (while forms - (let* ((sym (pop forms)) - (sym-new (or (cdr (assq sym env)) sym)) - (value-in-list - (and forms - (list (cconv-convert (pop forms) env extend))))) - (push (pcase sym-new - ((pred symbolp) `(setq ,sym-new ,@value-in-list)) - (`(car-safe ,iexp) `(setcar ,iexp ,@value-in-list)) - ;; This "should never happen", but for variables which are - ;; mutated+captured+unused, we may end up trying to `setq' - ;; on a closed-over variable, so just drop the setq. - (_ ;; (byte-compile-report-error - ;; (format "Internal error in cconv of (setq %s ..)" - ;; sym-new)) - (car value-in-list))) - prognlist))) - (if (cdr prognlist) - `(progn . ,(nreverse prognlist)) - (car prognlist)))) + (if (= (logand (length forms) 1) 1) + ;; With an odd number of args, let bytecomp.el handle the error. + form + (let ((prognlist ())) + (while forms + (let* ((sym (pop forms)) + (sym-new (or (cdr (assq sym env)) sym)) + (value (cconv-convert (pop forms) env extend))) + (push (pcase sym-new + ((pred symbolp) `(setq ,sym-new ,value)) + (`(car-safe ,iexp) `(setcar ,iexp ,value)) + ;; This "should never happen", but for variables which are + ;; mutated+captured+unused, we may end up trying to `setq' + ;; on a closed-over variable, so just drop the setq. + (_ ;; (byte-compile-report-error + ;; (format "Internal error in cconv of (setq %s ..)" + ;; sym-new)) + value)) + prognlist))) + (if (cdr prognlist) + `(progn . ,(nreverse prognlist)) + (car prognlist))))) (`(,(and (or `funcall `apply) callsym) ,fun . ,args) ;; These are not special forms but we treat them separately for the needs diff --git a/lisp/gnus/nnml.el b/lisp/gnus/nnml.el index 33eae1c166ec..a2947c0a9927 100644 --- a/lisp/gnus/nnml.el +++ b/lisp/gnus/nnml.el @@ -268,23 +268,6 @@ non-nil.") (max (1+ (- (cdr active) (car active))) 0) (car active) (cdr active) group))))))) -(deffoo nnml-retrieve-groups (groups &optional server) - (when nnml-get-new-mail - (if (nnmail-get-new-mail-per-group) - (dolist (group groups) - (nnml-request-scan group server)) - (nnml-request-scan nil server))) - (with-current-buffer nntp-server-buffer - (erase-buffer) - (dolist (group groups) - (let* ((entry (assoc group nnml-group-alist)) - (active (nth 1 entry))) - (if (consp active) - (insert (format "211 %d %d %d %s\n" - (max (1+ (- (cdr active) (car active))) 0) - (car active) (cdr active) group)))))) - 'group) - (deffoo nnml-request-scan (&optional group server) (setq nnml-article-file-alist nil) (nnml-possibly-change-directory group server) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 41911b8709c4..e750f51e0c4b 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -763,8 +763,12 @@ it is displayed along with the global value." (let ((from (point)) (line-beg (line-beginning-position)) (print-rep - (let ((print-quoted t)) - (prin1-to-string val)))) + (let ((rep + (let ((print-quoted t)) + (prin1-to-string val)))) + (if (and (symbolp val) (not (booleanp val))) + (format-message "`%s'" rep) + rep)))) (if (< (+ (length print-rep) (point) (- line-beg)) 68) (insert print-rep) (terpri) diff --git a/lisp/isearch.el b/lisp/isearch.el index d46611774b26..ce4d3aa7c4dd 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -96,8 +96,12 @@ in Isearch mode is always downcased." (defcustom search-nonincremental-instead t "If non-nil, do a nonincremental search instead of exiting immediately. -Actually, `isearch-edit-string' is called to let you enter the search -string, and RET terminates editing and does a nonincremental search." +This affects the behavior of `isearch-exit' and any key bound to that +command: if this variable is nil, `isearch-exit' always exits the search; +if the value is non-nil, and the search string is empty, `isearch-exit' +starts a nonincremental search instead. (Actually, `isearch-edit-string' +is called to let you enter the search string, and RET terminates editing +and does a nonincremental search.)" :type 'boolean) (defcustom search-whitespace-regexp (purecopy "\\s-+") @@ -142,9 +146,11 @@ whenever point is in one of them." (defcustom isearch-hide-immediately t "If non-nil, re-hide an invisible match right away. This variable makes a difference when `search-invisible' is set to `open'. +If non-nil, invisible matches are re-hidden as soon as the match moves +off the invisible text surrounding the match. If nil then do not re-hide opened invisible text when the match moves. Whatever the value, all opened invisible text is hidden again after exiting -the search." +the search, with the exception of the last successful match, if any." :type 'boolean) (defcustom isearch-resume-in-command-history nil diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 6a77b1b2456d..2c066df90bc3 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el @@ -799,9 +799,7 @@ If no tags table is loaded, do nothing and return nil." (let ((completion-ignore-case (if (memq tags-case-fold-search '(t nil)) tags-case-fold-search case-fold-search)) - (pattern (funcall (or find-tag-default-function - (get major-mode 'find-tag-default-function) - #'find-tag-default))) + (pattern (find-tag--default)) beg) (when pattern (save-excursion @@ -818,9 +816,7 @@ If no tags table is loaded, do nothing and return nil." (let* ((completion-ignore-case (if (memq tags-case-fold-search '(t nil)) tags-case-fold-search case-fold-search)) - (default (funcall (or find-tag-default-function - (get major-mode 'find-tag-default-function) - 'find-tag-default))) + (default (find-tag--default)) (spec (completing-read (if default (format "%s (default %s): " (substring string 0 (string-match "[ :]+\\'" string)) @@ -832,6 +828,11 @@ If no tags table is loaded, do nothing and return nil." (or default (user-error "There is no default tag")) spec))) +(defun find-tag--default () + (funcall (or find-tag-default-function + (get major-mode 'find-tag-default-function) + 'find-tag-default))) + (defvar last-tag nil "Last tag found by \\[find-tag].") @@ -2084,6 +2085,9 @@ for \\[find-tag] (which see)." tag-implicit-name-match-p) "Tag order used in `xref-backend-definitions' to look for definitions.") +(cl-defmethod xref-backend-identifier-at-point ((_backend (eql etags))) + (find-tag--default)) + (cl-defmethod xref-backend-identifier-completion-table ((_backend (eql etags))) (tags-lazy-completion-table)) diff --git a/lisp/replace.el b/lisp/replace.el index 7727562cf314..a671a98b7a03 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -111,7 +111,8 @@ strings or patterns." :version "22.1") (defcustom query-replace-show-replacement t - "Non-nil means to show what actual replacement text will be." + "Non-nil means show substituted replacement text in the minibuffer. +This variable affects only `query-replace-regexp'." :type 'boolean :group 'matching :version "23.1") diff --git a/lisp/simple.el b/lisp/simple.el index dbbe832104bf..c2504ad049aa 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2878,10 +2878,11 @@ See also `undo-auto--buffer-undoably-changed'.") (defun undo-auto--add-boundary () "Add an `undo-boundary' in appropriate buffers." (undo-auto--boundaries - (if undo-auto--this-command-amalgamating - 'amalgamate - 'command)) - (setq undo-auto--this-command-amalgamating nil)) + (let ((amal undo-auto--this-command-amalgamating)) + (setq undo-auto--this-command-amalgamating nil) + (if amal + 'amalgamate + 'command)))) (defun undo-auto--amalgamate () "Amalgamate undo if necessary. diff --git a/lisp/term.el b/lisp/term.el index 033eef426ac2..bb718cf90904 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -110,19 +110,6 @@ ;; ;; ---------------------------------------- ;; -;; If you'd like to check out my complete configuration, you can download -;; it from http://www.polito.it/~s64912/things.html, it's ~500k in size and -;; contains my .cshrc, .emacs and my whole site-lisp subdirectory. (notice -;; that this term.el may be newer/older than the one in there, please -;; check!) -;; -;; This complete configuration contains, among other things, a complete -;; rectangular marking solution (based on rect-mark.el and -;; pc-bindings.el) and should be a good example of how extensively Emacs -;; can be configured on a ppp-connected ws. -;; -;; ---------------------------------------- -;; ;; TODO: ;; ;; - Add hooks to allow raw-mode keys to be configurable diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el index ec55867fcfe0..b8593e30a547 100644 --- a/lisp/vc/vc-dispatcher.el +++ b/lisp/vc/vc-dispatcher.el @@ -580,12 +580,20 @@ editing!" (defun vc-buffer-sync (&optional not-urgent) "Make sure the current buffer and its working file are in sync. NOT-URGENT means it is ok to continue if the user says not to save." - (when (buffer-modified-p) - (if (or vc-suppress-confirm - (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name)))) - (save-buffer) - (unless not-urgent - (error "Aborted"))))) + (let (missing) + (when (cond + ((buffer-modified-p)) + ((not (file-exists-p buffer-file-name)) + (setq missing t))) + (if (or vc-suppress-confirm + (y-or-n-p (format "Buffer %s %s; save it? " + (buffer-name) + (if missing + "is missing on disk" + "modified")))) + (save-buffer) + (unless not-urgent + (error "Aborted")))))) ;; Command closures diff --git a/src/emacs-module.c b/src/emacs-module.c index 11aefc313590..1388e5348bb2 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -1035,15 +1035,15 @@ module_format_fun_env (const struct module_fun_env *env) { /* Try to print a function name if possible. */ const char *path, *sym; - char buffer[256]; + static char const noaddr_format[] = "#"; + char buffer[sizeof noaddr_format + INT_STRLEN_BOUND (intptr_t) + 256]; char *buf = buffer; ptrdiff_t bufsize = sizeof buffer; ptrdiff_t size = (dynlib_addr (env->subr, &path, &sym) ? exprintf (&buf, &bufsize, buffer, -1, "#", sym, path) - : exprintf (&buf, &bufsize, buffer, -1, - "#", env->subr)); + : sprintf (buffer, noaddr_format, env->subr)); Lisp_Object unibyte_result = make_unibyte_string (buffer, size); if (buf != buffer) xfree (buf); diff --git a/src/insdel.c b/src/insdel.c index 24807b1e8f49..bb3171b14ceb 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1765,6 +1765,18 @@ modify_text (ptrdiff_t start, ptrdiff_t end) bset_point_before_scroll (current_buffer, Qnil); } +/* Signal that we are about to make a change that may result in new + undo information. + */ +static void +run_undoable_change (void) +{ + if (EQ (BVAR (current_buffer, undo_list), Qt)) + return; + + call0 (Qundo_auto__undoable_change); +} + /* Check that it is okay to modify the buffer between START and END, which are char positions. @@ -1773,7 +1785,12 @@ modify_text (ptrdiff_t start, ptrdiff_t end) any modification properties the text may have. If PRESERVE_PTR is nonzero, we relocate *PRESERVE_PTR - by holding its value temporarily in a marker. */ + by holding its value temporarily in a marker. + + This function runs Lisp, which means it can GC, which means it can + compact buffers, including the current buffer being worked on here. + So don't you dare calling this function while manipulating the gap, + or during some other similar "critical section". */ void prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end, @@ -1786,6 +1803,8 @@ prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end, if (!NILP (BVAR (current_buffer, read_only))) Fbarf_if_buffer_read_only (temp); + run_undoable_change(); + bset_redisplay (current_buffer); if (buffer_intervals (current_buffer)) @@ -2187,6 +2206,8 @@ syms_of_insdel (void) combine_after_change_list = Qnil; combine_after_change_buffer = Qnil; + DEFSYM (Qundo_auto__undoable_change, "undo-auto--undoable-change"); + DEFVAR_LISP ("combine-after-change-calls", Vcombine_after_change_calls, doc: /* Used internally by the function `combine-after-change-calls' macro. */); Vcombine_after_change_calls = Qnil; diff --git a/src/keyboard.c b/src/keyboard.c index dc4b670a64e0..fd9c82fe7e3e 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -202,7 +202,7 @@ uintmax_t num_input_events; static EMACS_INT last_auto_save; -/* The value of point when the last command was started. */ +/* The value of point when the last command was started. */ static ptrdiff_t last_point_position; /* The frame in which the last input event occurred, or Qmacro if the @@ -1449,6 +1449,11 @@ command_loop_1 (void) result of changes from the last command. */ call0 (Qundo_auto__add_boundary); + /* Record point and buffer, so we can put point into the undo + information if necessary. */ + point_before_last_command_or_undo = PT; + buffer_before_last_command_or_undo = current_buffer; + call1 (Qcommand_execute, Vthis_command); #ifdef HAVE_WINDOW_SYSTEM diff --git a/src/keyboard.h b/src/keyboard.h index 98bc86b58ed7..6c715a44fba1 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -245,6 +245,19 @@ extern KBOARD *current_kboard; /* Total number of times read_char has returned, modulo UINTMAX_MAX + 1. */ extern uintmax_t num_input_events; + +/* The location of point immediately before the last command was + executed, or the last time the undo-boundary command added a + boundary.*/ +ptrdiff_t point_before_last_command_or_undo; + +/* The value of current_buffer immediately before the last command was + executed, or the last time the undo-boundary command added a + boundary.*/ +struct buffer *buffer_before_last_command_or_undo; + +extern struct buffer *prev_buffer; + /* Nonzero means polling for input is temporarily suppressed. */ extern int poll_suppress_count; diff --git a/src/undo.c b/src/undo.c index 214beaeb9ea5..7659224b6c61 100644 --- a/src/undo.c +++ b/src/undo.c @@ -22,10 +22,7 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #include "buffer.h" - -/* Position of point last time we inserted a boundary. */ -static struct buffer *last_boundary_buffer; -static ptrdiff_t last_boundary_position; +#include "keyboard.h" /* The first time a command records something for undo. it also allocates the undo-boundary object @@ -34,46 +31,44 @@ static ptrdiff_t last_boundary_position; an undo-boundary. */ static Lisp_Object pending_boundary; +/* Record point as it was at beginning of this command (if necessary) + and prepare the undo info for recording a change. +/* Prepare the undo info for recording a change. */ static void -run_undoable_change (void) +prepare_record () { - call0 (Qundo_auto__undoable_change); + /* Allocate a cons cell to be the undo boundary after this command. */ + if (NILP (pending_boundary)) + pending_boundary = Fcons (Qnil, Qnil); + + if (MODIFF <= SAVE_MODIFF) + record_first_change (); } -/* Record point as it was at beginning of this command (if necessary) - and prepare the undo info for recording a change. +/* Record point as it was at beginning of this command. PT is the position of point that will naturally occur as a result of the undo record that will be added just after this command terminates. */ - static void record_point (ptrdiff_t pt) { - bool at_boundary; - /* Don't record position of pt when undo_inhibit_record_point holds. */ if (undo_inhibit_record_point) return; - /* Allocate a cons cell to be the undo boundary after this command. */ - if (NILP (pending_boundary)) - pending_boundary = Fcons (Qnil, Qnil); - - run_undoable_change (); + bool at_boundary; at_boundary = ! CONSP (BVAR (current_buffer, undo_list)) || NILP (XCAR (BVAR (current_buffer, undo_list))); - if (MODIFF <= SAVE_MODIFF) - record_first_change (); + prepare_record(); /* If we are just after an undo boundary, and point wasn't at start of deleted range, record where it was. */ - if (at_boundary - && current_buffer == last_boundary_buffer - && last_boundary_position != pt) + if (at_boundary){ bset_undo_list (current_buffer, - Fcons (make_number (last_boundary_position), + Fcons (make_number (pt), BVAR (current_buffer, undo_list))); + } } /* Record an insertion that just happened or is about to happen, @@ -89,7 +84,7 @@ record_insert (ptrdiff_t beg, ptrdiff_t length) if (EQ (BVAR (current_buffer, undo_list), Qt)) return; - record_point (beg); + prepare_record (); /* If this is following another insertion and consecutive with it in the buffer, combine the two. */ @@ -130,8 +125,6 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to) if (NILP (pending_boundary)) pending_boundary = Fcons (Qnil, Qnil); - run_undoable_change (); - for (m = BUF_MARKERS (current_buffer); m; m = m->next) { charpos = m->charpos; @@ -163,7 +156,6 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to) /* Record that a deletion is about to take place, of the characters in STRING, at location BEG. Optionally record adjustments for markers in the region STRING occupies in the current buffer. */ - void record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) { @@ -172,15 +164,21 @@ record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) if (EQ (BVAR (current_buffer, undo_list), Qt)) return; + if (point_before_last_command_or_undo != beg && + buffer_before_last_command_or_undo == current_buffer) + { + record_point (point_before_last_command_or_undo); + } + if (PT == beg + SCHARS (string)) { XSETINT (sbeg, -beg); - record_point (PT); + prepare_record (); } else { XSETFASTINT (sbeg, beg); - record_point (beg); + prepare_record (); } /* primitive-undo assumes marker adjustments are recorded @@ -234,7 +232,7 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length, Lisp_Object buffer) { Lisp_Object lbeg, lend, entry; - struct buffer *obuf = current_buffer, *buf = XBUFFER (buffer); + struct buffer *buf = XBUFFER (buffer); if (EQ (BVAR (buf, undo_list), Qt)) return; @@ -243,11 +241,6 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length, if (NILP (pending_boundary)) pending_boundary = Fcons (Qnil, Qnil); - /* Switch temporarily to the buffer that was changed. */ - set_buffer_internal (buf); - - run_undoable_change (); - if (MODIFF <= SAVE_MODIFF) record_first_change (); @@ -256,9 +249,6 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length, entry = Fcons (Qnil, Fcons (prop, Fcons (value, Fcons (lbeg, lend)))); bset_undo_list (current_buffer, Fcons (entry, BVAR (current_buffer, undo_list))); - - /* Reset the buffer */ - set_buffer_internal (obuf); } DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0, @@ -286,10 +276,11 @@ but another undo command will undo to the previous boundary. */) bset_undo_list (current_buffer, Fcons (Qnil, BVAR (current_buffer, undo_list))); } - last_boundary_position = PT; - last_boundary_buffer = current_buffer; Fset (Qundo_auto__last_boundary_cause, Qexplicit); + point_before_last_command_or_undo = PT; + buffer_before_last_command_or_undo = current_buffer; + return Qnil; } @@ -432,7 +423,6 @@ void syms_of_undo (void) { DEFSYM (Qinhibit_read_only, "inhibit-read-only"); - DEFSYM (Qundo_auto__undoable_change, "undo-auto--undoable-change"); DEFSYM (Qundo_auto__last_boundary_cause, "undo-auto--last-boundary-cause"); DEFSYM (Qexplicit, "explicit"); @@ -442,8 +432,6 @@ syms_of_undo (void) pending_boundary = Qnil; staticpro (&pending_boundary); - last_boundary_buffer = NULL; - defsubr (&Sundo_boundary); DEFVAR_INT ("undo-limit", undo_limit, diff --git a/src/w32.c b/src/w32.c index 9601012acd6a..9b1d94de7862 100644 --- a/src/w32.c +++ b/src/w32.c @@ -7432,7 +7432,7 @@ sys_socket (int af, int type, int protocol) if (winsock_lib == NULL) { errno = ENETDOWN; - return INVALID_SOCKET; + return -1; } check_errno (); @@ -9270,8 +9270,10 @@ maybe_load_unicows_dll (void) pointers, and assign the correct addresses to these pointers at program startup (see emacs.c, which calls this function early on). */ - pMultiByteToWideChar = GetProcAddress (ret, "MultiByteToWideChar"); - pWideCharToMultiByte = GetProcAddress (ret, "WideCharToMultiByte"); + pMultiByteToWideChar = + (MultiByteToWideChar_Proc)GetProcAddress (ret, "MultiByteToWideChar"); + pWideCharToMultiByte = + (WideCharToMultiByte_Proc)GetProcAddress (ret, "WideCharToMultiByte"); return ret; } else diff --git a/src/w32.h b/src/w32.h index 2c711502593a..1efd562eadbf 100644 --- a/src/w32.h +++ b/src/w32.h @@ -179,8 +179,10 @@ extern int _sys_wait_connect (int fd); extern HMODULE w32_delayed_load (Lisp_Object); -extern int (WINAPI *pMultiByteToWideChar)(UINT,DWORD,LPCSTR,int,LPWSTR,int); -extern int (WINAPI *pWideCharToMultiByte)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); +typedef int (WINAPI *MultiByteToWideChar_Proc)(UINT,DWORD,LPCSTR,int,LPWSTR,int); +typedef int (WINAPI *WideCharToMultiByte_Proc)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); +extern MultiByteToWideChar_Proc pMultiByteToWideChar; +extern WideCharToMultiByte_Proc pWideCharToMultiByte; extern void init_environment (char **); extern void check_windows_init_file (void); diff --git a/test/automated/simple-test.el b/test/automated/simple-test.el index a3931ef92771..c758d7cc8ef8 100644 --- a/test/automated/simple-test.el +++ b/test/automated/simple-test.el @@ -263,5 +263,53 @@ '("(s1) (s4)" . " (s2) (s3) (s5)")))) +;; Test for a regression introduced by undo-auto--boundaries changes. +;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg01652.html +(defun undo-test-kill-c-a-then-undo () + (with-temp-buffer + (switch-to-buffer (current-buffer)) + (setq buffer-undo-list nil) + (insert "a\nb\n\c\n") + (goto-char (point-max)) + ;; We use a keyboard macro because it adds undo events in the same + ;; way as if a user were involved. + (kmacro-call-macro nil nil nil + [left + ;; Delete "c" + backspace + left left left + ;; Delete "a" + backspace + ;; C-/ or undo + 67108911 + ]) + (point))) + +(defun undo-test-point-after-forward-kill () + (with-temp-buffer + (switch-to-buffer (current-buffer)) + (setq buffer-undo-list nil) + (insert "kill word forward") + ;; Move to word "word". + (goto-char 6) + (kmacro-call-macro nil nil nil + [ + ;; kill-word + C-delete + ;; undo + 67108911 + ]) + (point))) + +(ert-deftest undo-point-in-wrong-place () + (should + ;; returns 5 with the bug + (= 2 + (undo-test-kill-c-a-then-undo))) + (should + (= 6 + (undo-test-point-after-forward-kill)))) + + (provide 'simple-test) ;;; simple-test.el ends here