Emacs regexp groups in regex-replace -
i have bunch of c macros in files, stuff next( pl )
expanded ( ( pl ) -> next )
i want remove of them because they're unnecessary.
what do, text inside parentheses in macro, pl
. want replacing regexp use text rewriting. example, in perl /next\(\s*(.+)\s*)
(may little incorrect) , output $1->next
, should turn line
if ( next( pl ) != null ) {
into
if ( pl->next != null ) {
in emacs, use match groups in emacs replace-regexp on file file basis. i'm not entirely sure how in emacs.
m-x query-replace-regexp next(\([^)]+\)) ret \1->next ret
which can done inside function (to apply entire buffer)
(defun expand-next () "interactive" (goto-char (point-min)) (while (re-search-forward "\\<next(\\([^\)]+\\))" nil t) (replace-match "\\1->next")))
and, apply multiple files, can mark files in dired , type q query-replace-regexp
on marked files (use regexp/replacement in first line of answer).
Comments
Post a Comment