emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Word wrapping and long lines


From: Lennart Borgman (gmail)
Subject: Re: Word wrapping and long lines
Date: Fri, 19 Sep 2008 04:03:26 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

Miles Bader wrote:
> "Lennart Borgman (gmail)" <address@hidden> writes:
>> Maybe something like this can be used:
> ...
>> (define-minor-mode wrap-to-fill-mode
> 
> A clever idea, but...
> (1) _centering_ the display like that is bizarre and unpleasant
> (2) Having the margin be on the other side of the fringe is kind of
> annoying; personally, when I want a bunch of whitespace on the right, I
> want it to be whitespace, without the "barrier" the fringe represents.
> 
> But maybe it's a good start...
> 
> -Miles

I do not know what to do about the barrier, but this takes care of the
left margin.

(defun set-wrap-to-fill-values ()
  "Use `fill-column' display columns in buffer windows."
  (let ((buf-windows (get-buffer-window-list (current-buffer))))
    (dolist (win buf-windows)
      (if wrap-to-fill-mode
          (let* ((edges (window-edges win))
                 (win-width (- (nth 2 edges) (nth 0 edges)))
                 (extra-width (- win-width fill-column))
                 (left-marg (if wrap-to-fill-left-marg
                                wrap-to-fill-left-marg
                              (- (/ extra-width 2) 1)))
                 (right-marg (- win-width fill-column left-marg))
                 (win-margs (window-margins win))
                 (old-left (or (car win-margs) 0))
                 (old-right (or (cdr win-margs) 0)))
            (unless (> left-marg 0) (setq left-marg 0))
            (unless (> right-marg 0) (setq right-marg 0))
            (unless (and (= old-left left-marg)
                         (= old-right right-marg))
              (set-window-margins win left-marg right-marg)))
        (set-window-buffer win (current-buffer))))))

(defcustom wrap-to-fill-left-marg nil
  "Left margin handling for `wrap-to-fill-mode'.
Used by `wrap-to-fill-mode'. If nil then center the display
columns. Otherwise it should be a number which will be the left
margin."
  :type '(choice (const :tag "Center" nil)
                 (integer :tag "Left margin"))
  :group 'emacs)
(make-variable-buffer-local 'wrap-to-fill-left-marg)

(define-minor-mode wrap-to-fill-mode
  "Use `fill-column' display columns in buffer windows.
By default the display columns are centered, but see the option
`wrap-to-fill-left-marg'.

Note: When turning this on `visual-line-mode' is also turned on. This
is not reset when turning off this mode."
  :group 'emacs
  (if wrap-to-fill-mode
      (progn
        (add-hook 'window-configuration-change-hook
'set-wrap-to-fill-values nil t)
        (visual-line-mode 1))
    (remove-hook 'window-configuration-change-hook
'set-wrap-to-fill-values t))
  (set-wrap-to-fill-values))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]