unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* repeating input with different outputs
@ 2011-10-14 11:20 ishi soichi
  2011-10-14 11:29 ` Jambunathan K
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: ishi soichi @ 2011-10-14 11:20 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]

I have a question about typing (or programming, or maybe a macro).

Say, I'm writing a text (which can be in any mode, html-mode, cpp-mode, or
whatever)

I would like to input like

chapter 4.1
chapter 4.2
chapter 4.3
...

chapter 4.46

So, it is very tedious. I would rather set up a program or a command that
can do this job instantaneously.

Could Emacs do this?

soichi

[-- Attachment #2: Type: text/html, Size: 582 bytes --]

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

* Re: repeating input with different outputs
  2011-10-14 11:20 repeating input with different outputs ishi soichi
@ 2011-10-14 11:29 ` Jambunathan K
  2011-10-14 12:13 ` Rustom Mody
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jambunathan K @ 2011-10-14 11:29 UTC (permalink / raw)
  To: ishi soichi; +Cc: help-gnu-emacs


Turn on orgstruct++-mode and pretend that you are creating a numbered
list. Once the basic editing is done you can add 'chapter 4.'  prefix as
a convenient afterthought.

> I have a question about typing (or programming, or maybe a macro).
>
> Say, I'm writing a text (which can be in any mode, html-mode,
> cpp-mode, or whatever)
>
> I would like to input like 
>
> chapter 4.1
> chapter 4.2
> chapter 4.3
> ...
>
> chapter 4.46
>
> So, it is very tedious. I would rather set up a program or a command
> that can do this job instantaneously.
>
> Could Emacs do this?
>
> soichi
>
>

-- 



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

* Re: repeating input with different outputs
  2011-10-14 11:20 repeating input with different outputs ishi soichi
  2011-10-14 11:29 ` Jambunathan K
@ 2011-10-14 12:13 ` Rustom Mody
  2011-10-14 17:43 ` Ken Goldman
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Rustom Mody @ 2011-10-14 12:13 UTC (permalink / raw)
  To: ishi soichi; +Cc: help-gnu-emacs

On Fri, Oct 14, 2011 at 4:50 PM, ishi soichi <soichi777@gmail.com> wrote:
> I have a question about typing (or programming, or maybe a macro).
> Say, I'm writing a text (which can be in any mode, html-mode, cpp-mode, or
> whatever)
> I would like to input like
> chapter 4.1
> chapter 4.2
> chapter 4.3
> ...
> chapter 4.46
> So, it is very tedious. I would rather set up a program or a command that
> can do this job instantaneously.
> Could Emacs do this?
> soichi

You may want to check out column editing mode (part of cua)
http://www.youtube.com/watch?v=k-6BVjlBSVo



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

* Re: repeating input with different outputs
  2011-10-14 11:20 repeating input with different outputs ishi soichi
  2011-10-14 11:29 ` Jambunathan K
  2011-10-14 12:13 ` Rustom Mody
@ 2011-10-14 17:43 ` Ken Goldman
  2011-10-15  3:07   ` ishi soichi
  2011-10-15  3:14 ` Tim Landscheidt
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Ken Goldman @ 2011-10-14 17:43 UTC (permalink / raw)
  To: help-gnu-emacs

On 10/14/2011 07:20 AM, ishi soichi wrote:
> I have a question about typing (or programming, or maybe a macro).
>
> Say, I'm writing a text (which can be in any mode, html-mode, cpp-mode,
> or whatever)
>
> I would like to input like
>
> chapter 4.1
> chapter 4.2
> chapter 4.3
> ...
>
> chapter 4.46
>
> So, it is very tedious. I would rather set up a program or a command
> that can do this job instantaneously.
>
> Could Emacs do this?

Of course.

I copied this off the group years ago.  Incorporate it in a keyboard 
macro and you're done.

(defun increment (n) (interactive "p")
  ;; Increment the number after point.  With an argument, add that much.
  (let (val)
    (delete-region
     (point)
     (progn
       (setq val (read (current-buffer)))
       (if (not (numberp val)) (error "Not in front of a number"))
       (point)))
    (insert (int-to-string (+ val n)))))
(global-set-key "\C-c+" 'increment)





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

* Re: repeating input with different outputs
  2011-10-14 17:43 ` Ken Goldman
