It sounds like you don't want "hard" returns at the end of lines, and you instead just want "soft" returns. That is, you don't want to insert end-of-line characters, such as
newline. You just want lines to appear broken, and you want the apparent line breaks to be just before the window edge. Is that right?
If so, what you want is to just turn on
visual-line-mode in a given buffer -- or
global-visual-line-mode, if you want this behavior in all buffers. (And turn off
C-h f visual-line-mode tells you this:
visual-line-mode is an interactive compiled Lisp function in
(visual-line-mode &optional ARG)
Toggle visual line based editing (Visual Line mode) in the current buffer.
Interactively, with a prefix argument, enable
Visual Line mode if the prefix argument is positive,
and disable it otherwise. If called from Lisp, toggle
the mode if
toggle, disable the mode if
a non-positive integer, and enable the mode otherwise
ARG is omitted or
nil or a positive integer).
When Visual Line mode is enabled,
word-wrap is turned on in
this buffer, and simple editing commands are redefined to act on
visual lines, not logical lines. See Info node Visual Line Mode for details.