3

Copy/Paste seems broken for hexl-mode, eg. M-w copies the hex tables to the clipboard, rather useless. Since hexl-mode has overwrite-mode by default, how can the following be implemented?

  • M-w should copy marked binary data to the clipboard
  • C-y should insert contents of clipboard by overwriting, starting at cursor position
  • C-w should overwrite the marked area with hexl-mode-clear-value
  • DEL should set current byte to hexl-mode-clear-value and go to previous byte

hexl-mode-clear-value should be a customisable variable defaulting to \x00.

If Emacs is not in overwrite mode, copy/paste should work like plain text files, though this seems like low priority / undesirable since skewing binary data equals data corruption in most cases.

forthrin
  • 451
  • 2
  • 10

1 Answers1

2

I implemented such a variant of overwrite-mode as part of nhexl-mode-0.4 (available from GNU ELPA), which I called nhexl-overwrite-only-mode. It also works in "normal" editing modes (i.e. outside of nhexl-mode) but it won't work for hexl-mode, I'm afraid.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • Literally immediately installed `nhexl-mode` solely for the overwriting yank! Great work, and huge thank you. Wild to me that this isn't anything available in Emacs out-of-the-box to do this (especially since `overwrite-mode` exists, it's such a small step from that to realizing that it would be useful to have the ability to apply the same behavior change to inserts done from Lisp). You may want to consider turning `nhexl-overwrite--yank-wrapper` in a public API: [here's one example use-case](https://github.com/mentalisttraceur/home/commit/820a340795c81ba6b7ec87b06dc804da981f94e6)). – mtraceur May 18 '23 at 07:39
  • For what it's worth, I'm implementing my own alternative which handles block yanking and vi-style line pasting (in a way that builds on Evil and reuses some of the code I already inject into Evil to fix up the paste behavior into something I consider more sensible), so I'll be totally fine if you don't promote your yank wrapper to a public API, but I do think this is a good example of how this kind of thing might be really useful to other people as a building block. – mtraceur May 18 '23 at 07:44
  • I should move that overwrite-only thingy out of nhexl-mode, indeed. [ BTW, Emacs really needs someone (or a group of people) to sit down and figure out how to better integrate Evil and "normal" Emacs, because the two communities are forking. ] – Stefan May 19 '23 at 12:30