我的问题是我使用(set-buffer (find-tag-noselect (current-word)))
打开一个缓冲区,然后我尝试从该缓冲区中复制一些文本。我得到的文本只有(fontified nil)
属性。 find-tag-noselect
会自动打开TAGS文件中找到的缓冲区,但它似乎没有对其运行字体锁定模式。当我打开后手动切换到此缓冲区,然后在复制文本时再次运行该函数时,它附加了所有正确的文本属性。那么我需要做什么才能完全初始化这个缓冲区,以便复制正确的语法高亮?
(defvar newline-string "
")
(defun get-initial-indent-regexp-python()
"Gets the initial amount of spaces for the function we are looking at, does not account for tabs"
(concat "^" (get-current-indent-string) (concat "[^ #" newline-string "]")))
(defun get-end-of-function-python(spaces-regex)
"Gets the point at the end of a python block"
(save-excursion
(forward-line 1)
(while (and (not (looking-at spaces-regex)) (equal (forward-line 1) 0)))
(point)))
(defun get-point-at-end-of-function ()
"This might be better served checking the major mode."
(setq extension (file-name-extension (buffer-file-name)))
(if (equal extension "py")
(get-end-of-function-python (get-initial-indent-regexp-python))))
(defun inline-function ()
"Must change to overlays, be able to toggle visibility"
(interactive)
(let (text indent-string)
; clean all overlays without attached buffer
(save-excursion
(set-buffer (find-tag-noselect (current-word)))
(setq text (buffer-substring (point) (get-point-at-end-of-function))))
(setq text (concat newline-string text))
(save-excursion
(move-end-of-line nil)
(let (overlay)
(setq overlay (make-overlay (point) (+ (point) 1) (current-buffer)))
(overlay-put overlay 'display text)
(setq inline-func-overlays (cons overlay inline-func-overlays))))))
答案 0 :(得分:2)
正在发生的是字体锁是即时完成的,因此只有缓冲区的显示部分才会“完成”。如果您希望/需要否决此优化,则根据具体情况需要不同的功能(取决于如何配置字体锁定)。我们应该为它添加一个新的font-lock-ensure-fontified函数,但同时你可以把ps-print-.el作为例子:
(defun ps-print-ensure-fontified (start end)
(cond ((and (boundp 'jit-lock-mode) (symbol-value 'jit-lock-mode))
(jit-lock-fontify-now start end))
((and (boundp 'lazy-lock-mode) (symbol-value 'lazy-lock-mode))
(lazy-lock-fontify-region start end))))
答案 1 :(得分:0)
我不确定你要做什么,但是set-buffer没有显示缓冲区,因此当当前命令终止时它的效果结束。它通常只对函数内的临时缓冲区开关有用,我想这就是它不在缓冲区上运行字体锁的原因。当您手动转到缓冲区时,您可能正在使用不同的功能 - 切换到缓冲区。
答案 2 :(得分:0)
尝试显式调用'font-lock-fontify-buffer'。