2

How can I insert text so that the cursor stays in the same position while text I type is shifted to the left, overwriting existing text? For example:

   row_title: some words
   old_title: letters here
            ^

   row_title: some words
 newer_title: letters here
            ^

Where the ^ represents the position of the cursor.

1

There is no predefined way to do this.

You'll probably want to start by defining your own replacement for overwrite-mode, mirroring what is done for overwrite-mode but:

  • Switching (for example), the keys for commands delete-backward-char and delete-forward-char.

  • Binding your own replacement command for quoted-insert (C-q), using backward-delete-char in place of delete-char in the definition.

However, because there are multiple predefined Lisp functions that use overwrite-mode (e.g., check the value and do something accordingly), you might just want to advise overwrite-mode, instead of defining a replacement command.

Finally, I would ask why you want to do this? What is your actual use case?


Update after your use-case comment:

In that case:

  • Try M-x picture-mode -- see the Emacs manual, node Picture-Mode and its 4 subnodes.

  • Maybe try the table package -- see the Emacs manual, node Text Based Tables and its 8 subnodes.

  • My use case is editing ascii tables while keeping things in line. – Ell Oct 19 '15 at 20:05
  • @Ell Even align-regexp might help you out in that case. Do you want to update the question with a sample of ascii table text you need to edit? – Kaushal Modi Oct 19 '15 at 20:17

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.