如何通过删除命令完全删除emacs中的无形文本?

时间:2010-09-29 08:06:45

标签: emacs elisp

我希望delete-charbackward-delete-char删除整个无形文本。有什么简单的方法吗?

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

kill-wordbackward-kill-word会删除无形文本,我希望*-char命令也能这样做。

在我正在构建的用户界面中,一些关键文本是不可见且无形的。因此,当用户在隐藏的无形文本之后(之前)按 DEL C-d )时,整个文本应该消失。

谢谢!

1 个答案:

答案 0 :(得分:1)

使用没有任何初始化文件的Emacs和您提供的(put-text...代码,我可以使用 Mx delete-char 删除行尾的字符( Cd < / kbd>),并删除行尾的字符 Mx backward-delete-char DEL (好吧,那真的是delete-backward-char))。

在澄清问题时编辑

这两条建议将删除整个无形区域:

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

建议检查以确保使用参数1调用命令,然后才会删除整个无形区域,否则它将正常运行。