all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* putting double quotes efficiently
@ 2013-06-03  5:43 C K Kashyap
  2013-06-03  7:26 ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: C K Kashyap @ 2013-06-03  5:43 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,
I am looking for a way to transform

print line1
print line two
print line3

into

print "line1";
print "line two";
print "line3";

most efficiently. For the first quote of each line I place the cursor
before line1 and I set the mark and then move all the way down to just
before line3 and then do a C-x-r-t " <RET>
Then I do a regexp replace to change $ to ";

I'd like to do better. While at it, can I please also know how I can use
the line range in the mark set mode in user defined function?

Regards,
Kashyap


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-03  5:43 C K Kashyap
@ 2013-06-03  7:26 ` Andreas Röhler
  2013-06-03  7:55   ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2013-06-03  7:26 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org List

Am 03.06.2013 07:43, schrieb C K Kashyap:
> Hi,
> I am looking for a way to transform
>
> print line1
> print line two
> print line3
>
> into
>
> print "line1";
> print "line two";
> print "line3";
>
> most efficiently. For the first quote of each line I place the cursor
> before line1 and I set the mark and then move all the way down to just
> before line3 and then do a C-x-r-t " <RET>
> Then I do a regexp replace to change $ to ";
>
> I'd like to do better. While at it, can I please also know how I can use
> the line range in the mark set mode in user defined function?
>
> Regards,
> Kashyap
>

M-x query-replace-regexp

^\([^ ]+\) \(.+\)
RET
\1 "\2;
RET



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-03  7:26 ` Andreas Röhler
@ 2013-06-03  7:55   ` Andreas Röhler
  2013-06-03  8:03     ` C K Kashyap
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2013-06-03  7:55 UTC (permalink / raw)
  To: help-gnu-emacs

Am 03.06.2013 09:26, schrieb Andreas Röhler:
> Am 03.06.2013 07:43, schrieb C K Kashyap:
>> Hi,
>> I am looking for a way to transform
>>
>> print line1
>> print line two
>> print line3
>>
>> into
>>
>> print "line1";
>> print "line two";
>> print "line3";
>>
>> most efficiently. For the first quote of each line I place the cursor
>> before line1 and I set the mark and then move all the way down to just
>> before line3 and then do a C-x-r-t " <RET>
>> Then I do a regexp replace to change $ to ";
>>
>> I'd like to do better. While at it, can I please also know how I can use
>> the line range in the mark set mode in user defined function?
>>
>> Regards,
>> Kashyap
>>
>
> M-x query-replace-regexp
>
> ^\([^ ]+\) \(.+\)
> RET
> \1 "\2;
> RET
>
>

resp. with missing " in replace expression

  \1 "\2";



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-03  7:55   ` Andreas Röhler
@ 2013-06-03  8:03     ` C K Kashyap
  2013-06-03  9:10       ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: C K Kashyap @ 2013-06-03  8:03 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: help-gnu-emacs

Thanks Andreas,
This works.
Although I'd still like to know how to write custom function that work over
a marked region.
Regards,
Kashyap


On Mon, Jun 3, 2013 at 1:25 PM, Andreas Röhler <
andreas.roehler@easy-emacs.de> wrote:

