From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Newsgroups: gmane.emacs.help Subject: Re: Then how to replace all my $$ ... $$ to \[ \] through search and replace? Date: Fri, 15 Aug 2008 01:01:51 -0700 (PDT) Organization: http://groups.google.com Message-ID: <46f723d8-34fc-4588-8c6e-24571fe05c4a@p31g2000prf.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1218789794 4726 80.91.229.12 (15 Aug 2008 08:43:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Aug 2008 08:43:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 15 10:44:03 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KTuuQ-0005Gm-8j for geh-help-gnu-emacs@m.gmane.org; Fri, 15 Aug 2008 10:43:48 +0200 Original-Received: from localhost ([127.0.0.1]:40633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTutS-0002L2-Tt for geh-help-gnu-emacs@m.gmane.org; Fri, 15 Aug 2008 04:42:46 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!p31g2000prf.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 155 Original-NNTP-Posting-Host: 24.6.97.120 Original-X-Trace: posting.google.com 1218787311 32753 127.0.0.1 (15 Aug 2008 08:01:51 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 15 Aug 2008 08:01:51 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p31g2000prf.googlegroups.com; posting-host=24.6.97.120; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.22, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:161313 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:56659 Archived-At: On Aug 15, 12:29 am, "xiaopeng hu" 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 =E2=80=9CHelp= =E2=80=A3Read Emacs Manual=E2=80=9D 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 =E2=80=9CEdit=E2=80=A3Replace=E2=80=9D. Command Name keybard shortcut Target Description query-replace =E2=80=9CAlt+%=E2=80=9D or menu =E2=80=9CEdit=E2=80=A3Replace= =E2=80=9D region, or cursor point to end interactive find and replace query-replace-regexp =E2=80=9CCtrl+Alt+%=E2=80=9D or menu =E2=80=9CEdit=E2= =80=A3Replace=E2=80=9D region, or cusor point to end interactive find and replace with regex pattern dired-do-query-replace-regexp In dired, =E2=80=9CQ=E2=80=9D, or menu =E2=80= =9COperate=E2=80=A3Query Replace in Files...=E2=80=9D multiple files interactive find and replace wi= th regex pattern on multiple files For example, to use query-replace, type =E2=80=9CAlt+%=E2=80=9D, then type = your search string, then type your replacement string. When the query commands stops to ask you for confirmation, type =E2=80=9Cy=E2=80=9D (or space bar) to do the replacement, type =E2=80=9Cn= =E2=80=9D to skip, type =E2=80=9C!=E2=80=9D to do all remaining replacements without asking, type =E2=80=9Cq=E2=80=9D t= o 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 =E2=80=9COptions=E2=80=A3Case-Insensitive Search=E2=80=9D. The menu is a to= ggle. 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 =E2=80=9CM-x set-variable=E2=80=9D, then the vaiable name, then give= a value =E2=80=9Ct=E2=80=9D or =E2=80=9Cnil=E2=80=9D. To see what the current value= is, type =E2=80=9CM-x describe- variable=E2=80=9D then give the variable name. There is also a command togg= le- 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 =E2=80=9Chere=E2= =80=9D, and your replacement string is =E2=80=9Cdragon=E2=80=9D (and assume you are usi= ng default emacs setup so that it will match both =E2=80=9Chere=E2=80=9D, =E2=80=9CHer= e=E2=80=9D, =E2=80=9CHERE=E2=80=9D). Now, when emacs found =E2=80=9Chere=E2=80=9D, the replacement will be =E2=80=9Cd= ragon=E2=80=9D, when emacs found =E2=80=9CHere=E2=80=9D, the replacement will be =E2=80=9CDragon=E2=80= =9D, when emacs found =E2=80=9CHERE=E2=80=9D, the replacement will be =E2=80=9CDRAGON=E2=80=9D. If you want the letter case of your replacement string be literal, you need to set the variable case-replace to =E2=80=9Ct=E2=80=9D. Type =E2=80= =9CAlt+x set- variable=E2=80=9D then the variable name, then give it a value of =E2=80=9C= t=E2=80=9D. 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:

once upon a time ...

There is a dragon who lived in ...

princess Tana is still waiting ...

You want to make sure that all paragraphs starts with a capital letter. So, you use a pattern that catches the first letter after

, like this =E2=80=9C

\([a-z]\)=E2=80=9D. By default, emacs will match both= =E2=80=9C

=E2=80=9D and =E2=80=9C

=E2=80=9D. To make your captured pattern upper case, give your replacement string this expression: =E2=80=9C

\,(upcase \1)=E2=80=9D. The =E2=80=9C\,=E2=80= =9D tells emacs that what follows should be a lisp expression. The =E2=80=9C(upcase \1)=E2=80=9D is a= lisp expression. The =E2=80=9Cupcase=E2=80=9D is a lisp function and the =E2=80= =9C\1=E2=80=9D means the 1st captured string in your regex pattern. If you want lower case, use =E2=80=9Cdowncase=E2=80=9D in place of =E2=80=9Cupcase=E2=80=9D. For a more complex example in using the =E2=80=9C\,=E2=80=9D in replacement= , see: Lisp Lesson: Regex Replace with a Function. Reference: (info "(emacs)Search"). ---------------------------- Xah =E2=88=91 http://xahlee.org/ =E2=98=84