Emacs根据字体从字符串中删除文本
我通过调用Emacs根据字体从字符串中删除文本,emacs,elisp,substring,font-lock,emacs-faces,Emacs,Elisp,Substring,Font Lock,Emacs Faces,我通过调用缓冲区子字符串得到了一个字符串。有没有办法根据字符串的面设置从字符串中删除文本?作为一个随机的例子: (save-excursion (let ((end (point))) (ignore-errors (while (not (looking-at "[^][ \t\r\n(){}]+:")) (backward-sexp))) 不知道如何突出显示它,但是在Emacs中,保存偏移、让、忽略错误和while都突出显示为关键字,而查看的的regex参数突出显示为字
缓冲区子字符串
得到了一个字符串。有没有办法根据字符串的面设置从字符串中删除文本?作为一个随机的例子:
(save-excursion
(let ((end (point)))
(ignore-errors
(while (not (looking-at "[^][ \t\r\n(){}]+:"))
(backward-sexp)))
不知道如何突出显示它,但是在Emacs中,保存偏移
、让
、忽略错误
和while
都突出显示为关键字,而查看
的的regex参数突出显示为字符串。缓冲区子字符串的返回值如下所示
#(" (save-excursion
(let ((end (point)))
(ignore-errors
(while (not (looking-at \"[^][ \\t\\r\\n(){}]+:\"))
(backward-sexp)))" 0 5 (fontified t) 5 19 (fontified t face font-lock-keyword-face) 19 28 (fontified t) 28 31 (fontified t face font-lock-keyword-face) 31 50 (fontified t) 50 63 (fontified t face font-lock-keyword-face) 63 65 (fontified t) 65 69 (fontified t) 69 74 (fontified t face font-lock-keyword-face) 74 75 (fontified t) 75 92 (fontified t) 92 94 (fontified t face font-lock-string-face) 94 95 (fontified t face (font-lock-negation-char-face font-lock-string-face)) 95 112 (fontified t face font-lock-string-face) 112 115 (fontified t) 115 137 (fontified t))
给定这个示例字符串,我将如何剥离所有具有face
字体锁定关键字face
的内容?也就是说,我想做一些事情,比如
(foo-bar *that-region* 'font-lock-keyword-face)
把它还给我
(
( ((end (point)))
(
( (not (looking-at "[^][ \t\r\n(){}]+:"))
(backward-sexp)))
您必须使用text属性any
查找冒犯面部的开头,而text属性not all
查找其结尾。然后需要迭代
(defun kill-text-with-property (start end property value &optional object)
"Delete the text with the PROPERTY in the part of OBJECT from START and END."
(interactive "r\nsProperty: \nsValue: ")
(let ((delenda ()) (here start))
;; collect the list of regions to kill
;; note that delenda contains the regions in the reverse order so that
;; deleting the later ones do not affect the boundaries of the ealier ones
(while (< here end)
(let ((beg (text-property-any here end property value object))
(stop (and beg (text-property-not-all beg end property value object) end)))
(if (null beg)
(setq here end) ; done
(push (cons beg stop) delenda)
(setq here stop))))
(if (stringp object)
;; collect the complements of delenda into a new string
(....)
;; buffer: kill the delenda regions
(with-current-buffer (or object (current-buffer))
(dolist (pair delenda)
(kill-region (car pair) (cdr pair)))))))
(使用属性(开始-结束属性值和可选对象)定义终止文本)
“从“开始”和“结束”删除对象部分中具有属性的文本。”
(交互式“r\n属性:\n值:”)
(让((delenda())(从这里开始)
收集要杀死的区域的列表
;请注意,delenda以相反的顺序包含区域,以便
删除后面的不会影响前面的边界
(while(<此处结束)
(let((beg(文本属性任意此处结束属性值对象))
(停止(和beg(文本属性并非全部beg结束属性值对象)结束)))
(如果为空)
(此处设置结束);完成
(推动(停止)delenda)
(此处设置停止)
(如果(stringp对象)
;;将delenda的补语收集到一个新字符串中
(....)
;缓冲区:杀死delenda区域
(使用当前缓冲区(或对象(当前缓冲区))
(多利斯特(德兰达对)
(杀伤区(车对)(cdr对‘‘‘‘‘‘‘‘‘‘‘)
remove是什么意思?为什么不在问题中粘贴这样一个字符串的示例?@abo abo-我的意思是“返回一个字符串的副本,其中没有在特定font
face
中突出显示的部分”。