* How to increase a number under cursor?
@ 2003-05-20 8:37 Wang Yin
2003-05-20 12:58 ` Brendan Halpin
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Wang Yin @ 2003-05-20 8:37 UTC (permalink / raw)
Hi,
I want to record a macro to type flexible numbered lists.
for example:
continuous:
1.
2.
3.
4.
...
odd:
1.
3.
5.
7.
...
hex:
0x9
0xA
0xB
octal:
007
010
011
The only problem I meet is how to increase the number under
the cursor?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to increase a number under cursor?
2003-05-20 8:37 How to increase a number under cursor? Wang Yin
@ 2003-05-20 12:58 ` Brendan Halpin
2003-05-21 8:10 ` Wang Yin
2003-05-20 13:34 ` Oliver Scholz
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Brendan Halpin @ 2003-05-20 12:58 UTC (permalink / raw)
Wang Yin <wang-y01@mails.tsinghua.edu.cn> writes:
> The only problem I meet is how to increase the number under
> the cursor?
How about this?
(defun wy-incr-num-at-cursor ()
(interactive)
(let ((number (number-at-point)))
(and number
(let ((bounds (bounds-of-thing-at-point 'sexp)))
(delete-region (car bounds) (cdr bounds))
(insert (format "%d" (1+ number)))))))
(local-set-key "\x03a" 'wy-incr-num-at-cursor)
For hex and octal, you'll need to look into where number-at-point
is defined, i.e. thingatpt.el, which comes with Emacs.
Brendan
PS This answers some of what you asked for, but there are probably
cleverer ways of achieving what you actually want to do.
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-390476; Room F2-025 x 3147
mailto:brendan.halpin@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to increase a number under cursor?
2003-05-20 8:37 How to increase a number under cursor? Wang Yin
2003-05-20 12:58 ` Brendan Halpin
@ 2003-05-20 13:34 ` Oliver Scholz
2003-05-20 14:17 ` David Kastrup
2003-05-21 12:27 ` Eric Ludlam
2003-05-21 16:13 ` Sandip Chitale
3 siblings, 1 reply; 7+ messages in thread
From: Oliver Scholz @ 2003-05-20 13:34 UTC (permalink / raw)
Wang Yin <wang-y01@mails.tsinghua.edu.cn> writes:
> Hi,
>
> I want to record a macro to type flexible numbered lists.
> for example:
Are you talking about a keyboard macro?
[...]
> The only problem I meet is how to increase the number under
> the cursor?
It is not clear to me what you want here. Do you simply want a
function that deletes the number at point and inserts number + X into
the buffer again? What do you want to achieve?
If you simply want a skeleton for lists, you could use something like
this:
(defun wy-list-skel ()
(interactive)
(let ((num 0))
(skeleton-insert
'(nil
("Type something: "
(number-to-string (setq num (1+ num)))
". " str "\n")))))
Hexadezimal:
(defun wy-hex-list-skel ()
(interactive)
(let ((num 0))
(skeleton-insert
'(nil
("Type something: "
(format "0x%02x" (setq num (1+ num)))
". " str "\n")))))
Oliver
--
1 Prairial an 211 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to increase a number under cursor?
2003-05-20 13:34 ` Oliver Scholz
@ 2003-05-20 14:17 ` David Kastrup
0 siblings, 0 replies; 7+ messages in thread
From: David Kastrup @ 2003-05-20 14:17 UTC (permalink / raw)
Oliver Scholz <alkibiades@gmx.de> writes:
> Wang Yin <wang-y01@mails.tsinghua.edu.cn> writes:
>
> > I want to record a macro to type flexible numbered lists.
> > for example:
>
> Are you talking about a keyboard macro?
>
> [...]
> > The only problem I meet is how to increase the number under
> > the cursor?
>
> It is not clear to me what you want here. Do you simply want a
> function that deletes the number at point and inserts number + X
> into the buffer again? What do you want to achieve?
Well, with a development Emacs we have the silly answer: type
M-# e 1 + q
Which will incidentally also increment -3/8 to 5:8, and simplify
polynomial expressions and stuff.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to increase a number under cursor?
2003-05-20 12:58 ` Brendan Halpin
@ 2003-05-21 8:10 ` Wang Yin
0 siblings, 0 replies; 7+ messages in thread
From: Wang Yin @ 2003-05-21 8:10 UTC (permalink / raw)
Yes! This is what I wanted!
Thank you.
But thingatpt.el seems can't solve the problem of increase a
hexadecimal number and octal number.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to increase a number under cursor?
2003-05-20 8:37 How to increase a number under cursor? Wang Yin
2003-05-20 12:58 ` Brendan Halpin
2003-05-20 13:34 ` Oliver Scholz
@ 2003-05-21 12:27 ` Eric Ludlam
2003-05-21 16:13 ` Sandip Chitale
3 siblings, 0 replies; 7+ messages in thread
From: Eric Ludlam @ 2003-05-21 12:27 UTC (permalink / raw)
>>> Wang Yin <wang-y01@mails.tsinghua.edu.cn> seems to think that:
>Hi,
>
>I want to record a macro to type flexible numbered lists.
This is one of my favorite commands I pulled off of one of these
newsgroups many years ago, and have been tweaking ever since. I bound
it to M-o, and use it quite often.
;;; Original author: ttn@netcom.com, 28-Jan-1996
;;; Modified for multiple lines: Eric
(defun another-line (num-lines)
"Copies line, preserving cursor column, and increments any numbers found.
Copies a block of optional NUM-LINES lines. If no optional argument is given,
then only one line is copied."
(interactive "p")
(if (not num-lines) (setq num-lines 0) (setq num-lines (1- num-lines)))
(let* ((col (current-column))
(bol (save-excursion (forward-line (- num-lines)) (beginning-of-line) (point)))
(eol (progn (end-of-line) (point)))
(line (buffer-substring bol eol)))
(goto-char bol)
(while (re-search-forward "[0-9]+" eol 1)
(let ((num (string-to-int (buffer-substring
(match-beginning 0) (match-end 0)))))
(replace-match (int-to-string (1+ num))))
(setq eol (save-excursion (goto-char eol) (end-of-line) (point))))
(goto-char bol)
(insert line "\n")
(move-to-column col)))
--
Eric Ludlam "Photonic Doodler" The MathWorks x 7556
eludlam@mathworks.com (work) http://www.mathworks.com
eric@siege-engine.com (home) http://www.siege-engine.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to increase a number under cursor?
2003-05-20 8:37 How to increase a number under cursor? Wang Yin
` (2 preceding siblings ...)
2003-05-21 12:27 ` Eric Ludlam
@ 2003-05-21 16:13 ` Sandip Chitale
3 siblings, 0 replies; 7+ messages in thread
From: Sandip Chitale @ 2003-05-21 16:13 UTC (permalink / raw)
Well, I am not sure if this is what you want but here is a defun
that inserts a template into a file:
(defun insert-template (template &optional count)
(interactive "sTemplate: \np")
(let ((i 1))
(while (<= i count)
(insert (format template i))
(setq i (+ i 1)))))
Type:
C-u 5 M-x insert-template Ret
Prompt in minibuffer:
---------------------------------
Template:
---------------------------------
Type:
% d . C-q C-j Ret
The following is inserted in the buffer:
1.
2.
3.
4.
5.
Wang Yin <wang-y01@mails.tsinghua.edu.cn> wrote in message news:<phwugm3tfv.fsf@wangyin.com>...
> Hi,
>
> I want to record a macro to type flexible numbered lists.
> for example:
>
> continuous:
> 1.
> 2.
> 3.
> 4.
> ...
>
> odd:
> 1.
> 3.
> 5.
> 7.
> ...
>
>
> hex:
>
> 0x9
> 0xA
> 0xB
>
> octal:
> 007
> 010
> 011
>
> The only problem I meet is how to increase the number under
> the cursor?
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-05-21 16:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-20 8:37 How to increase a number under cursor? Wang Yin
2003-05-20 12:58 ` Brendan Halpin
2003-05-21 8:10 ` Wang Yin
2003-05-20 13:34 ` Oliver Scholz
2003-05-20 14:17 ` David Kastrup
2003-05-21 12:27 ` Eric Ludlam
2003-05-21 16:13 ` Sandip Chitale
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).