]> code.delx.au - gnu-emacs/blobdiff - lisp/longlines.el
(fancy-about-text): New variable.
[gnu-emacs] / lisp / longlines.el
index f39d31e69f0471601ff4926d50a64aef2dd5136c..07977910a2213acca65f5a406b3c92b296765f08 100644 (file)
@@ -12,7 +12,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -79,11 +79,13 @@ This is used when `longlines-show-hard-newlines' is on."
 (defvar longlines-wrap-end nil)
 (defvar longlines-wrap-point nil)
 (defvar longlines-showing nil)
+(defvar longlines-decoded nil)
 
 (make-variable-buffer-local 'longlines-wrap-beg)
 (make-variable-buffer-local 'longlines-wrap-end)
 (make-variable-buffer-local 'longlines-wrap-point)
 (make-variable-buffer-local 'longlines-showing)
+(make-variable-buffer-local 'longlines-decoded)
 
 ;; Mode
 
@@ -128,7 +130,9 @@ are indicated with a symbol."
           ;; longlines-wrap-lines that we'll never encounter from here
          (save-restriction
            (widen)
-           (longlines-decode-buffer)
+           (unless longlines-decoded
+             (longlines-decode-buffer)
+             (setq longlines-decoded t))
            (longlines-wrap-region (point-min) (point-max)))
           (set-buffer-modified-p mod))
         (when (and longlines-show-hard-newlines
@@ -161,9 +165,11 @@ are indicated with a symbol."
     (let ((buffer-undo-list t)
          (after-change-functions nil)
           (inhibit-read-only t))
-      (save-restriction
-       (widen)
-       (longlines-encode-region (point-min) (point-max))))
+      (if longlines-decoded
+         (save-restriction
+           (widen)
+           (longlines-encode-region (point-min) (point-max))
+           (setq longlines-decoded nil))))
     (remove-hook 'change-major-mode-hook 'longlines-mode-off t)
     (remove-hook 'after-change-functions 'longlines-after-change-function t)
     (remove-hook 'post-command-hook 'longlines-post-command-function t)
@@ -223,16 +229,18 @@ With optional argument ARG, make the hard newlines invisible again."
   "Wrap each successive line, starting with the line before BEG.
 Stop when we reach lines after END that don't need wrapping, or the
 end of the buffer."
-  (setq longlines-wrap-point (point))
-  (goto-char beg)
-  (forward-line -1)
-  ;; Two successful longlines-wrap-line's in a row mean successive
-  ;; lines don't need wrapping.
-  (while (null (and (longlines-wrap-line)
-                    (or (eobp)
-                        (and (>= (point) end)
-                             (longlines-wrap-line))))))
-  (goto-char longlines-wrap-point))
+  (let ((mod (buffer-modified-p)))
+    (setq longlines-wrap-point (point))
+    (goto-char beg)
+    (forward-line -1)
+    ;; Two successful longlines-wrap-line's in a row mean successive
+    ;; lines don't need wrapping.
+    (while (null (and (longlines-wrap-line)
+                     (or (eobp)
+                         (and (>= (point) end)
+                              (longlines-wrap-line))))))
+    (goto-char longlines-wrap-point)
+    (set-buffer-modified-p mod)))
 
 (defun longlines-wrap-line ()
   "If the current line needs to be wrapped, wrap it and return nil.
@@ -368,14 +376,13 @@ Hard newlines are left intact."
 With optional argument ARG, turn on line wrapping if and only if ARG is positive.
 If automatic line wrapping is turned on, wrap the entire buffer."
   (interactive "P")
-  (and (null arg)
-       (null longlines-auto-wrap)
-       (setq arg 1))
-  (if (> (prefix-numeric-value arg) 0)
-      (let ((mod (buffer-modified-p)))
+  (setq arg (if arg
+               (> (prefix-numeric-value arg) 0)
+             (not longlines-auto-wrap)))
+  (if arg
+      (progn
        (setq longlines-auto-wrap t)
        (longlines-wrap-region (point-min) (point-max))
-       (set-buffer-modified-p mod)
        (message "Auto wrap enabled."))
     (setq longlines-auto-wrap nil)
     (message "Auto wrap disabled.")))
@@ -410,9 +417,7 @@ This is called by `post-command-hook' after each command."
 This is called by `window-configuration-change-hook'."
   (when (/= fill-column (- (window-width) window-min-width))
     (setq fill-column (- (window-width) window-min-width))
-    (let ((mod (buffer-modified-p)))
-      (longlines-wrap-region (point-min) (point-max))
-      (set-buffer-modified-p mod))))
+    (longlines-wrap-region (point-min) (point-max))))
 
 ;; Isearch