comparison lisp/longlines.el @ 79120:3516a7d8862b

(longlines-wrap-follows-window-size): Integer value specifies wrapping margin. (longlines-mode, longlines-window-change-function): Set window-specific wrapping margin based on the above.
author Chong Yidong <cyd@stupidchicken.com>
date Wed, 17 Oct 2007 02:47:39 +0000
parents 65140a5dc349
children 73661ddc7ac7
comparison
equal deleted inserted replaced
79119:f17c3647c3fe 79120:3516a7d8862b
53 53
54 (defcustom longlines-wrap-follows-window-size nil 54 (defcustom longlines-wrap-follows-window-size nil
55 "Non-nil means wrapping and filling happen at the edge of the window. 55 "Non-nil means wrapping and filling happen at the edge of the window.
56 Otherwise, `fill-column' is used, regardless of the window size. This 56 Otherwise, `fill-column' is used, regardless of the window size. This
57 does not work well when the buffer is displayed in multiple windows 57 does not work well when the buffer is displayed in multiple windows
58 with differing widths." 58 with differing widths.
59
60 If the value is an integer, that specifies the distance from the
61 right edge of the window at which wrapping occurs. For any other
62 non-nil value, wrapping occurs 2 characters from the right edge."
59 :group 'longlines 63 :group 'longlines
60 :type 'boolean) 64 :type 'boolean)
61 65
62 (defcustom longlines-show-hard-newlines nil 66 (defcustom longlines-show-hard-newlines nil
63 "Non-nil means each hard newline is marked on the screen. 67 "Non-nil means each hard newline is marked on the screen.
115 (make-local-variable 'longlines-auto-wrap) 119 (make-local-variable 'longlines-auto-wrap)
116 (set (make-local-variable 'isearch-search-fun-function) 120 (set (make-local-variable 'isearch-search-fun-function)
117 'longlines-search-function) 121 'longlines-search-function)
118 (add-to-list 'buffer-substring-filters 'longlines-encode-string) 122 (add-to-list 'buffer-substring-filters 'longlines-encode-string)
119 (when longlines-wrap-follows-window-size 123 (when longlines-wrap-follows-window-size
120 (set (make-local-variable 'fill-column) 124 (let ((dw (if (and (integerp longlines-wrap-follows-window-size)
121 (- (window-width) window-min-width)) 125 (>= longlines-wrap-follows-window-size 0)
126 (< longlines-wrap-follows-window-size
127 (window-width)))
128 longlines-wrap-follows-window-size
129 2)))
130 (set (make-local-variable 'fill-column)
131 (- (window-width) dw)))
122 (add-hook 'window-configuration-change-hook 132 (add-hook 'window-configuration-change-hook
123 'longlines-window-change-function nil t)) 133 'longlines-window-change-function nil t))
124 (let ((buffer-undo-list t) 134 (let ((buffer-undo-list t)
125 (inhibit-read-only t) 135 (inhibit-read-only t)
126 (after-change-functions nil) 136 (after-change-functions nil)
413 (setq longlines-wrap-end nil))) 423 (setq longlines-wrap-end nil)))
414 424
415 (defun longlines-window-change-function () 425 (defun longlines-window-change-function ()
416 "Re-wrap the buffer if the window width has changed. 426 "Re-wrap the buffer if the window width has changed.
417 This is called by `window-configuration-change-hook'." 427 This is called by `window-configuration-change-hook'."
418 (when (/= fill-column (- (window-width) window-min-width)) 428 (let ((dw (if (and (integerp longlines-wrap-follows-window-size)
419 (setq fill-column (- (window-width) window-min-width)) 429 (>= longlines-wrap-follows-window-size 0)
420 (longlines-wrap-region (point-min) (point-max)))) 430 (< longlines-wrap-follows-window-size (window-width)))
431 longlines-wrap-follows-window-size
432 2)))
433 (when (/= fill-column (- (window-width) dw))
434 (setq fill-column (- (window-width) dw))
435 (longlines-wrap-region (point-min) (point-max)))))
421 436
422 ;; Isearch 437 ;; Isearch
423 438
424 (defun longlines-search-function () 439 (defun longlines-search-function ()
425 (cond 440 (cond