@ 2011-10-15  3:07   ` ishi soichi
  0 siblings, 0 replies; 10+ messages in thread
From: ishi soichi @ 2011-10-15  3:07 UTC (permalink / raw)
  To: Ken Goldman; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]

Thanks all of you.
Emacs is great! There are still many capabilities that I don't know.

soichi

2011/10/15 Ken Goldman <kgold@watson.ibm.com>

> On 10/14/2011 07:20 AM, ishi soichi wrote:
>
>> I have a question about typing (or programming, or maybe a macro).
>>
>> Say, I'm writing a text (which can be in any mode, html-mode, cpp-mode,
>> or whatever)
>>
>> I would like to input like
>>
>> chapter 4.1
>> chapter 4.2
>> chapter 4.3
>> ...
>>
>> chapter 4.46
>>
>> So, it is very tedious. I would rather set up a program or a command
>> that can do this job instantaneously.
>>
>> Could Emacs do this?
>>
>
> Of course.
>
> I copied this off the group years ago.  Incorporate it in a keyboard macro
> and you're done.
>
> (defun increment (n) (interactive "p")
>  ;; Increment the number after point.  With an argument, add that much.
>  (let (val)
>   (delete-region
>    (point)
>    (progn
>      (setq val (read (current-buffer)))
>      (if (not (numberp val)) (error "Not in front of a number"))
>      (point)))
>   (insert (int-to-string (+ val n)))))
> (global-set-key "\C-c+" 'increment)
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 1692 bytes --]

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

* Re: repeating input with different outputs
  2011-10-14 11:20 repeating input with different outputs ishi soichi
                   ` (2 preceding siblings ...)
  2011-10-14 17:43 ` Ken Goldman
@ 2011-10-15  3:14 ` Tim Landscheidt
  2011-10-15  4:46 ` Eric Abrahamsen
  2011-10-15  7:50 ` Andreas Röhler
  5 siblings, 0 replies; 10+ messages in thread
From: Tim Landscheidt @ 2011-10-15  3:14 UTC (permalink / raw)
  To: help-gnu-emacs

ishi soichi <soichi777@gmail.com> wrote:

> I have a question about typing (or programming, or maybe a macro).

> Say, I'm writing a text (which can be in any mode, html-mode, cpp-mode, or
> whatever)

> I would like to input like

> chapter 4.1
> chapter 4.2
> chapter 4.3
> ...

> chapter 4.46

> So, it is very tedious. I would rather set up a program or a command that
> can do this job instantaneously.

> Could Emacs do this?

Of course :-). For example, try M-: (dotimes (i 46) (insert
(format "chapter 4.%d\n" (+ i 1)))) RET.

Tim




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

* Re: repeating input with different outputs
  2011-10-14 11:20 repeating input with different outputs ishi soichi
                   ` (3 preceding siblings ...)
  2011-10-15  3:14 ` Tim Landscheidt
@ 2011-10-15  4:46 ` Eric Abrahamsen
  2011-10-15  8:17   ` XeCycle
  2011-10-15  7:50 ` Andreas Röhler
  5 siblings, 1 reply; 10+ messages in thread
From: Eric Abrahamsen @ 2011-10-15  4:46 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Oct 14 2011, ishi soichi wrote:

> I have a question about typing (or programming, or maybe a macro).
>
> Say, I'm writing a text (which can be in any mode, html-mode,
> cpp-mode, or whatever)
>
> I would like to input like 
>
> chapter 4.1
> chapter 4.2
> chapter 4.3
> ...
>
> chapter 4.46
>
> So, it is very tedious. I would rather set up a program or a command
> that can do this job instantaneously.
>
> Could Emacs do this?

Not that you really need another solution, but keyboard macros come with
a counter that can be (de|in)cremented. To learn keyboard macros, I once
made one that sang the "100 Bottles of Beer on the Wall" song all the
way down to zero. Well, didn't actually "sing" it (I didn't have that
package installed).

So:

C-x C-k C-c (kmacro-set-counter) '1'
<f3> (start the macro)
'chapter 4.' then hit <f3> again (this time it runs kmacro-insert-counter)
newline, then <f4> to finish recording, and you're done.

The counter automatically increments by one for each pass. If you want a
different value you can use C-x C-k C-a in the macro to add a (possibly
negative) value to the default value of 1.

Just one more option…

Eric

-- 
GNU Emacs 24.0.90.1 (i686-pc-linux-gnu, GTK+ Version 2.24.4)
 of 2011-10-06 on pellet




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

* Re: repeating input with different outputs
  2011-10-14 11:20 repeating input with different outputs ishi soichi
                   ` (4 preceding siblings ...)
  2011-10-15  4:46 ` Eric Abrahamsen
@ 2011-10-15  7:50 ` Andreas Röhler
  5 siblings, 0 replies; 10+ messages in thread
