开发者

How to make intangible text in emacs to be completely removed by deletion commands?

I would like the whol开发者_如何转开发e 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