我有文件,其中某些部分(线)是固定宽度,其他部分是自由文本。
固定宽度线的格式有点像表格。
每行具有一定数量的字段,每个字段具有固定长度(以字符为单位)。
编辑这些行时,应使用与overwrite-mode
类似的内容。
我正在尝试弄清楚如何在Emacs Lisp中解决这个问题。
这是我到目前为止所做的:
(defun test-overlay ()
(interactive)
(let ((ovl (make-overlay 1 5 (current-buffer) t t)))
(overlay-put ovl 'face '(:background "grey50"))
(overlay-put ovl 'intangible t)
))
overwrite-mode
?也就是说,在右边添加文本时,叠加不应该展开。 输入文本时,叠加层中的文本应向左移动,左边缘的文本将被删除(删除)。在右边缘按删除应该删除右边的字符,在左边的空格中移动..
答案 0 :(得分:4)
不使用叠加层,而是使用文本属性 ---特别是文本属性read-only
。对于要写入的文本,将其值设置为nil
,将非nil
的值设置为您希望为只读的文本。 (没有read-only
重叠属性。)
来自(elisp) Special Properties
:
`read-only'
If a character has the property `read-only', then modifying that
character is not allowed. Any command that would do so gets an
error, `text-read-only'. If the property value is a string, that
string is used as the error message.
Insertion next to a read-only character is an error if inserting
ordinary text there would inherit the `read-only' property due to
stickiness. Thus, you can control permission to insert next to
read-only text by controlling the stickiness. *Note Sticky
Properties::.
Since changing properties counts as modifying the buffer, it is not
possible to remove a `read-only' property unless you know the
special trick: bind `inhibit-read-only' to a non-`nil' value and
then remove the property. *Note Read Only Buffers::.
答案 1 :(得分:1)
您需要使用modification-hooks
属性。这可以让你做与after-change-functions
相同的事情,从而指定你正在寻找的确切行为。