New answers tagged

2

Use a regular expression replacement with a bit of Lisp code. In the replacement text, you can use \,(…) to execute some Lisp code, and you can use \# as the number of replacements made so far. So \,(+ 2 \#) will be become successively 2, 3, 4, … in successive replacements. Thus, use C-M-% or M-x replace-regexp to replace \("id": \)[0-9]+ with \1\,(+ 2 \#)


0

That should do it: (defun cummulative-raise-regexp (&optional regexp) (interactive) (let* ((regexp (or regexp "\"id\": \\([0-9]+\\),")) (counter 1)) (while (re-search-forward regexp nil t) (replace-match (concat "\"id\": "(number-to-string (+ counter (string-to-number (match-string-no-properties 1))))",")) (setq counter (1+ ...


0

Not everything needs to be done in pure elisp or using just Emacs facilities. In this case, I would use shell-command-on-region (usually bound to M-|): first mark the region of interest and then type M-| and pass the following shell command to it (followed by RET): awk -F ":" '/finished/ {n = $2+1; printf "%s: %s,\n", $1, n; next;} {print $0;}' In words: ...


5

Use the following key sequence: M-C-% \("finished":[[:space:]]*\)\([0-9]+\) RET \1\,(1+ (string-to-number \2))RET M-C-% is bound to query-replace-regexp. \("finished":[[:space:]]*\)\([0-9]+\) is the regexp to search for, the first group is just for copying into the replacement string, the second group is the number to be transformed. \1\,(1+ (string-to-...


2

I'm going to use the function found here. (defun increment-number-at-point () (interactive) (skip-chars-backward "0-9") (or (looking-at "[0-9]+") (error "No number at point")) (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) For a quick solution, I would use a macro. This is appropriate if you only need to do it a ...


Top 50 recent answers are included