unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Getting rid of selective display in allout.el
@ 2005-12-19  0:00 Stefan Monnier
  0 siblings, 0 replies; only message in thread
From: Stefan Monnier @ 2005-12-19  0:00 UTC (permalink / raw)
  Cc: emacs-devel


Here is a 100% untested patch to allout.el that I expect to be a good start
to getting rid of selective-display in allout.el.

I don't have time to understand the code to really fix things properly, but
that should give you enough of an idea.  It took me at most 15min to come
up with the patch below.

It'd be great to get this finished and included in Emacs-22.


        Stefan


--- allout.el	02 déc 2005 14:04:20 -0500	1.64
+++ allout.el	18 déc 2005 18:56:12 -0500	
@@ -1465,7 +1465,7 @@
 	  (progn
 	   (allout-resumptions 'allout-primary-bullet)
 	   (allout-resumptions 'allout-old-style-prefixes)))
-      (allout-resumptions 'selective-display)
+      (remove-from-invisibility-spec '(allout . t))
       (if (and (boundp 'before-change-functions) before-change-functions)
 	  (allout-resumptions 'before-change-functions))
       (set write-file-hook-var-name
@@ -1528,7 +1528,7 @@
 				       ; selective-display is the
 				       ; emacs conditional exposure
 				       ; mechanism:
-      (allout-resumptions 'selective-display '(t))
+      (add-to-invisibility-spec '(allout . t))
       (add-hook 'pre-command-hook 'allout-pre-command-business)
       (add-hook 'post-command-hook 'allout-post-command-business)
       (add-hook write-file-hook-var-name 'allout-write-file-hook-handler)
@@ -1687,16 +1687,13 @@
 		       (looking-at allout-regexp))
        (= (point)(save-excursion (allout-end-of-prefix)(point)))))
 ;;;_    > allout-hidden-p ()
-(defmacro allout-hidden-p ()
+(defun allout-hidden-p ()
   "True if point is in hidden text."
-  '(save-excursion
-     (and (re-search-backward "[\n\r]" () t)
-	  (= ?\r (following-char)))))
+  (eq (get-char-property (point) 'invisible) 'allout))
 ;;;_    > allout-visible-p ()
-(defmacro allout-visible-p ()
+(defun allout-visible-p ()
   "True if point is not in hidden text."
-  (interactive)
-  '(not (allout-hidden-p)))
+  (not (allout-hidden-p)))
 ;;;_   : Location attributes
 ;;;_    > allout-depth ()
 (defsubst allout-depth ()
@@ -1954,7 +1951,7 @@
 	    (if further (setq result (append further result)))
 	    (setq chart (cdr chart)))
 	(goto-char here)
-	(if (= (preceding-char) ?\r)
+	(if (allout-hidden-p)
 	    (setq result (cons here result)))
 	(setq chart (cdr chart))))
     result))
@@ -2922,7 +2919,8 @@
 		(if before
 		    (progn (end-of-line)
 			   (allout-pre-next-preface)
-			   (while (= ?\r (following-char))
+			   (while (and (= ?\n (following-char))
+                                       (allout-hidden-p))
                              (forward-char 1))
 			   (if (not (looking-at "^$"))
 			       (allout-unprotected
@@ -3741,53 +3739,18 @@
 next C-j (newline) char.
 
 Returns the endpoint of the region."
-  ;; "OFR-" prefixes to avoid collisions with vars in code calling the macro.
-  ;; ie, elisp macro vars are not 'hygenic', so distinct names are necessary.
-  (let ((was-inhibit-r-o inhibit-read-only)
-        (was-undo-list buffer-undo-list)
-        (was-modified (buffer-modified-p))
-        trans)
-    (unwind-protect
-     (save-excursion
-       (setq inhibit-read-only t)
-       (setq buffer-undo-list t)
-       (if (> from to)
-           (setq trans from from to to trans))
-       (subst-char-in-region from to
-                             (if (= flag ?\n) ?\r ?\n)
-                             flag t)
-       ;; adjust character read-protection on all the affected lines.
-       ;; we handle the region line-by-line.
-       (goto-char to)
-       (end-of-line)
-       (setq to (min (+ 2 (point)) (point-max)))
+  (if (> from to) (setq trans from from to to trans))
+  (remove-overlays from to)
+  (when (eq flag ?\r)
+    (save-excursion
        (goto-char from)
-       (beginning-of-line)
-       (while (< (point) to)
-         ;; handle from start of exposed to beginning of hidden, or eol:
-         (remove-text-properties (point)
-                                 (progn (if (re-search-forward "[\r\n]"
-                                                               nil t)
-                                            (forward-char -1))
-                                        (point))
-                                 '(read-only nil))
-         ;; handle from start of hidden, if any, to eol:
-         (if (and (not (eobp)) (= (char-after (point)) ?\r))
-             (put-text-property (point) (progn (end-of-line) (point))
-                                'read-only t))
-         ;; Handle the end-of-line to beginning of next line:
-         (if (not (eobp))
-             (progn (forward-char 1)
-                    (remove-text-properties (1- (point)) (point)
-                                            '(read-only nil)))))
-       )
-     (if (not was-modified)
-         (set-buffer-modified-p nil))
-     (setq inhibit-read-only was-inhibit-r-o)
-     (setq buffer-undo-list was-undo-list)
-     )
-    )
-  )
+      (end-of-line)
+      (let ((ol (make-overlay (point) (progn (goto-char to) (end-of-line) (point)))))
+        (overlay-put ol 'invisible 'allout)
+        ;; This won't work until we implement allout-isearch-open-invisible.
+        (overlay-put ol 'isearch-open-invisible 'allout-isearch-open-invisible)
+        (overlay-put ol 'read-only t)))))
+
 ;;;_   > allout-flag-current-subtree (flag)
 (defun allout-flag-current-subtree (flag)
   "Hide or show subtree of currently-visible topic.
@@ -3815,7 +3778,7 @@
     (let ((at (point))
 	  beg end)
       (allout-goto-prefix)
-      (setq beg (if (= (preceding-char) ?\r) (1- (point)) (point)))
+      (setq beg (if (allout-hidden-p) (1- (point)) (point)))
       (re-search-forward "[\n\r]" nil t)
       (setq end (1- (if (< at (point))
 			;; We're on topic head line - show only it:
@@ -3859,7 +3822,7 @@
 		 (chart (allout-chart-subtree (or level 1)))
 		 (to-reveal (allout-chart-to-reveal chart (or level 1))))
 	    (goto-char start-pt)
-	    (if (and strict (= (preceding-char) ?\r))
+	    (if (and strict (allout-hidden-p)
 		;; Concealed root would already have been taken care of,
 		;; unless strict was set.
 		(progn
@@ -3885,7 +3848,7 @@
     (allout-goto-prefix)
     (allout-flag-region (if (not (bobp)) (1- (point)) (point))
                          (progn (allout-pre-next-preface)
-                                (if (= ?\r (following-char))
+                                (if (allout-hidden-p)
                                     (point)
                                   (1- (point))))
                          ?\r)))
@@ -3902,7 +3865,7 @@
 	  (orig-pref (allout-goto-prefix))
 	  (last-at (point))
 	  bag-it)
-      (while (or bag-it (= (preceding-char) ?\r))
+      (while (or bag-it (allout-hidden-p)
 	(beginning-of-line)
 	(if (= last-at (setq last-at (point)))
 	    ;; Oops, we're not making any progress!  Show the current
@@ -3954,7 +3917,7 @@
     (allout-goto-prefix)
     (allout-flag-region (if (not (bobp)) (1- (point)) (point))
                          (progn (allout-pre-next-preface)
-                                (if (= ?\r (following-char))
+                                (if (allout-hidden-p)
                                     (point)
                                   (1- (point))))
                          ?\r)))
@@ -4423,7 +4386,7 @@
 					 (save-excursion (end-of-line)
 							 (point))
 					 1)
-			 (if (= (preceding-char) ?\r)
+			 (if (allout-hidden-p)
 			     (1- (point))
 			   (point))))
 		      strings))

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-12-19  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-19  0:00 Getting rid of selective display in allout.el Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).