From: Werner LEMBERG <wl@gnu.org>
To: emacs-devel@gnu.org
Subject: I can see invisible characters
Date: Tue, 19 May 2009 08:16:12 +0200 (CEST) [thread overview]
Message-ID: <20090519.081612.200547853.wl@gnu.org> (raw)
[-- 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
next reply other threads:[~2009-05-19 6:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-19 6:16 Werner LEMBERG [this message]
2009-05-19 14:25 ` I can see invisible characters 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090519.081612.200547853.wl@gnu.org \
--to=wl@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.