comparison lisp/longlines.el @ 78088:4545583b711c

(longlines-wrap-region): Avoid marking buffer as modified. (longlines-auto-wrap, longlines-window-change-function): Remove unnecessary calls to set-buffer-modified-p.
author Chong Yidong <cyd@stupidchicken.com>
date Sun, 08 Jul 2007 18:07:46 +0000
parents 2b390b4a6ba8
children 9355f9b7bbff
comparison
equal deleted inserted replaced
78087:0b484e939e61 78088:4545583b711c
221 221
222 (defun longlines-wrap-region (beg end) 222 (defun longlines-wrap-region (beg end)
223 "Wrap each successive line, starting with the line before BEG. 223 "Wrap each successive line, starting with the line before BEG.
224 Stop when we reach lines after END that don't need wrapping, or the 224 Stop when we reach lines after END that don't need wrapping, or the
225 end of the buffer." 225 end of the buffer."
226 (setq longlines-wrap-point (point)) 226 (let ((mod (buffer-modified-p)))
227 (goto-char beg) 227 (setq longlines-wrap-point (point))
228 (forward-line -1) 228 (goto-char beg)
229 ;; Two successful longlines-wrap-line's in a row mean successive 229 (forward-line -1)
230 ;; lines don't need wrapping. 230 ;; Two successful longlines-wrap-line's in a row mean successive
231 (while (null (and (longlines-wrap-line) 231 ;; lines don't need wrapping.
232 (or (eobp) 232 (while (null (and (longlines-wrap-line)
233 (and (>= (point) end) 233 (or (eobp)
234 (longlines-wrap-line)))))) 234 (and (>= (point) end)
235 (goto-char longlines-wrap-point)) 235 (longlines-wrap-line))))))
236 (goto-char longlines-wrap-point)
237 (set-buffer-modified-p mod)))
236 238
237 (defun longlines-wrap-line () 239 (defun longlines-wrap-line ()
238 "If the current line needs to be wrapped, wrap it and return nil. 240 "If the current line needs to be wrapped, wrap it and return nil.
239 If wrapping is performed, point remains on the line. If the line does 241 If wrapping is performed, point remains on the line. If the line does
240 not need to be wrapped, move point to the next line and return t." 242 not need to be wrapped, move point to the next line and return t."
370 (interactive "P") 372 (interactive "P")
371 (setq arg (if arg 373 (setq arg (if arg
372 (> (prefix-numeric-value arg) 0) 374 (> (prefix-numeric-value arg) 0)
373 (not longlines-auto-wrap))) 375 (not longlines-auto-wrap)))
374 (if arg 376 (if arg
375 (let ((mod (buffer-modified-p))) 377 (progn
376 (setq longlines-auto-wrap t) 378 (setq longlines-auto-wrap t)
377 (longlines-wrap-region (point-min) (point-max)) 379 (longlines-wrap-region (point-min) (point-max))
378 (set-buffer-modified-p mod)
379 (message "Auto wrap enabled.")) 380 (message "Auto wrap enabled."))
380 (setq longlines-auto-wrap nil) 381 (setq longlines-auto-wrap nil)
381 (message "Auto wrap disabled."))) 382 (message "Auto wrap disabled.")))
382 383
383 (defun longlines-after-change-function (beg end len) 384 (defun longlines-after-change-function (beg end len)
408 (defun longlines-window-change-function () 409 (defun longlines-window-change-function ()
409 "Re-wrap the buffer if the window width has changed. 410 "Re-wrap the buffer if the window width has changed.
410 This is called by `window-configuration-change-hook'." 411 This is called by `window-configuration-change-hook'."
411 (when (/= fill-column (- (window-width) window-min-width)) 412 (when (/= fill-column (- (window-width) window-min-width))
412 (setq fill-column (- (window-width) window-min-width)) 413 (setq fill-column (- (window-width) window-min-width))
413 (let ((mod (buffer-modified-p))) 414 (longlines-wrap-region (point-min) (point-max))))
414 (longlines-wrap-region (point-min) (point-max))
415 (set-buffer-modified-p mod))))
416 415
417 ;; Isearch 416 ;; Isearch
418 417
419 (defun longlines-search-function () 418 (defun longlines-search-function ()
420 (cond 419 (cond