reddit / emacs

Paragraph indent for novel writing with Emacs

TiMueller · 2022-01-30 15:00
Hello everyone, I'm a writer who lives in Germany (12 published novels with Random House), and I started using emacs a year ago and am falling in love more and more. It is perfect for organizing material for my novels, and I even use Mu4e for e-mails by now. I would be happy to try to write my next novel with emacs. But there is one thing that just drives me crazy writing prose in emacs, and I wonder whether there is a solution to it. (Olivetti Mode or Writeroom mode do not solve this, regrettably.) When writing prose, I don't want to have a blank line between each paragraph, but to have them indented instead. It just looks awkard to me, to have lines of dialogue like this: "I met another woman", he said. . "Who is it?" . "You don't know her." . She gave him a furious stare. ​ ​ It reather should look like this: ​ "I met another woman", he said. ..... "Who is it?" ..... "You don't know her." ..... She gave him a furious stare. ​ (Reddit deletes blank space, I had to put dots there.) But the indentation shouldn't be Tabs or Spaces, it should just be how emacs displays the buffer. Is there a way to make this possible, a way to write prose without blank lines between the paragraphs and to have the first line of each paragraph indented? Formatted text properties like "indent more" insert spaces. Maybe this is the way emacs is made, and there is no way to just visually indent (like in a word processor) without putting characters in the document. Thank you so much for any help on this! Titus
Illiamen · 2022-01-30 15:38
I do not know of a way to only do this visually, but, if your are using Text Mode, maybe `paragraph-indent-text-mode` does what you want using whitespace characters. See here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Text-Mode.html That page also lists a `paragraph-indent-minor-mode`, but I've never tried it, and don't know how it interacts with other modes. For example, a "paragraph" in Org mode has a specific definition (https://orgmode.org/manual/Paragraphs.html): > Paragraphs are separated by at least one empty line.
TiMueller · 2022-01-30 16:02
Thank you very much, Illiamen! I tried out `paragraph-indent-text-mode`. At first it didn't do anything, but after I had found out one has to disable `electric-indent-mode` first, it did indent paragraphs after I gave them a few spaces in the first line (or after I set the `fill-prefix`). Although I would need to just indent the first line of a paragraph, not all of it, and `Parindent-mode` indents the whole paragraph instead. (Or am I doing it wrong?) If I got it to work right, I know it would be half of a solution. It just feels a bit awkward to put characters in that have to be deleted for every step of the text outside of Emacs. When I am done completely, I can of course export it and probably there is a way to delete the spaces during export. At least I hope so. I know Emacs isn't mainly used to write prose ... I just wondered if there would be a way. Thank you very much for hinting me to `Parindent-mode`! I'll experiment more with it, and secretly I still hope there would be a way to do it without spaces ...
ThorstoneS · 2022-01-30 16:20
Hmm, interesting question. What are you writing in? Plain text? Or a markup language? org-mode also uses empty lines, but there are a few "prettify" modes markdown makes paragraphs by either an empty line OR a double space at the end. ​ There's a rather popular video on youtube by a writer (prose) who set up emacs for that: [https://www.youtube.com/watch?v=FtieBc3KptU](https://www.youtube.com/watch?v=FtieBc3KptU) You may know that already, but there may be some interesting tricks in there.
TiMueller · 2022-01-30 16:41
I would prefer Org-mode, it would allow me to hide away chapters and scenes as I move around the book. But I would also be okay with plain text, if it would just allow me to stay within Emacs all the time. The video of Jay Dixit is wonderful! I watched it a year ago, but looked into it again after your post. He apparently is okay with no indentation in prose text, as is seen in minute 14:04 and minute 38:17. For me, that doesn't look too nice. (And for nonfictional works, he uses the block style with blank lines between the paragraphs, what is perfectly alright when you have no short dialogue lines.) I love those prettify-minor-modes! Typo, for instance, which allows me to use smart quotes (and even German ones). I thought, org-mode already is some kind of Markdown (except that it has \* for #). But I will look into that, maybe there is a markdown-mode with indented paragraphs? Thanks a lot!
doolio_ · 2022-01-30 19:43
Have you looked at [rnkn/fountain-mode](https://github.com/rnkn/fountain-mode) from the same author as olivetti-mode? It is for screenwriting but you may be to use elements of it for your passages of dialogue? They also wrote [rnkn/binder](https://github.com/rnkn/binder) which you may find useful in your writing projects.
gmfawcett · 2022-01-30 20:34
Here's a super-quick hack that will do what you want. Hopefully a better Elisper can help you improve on it. Evaluate this expression from time to time: e.g. you could put it into a keyboard binding, or a save hook, or just press `M-:` and evaluate it, or etc. (put-text-property 1 (save-excursion (end-of-buffer) (point)) 'line-prefix " ") It will tell each character in your file that, if it appears at the start of a newline, then the line prefix should be inserted in front of it. In this case I chose 5 spaces as the prefix text, but it could have been something else (an arrow, etc.). This is a *display* property, the prefix characters will not actually get inserted into the file. You may need to execute it again if you add new text and the indentation doesn't appear. ------ Welcome to Emacs, I'm glad you found it :)
pailanderCO · 2022-01-31 00:04
My two cents, for what they are worth. I have not published any novels, buy I have published several academic books, and I have worked as book designer/typesetter at a university press for many years (now I am a tenured professor, so my role has changed). For the person who receives your Ms. and has to typeset it, the best thing is to have paragraphs separated by hard line breaks (empty lines) rather than by indentations. Indentation can be handled later by the software they use (the usual suspects: InDesign, QuarkXPress, etc.). The typesetter needs to apply paragraph (and character) styles on your text, which is considerably easier to do when spotting the beginning and end of paragraphs. But these tend to disappear or hide if there are no visible (I mean, really visible) gaps between the paragraphs. So my recommendation is: use whatever software or package you like (I mostly use Emacs for all my writing, except when on XML languages), but leave empty lines between your paragraphs.
oantolin · 2022-01-31 02:57
I think you misunderstood what OP wanted: OP wants to display paragraphs without blanklines between them, instead indicating where paragraphs start by displaying the first line of each paragraph indented.
Prudent-Dimension554 · 2022-01-31 05:28
I thought I'd get some practice working with overlays so I wrote up a proof of concept of what such a mode might look like. https://github.com/zkry/paragraph-chain-indent It works by making the newline invisible and inserting an overlay with the indentation text displayed after it. It probably has a lot of rough edges but I hope you find it helpful!
TiMueller · 2022-01-31 07:27
It works! Thank you so so so much! And it really isn't saved in the file, it's just a display property. I am very happy. Is there a way to apply your function only to paragraphs that do not have a blank line before them? That would be the perfect solution. I wish I had more programming skills ... As your function is very fast, I think it would be best to keep it as it is (giving all lines in the buffer the line-prefix at once). But one could afterwards use another function to go through the buffer and take the prefix from lines that have a blank line before them. Puah. I need to learn Elisp fast! For me the wonderful thing is: Now I know it is possible to indent just in display. Emacs rocks! Thank you for helping me.
TiMueller · 2022-01-31 07:44
You are right, of course. For the typesetter, my indents would be something they need to take out again. For this reason I don't want them to be saved in the file. Thankfully gmfawcett has a nice solution that just displays indents that aren't really in the file. My wish for a display of indents will sound strange to you. As long as the text is transferred correctly to the publisher and the typesetter, blank lines should be no problem to me. But strangely, they are. I am used to set blank lines whenever there is a change of scene, a change in time and place. This is the typical "marker" for the readers in a novel (and for me, when writing, too). And it helps me to see the book like it is seen when printed, to get a feeling for the length of the scene and of the chapter. After some months, I probably could get used to the new "look", with one blank line between every paragraph, and two blank lines for the change of scene. But still, there would be the dialogues, where often a paragraph is just one short line, and the next one too, and then a third one -- when there is a blank line inserted every time, they are drawn far apart on the page and to me don't look like a consistent dialogue anymore. What thrills me is that you have published several books with writing them in Emacs. So it *is* possible! I applaud you (and thank you a lot for your thoughts and time). I'll give it a try too.
TiMueller · 2022-01-31 07:51
What sounds great is the second point of fountain-mode: "WYSIWYG auto-align elements (display only, does not modify file contents)", that is exactly what I need. And they say one can have "user-defined formats". Maybe I could work at a user-defined format for novels? I'll try that out! And binder-mode is also great, it really brings good functionality of Scrivener to Emacs. Thank you very much!
doolio_ · 2022-01-31 08:01
Oh, don't thank me. Thank Mr. Rankin and others that create these packages we all enjoy. Good luck.
TiMueller · 2022-01-31 08:13
Very, very interesting. I tried it out, and it really pulls together the shorter paragraphs and indents them. I played around with the settings a bit and now it also pulls together the longer paragraphs. Great! I would never be able to write the code to do that. But I'll try to find out how you did it and learn from it. Thank you so much! This really works very well.
TiMueller · 2022-01-31 09:37
Oh no, it doesn't seem to work with `paragraph-indent-text-mode` and `auto-fill`. At first, when I use your function, everything looks wonderful. But as soon as I start editing a paragraph, it gets broken down into single lines and each one of those lines is indented. Also, when writing new paragraphs, they suddenly are broken down into single indented lines. Somehow `Parindent` and `auto-fill` and your function don't like each other. But without those I would have to scroll far to the right for even reading what I've written. Sorry for being such a difficult patient. And still thank you a lot for trying (and for showing to me there is something like display only indentation).
_viz_ · 2022-01-31 12:21
I don't understand what you need perfectly but does the following work for you? Try evaluating it in an org-mode buffer and see the results (I found it quite jarring). And here's a screenshot: http://0x0.st/oH9O.png (add-hook 'font-lock-keywords '("^ *\n" (0 '(face nil display "aaaa "))) nil t) (setq font-lock-extra-managed-props '(display)) This is not perfect tho. Multiple empty lines don't really work properly and I don't have the time to try out multiline fontification.
gmfawcett · 2022-01-31 14:00
Ah... I didn't think about auto-fill. :) A more clever application of my hack would be to *only* add the special display-property at the right spots, rather than applying it to all characters (which my example did). Then, auto-fill could do its thing. We are leaving the realm of quick hacks and entering the realm of the slightly clever -- we need a way to identify which characters are the "starts of paragraphs" based on their position, context, etc. How are you using auto-fill without leaving a blank line between paragraphs? Isn't it just smooshing your paras together, and then re-wrapping them? (If you are leaving blank lines, that gives us a possible way to identify paragraph starts: the first character of a paragraph is the first character after a blank line.) Also, I'm checking if you're aware that auto-fill is only one way to wrap text. If you want a display-only wrapping, there are modes like `visual-line-mode` -- and since those don't insert new lines like auto-fill does, they would be compatible with my little hack.
gmfawcett · 2022-01-31 14:06
Right, that's what my example does. Well, at least it does if you visually wrap your paras instead of auto-filling them.
oantolin · 2022-01-31 14:08
Well, I don't think your example does anything about hiding the blank lines between paragraphs (which OP does want present in the file, just hidden from view). But yes, I was mostly thinking "this indents every single line of paragraph, not just the first one" because I temporarily forgot that some people _write entire paragraphs on a single line_. Heck, even I do it for emails, or in LaTeX when my coauthors do it (mixing both styles in a single file is even worse than writing paragraphs on a single line!).
rbslco · 2022-01-31 15:01
Coming from WYSIWYG world myself, and from my experience as an editor, here are three things for you to consider: 1. In plain text (org-mode, markdown, LaTeX) the only natural way to separate paragraphs is an actual empty line; you can hack your way around that, but sooner or later, you will likely encounter some issues. While adapting Emacs itself to your need is natural and recommended, trying to change some core concepts of a file type or a process might not be a good or even safe thing to do. 2. Unlike with WYSIWYG approach, there is usually a clear separation between source document and output document when you’re working with plain text, and this is actually a huge advantage, because, while writing and/or editing your work, you don’t have to (more accurately, you should not) pay any attention whatsoever to typographic side of the equation, and nothing is hidden from you – even worrying about details like smart quotes is unnecessary, because converters take care of that too when exporting the final draft (I still use smart quotes because Emacs makes that possible without fuss). 3. Don’t overuse the prettifiers, because some of them sometimes obfuscate valuable information. Even if you do use them, try to turn them off at least during the last editing run. In my experience, visual helpers like empty lines, forward slashes, stars... are immensely useful during the editing phase. As for the empty line used in prose as a separator, consider using a star or three stars or some other symbol instead while writing and editing the source document, and replace the symbol with empty line in the final exported document.
gmfawcett · 2022-01-31 16:22
Ah.. I thought he was trying not to have blank lines at all, just the start-of-para indents. I'm still a little unclear on that -- although he later added that he's auto-filling his paras, so that suggests a blank line separation. With a little more energy, we could hide the blank lines with the same display tricks of course. At that point we're halfway to a custom mode, rather than a little hack -- but, hey, that's how these things start. :)
TiMueller · 2022-02-01 10:44
I tried it with `visual-line-mode` instead of `auto-fill`, and now it works just wonderfully! Thank you so so much! Your "little hack" is THE solution for me. Have a look: [https://imgur.com/a/N6DA7En](https://imgur.com/a/N6DA7En) This is with your "little hack", `variable-pitch-mode`, `visual-line-mode` and `olivetti-mode`. I am very happy and thrilled to start the experiment of writing a whole novel in Emacs. Over the next days I will also try out some of the other hints, fountain-mode and the font-lock-keywords-hack. I wish my brain would be faster to grasp how all this is done, but I'll learn, and in the end I'll have a great working environment for all aspects of writing. Thank you to all of you for helping me! Emacs has a wonderful community.
TiMueller · 2022-02-01 10:47
I prefer having no blank lines at all. Of course, a custom mode sounds great. But your little hack already works wonderfully for me.
TiMueller · 2022-02-01 13:33
Works out of the box! It's like magic. Really great what can be done with Emacs. Only problem is, that it indents every line, not just the beginning of the paragraph. If I understand it right (it's really not that easy for a non-programmer), you are looking for the beginning of a new line and then display an invisible "aaaa " in front of it? But it must be some other marker, as with my prose every paragraph has just one line. If we could find a marker for the beginning of a line and just indent there, it would be working like I need it. Anyhow, gmfawcetts hack already works. Not in org-mode, though, when I put the prose text after a heading. I'll experiment a little more to try to get in work there too. Org-mode has its own indentation function and doesn't like it to be mingled with another one, it seems ...
gmfawcett · 2022-02-01 13:39
Thank you for sharing the screenshot. Wow, that looks great! I wish you all the best on your Emacs travels. Have fun!
TiMueller · 2022-02-01 13:43
You are right, I am a bit off the concept of separation between source document and output document here. Being used to the sweet WYSIWYG world for twenty years of novel writing now, it is hard to let it go. And don't forget, I am sitting a whole year (!) staring at the source document, before it is time to convert it to an output document. That entices me to have it looking as nice as possible. But your warning makes me waver, I don't want to overdo it. And there is a side of me that just wants to delve into the Emacs world the way it is meant ... I'll think more about this. Thanks a lot for your experienced look at my situation!
_viz_ · 2022-02-01 16:06
I still don't really understand what you need so I don't think I can help you much, sorry about that. > If I understand it right (it's really not that easy for a > non-programmer), you are looking for the beginning of a new line and > then display an invisible "aaaa " in front of it? You're almost there: I am looking for empty lines and display them as "aaaa " instead. > But it must be some other marker Sure, change "aaaa " to "\\t" or whatever you like. "aaaaa " is what I mashed in my keyboard to write a marker that will stand out. If you want it to be coloured, then change the nil after the face to a VARIABLE that holds a face (C-h v font-lock-keyword-face RET for example). > as with my prose every paragraph has just one line. If we could find a > marker for the beginning of a line and just indent there, it would be > working like I need it. And I'm lost here. I think the problem is that we have different notions of what a paragraph is. When I read paragraph, I interpret it as what Emacs defines it as (try out the paragraph movement and marking commands). If you can explain your notion, then I might be able to get closer to your goal.
TiMueller · 2022-02-02 08:27
Oh, I understand. I didn't know that, I have just learned in this thread that no matter how many lines I end with the return key, a paragraph in Emacs (and Markdown for general) ends with blank line and not before that. In the WYSIWYG world I have come from, a paragraph ended as soon as I hit the return key for the first time. So here began the misunderstanding. There must be some sort of functional character that is not shown, but is saved in the file and marks the end of a line. In terms of Emacs, what I meant the whole time was lines, not paragraphs, as in my prose writing, every "paragraph" consists of just one line. Thanks for helping me learn! It is an interesting new world I delve into. :)