1

I'm using mc/insert-numbers quite often for numbering classes on html. I know that I can use C-u 6 M-x mc/insert-numbers to start counting from 6, but how could I use it to create a list like:

06
08
10
12
14
16
18

is it possible?

2

The mc/insert-numbers has the increment and number format hard-coded, but you can use this mc/insert-fancy-numbers command instead. It'll prompt for start, step and format specifier; for your example you'd answer 6, 2 and %02d, respectively:

(defvar mc--insert-fancy-numbers-increment 1)
(defvar mc--insert-fancy-numbers-format "%d")

(defun mc/insert-fancy-numbers (start step format)
  "Insert increasing numbers for each cursor, starting from START,
counting by STEP and formatting them with the FORMAT specifier."
  (interactive "nStarting number: \nnIncrement: \nsFormat specifier (RET for '%%d'): ")
  (setq mc--insert-numbers-number start)
  (setq mc--insert-fancy-numbers-increment step)
  (setq mc--insert-fancy-numbers-format
        (if (string= format "") "%d" format))
  (mc/for-each-cursor-ordered
   (mc/execute-command-for-fake-cursor 'mc--insert-fancy-number-and-increase cursor)))

(defun mc--insert-fancy-number-and-increase ()
  (interactive)
  (insert (format mc--insert-fancy-numbers-format mc--insert-numbers-number))
  (setq mc--insert-numbers-number
        (+ mc--insert-numbers-number mc--insert-fancy-numbers-increment)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.