From: Andreas Röhler @ 2011-10-15  7:50 UTC (permalink / raw)
  To: help-gnu-emacs

Am 14.10.2011 13:20, schrieb ishi soichi:
> I have a question about typing (or programming, or maybe a macro).
>
> Say, I'm writing a text (which can be in any mode, html-mode, cpp-mode, or
> whatever)
>
> I would like to input like
>
> chapter 4.1
> chapter 4.2
> chapter 4.3
> ...
>
> chapter 4.46
>
> So, it is very tedious. I would rather set up a program or a command that
> can do this job instantaneously.
>
> Could Emacs do this?
>
> soichi
>

you may use query-replace-regexp


chapter 4.\([0-9]+\)
RET
chapter 4.\,(1+ (string-to-number \1))
RET

cheers,

Andreas

--
https://launchpad.net/python-mode
https://launchpad.net/s-x-emacs-werkstatt/



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

* Re: repeating input with different outputs
  2011-10-15  4:46 ` Eric Abrahamsen
@ 2011-10-15  8:17   ` XeCycle
  2011-10-16  3:27     ` Tim Landscheidt
  0 siblings, 1 reply; 10+ messages in thread
From: XeCycle @ 2011-10-15  8:17 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

[...]

> Not that you really need another solution, but keyboard macros come with
> a counter that can be (de|in)cremented. To learn keyboard macros, I once
> made one that sang the "100 Bottles of Beer on the Wall" song all the
> way down to zero. Well, didn't actually "sing" it (I didn't have that
> package installed).
>
> So:
>
> C-x C-k C-c (kmacro-set-counter) '1'
> <f3> (start the macro)
> 'chapter 4.' then hit <f3> again (this time it runs kmacro-insert-counter)
> newline, then <f4> to finish recording, and you're done.
>
> The counter automatically increments by one for each pass. If you want a
> different value you can use C-x C-k C-a in the macro to add a (possibly
> negative) value to the default value of 1.
>
> Just one more option…

I believe this would be the preferred way, as said in the manual.

BTW I want to ask this:  I have a sorted list (logically), but with
wrong numbers in them.  What if I want to correct these numbers to be
consistent with the logical order?  Is deleting all the numbers at first
the best solution?

-- 
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

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

* Re: repeating input with different outputs
  2011-10-15  8:17   ` XeCycle
@ 2011-10-16  3:27     ` Tim Landscheidt
  0 siblings, 0 replies; 10+ messages in thread
From: Tim Landscheidt @ 2011-10-16  3:27 UTC (permalink / raw)
  To: help-gnu-emacs

XeCycle <xecycle@gmail.com> wrote:

> [...]
> BTW I want to ask this:  I have a sorted list (logically), but with
> wrong numbers in them.  What if I want to correct these numbers to be
> consistent with the logical order?  Is deleting all the numbers at first
> the best solution?

You can just replace them with one query-replace-regexp run
and use \# as a counter, as Andreas showed in a parallel
posting.

Tim




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

end of thread, other threads:[~2011-10-16  3:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-14 11:20 repeating input with different outputs ishi soichi
2011-10-14 11:29 ` Jambunathan K
2011-10-14 12:13 ` Rustom Mody
2011-10-14 17:43 ` Ken Goldman
2011-10-15  3:07   ` ishi soichi
2011-10-15  3:14 ` Tim Landscheidt
2011-10-15  4:46 ` Eric Abrahamsen
2011-10-15  8:17   ` XeCycle
2011-10-16  3:27     ` Tim Landscheidt
2011-10-15  7:50 ` Andreas Röhler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).