> Am 03.06.2013 09:26, schrieb Andreas Röhler:
>
>  Am 03.06.2013 07:43, schrieb C K Kashyap:
>>
>>> Hi,
>>> I am looking for a way to transform
>>>
>>> print line1
>>> print line two
>>> print line3
>>>
>>> into
>>>
>>> print "line1";
>>> print "line two";
>>> print "line3";
>>>
>>> most efficiently. For the first quote of each line I place the cursor
>>> before line1 and I set the mark and then move all the way down to just
>>> before line3 and then do a C-x-r-t " <RET>
>>> Then I do a regexp replace to change $ to ";
>>>
>>> I'd like to do better. While at it, can I please also know how I can use
>>> the line range in the mark set mode in user defined function?
>>>
>>> Regards,
>>> Kashyap
>>>
>>>
>> M-x query-replace-regexp
>>
>> ^\([^ ]+\) \(.+\)
>> RET
>> \1 "\2;
>> RET
>>
>>
>>
> resp. with missing " in replace expression
>
>  \1 "\2";
>
>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-03  8:03     ` C K Kashyap
@ 2013-06-03  9:10       ` Andreas Röhler
  2013-06-03 11:52         ` C K Kashyap
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2013-06-03  9:10 UTC (permalink / raw)
  To: C K Kashyap; +Cc: help-gnu-emacs

Am 03.06.2013 10:03, schrieb C K Kashyap:
> Thanks Andreas,
> This works.
> Although I'd still like to know how to write custom function that work over
> a marked region.

For example that way:

(defun my-New-Command (beg end)
   (interactive "r*")
   (save-excursion
     (save-restriction
       (narrow-to-region beg end)
       (goto-char beg)
       (DO-What-I-Want...

Recommend a walk through Info section Elisp, you will find plenty of useful stuff.

Cheers,

Andreas



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-03  9:10       ` Andreas Röhler
@ 2013-06-03 11:52         ` C K Kashyap
  0 siblings, 0 replies; 11+ messages in thread
From: C K Kashyap @ 2013-06-03 11:52 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: help-gnu-emacs

Thanks Andreas,

This is exactly what I was looking for -

(defun kash-util-quotes (beg end st en)
  (interactive "r*\nsStart Pattern: \nsEnd Pattern: \n")
  (save-excursion
    (save-restriction
      (string-rectangle beg end st)
;      (narrow-to-region beg end)
      (goto-char beg)
      (replace-regexp "$" en)
      )))


Thanks,
Kashyap


On Mon, Jun 3, 2013 at 2:40 PM, Andreas Röhler <
andreas.roehler@easy-emacs.de> wrote:

> Am 03.06.2013 10:03, schrieb C K Kashyap:
>
>  Thanks Andreas,
>> This works.
>> Although I'd still like to know how to write custom function that work
>> over
>> a marked region.
>>
>
> For example that way:
>
> (defun my-New-Command (beg end)
>   (interactive "r*")
>   (save-excursion
>     (save-restriction
>       (narrow-to-region beg end)
>       (goto-char beg)
>       (DO-What-I-Want...
>
> Recommend a walk through Info section Elisp, you will find plenty of
> useful stuff.
>
> Cheers,
>
> Andreas
>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
       [not found] <mailman.910.1370238187.22516.help-gnu-emacs@gnu.org>
@ 2013-06-03 15:50 ` Udyant Wig
  2013-06-04 14:52   ` Kevin Rodgers
  2013-06-03 17:39 ` Joost Kremers
  1 sibling, 1 reply; 11+ messages in thread
From: Udyant Wig @ 2013-06-03 15:50 UTC (permalink / raw)
  To: help-gnu-emacs

You might also try keyboard macros.

Here's how I'd do it:

0.  Move point to the first line (anywhere will do).

        print _!_line1
        print linetwo
        print line3

1.  Press C-x ( to begin recording a keyboard macro

2.  Press C-a to move to the beginning of the line

        _!_print line1
        print linetwo
        print line3

3.  Press M-f to move forward a word 

        print _!_line1
        print linetwo
        print line3
        
4.  Press " to insert one double-qoutes

        print "_!_line1
        print linetwo
        print line3

5.  There are two options here, any of which work fine:

    5.0.  Either, M-f again to move forward,
    5.1.  Or, C-e to move to the end of the line

        print "line1_!_
        print linetwo
        print line3

6.  Press " to insert the second double-quotes

        print "line1"_!_
        print linetwo
        print line3

7.  Press ; to insert the semi-colon

        print "line1";_!_
        print linetwo
        print line3

8.  Press C-n to move down a line

        print "line1";
        print linetwo_!_
        print line3

9.  Press C-x ) to finish recording the keyboard macro

10.  Press C-x e to repeat the keyboard macro

        print "line1";
        print "linetwo";
        print line3_!_

11.  You can now simply press `e' to repeat

        print "line1";
        print "linetwo";
        print "line3";

The above goes very quickly when actually typing.        
        
The Info node (emacs)Keyboard Macros is the authoritative reference.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
       [not found] <mailman.910.1370238187.22516.help-gnu-emacs@gnu.org>
  2013-06-03 15:50 ` putting double quotes efficiently Udyant Wig
@ 2013-06-03 17:39 ` Joost Kremers
  2013-06-04 12:21   ` C K Kashyap
  1 sibling, 1 reply; 11+ messages in thread
From: Joost Kremers @ 2013-06-03 17:39 UTC (permalink / raw)
  To: help-gnu-emacs

C K Kashyap wrote:
> Hi,
> I am looking for a way to transform
>
> print line1
> print line two
> print line3
>
> into
>
> print "line1";
> print "line two";
> print "line3";
>
> most efficiently.

Personally, I'd use Magnar Sveen's nifty multiple-cursors library for
this. Put the cursor on the l of `line1', activate the mark (C-SPC),
move down to the l of `line3', hit C-S-c C-S-c, then type `"', then C-e,
then `";' and done.



-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-03 17:39 ` Joost Kremers
@ 2013-06-04 12:21   ` C K Kashyap
  2013-06-04 12:21     ` C K Kashyap
  0 siblings, 1 reply; 11+ messages in thread
