Макрос Emacs для генерации последовательности?

Или используйте инструмент, который анализирует Ваши файлы журнала и дает Вам отчет 'о неработающих ссылках' (например, Аналог или Инструменты Веб-мастера Google ) или выполняет инструмент, что пауки Ваш веб-сайт и сообщают о неработающих ссылках (например, Проверка ссылок W3C ).

42
задан 2 October 2009 в 15:08
поделиться

6 ответов

If you are using Emacs 23 (and maybe 22?), use kmacro-insert-counter which is bound to C-x C-k TAB by default. So for your example, you'd do:

C-x ( C-x C-k TAB . RET C-x )

So start macro, insert counter followed by '.', newline, end macro. Then C-x e e e e e e e etc. Or M-1 0 0 C-x e to get 100 of them.

EDIT:

Forgot to mention you can set the counter to an initial value also. For example to start at 1 instead of 0 do M-1 C-x C-k C-c.

And if you don't want the counter to increment at a particular point, prefix it with C-u. Of course the keystrokes are getting a bit ridiculous at this point, so I usually bind a key to insert-but-don't-increment.

63
ответ дан 26 November 2019 в 23:16
поделиться

Those who feel there are too many tricks to memorize might find acquiring some elisp more profitable:

M-: (dotimes (i 20) (insert (format "%2d.\n" (1+ i))))
54
ответ дан 26 November 2019 в 23:16
поделиться

Emacs 23 supports elisp snippets in the replacement text of replace-regexp.

I frequently define keyboard macros that follow this pattern:

  • Copy a block of text
  • Navigate to a number that I want to increment in the copied block of text with isearch
  • Activate the mark and move the point to define a region encompassing the number
  • M-x replace-regexp
  • At the "Replace regexp" prompt, enter \([0-9]+\) to capture a group of one or more digits
  • At the "Replace regexp ([0-9]+) with:" prompt, enter \,(1+ \#1), where , indicates that an elisp form to substitute follows, 1+ is an increment function, and \#1 is the first captured match text, interpreted as a number.

After taking a minute to define the keyboard macro, this allows me to have almost the convenience of cutting and pasting to generate lots of blocks of almost-identical code, such as for case statements.

Note that this technique can be easily adapted to e.g. double numbers (\,(* 2 \#1)) or whatever. You can even use it to substitute the next element in an arbitrary sequence by using a combination of 'position and 'nth, but I won't go into that now :).

18
ответ дан 26 November 2019 в 23:16
поделиться

Помимо ответа Скоттфрейзера , есть еще один способ создать последовательность чисел в режиме CUA , который может очень помочь вам при редактировании существующего контента. См. скринкаст Марка Мансура о редактировании столбцов Emacs с позиции 2:30.

7
ответ дан 26 November 2019 в 23:16
поделиться

Here is an extension that may help.

1
ответ дан 26 November 2019 в 23:16
поделиться

There's also:

C-u M-! jot -s '.C-q C-j' 10

It's not pure elisp, but has the same effect. You could write a named macro to run it for you.

1
ответ дан 26 November 2019 в 23:16
поделиться
Другие вопросы по тегам:

Похожие вопросы: