reddit / emacs

Possible to set line-length based on length of line, not specific column?

campbellm · 2022-08-23 18:43
Is it possible to set a right margin based on the length of the line, starting at the first character, rather than a specific column? My use case is this: I'm writing a document that has various indentation levels, and due to how its processed I can afford (eg) 50 characters on a "line". But the line may be indented so I can't just set the fill-column to 50, since I might be at column 8, 12, 16, etc. indentation. So I'd like it to be 50+column_of_first_character. Ideally then things like auto-fill-mode and fill-paragraph and such would work. Is this possible?
thetemp_ · 2022-08-23 20:50
Could probably do it with a function and add it to the [fill-nobreak-predicate](https://www.gnu.org/software/emacs/manual/html_node/emacs/Fill-Commands.html) hook. You'd set `fill-column` to 50, but the function would override filling whenever (point - starting text position + length of word that would be moved to next line) < 50. Can't say if it'll work, as I haven't tried it myself.