]> code.delx.au - gnu-emacs/blobdiff - lisp/longlines.el
* menu-bar.el (menu-bar-help-menu): Rename "psychiatrist", in line
[gnu-emacs] / lisp / longlines.el
index c6de1d2347e4bf8468cda5a9fc8e87ea04ded772..00a2782d0a38ab96391b6a1221296d8a452cbd5e 100644 (file)
@@ -1,6 +1,6 @@
 ;;; longlines.el --- automatically wrap long lines
 
-;; Copyright (C) 2000, 2001, 2004, 2005 by Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
 
 ;; Authors:    Kai Grossjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>
 ;;             Alex Schroeder <alex@gnu.org>
@@ -22,8 +22,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -109,6 +109,8 @@ are indicated with a symbol."
         (add-to-list 'buffer-file-format 'longlines)
         (add-hook 'change-major-mode-hook 'longlines-mode-off nil t)
         (make-local-variable 'buffer-substring-filters)
+       (set (make-local-variable 'isearch-search-fun-function)
+            'longlinges-search-function)
         (add-to-list 'buffer-substring-filters 'longlines-encode-string)
         (when longlines-wrap-follows-window-size
           (set (make-local-variable 'fill-column)
@@ -116,6 +118,7 @@ are indicated with a symbol."
           (add-hook 'window-configuration-change-hook
                     'longlines-window-change-function nil t))
         (let ((buffer-undo-list t)
+              (inhibit-read-only t)
               (mod (buffer-modified-p)))
           ;; Turning off undo is OK since (spaces + newlines) is
           ;; conserved, except for a corner case in
@@ -136,7 +139,8 @@ are indicated with a symbol."
     (setq buffer-file-format (delete 'longlines buffer-file-format))
     (if longlines-showing
         (longlines-unshow-hard-newlines))
-    (let ((buffer-undo-list t))
+    (let ((buffer-undo-list t)
+          (inhibit-read-only t))
       (longlines-encode-region (point-min) (point-max)))
     (remove-hook 'change-major-mode-hook 'longlines-mode-off t)
     (remove-hook 'before-kill-functions 'longlines-encode-region t)
@@ -144,7 +148,12 @@ are indicated with a symbol."
     (remove-hook 'post-command-hook 'longlines-post-command-function t)
     (remove-hook 'window-configuration-change-hook
                  'longlines-window-change-function t)
-    (kill-local-variable 'fill-column)))
+    (when longlines-wrap-follows-window-size
+      (kill-local-variable 'fill-column))
+    (kill-local-variable 'isearch-search-fun-function)
+    (kill-local-variable 'require-final-newline)
+    (kill-local-variable 'buffer-substring-filters)
+    (kill-local-variable 'use-hard-newlines)))
 
 (defun longlines-mode-off ()
   "Turn off longlines mode.
@@ -170,20 +179,20 @@ With optional argument ARG, make the hard newlines invisible again."
   "Make hard newlines between BEG and END visible."
   (let* ((pmin (min beg end))
          (pmax (max beg end))
-         (pos (text-property-any pmin pmax 'hard t)))
+         (pos (text-property-not-all pmin pmax 'hard nil)))
     (while pos
       (put-text-property pos (1+ pos) 'display
                          (copy-sequence longlines-show-effect))
-      (setq pos (text-property-any (1+ pos) pmax 'hard t)))))
+      (setq pos (text-property-not-all (1+ pos) pmax 'hard nil)))))
 
 (defun longlines-unshow-hard-newlines ()
   "Make hard newlines invisible again."
   (interactive)
   (setq longlines-showing nil)
-  (let ((pos (text-property-any (point-min) (point-max) 'hard t)))
+  (let ((pos (text-property-not-all (point-min) (point-max) 'hard nil)))
     (while pos
       (remove-text-properties pos (1+ pos) '(display))
-      (setq pos (text-property-any (1+ pos) (point-max) 'hard t)))))
+      (setq pos (text-property-not-all (1+ pos) (point-max) 'hard nil)))))
 
 ;; Wrapping the paragraphs.
 
@@ -375,6 +384,27 @@ This is called by `window-size-change-functions'."
       (longlines-wrap-region (point-min) (point-max))
       (set-buffer-modified-p mod))))
 
+;; Isearch
+
+(defun longlinges-search-function ()
+  (cond
+   (isearch-word
+    (if isearch-forward 'word-search-forward 'word-search-backward))
+   (isearch-regexp
+    (if isearch-forward 're-search-forward 're-search-backward))
+   (t
+    (if isearch-forward
+       'longlines-search-forward
+      'longlines-search-backward))))
+
+(defun longlines-search-forward (string &optional bound noerror count)
+  (let ((search-spaces-regexp "[ \n]+"))
+    (re-search-forward (regexp-quote string) bound noerror count)))
+
+(defun longlines-search-backward (string &optional bound noerror count)
+  (let ((search-spaces-regexp "[ \n]+"))
+    (re-search-backward (regexp-quote string) bound noerror count)))
+
 ;; Loading and saving
 
 (add-to-list