(defvar refill-help-buffer-max-fill-column 68) (defun refill-help-buffer (&optional frame) (interactive) (walk-windows #'(lambda (win) (with-selected-window win (save-excursion (when (and (eq major-mode 'help-mode) (or (< fill-column refill-help-buffer-max-fill-column) (window-truncated-p)) (progn (goto-char (point-min)) (forward-sentence) (re-search-backward "variable\\|function\\|command\\|face\\|form\\|macro" nil t))) (let (buffer-read-only) (setq fill-column (min refill-help-buffer-max-fill-column (- (window-width) 1))) (fill-region (point-min) (point-max))))))) 'no-minibuffer frame)) (defun window-truncated-p (&optional window) "Return non-nil if current window (or the argument) has some truncated lines." (with-selected-window (or window (selected-window)) (save-excursion (goto-char (point-min)) (re-search-forward (format "^..\\{%d\\}" (window-width)) nil t)))) (defun refill-help-buffer-reset-fill-column-and-refill nil (setq fill-column 0) (refill-help-buffer)) (define-minor-mode refill-help-buffer-mode "Automatically fill help buffer to \(min `refill-help-buffer-max-fill-column' \(window-width\)\) on displaying and resizing." nil nil nil :global t (if refill-help-buffer-mode (progn (add-hook 'window-size-change-functions 'refill-help-buffer) (add-hook 'temp-buffer-show-hook 'refill-help-buffer-reset-fill-column-and-refill)) (remove-hook 'window-size-change-functions 'refill-help-buffer) (remove-hook 'temp-buffer-show-hook 'refill-help-buffer-reset-fill-column-and-refill))) (provide 'refill-help-buffer)