[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: line beginning with a regexp.

From: Eduardo Ochs
Subject: Re: line beginning with a regexp.
Date: Fri, 23 Feb 2001 00:52:30 -0300 (BRT)

Hi Annamalai,

> Hello All,
> I was wondering whether this kind of "editing" can be done in Emacs
> itself using elisp rather than using a shell script or a perl script.
> I have this file containing a few lines.  They are all sql commands.
> <snip>
> call procedure_name( long list of
> argument calls );
> call procedure_name( another long long
> list of arguments that seems
> to be very long indeed);
> call procedure_name( yet another long
> argument list);
> </snip>
> Something like that.  I would like to edit this file so that
> each command is in its own line, like,
> <snip>
> call procedure_name( long ... calls );
> call procedure_name( another ...  indeed);
> call procedure_name( yet ... list);
> </snip>
> Can anyone help me?  Or is this not the right list?  Is there a
> mailing list for Elisp? 
> Thanks for your time and help.
> Cheers,
> anna

This is the right list for Elisp (AFAIK), but discussions usually
don't get as heated as they should.

I would use the following dirty trick if I were you:

  (defun foo () (interactive)
    (let ((fill-column 4000))
       (search-forward ");"))))

maybe in conjunction with:

  (global-set-command "\M-A" 'foo)

It is reasonably harmless to assign temporarily (with C-x C-e, say) a
quick hack to a key like "meta-uppercase letter", as Emacs generally
doesn't use those keys... Not all OSs and terminals distinguish
between M-A and M-a, though, and if "esc A" is too clumsy to type then
I think that something like

  (global-set-command "\C-ca" 'foo)

would be the recommended way, or just "M-x foo", used in a keyboard

BTW, if you commit as many typing errors as I do, and you prefer to
write small chunks of lisp code and save them to diary entries
(to share & recycle) instead of doing everything interactively, then
here is the other trick I would use for these cases, that is closer to
maragato's suggestion, that was:

> no elisp needed, just an old hack:
> Copy section to alter into another buffer, for safety
> Go to beginning of that buffer
> M-x replace-string "^Jcall procedure_name(" 
>   with "@#$#@call procedure_name("
> M-x replace-string "^J" with ""
> M-x replace-string "@#$#@call procedure_name(" 
>   with "^Jcall procedure_name("
> Copy the altered section back

I'm just rambling over religious matters, of course, because IMNSHO
elisp is good for the soul and that first sentence in maragato's
message is immoral. Anyway, I have something like this in my .emacs:

(defun query-replaces (&rest rest)
      (narrow-to-region (point) (mark))
      (while rest
        (goto-char (point-min))
        (query-replace (car rest) (car (cdr rest)))
        ;; (query-replace-regexp (regexp-quote (car rest)) (car (cdr rest)))
        (setq rest (cdr (cdr rest)))))))

and if I put the mark in the "# end of stuff" and the point just after
the Lisp expression in the block below and type C-x C-e then Emacs
will enter a query-replace loop for each of the pairs of strings...

# (query-replaces "\ncall " "\n@#$#@call " "\n" "" "@#$#@call " "\ncall ")
call foo( a,
call bar( e, f,
g, h, i, j);
call plic( k, l, m);
# end of stuff

I have used this `query-replaces' function zillions of times, often
with many pairs of strings, and almost always the pairs were wrong at
first and I had to make corrections.

  Many cheers,
    Eduardo Ochs

reply via email to

[Prev in Thread] Current Thread [Next in Thread]