Skip to content

Instantly share code, notes, and snippets.

@priyadarshan
Forked from sabof/wrap-column.el
Created April 18, 2013 00:22
Show Gist options
  • Save priyadarshan/5408877 to your computer and use it in GitHub Desktop.
Save priyadarshan/5408877 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