4

On a regular basis I need to open files that have really long lines, which unfortunately causes emacs to grind to a halt. My understanding is that this is a long-term issue with the renderer. I've tried disabling every possible mode, using every possible line wrapping package, etc. but none work well enough.

What I have found does work is first transforming the files in shell before opening them:

$ fold -w80 myfile > temp

Generally speaking I don't need to edit the files that have this property just view them, but it would still be convenient to look at them in emacs instead of going to less in the terminal. Is it possible to automate this and just have emacs do this every time I open a file that is sufficiently large or that has a sufficiently large first line?

Find file hooks look like they let me run code after the buffer is opened, but in this case I want to intercept the request to open the file and make it open the a synchronously arriving shell command output instead. Preferably in a way that will just work regardless of whether I open the file with helm, dired, etc.

4

Have emacs read from stdin device and insert contents into *scratch* buffer.

$ fold -w80 myfile | emacs --insert /path/to/stdin

Note: You will need to update /path/to/stdin path

e.g.

$ fold -w80 myfile | emacs --insert /dev/stdin

This answer was validated using:
emacs version: GNU Emacs 25.2.1
This question was used as a reference.

1

Not quite what you are asking for, but perhaps a helpful step in the right direction: the command shell-command, bound to M-! by default, allows you to run a shell command from Emacs. If you call it with a prefix argument, the output from that command is inserted at point in the current buffer.

So, if you open a new buffer and invoke C-u M-! fold -w80 ./path/to/myfile, myfile will be wrapped at 80 columns and inserted in the new buffer.

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.