[Top][All Lists]

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

Longlines mode and visual-line mode... again

From: Danil Orlov
Subject: Longlines mode and visual-line mode... again
Date: Sun, 15 Dec 2013 22:42:36 +0200
User-agent: Mutt/1.5.21 (2010-09-15)


  The main feature  for me(and I hop  for many others too) in  longlines mode is
soft line wrap  on given column.  Occasionally, ll-mode is  obsolete, and we 
visual-line instead of it. That's ok. But that new mode doesn't have this useful
feature from the box. That's not ok.

  So, what is typical action for a typical emacs user who wants to get soft line
break,  avoiding to  see  message about  ll-mode  could be  dropped  in any  
release? Right! He goes to:


And copy this fragment into his .emacs or what-else-he-use:

(defvar visual-wrap-column nil)

(defun set-visual-wrap-column (new-wrap-column &optional buffer)
  "Force visual line wrap at NEW-WRAP-COLUMN in BUFFER (defaults
to current buffer) by setting the right-hand margin on every
window that displays BUFFER.  A value of NIL or 0 for
NEW-WRAP-COLUMN disables this behavior."
  (interactive (list (read-number "New visual wrap column, 0 to disable: " (or 
visual-wrap-column fill-column 0))))
  (if (and (numberp new-wrap-column)
           (zerop new-wrap-column))
    (setq new-wrap-column nil))
  (with-current-buffer (or buffer (current-buffer))
    (visual-line-mode t)
    (set (make-local-variable 'visual-wrap-column) new-wrap-column)
    (add-hook 'window-configuration-change-hook 'update-visual-wrap-column nil 
    (let ((windows (get-buffer-window-list)))
      (while windows
        (when (window-live-p (car windows))
          (with-selected-window (car windows)
        (setq windows (cdr windows))))))

(defun update-visual-wrap-column ()
  (if (not visual-wrap-column)
    (set-window-margins nil nil)
    (let* ((current-margins (window-margins))
           (right-margin (or (cdr current-margins) 0))
           (current-width (window-width))
           (current-available (+ current-width right-margin)))
      (if (<= current-available visual-wrap-column)
        (set-window-margins nil (car current-margins))
        (set-window-margins nil (car current-margins)
                            (- current-available visual-wrap-column))))))

  And  why  this  little  piece   of  functionality  cannot  be  integrated  
visual-line mode?  Especially if visual-line-mode is  recommended as replacement
for ll-mode.

reply via email to

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