I copied a long sentence to org-mode

As I mentioned in the last section, Richard Stallman, the founder of the Free Software Foundation, was more than a programmer. He was an educated social critic, and his vision of the future was to have an enormous impact on the world. enter image description here

I tried to achieve line-break automatically with auto-fill-mode, but get a result as

enter image description here

How could I enable it to extend and shrink according the the screen width rather than the line limitation of 80 words.


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 auto-fill-mode.)

C-h f visual-line-mode tells you this:

visual-line-mode is an interactive compiled Lisp function in simple.el.

(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 ARG is toggle, disable the mode if ARG is a non-positive integer, and enable the mode otherwise (including if 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.


create a function that sets the fill-mode width to (window-width) and add it to the post-command-hook

  • 3
    An example would make this answer much more useful. – Stefan Jan 6 at 18:11

C-x f to set a fill-column variable.
M-q to fill paragraph or selection to that width.

As a minor mode:

(defun dynamic-fill-column-set-var (frame)
  (when dynamic-fill-column-mode
    (setq fill-column (- (window-total-width) 3))))

(defun dynamic-fill-column-buffer-list-change ()
  (when dynamic-fill-column-mode
    (setq fill-column (- (window-total-width) 3))))

(define-minor-mode dynamic-fill-column-mode
  "Sets `fill-column' when buffer's window is resized"
  :lighter " DFC"
  (if dynamic-fill-column-mode
        (add-hook 'window-size-change-functions 'dynamic-fill-column-set-var nil t)
        (add-hook 'buffer-list-update-hook 'dynamic-fill-column-buffer-list-change nil t))
    (remove-hook 'window-size-change-functions 'dynamic-fill-column-set-var t)
    (remove-hook 'buffer-list-update-hook 'dynamic-fill-column-buffer-list-change t)))

after resizing M-q(executes fill-paragraph function).

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.