unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* I can see invisible characters
@ 2009-05-19  6:16 Werner LEMBERG
  2009-05-19 14:25 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Werner LEMBERG @ 2009-05-19  6:16 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: Text/Plain, Size: 640 bytes --]

[Emacs CVS 2009-05-13]

0. Start `emacs -Q'.

1. Do `M-x load-file line-invisible.el' (this assigns
   `make-lines-invisible' to `C-c z').

2. Load file `w' with `C-x C-f w'.

3. Do `C-c z ·' (this is, make all lines invisible which contain a
   middle dot).

4. Do `C-u C-x =': The first visible character in the buffer has set
   the `invisible' property.  It seems to be a bug that I can see that
   character.  It has also set the `intangible' property, and I can
   move the cursor on top of it (with the arrow keys, but not with
   C-a).  This doesn't look right too...

   An off-by-one error?


     Werner


[-- Attachment #2: w --]
[-- Type: Application/Octet-Stream, Size: 390 bytes --]

Aachen;Aa·chen
Aachener;Aa·che·ner
Aachenerin;Aa·che·ne·rin
Aachenern;Aa·che·nern
Aacheners;Aa·che·ners
Aachens;Aa·chens
Aadorf;Aa·dorf
Aalbauer;Aal=bau-er
Aalbeck;Aal·beck
Aalbestand;Aal=be-stand
Aalbestände;Aal=be-stän-de
Aalborg;Aal-borg
Aalborger;Aal=bor-ger
Aalders;Aal·ders
Aale;Aa-le
Aalen;Aa-len
Aalener;Aa-le-ner
Aalenern;Aa-le-nern
Aaleners;Aa-le-ners
Aalens;Aa-lens
Aaler;Aa-ler

[-- Attachment #3: line-invisible.el --]
[-- Type: Text/Plain, Size: 3818 bytes --]

;;; line-invisible.el
;;;
;;; Werner Lemberg, April 2009


;; from font-lock.el
(defmacro save-buffer-state (varlist &rest body)
  "Bind variables according to VARLIST and eval BODY restoring
buffer state."
  (declare (indent 1) (debug let))
  (let ((modified (make-symbol "modified")))
    `(let* ,(append varlist
		    `((,modified (buffer-modified-p))
		      (buffer-undo-list t)
		      (inhibit-read-only t)
		      (inhibit-point-motion-hooks t)
		      (inhibit-modification-hooks t)
		      deactivate-mark
		      buffer-file-name
		      buffer-file-truename))
       (unwind-protect
	   (progn
	     ,@body)
	 (unless ,modified
	   (restore-buffer-modified-p nil))))))

(defun make-lines-invisible (regexp &optional arg)
  "Make all lines matching a regexp invisible and intangible.
With a prefix arg, make them visible again.  It is not necessary
that REGEXP matches the whole line; if a hit is found, the
affected line gets automatically selected.

This function always applies to the whole buffer.

Note that this function modifies the `invisible' and `intangible'
text properties; it may thus interfere with modes which use them.
Due to implementation restrictions in current Emacs versions it
is not possible to use overlays -- which would avoid text
property modifications -- without becoming unbearably slow for
large buffers with many matches."
  (interactive "MLine matching regexp: \nP")
  (save-excursion
    (cond
     (arg
      (save-buffer-state ((next-pos (point-min)))
	(while (setq next-pos
		     (text-property-any next-pos
					(point-max)
					'make-lines-invisible
					t))
	  (goto-char next-pos)
	  (setq next-pos (or (next-single-property-change
			      (point)
			      'make-lines-invisible)
			     (point-max)))
	  (remove-list-of-text-properties (point)
					  next-pos
					  '(make-lines-invisible
					    invisible
					    intangible)))))
    (t
     (save-buffer-state ((start 0)
			 (end 0))
       (goto-char (point-min))
       (while (re-search-forward regexp nil t)
	 (setq start (match-beginning 0))
	 (goto-char start)
	 (setq start (line-beginning-position))
	 (setq end (match-end 0))
	 (goto-char end)
	 (setq end (1+ (line-end-position))) ; handle \n
	 (add-text-properties start
			      end
			      '(make-lines-invisible t
				invisible t
				intangible t))
	 (goto-char (line-end-position))))))))

(defun make-other-lines-invisible (regexp)
  "Make all lines not matching a regexp invisible and intangible.
It is not necessary that REGEXP matches the whole line; if a hit
is found, the affected line gets automatically unselected.

This function always applies to the whole buffer.

Note that this function modifies the `invisible' and `intangible'
text properties; it may thus interfere with modes which use them.
Due to implementation restrictions in current Emacs versions it
is not possible to use overlays -- which would avoid text
property modifications -- without becoming unbearably slow for
large buffers with many matches."
  (interactive "MLine matching regexp: \n")
  (save-excursion
    (save-buffer-state ((start 1)
			(end 1))
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
	(setq end (match-beginning 0))
	(goto-char end)
	(setq end (1- (line-beginning-position))) ; handle \n
	(if (<= start end)
	    (add-text-properties start
				 end
				 '(make-lines-invisible t
				   invisible t
				   intangible t)))
	(setq start (match-end 0))
	(goto-char start)
	(setq start (line-end-position))
	(goto-char (line-end-position)))
      (setq end (point-max))
      (if (< start end)
	  (add-text-properties start
			       end
			       '(make-lines-invisible t
				 invisible t
				 intangible t))))))

(global-set-key "\C-cz" 'make-lines-invisible)
(global-set-key "\C-cZ" 'make-other-lines-invisible)

;; eof

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: I can see invisible characters
@ 2009-05-20 20:49 grischka
  2009-05-21  0:32 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: grischka @ 2009-05-20 20:49 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

Stefan Monnier wrote:
 > In your case, the property is not front-sticky, so point can be at
 > beginning of the intangible span, i.e. at BOB.

But note that even both "front sticky" and "intangible" set on
the topmost area don't prevent point from going to BOB.

--- grischka




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-05-22 12:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-19  6:16 I can see invisible characters Werner LEMBERG
2009-05-19 14:25 ` Stefan Monnier
2009-05-20  6:03   ` Werner LEMBERG
2009-05-20 18:17     ` Stefan Monnier
2009-05-21  4:02       ` Werner LEMBERG
2009-05-21 14:05         ` Stefan Monnier
2009-05-21 18:03           ` Werner LEMBERG
2009-05-22  5:33           ` Werner LEMBERG
  -- strict thread matches above, loose matches on Subject: below --
2009-05-20 20:49 grischka
2009-05-21  0:32 ` Stefan Monnier
2009-05-21 18:02   ` grischka
2009-05-22  1:25     ` Stefan Monnier
2009-05-22 12:14       ` grischka

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).