🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #189224

Re: Atom Query Replace

#189224
From: Gabriel
Date: Sun, 14 Apr 1991 17:48
50 lines
2534 bytes
 => Anyone have a GNU implementation of the Atom Query Replace command
 => available with ZEMACS on the Symbolics Lisp Machines?  In case you
 => are wondering, this command only replaces atoms, and is great for
 => renaming variables in code.  Thanks in advance...Jeff

No that I know of, but you can easily simulate it with regular
expressions and syntax tables. An "atom" is basically a non-symbol
character, followed by a word, followed by another non-symbol character.
In regexps, we can use:

	\S_\<the-word-you-are-searching\>\S_

In regexp syntax, \S_ refers to a character whose syntax is NOT `_'; the
`_' syntax is the syntax of symbols which, in addition to the characters
that make up words, make up variable and command names. (For example,
"-", "_", "*", etc.) This excludes whitespace, "(" and ")", etc. Then,
\< refers to the beginning of a word, and \> refers to the end of a
word.

So, if you use M-x query-replace-regexp, or M-x tags-query-replace,
suppose you want to replace "old-variable-name" with
"new-variable-name". Just use

	\S_\<old-variable-name\>\S_

and replace with

	new-variable-name

Or you can write your own function:

   (defun atom-query-replace (&optional old new)
     (interactive)
     (if (not (and old new))
	 (setq old (read-from-minibuffer "Query replace: ")
	       new (read-from-minibuffer (format "Query replace %s with: "
						 old))))
     (query-replace-regexp (concat "\\S_\\<" old "\\>\\S_") new))

The elisp Info nodes to look at are "Syntax Tables" and "Regular
Expressions". Hope this helps!
--
Raul Acevedo
acevedo@athena.mit.edu

"Remember, Information is not knowledge; Knowledge is not Wisdom;
Wisdom is not truth; Truth is not beauty; Beauty is not love;
Love is not music; Music is the best."
	 - Frank Zappa
Technical Details
Message-ID: <ACEVEDO.91Apr14134830@hydrox-cookie.mit.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!think.com!mintaka!bloom-picayune.mit.edu!athena.mit.edu!acevedo
References: <1991Apr11.211036.15528@aero.org>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103b8b,fe317d6997c35879
X-Google-Attributes: gid103b8b,public
X-Google-ArrivalTime: 1991-04-14 11:29:04 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!think.com!mintaka!bloom-picayune.mit.edu!athena.mit.edu!acevedo
From: acevedo@athena.mit.edu (Gabriel)
Newsgroups: gnu.emacs.help
Subject: Re: Atom Query Replace
Message-ID: <ACEVEDO.91Apr14134830@hydrox-cookie.mit.edu>
Date: 14 Apr 91 17:48:35 GMT
References: <1991Apr11.211036.15528@aero.org>
Sender: news@athena.mit.edu (News system)
Organization: Massachusetts Institute of Technology
Lines: 50
In-Reply-To: jvc@Aero.org's message of 11 Apr 91 21:10:36 GMT