tags:

views:

42

answers:

1

Hi there!

I would like the whole intangible text to be deleted by delete-char and backward-delete-char. Any easy way?

(put-text-property (point-at-bol) (point-at-eol) 'intangible t)

kill-word and backward-kill-word will delete the intangible text, and I'd like the *-char commands to do the same.

In the user interface I am building, some critical text is invisible and intangible. So when user presses DEL (C-d) just after (before) the hidden, intangible text, the whole text should disappear.

Thanks!

A: 

Using an Emacs without any initialization files, and the (put-text... code you provided, I can delete characters at the beginning of the line with M-x delete-char (C-d), and delete characters at the end of the line with M-x backward-delete-char (DEL (well, that's really delete-backward-char)).

Edited upon clarification of question:

These two pieces of advice will delete the entire intangible region:

(defadvice delete-char (around delete-char-intangible activate)
  "when about to delete a char that's intangible, delete the whole region
Only do this when #chars is 1"
  (if (and (= (ad-get-arg 0) 1)
           (get-text-property (point) 'intangible))
      (kill-region (point) (save-excursion (forward-char 1) (point)))
    ad-do-it))

(defadvice delete-backward-char (around delete-backward-char-intangible activate)
  "when about to delete a char that's intangible, delete the whole region
Only do this interactively and when #chars is 1"
  (if (and (= (ad-get-arg 0) 1) (> (point) (point-min))
           (get-text-property (- (point) 1) 'intangible))
      (kill-region (point) (save-excursion (backward-char 1) (point)))
    ad-do-it))

The advice checks to ensure that the command is being called with an argument of 1, and only then will delete the entire intangible region, otherwise it behaves as normal.

Trey Jackson
Sorry for not being very precise. I would like the deletion commands to delete the whole intangible text not onlypart of it. In the user interface I am building, some critical text is invisible and intangible. So when userpresses DEL (C-d) just after (before) the hidden, intangible text the whole text should disappear.Thanks.
VitoshKa
Thanks Trey, it works!
VitoshKa