删除文本属性似乎不会影响“显示”文本 属性
remove-text-properties doesn't seem to affect `display` text property
我很困惑为什么使用 remove-text-properties
删除 display
文本 属性 不会更改缓冲区中的显示。相反,我似乎必须使用 set-text-properties
到 nil
完全删除所有文本属性。例如,为什么 remove-text-properties
不能代替 set-text-properties
在这里工作:
(defvar my-regex "#\([[:alnum:]]+\) \([0-9]+\)")
(defvar-local my--fontified-p nil)
(defun my-remove-display ()
"Remove the display, eg. '#blah<2020>' -> '#blah 2020."
(save-excursion
(goto-char (point-min))
(while (re-search-forward my-regex nil 'move)
;; why can't I use remove-text-properties here to get rid of 'display?
(set-text-properties (match-beginning 0) (match-end 0) nil))))
(defun my-toggle-display ()
"Toggle font-locking and display of '#blah 2020'."
(interactive)
(if (setq my--fontified-p (not my--fontified-p))
(progn
(font-lock-add-keywords
nil
`((,my-regex
(0 (prog1 nil
(put-text-property
(1+ (match-beginning 0)) (match-end 0)
'display
(format "%s<%s>"
(match-string-no-properties 1)
(match-string-no-properties 2)))))
(0 'font-lock-constant-face t))))
(font-lock-flush)
(font-lock-ensure))
(my-remove-display)
(font-lock-refresh-defaults)))
;;; Example that gets fontified
;; #blah 2020
对我有用:
(defun my-remove-display ()
"Remove the display, eg. '#blah<2020>' -> '#blah 2020."
(save-excursion
(goto-char (point-min))
(while (re-search-forward my-regex nil 'move)
(remove-text-properties (match-beginning 0) (match-end 0) '(display)))))
您没有显示您尝试过的 remove-text-properties
代码。这是你试过的吗?您是否传递了 'display
而不是 '(display)
?
我很困惑为什么使用 remove-text-properties
删除 display
文本 属性 不会更改缓冲区中的显示。相反,我似乎必须使用 set-text-properties
到 nil
完全删除所有文本属性。例如,为什么 remove-text-properties
不能代替 set-text-properties
在这里工作:
(defvar my-regex "#\([[:alnum:]]+\) \([0-9]+\)")
(defvar-local my--fontified-p nil)
(defun my-remove-display ()
"Remove the display, eg. '#blah<2020>' -> '#blah 2020."
(save-excursion
(goto-char (point-min))
(while (re-search-forward my-regex nil 'move)
;; why can't I use remove-text-properties here to get rid of 'display?
(set-text-properties (match-beginning 0) (match-end 0) nil))))
(defun my-toggle-display ()
"Toggle font-locking and display of '#blah 2020'."
(interactive)
(if (setq my--fontified-p (not my--fontified-p))
(progn
(font-lock-add-keywords
nil
`((,my-regex
(0 (prog1 nil
(put-text-property
(1+ (match-beginning 0)) (match-end 0)
'display
(format "%s<%s>"
(match-string-no-properties 1)
(match-string-no-properties 2)))))
(0 'font-lock-constant-face t))))
(font-lock-flush)
(font-lock-ensure))
(my-remove-display)
(font-lock-refresh-defaults)))
;;; Example that gets fontified
;; #blah 2020
对我有用:
(defun my-remove-display ()
"Remove the display, eg. '#blah<2020>' -> '#blah 2020."
(save-excursion
(goto-char (point-min))
(while (re-search-forward my-regex nil 'move)
(remove-text-properties (match-beginning 0) (match-end 0) '(display)))))
您没有显示您尝试过的 remove-text-properties
代码。这是你试过的吗?您是否传递了 'display
而不是 '(display)
?