0

Below script will insert a char at position:

#!/usr/bin/env emacs --script

(defun modify(filename)
  (find-file-literally filename)
  (goto-char 3)
  (insert "\x39")
  (save-buffer 0)
  (kill-buffer))

(modify "a.txt")

How can I modify it to replace a char at positon? for example:

a.txt content is:

abcdefg

Output changed to:

ab9defg

Current script output is ab9cdefg.

2
  • 2
    Have you tried using (delete-char 1) before inserting?
    – user12563
    May 19, 2019 at 18:52
  • insert accepts chars as well as strings. You might find it clearer to write (insert ?9) or (insert "9") than to write (insert "\x39").
    – Drew
    May 19, 2019 at 20:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.