From: C K Kashyap @ 2013-06-04 12:21 UTC (permalink / raw)
  To: Joost Kremers; +Cc: help-gnu-emacs

Thanks Udyant,

Regards,
Kashyap


On Mon, Jun 3, 2013 at 11:09 PM, Joost Kremers <joostkremers@yahoo.com>wrote:

> C K Kashyap wrote:
> > Hi,
> > I am looking for a way to transform
> >
> > print line1
> > print line two
> > print line3
> >
> > into
> >
> > print "line1";
> > print "line two";
> > print "line3";
> >
> > most efficiently.
>
> Personally, I'd use Magnar Sveen's nifty multiple-cursors library for
> this. Put the cursor on the l of `line1', activate the mark (C-SPC),
> move down to the l of `line3', hit C-S-c C-S-c, then type `"', then C-e,
> then `";' and done.
>
>
>
> --
> Joost Kremers                                   joostkremers@fastmail.fm
> Selbst in die Unterwelt dringt durch Spalten Licht
> EN:SiS(9)
>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-04 12:21   ` C K Kashyap
@ 2013-06-04 12:21     ` C K Kashyap
  0 siblings, 0 replies; 11+ messages in thread
From: C K Kashyap @ 2013-06-04 12:21 UTC (permalink / raw)
  To: Joost Kremers; +Cc: help-gnu-emacs

And Joost :)


On Tue, Jun 4, 2013 at 5:51 PM, C K Kashyap <ckkashyap@gmail.com> wrote:

> Thanks Udyant,
>
> Regards,
> Kashyap
>
>
> On Mon, Jun 3, 2013 at 11:09 PM, Joost Kremers <joostkremers@yahoo.com>wrote:
>
>> C K Kashyap wrote:
>> > Hi,
>> > I am looking for a way to transform
>> >
>> > print line1
>> > print line two
>> > print line3
>> >
>> > into
>> >
>> > print "line1";
>> > print "line two";
>> > print "line3";
>> >
>> > most efficiently.
>>
>> Personally, I'd use Magnar Sveen's nifty multiple-cursors library for
>> this. Put the cursor on the l of `line1', activate the mark (C-SPC),
>> move down to the l of `line3', hit C-S-c C-S-c, then type `"', then C-e,
>> then `";' and done.
>>
>>
>>
>> --
>> Joost Kremers                                   joostkremers@fastmail.fm
>> Selbst in die Unterwelt dringt durch Spalten Licht
>> EN:SiS(9)
>>
>
>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: putting double quotes efficiently
  2013-06-03 15:50 ` putting double quotes efficiently Udyant Wig
@ 2013-06-04 14:52   ` Kevin Rodgers
  0 siblings, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2013-06-04 14:52 UTC (permalink / raw)
  To: help-gnu-emacs

On 6/3/13 9:50 AM, Udyant Wig wrote:
> You might also try keyboard macros.
>
> Here's how I'd do it:
>
> 0.  Move point to the first line (anywhere will do).
>
>          print _!_line1
>          print linetwo
>          print line3
>
> 1.  Press C-x ( to begin recording a keyboard macro
>
> 2.  Press C-a to move to the beginning of the line
>
>          _!_print line1
>          print linetwo
>          print line3
>
...
> 9.  Press C-x ) to finish recording the keyboard macro
>
> 10.  Press C-x e to repeat the keyboard macro
>
>          print "line1";
>          print "linetwo";
>          print line3_!_
>
> 11.  You can now simply press `e' to repeat
>
>          print "line1";
>          print "linetwo";
>          print "line3";

Or: Mark the remaining lines you want to change and `C-x C-k r' 
(apply-macro-to-region-lines).

If you plan on doing that, you can move point to the beginning of the line
before starting the keyboard macro definition and leave C-a out of the macro
(because `C-x C-k r' will move to the beginning of each line automatically).

-- 
Kevin Rodgers
Denver, Colorado, USA




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-06-04 14:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.910.1370238187.22516.help-gnu-emacs@gnu.org>
2013-06-03 15:50 ` putting double quotes efficiently Udyant Wig
2013-06-04 14:52   ` Kevin Rodgers
2013-06-03 17:39 ` Joost Kremers
2013-06-04 12:21   ` C K Kashyap
2013-06-04 12:21     ` C K Kashyap
2013-06-03  5:43 C K Kashyap
2013-06-03  7:26 ` Andreas Röhler
2013-06-03  7:55   ` Andreas Röhler
2013-06-03  8:03     ` C K Kashyap
2013-06-03  9:10       ` Andreas Röhler
2013-06-03 11:52         ` C K Kashyap

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.