* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? [not found] <mailman.16760.1218785698.18990.help-gnu-emacs@gnu.org> @ 2008-08-15 8:01 ` Xah 2008-08-15 14:25 ` Malte Spiess 1 sibling, 0 replies; 14+ messages in thread From: Xah @ 2008-08-15 8:01 UTC (permalink / raw) To: help-gnu-emacs On Aug 15, 12:29 am, "xiaopeng hu" <huxiaopengs...@gmail.com> wrote: > Then how to replace all my $$ ... $$ to \[ \] through search and replace? > Thanks Please read the manual! You can read the manual in the menu “Help‣Read Emacs Manual” section. Then, you can easily find search and replace section. your question seems to be a basic question of using emacs. Are you having a problem with regex? or you don't know what command to use?? If your question is about regex, see: Text Pattern Matching in Emacs http://xahlee.org/emacs/emacs_regex.html or the emacs manual about regex. If your question is about emacs's find/replace commands, see: Find and Replace with Emacs http://xahlee.org/emacs/emacs_find_replace.html Plain text version follows. ------------------------ Find and Replace with Emacs Xah Lee, 2008-03 This page shows you how to use emacs to do find and replace operations, and tells you how to do case-sensitive or case-insensitive match or replacement, and how to force captured regex text pattern into upper or lower case. EMACS'S FIND AND REPLACE COMMANDS Here are the emacs find and replace commands. These are also under the graphical menu “Edit‣Replace”. Command Name keybard shortcut Target Description query-replace “Alt+%” or menu “Edit‣Replace” region, or cursor point to end interactive find and replace query-replace-regexp “Ctrl+Alt+%” or menu “Edit‣Replace” region, or cusor point to end interactive find and replace with regex pattern dired-do-query-replace-regexp In dired, “Q”, or menu “Operate‣Query Replace in Files...” multiple files interactive find and replace with regex pattern on multiple files For example, to use query-replace, type “Alt+%”, then type your search string, then type your replacement string. When the query commands stops to ask you for confirmation, type “y” (or space bar) to do the replacement, type “n” to skip, type “!” to do all remaining replacements without asking, type “q” to exit. For tutorial on how to use dired-do-query-replace-regexp, see Interactively Find and Replace String Patterns on Multiple Files. Emacs also have commands replace-string and replace-regexp. They are the non-interactive versions of query-replace and query-replace- regexp. They do all replacements in one-shot without asking confirmation for each replacement. CASE SENSITIVITY IN SEARCH STRING By default, search is not case sensitive; however, if your search string contains a capital letter, search is automatically case sensitive. To make your search absolutely case-sensitive, use the menu “Options‣Case-Insensitive Search”. The menu is a toggle. A checkmark in front of the menu means it is on. (Technically, the case sensitivity is controlled by the variable case- fold-search. You can set this variable to true (t) or false (nil) by typing “M-x set-variable”, then the vaiable name, then give a value “t” or “nil”. To see what the current value is, type “M-x describe- variable” then give the variable name. There is also a command toggle- case-fold-search, which toggles the value of case-fold-search) CASE IN REPLACEMENT STRING By default, the case of the replaced text is smartly dependent on the matched text. For example, suppose your search string is “here”, and your replacement string is “dragon” (and assume you are using default emacs setup so that it will match both “here”, “Here”, “HERE”). Now, when emacs found “here”, the replacement will be “dragon”, when emacs found “Here”, the replacement will be “Dragon”, when emacs found “HERE”, the replacement will be “DRAGON”. If you want the letter case of your replacement string be literal, you need to set the variable case-replace to “t”. Type “Alt+x set- variable” then the variable name, then give it a value of “t”. FORCE CASE OF MATCHED TEXT Sometimes you need to do regex search to find a pattern, and have the case of the pattern be changed. For example, suppose in your html code you have: <p>once upon a time ...</p> <P>There is a dragon who lived in ...</P> <p>princess Tana is still waiting ...</p> You want to make sure that all paragraphs starts with a capital letter. So, you use a pattern that catches the first letter after <p>, like this “<p>\([a-z]\)”. By default, emacs will match both “<P>” and “<p>”. To make your captured pattern upper case, give your replacement string this expression: “<p>\,(upcase \1)”. The “\,” tells emacs that what follows should be a lisp expression. The “(upcase \1)” is a lisp expression. The “upcase” is a lisp function and the “\1” means the 1st captured string in your regex pattern. If you want lower case, use “downcase” in place of “upcase”. For a more complex example in using the “\,” in replacement, see: Lisp Lesson: Regex Replace with a Function. Reference: (info "(emacs)Search"). ---------------------------- Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? [not found] <mailman.16760.1218785698.18990.help-gnu-emacs@gnu.org> 2008-08-15 8:01 ` Then how to replace all my $$ ... $$ to \[ \] through search and replace? Xah @ 2008-08-15 14:25 ` Malte Spiess 1 sibling, 0 replies; 14+ messages in thread From: Malte Spiess @ 2008-08-15 14:25 UTC (permalink / raw) To: help-gnu-emacs "xiaopeng hu" <huxiaopengstat@gmail.com> writes: > Then how to replace all my $$ ... $$ to \[ \] through search and > replace? I would suggest making a keyboard makro: 1. search for $$ 2. replace with \[ 3. search for $$ 4. replace with \] And repeat that til the end of the file. > Thanks Greetings Malte ^ permalink raw reply [flat|nested] 14+ messages in thread
* Then how to replace all my $$ ... $$ to \[ \] through search and replace? @ 2008-08-15 7:29 xiaopeng hu 2008-08-15 7:54 ` Tassilo Horn [not found] ` <mailman.16764.1218786903.18990.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 14+ messages in thread From: xiaopeng hu @ 2008-08-15 7:29 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 81 bytes --] Then how to replace all my $$ ... $$ to \[ \] through search and replace? Thanks [-- Attachment #2: Type: text/html, Size: 106 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-15 7:29 xiaopeng hu @ 2008-08-15 7:54 ` Tassilo Horn [not found] ` <mailman.16764.1218786903.18990.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 14+ messages in thread From: Tassilo Horn @ 2008-08-15 7:54 UTC (permalink / raw) To: help-gnu-emacs "xiaopeng hu" <huxiaopengstat@gmail.com> writes: Hi! > Then how to replace all my $$ ... $$ to \[ \] through search and > replace? Thanks M-x query-replace-regexp RET \$\$\(.+\)\$\$ RET \\[\1\\] RET Bye, Tassilo -- Richard Stallman has no problem using emacs. He wrote it with his 4 hands. ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.16764.1218786903.18990.help-gnu-emacs@gnu.org>]
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? [not found] ` <mailman.16764.1218786903.18990.help-gnu-emacs@gnu.org> @ 2008-08-15 8:40 ` Ralf Angeli 2008-08-15 9:05 ` Tassilo Horn ` (2 more replies) 0 siblings, 3 replies; 14+ messages in thread From: Ralf Angeli @ 2008-08-15 8:40 UTC (permalink / raw) To: help-gnu-emacs * Tassilo Horn (2008-08-15) writes: > "xiaopeng hu" <huxiaopengstat@gmail.com> writes: > >> Then how to replace all my $$ ... $$ to \[ \] through search and >> replace? Thanks > > M-x query-replace-regexp RET \$\$\(.+\)\$\$ RET \\[\1\\] RET This won't work because `.' does not match a newline. Using `[^$]' instead should do it. -- Ralf ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-15 8:40 ` Ralf Angeli @ 2008-08-15 9:05 ` Tassilo Horn 2008-08-15 9:08 ` Thierry Volpiatto [not found] ` <mailman.16770.1218791143.18990.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 14+ messages in thread From: Tassilo Horn @ 2008-08-15 9:05 UTC (permalink / raw) To: help-gnu-emacs Ralf Angeli <dev.null@caeruleus.net> writes: Hi Ralf, >> M-x query-replace-regexp RET \$\$\(.+\)\$\$ RET \\[\1\\] RET > > This won't work because `.' does not match a newline. Ok, but at least it works for oneliners. > Using `[^$]' instead should do it. Right, that's better. Bye, Tassilo -- [Emacs] is written in Lisp, which is the only computer language that is beautiful. -- Neal Stephenson, _In the Beginning was the Command Line_ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-15 8:40 ` Ralf Angeli 2008-08-15 9:05 ` Tassilo Horn @ 2008-08-15 9:08 ` Thierry Volpiatto [not found] ` <mailman.16770.1218791143.18990.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 14+ messages in thread From: Thierry Volpiatto @ 2008-08-15 9:08 UTC (permalink / raw) To: help-gnu-emacs Ralf Angeli <dev.null@caeruleus.net> writes: > * Tassilo Horn (2008-08-15) writes: > >> "xiaopeng hu" <huxiaopengstat@gmail.com> writes: >> >>> Then how to replace all my $$ ... $$ to \[ \] through search and >>> replace? Thanks >> >> M-x query-replace-regexp RET \$\$\(.+\)\$\$ RET \\[\1\\] RET > > This won't work because `.' does not match a newline. Using `[^$]' > instead should do it. Just a note about re-builder and regex-tool: To build a regex to use in a program or with query-replace-regexp, you can use one of these tools, however, re-builder will build a regex to use in a program and this regex will not work in query-replace-regexp. Regex-tool will build a regex more usable with query-replace-regexp. [0-9]\\{2\\} ==> work in a program but not in query-replace [0-9]\{2\} ==> work in query-replace but not in a program -- A + Thierry Volpiatto Location: Saint-Cyr-Sur-Mer - France ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.16770.1218791143.18990.help-gnu-emacs@gnu.org>]
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? [not found] ` <mailman.16770.1218791143.18990.help-gnu-emacs@gnu.org> @ 2008-08-15 9:34 ` Phil Carmody 2008-08-15 10:13 ` Ralf Angeli 0 siblings, 1 reply; 14+ messages in thread From: Phil Carmody @ 2008-08-15 9:34 UTC (permalink / raw) To: help-gnu-emacs Tassilo Horn <tassilo@member.fsf.org> writes: > Ralf Angeli <dev.null@caeruleus.net> writes: > > Hi Ralf, > >>> M-x query-replace-regexp RET \$\$\(.+\)\$\$ RET \\[\1\\] RET >> >> This won't work because `.' does not match a newline. > > Ok, but at least it works for oneliners. > >> Using `[^$]' instead should do it. > > Right, that's better. $$ What about this $1,000,000 example? $$ Such strings may not be possible in the original data set, of course, so it might not be an issue. Phil -- The fact that a believer is happier than a sceptic is no more to the point than the fact that a drunken man is happier than a sober one. The happiness of credulity is a cheap and dangerous quality. -- George Bernard Shaw (1856-1950), Preface to Androcles and the Lion ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-15 9:34 ` Phil Carmody @ 2008-08-15 10:13 ` Ralf Angeli 2008-08-15 17:24 ` Reiner Steib 0 siblings, 1 reply; 14+ messages in thread From: Ralf Angeli @ 2008-08-15 10:13 UTC (permalink / raw) To: help-gnu-emacs * Phil Carmody (2008-08-15) writes: > Tassilo Horn <tassilo@member.fsf.org> writes: >> Ralf Angeli <dev.null@caeruleus.net> writes: >> >>>> M-x query-replace-regexp RET \$\$\(.+\)\$\$ RET \\[\1\\] RET >>> >>> This won't work because `.' does not match a newline. >> >> Ok, but at least it works for oneliners. >> >>> Using `[^$]' instead should do it. >> >> Right, that's better. > > $$ What about this $1,000,000 example? $$ Then you could use something like C-M-% \$\$ <RET> \,(if (zerop (mod \# 2)) "\\[" "\\]") <RET> -- Ralf ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-15 10:13 ` Ralf Angeli @ 2008-08-15 17:24 ` Reiner Steib 2008-08-16 1:18 ` Nikos Apostolakis 0 siblings, 1 reply; 14+ messages in thread From: Reiner Steib @ 2008-08-15 17:24 UTC (permalink / raw) To: help-gnu-emacs On Fri, Aug 15 2008, Ralf Angeli wrote: > * Phil Carmody (2008-08-15) writes: >> $$ What about this $1,000,000 example? $$ > C-M-% \$\$ <RET> \,(if (zerop (mod \# 2)) "\\[" "\\]") <RET> (replace-string "$$" '("\\\[" "\\\]")) Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-15 17:24 ` Reiner Steib @ 2008-08-16 1:18 ` Nikos Apostolakis 2008-08-16 9:21 ` Reiner Steib 0 siblings, 1 reply; 14+ messages in thread From: Nikos Apostolakis @ 2008-08-16 1:18 UTC (permalink / raw) To: help-gnu-emacs Reiner Steib <reinersteib+gmane@imap.cc> writes: > On Fri, Aug 15 2008, Ralf Angeli wrote: > >> * Phil Carmody (2008-08-15) writes: >>> $$ What about this $1,000,000 example? $$ >> C-M-% \$\$ <RET> \,(if (zerop (mod \# 2)) "\\[" "\\]") <RET> > > (replace-string "$$" '("\\\[" "\\\]")) > This is great! Is this an undocumented feature of replace-string? I can't find it in the help string or the info manual. Nikos ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-16 1:18 ` Nikos Apostolakis @ 2008-08-16 9:21 ` Reiner Steib 2008-08-16 13:49 ` harven 0 siblings, 1 reply; 14+ messages in thread From: Reiner Steib @ 2008-08-16 9:21 UTC (permalink / raw) To: help-gnu-emacs On Sat, Aug 16 2008, Nikos Apostolakis wrote: > Reiner Steib <reinersteib+gmane@imap.cc> writes: >> (replace-string "$$" '("\\\[" "\\\]")) > > This is great! David Kastrup once mention this (or a similar example with `replace-regexp') on some newsgroup or mailing list. I don't remember if it is possible to use this with M-x replace-... or query-replace... as well. > Is this an undocumented feature of replace-string? I can't find it in > the help string or the info manual. I can't find it in the docs neither. Please suggest to document it (via M-x report-emacs-bug RET). Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-16 9:21 ` Reiner Steib @ 2008-08-16 13:49 ` harven 2008-08-16 15:45 ` Reiner Steib 0 siblings, 1 reply; 14+ messages in thread From: harven @ 2008-08-16 13:49 UTC (permalink / raw) To: help-gnu-emacs > David Kastrup once mention this (or a similar example with > `replace-regexp') on some newsgroup or mailing list. I don't remember > if it is possible to use this with M-x replace-... or > query-replace... as well. M-:(replace-regexp "\\$\\$" '("\\\[" "\\\]")) It is in fact a feature of the perform-replace function. Quoting the elisp manual section dealing with this function: > The argument REPLACEMENTS specifies what to replace occurrences > with. If it is a string, that string is used. It can also be a > list of strings, to be used in cyclic order. > If REPLACEMENTS is a cons cell, `(FUNCTION . DATA)', this means to > call FUNCTION after each match to get the replacement text. This > function is called with two arguments: DATA, and the number of > replacements already made. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? 2008-08-16 13:49 ` harven @ 2008-08-16 15:45 ` Reiner Steib 0 siblings, 0 replies; 14+ messages in thread From: Reiner Steib @ 2008-08-16 15:45 UTC (permalink / raw) To: help-gnu-emacs On Sat, Aug 16 2008, harven wrote: >> David Kastrup once mention this (or a similar example with >> `replace-regexp') on some newsgroup or mailing list. I don't remember >> if it is possible to use this with M-x replace-... or >> query-replace... as well. > > M-:(replace-regexp "\\$\\$" '("\\\[" "\\\]")) Of course you can call `eval-expression', but I was takling about commands (interactive functions). > It is in fact a feature of the perform-replace function. > Quoting the elisp manual section dealing with this function: ,----[ (info "(elisp)Search and Replace") ] | -- Function: perform-replace from-string replacements query-flag | regexp-flag delimited-flag &optional repeat-count map start | end | This function is the guts of `query-replace' and related commands. | [...] | | The argument REPLACEMENTS specifies what to replace occurrences | with. If it is a string, that string is used. It can also be a | list of strings, to be used in cyclic order. `---- Thanks. However, IMHO this neat feature should be available interactively (maybe it is?) and the documentation should not be hidden in (info "(elisp)Search and Replace") under the internal function `perform-replace'. Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2008-08-16 15:45 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <mailman.16760.1218785698.18990.help-gnu-emacs@gnu.org> 2008-08-15 8:01 ` Then how to replace all my $$ ... $$ to \[ \] through search and replace? Xah 2008-08-15 14:25 ` Malte Spiess 2008-08-15 7:29 xiaopeng hu 2008-08-15 7:54 ` Tassilo Horn [not found] ` <mailman.16764.1218786903.18990.help-gnu-emacs@gnu.org> 2008-08-15 8:40 ` Ralf Angeli 2008-08-15 9:05 ` Tassilo Horn 2008-08-15 9:08 ` Thierry Volpiatto [not found] ` <mailman.16770.1218791143.18990.help-gnu-emacs@gnu.org> 2008-08-15 9:34 ` Phil Carmody 2008-08-15 10:13 ` Ralf Angeli 2008-08-15 17:24 ` Reiner Steib 2008-08-16 1:18 ` Nikos Apostolakis 2008-08-16 9:21 ` Reiner Steib 2008-08-16 13:49 ` harven 2008-08-16 15:45 ` Reiner Steib
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).