Skip to content

Instantly share code, notes, and snippets.

@sabof
Last active December 16, 2015 05:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sabof/5383987 to your computer and use it in GitHub Desktop.
Save sabof/5383987 to your computer and use it in GitHub Desktop.
(defun wc/narrow-window ()
(let (( new-right
(max 0 (+ (or (cdr (window-margins)) 0)
(- (window-body-width) fill-column)))))
(set-window-margins nil (car (window-margins)) new-right)
(set-window-fringes nil (car (window-fringes)) 2)))
(define-minor-mode wrap-column-mode
"Wrap the text at `fill-column'.
Works by adjusting the right margin."
nil nil nil
(if wrap-column-mode
(progn
(visual-line-mode 1)
(add-hook 'window-configuration-change-hook
'wc/narrow-window nil t)
(wc/narrow-window))
(progn
(remove-hook 'window-configuration-change-hook
'wc/narrow-window t)
(set-window-margins nil (car (window-margins)) nil)
(set-window-fringes nil (car (window-fringes))
(car (window-fringes))))))
(provide 'wrap-column)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment