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)

(modify "a.txt")

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

a.txt content is:


Output changed to:


Current script output is ab9cdefg.

  • 2
    Have you tried using (delete-char 1) before inserting? – DoMiNeLa10 May 19 '19 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 '19 at 20:00

Your Answer

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

Browse other questions tagged or ask your own question.