help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: [External] : Re: Emacs: adding 1 to every number made of 2 digits in


From: Emanuel Berg
Subject: Re: [External] : Re: Emacs: adding 1 to every number made of 2 digits inside a marked region.
Date: Fri, 24 Sep 2021 01:50:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Drew Adams wrote:

>>> This is a typical job for a macro.
>>> C-x (
>>> C-e
>>> M-b
>>> M-: (insert (format "%d" (1+ (number-at-point))))
>>> C-k
>>> C-a
>>> C-n
>>> C-x )
>>>
>>> Then type C-x e e e ...
>> 
>> Seems complicated :-)
>
> It's not.  Just record the keystrokes you use to
> make one change, then replay the recording.

Poor man's programming, don't encourage him to start with
that :)

This is a very simple task to solve with Elisp and the problem
with the point position is easily solved by either putting the
point at the correct position before invocation (this method
allows for bigger flexibility) _or_ but using
`save-mark-and-excursion' and `goto-char' to put point at
`point-min'.

This is also a good candidate for a DWIM interface:

(defun test-dwim (&optional beg end)
  (interactive (when (use-region-p)
                 (list (region-beginning) (region-end)) ))
  (let ((bg (or beg (point-min))) ; or just (point) here
        (ed (or end (point-max))) )
    (list bg ed) ; code here
    ))

If you get the point ...

https://dataswamp.org/~incal/emacs-init/dwim.el

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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