0

I can't figure out how to paste a string, for example 145 characters long, into a text line in a way, that the next 145 characters after the string are overwritten by this string or simply erased.

An example with a 34 character string would be

| |

which is supposed to become this by pasting in the 34 character string "This is an example for the problem"

| This is an example for the problem |

Why should one want to do that?

While working with huge org mode tables any refreshing or re-aligning can become a pain in the ass, involving 20 minutes of frozen emacs session. So, avoiding the need for re-freshing or re-aligning becomes very interesting, by editing a table in a way that doesn't break aligning or trigger refresh in any way.

What I've tried (and didn't work)

  • A manual way to do so is going into a field containing let's say 180 space characters between both vertical column separator lines |, place cursor behind the 1st space character, paste the 145 character string, delete the 145 space characters after the pasted string. Then everything is still aligned in relation to neighbor lines and how the edited line was before, and no re-fresh is triggered.

    But the problem with that approach is, that it can't be automated effectively by keyboard makros - that's my only tool so far, because I can't program:

    For that you need to be able to count how many characters the string is built of by M-= - as a consequence the number of characters is explicitely mentioned in *Messages* buffer - then go to *Messages* buffer, navigate in a general way to that number, copy it, go back to your table at the spot right after the pasted string, and doing C-d with prefix argument of that copied number.

    But that doesn't work out: You can do all that, but at the very end it fails by not handling the pasted number from *Messages* buffer as numeric input for the prefix argument. So instead of doing C-u 145 C-d, pasting by C-y after having typed in C-u right before simply ends the C-u C-d operation and instead simply pastes that number 145 into the buffer right after the pasted 145 character string.

    The way all this came up is, that I've noticed that while filling the tables with huge amounts of data mistakes sneaked in for no reason.

    That made me start verifying every line filling to make sure that it's filled correctly. That procedure was always the same, so after a while I made it so often, that it was so clear for me how to do it and so dull as a task, that I've created a keyboard macro for it. Whenever verification failed, it was always the same way so far, and that happened so often, that now I want to create a keyboard marco also for the fixing of lines where verification failed.

  • That overwriting by pasting I've done so far was like a manual re-construction of writing in overwrite mode, so why not going into overwrite mode instead, doing the pasting, and then going out of it again within the keyboard macro?

    That 2nd possibility, though, doesn't work, either. It works just for typing in 1 character after another, not pasting a 145 character string. One could mark or select a region before and then paste the 145 character string, but that just leads you back to the core problem: You have the number of characters counted in the cache - this failed verification fix it's 145, but the next one maybe 89, or 458, it's always different from routine run to routine run - and you need to work with that number, apply it so that the selected region is just as long as 145 characters like the pasted string, and if you could do that, if you achieved this, then you could stick to the 1st possibility in the first place and wouldn't need to try the 2nd possibility, because the problem is already solved.

I've tried a lot, checked the manual, but couldn't solve that by myself.

There gotta has to be a straight way to do it. When using isearch pasting with C-y a number like 145 is taken just as if one typed 1-4-5 straight away into the mini-buffer. But prefix arguments are not really mini-buffer and don't work like that. So that way I've tried didn't work, so far.

  • If I do understand correctly, it all falls down to making columns of a fixed width, and perhaps using org-paste-special. I'm trying to reformat your question because as it is, is very hard to follow. – Muihlinn Jul 20 at 11:56
  • "...involving 20 minutes of frozen emacs session" - that's a dead give-away that you need a different approach to your problem. How big are these tables (how many rows, how many columns, what is the (mean, max) length of each entry)? There are limitations that are imposed by Org mode (big tables become slow), there might be limitations imposed by emacs (long lines might cause problems): you have to take these into account for any solution. Have you considered using a database for storing these tables? – NickD Jul 20 at 13:44
  • @Muihlinn: Thank you for the help. Sorry for the inconvenience. I'm still learning. Yes, it's about keeping fixed width without re-freshing the edited table. 2 other ways how to bring it to the point: "How to type in C-u 134 C-d with pasting 134 with C-y instead of having to type in 1-3-4 manually?", or "How to overwrite by pasting?" - both ways would solve the problem. – starquake Jul 20 at 16:02
  • @NickD: 1 file, containing 21 tables. The main table has almost 800 rows, 3 columns. The other 20 tables at least 200 rows, 3 columns. And it's just getting started: At one point in time within the procedure the number of columns will be extended to at least 300, I guess. A database? Am I not doing that right now? To my understanding a database is a set of data in form of a table with functional abilities like spreadsheet, switching columns, etc. - that's exactly what said file in the buffer is, I'm editing right now. – starquake Jul 20 at 16:09
  • No, do not confuse Org mode tables (or any spreadsheet for that matter) with a database. But the tables don't look too big: with a recent version of Org mode, a 1000x26 table gets reformatted in about 6 secs on my laptop. That's still very slow but it is a far cry from 20 mins. Probably your biggest problem is the outdated Org mode you are running: 8.2.10 is from 2014. I suggest you upgrade. – NickD Jul 20 at 17:20
0

You can write

(defun overwriting-yank ()
  "Like `yank` but overwrites the corresponding text."
  (interactive)
  (let ((txt (current-kill 0)))
    (insert-for-yank txt)
    (delete-char (length txt))))

But this will misbehave in all kinds of circumstances (e.g. when yanking a multiline string, when yanking into a line shorter than the text you're yanking, ...).

Also, IIUC you're interested in columns more than in number of chars, so the behavior won't be quite right if there are double-width chars or TAB chars involved.

etc...

Finally, your description makes it clear that the only reason you want such an operation is in order to work around bugs in Org. So please make sure you report those bugs and try to work with Org mode's maintainers to get rid of them.

| improve this answer | |
  • I believe the org-mode people have recently improved the performance of large tables, so trying a more recent version might help – rpluim Jul 20 at 16:10
  • @Stefan: You're pushing me out of my comfort zone, this is elisp code, right? This section, what do I do with it after copying it? I don't understand these 6 lines.1st line: Probably simply names this piece of code. The second seems to be just a comment. 3rd & 4th? No clue. 5th, I don't know if that's meant literally or if this is just a template for me to change according to the changing number in Messages buffer. 6th gets rid of the corresponding space characters, but I don't see how that part of it - (length txt) - is connected to the previous lines, shouldn't it appear there, as well? – starquake Jul 20 at 16:18
  • @rpluim: That's a very good idea. Currently I'm using GNU Emacs 24.5.1 with Org-mode version 8.2.10. If I knew how, I would update to most recent versions of Emacs & Org-mode. The reason why I'm stuck at these both rather old versions is, that I'm inexperienced in installing & updating software on GNU/linux & apt-get just pulled these both versions out of the Trisquel repository. Unfortunally the Trisquel developers don't offer newer versions. For me it's important to get newer versions by apt-get so that everything is neat, tidy & libre, no independencies of other software broken, etc. – starquake Jul 20 at 16:28

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.