comparison lisp/longlines.el @ 78447:65140a5dc349

(longlines-decoded): New variable. (longlines-mode): Avoid encoding or decoding the buffer twice.
author Chong Yidong <cyd@stupidchicken.com>
date Tue, 07 Aug 2007 16:08:39 +0000
parents 9355f9b7bbff
children 3516a7d8862b
comparison
equal deleted inserted replaced
78446:8b571462df23 78447:65140a5dc349
77 77
78 (defvar longlines-wrap-beg nil) 78 (defvar longlines-wrap-beg nil)
79 (defvar longlines-wrap-end nil) 79 (defvar longlines-wrap-end nil)
80 (defvar longlines-wrap-point nil) 80 (defvar longlines-wrap-point nil)
81 (defvar longlines-showing nil) 81 (defvar longlines-showing nil)
82 (defvar longlines-decoded nil)
82 83
83 (make-variable-buffer-local 'longlines-wrap-beg) 84 (make-variable-buffer-local 'longlines-wrap-beg)
84 (make-variable-buffer-local 'longlines-wrap-end) 85 (make-variable-buffer-local 'longlines-wrap-end)
85 (make-variable-buffer-local 'longlines-wrap-point) 86 (make-variable-buffer-local 'longlines-wrap-point)
86 (make-variable-buffer-local 'longlines-showing) 87 (make-variable-buffer-local 'longlines-showing)
88 (make-variable-buffer-local 'longlines-decoded)
87 89
88 ;; Mode 90 ;; Mode
89 91
90 ;;;###autoload 92 ;;;###autoload
91 (define-minor-mode longlines-mode 93 (define-minor-mode longlines-mode
126 ;; Turning off undo is OK since (spaces + newlines) is 128 ;; Turning off undo is OK since (spaces + newlines) is
127 ;; conserved, except for a corner case in 129 ;; conserved, except for a corner case in
128 ;; longlines-wrap-lines that we'll never encounter from here 130 ;; longlines-wrap-lines that we'll never encounter from here
129 (save-restriction 131 (save-restriction
130 (widen) 132 (widen)
131 (longlines-decode-buffer) 133 (unless longlines-decoded
134 (longlines-decode-buffer)
135 (setq longlines-decoded t))
132 (longlines-wrap-region (point-min) (point-max))) 136 (longlines-wrap-region (point-min) (point-max)))
133 (set-buffer-modified-p mod)) 137 (set-buffer-modified-p mod))
134 (when (and longlines-show-hard-newlines 138 (when (and longlines-show-hard-newlines
135 (not longlines-showing)) 139 (not longlines-showing))
136 (longlines-show-hard-newlines)) 140 (longlines-show-hard-newlines))
159 (if longlines-showing 163 (if longlines-showing
160 (longlines-unshow-hard-newlines)) 164 (longlines-unshow-hard-newlines))
161 (let ((buffer-undo-list t) 165 (let ((buffer-undo-list t)
162 (after-change-functions nil) 166 (after-change-functions nil)
163 (inhibit-read-only t)) 167 (inhibit-read-only t))
164 (save-restriction 168 (if longlines-decoded
165 (widen) 169 (save-restriction
166 (longlines-encode-region (point-min) (point-max)))) 170 (widen)
171 (longlines-encode-region (point-min) (point-max))
172 (setq longlines-decoded nil))))
167 (remove-hook 'change-major-mode-hook 'longlines-mode-off t) 173 (remove-hook 'change-major-mode-hook 'longlines-mode-off t)
168 (remove-hook 'after-change-functions 'longlines-after-change-function t) 174 (remove-hook 'after-change-functions 'longlines-after-change-function t)
169 (remove-hook 'post-command-hook 'longlines-post-command-function t) 175 (remove-hook 'post-command-hook 'longlines-post-command-function t)
170 (remove-hook 'before-revert-hook 'longlines-before-revert-hook t) 176 (remove-hook 'before-revert-hook 'longlines-before-revert-hook t)
171 (remove-hook 'window-configuration-change-hook 177 (remove-hook 'window-configuration-change-hook