下面的函数名为my-modeline-face-function使Emacs暂停大约半到一秒,我正在寻找一些建议,请显着地提高速度。
它看起来并不多,但是这个函数经常被使用。例如,每次我启用多个游标模式(也称为mc-模式)时,在我开始工作之前,我都会旋转拇指--在退出多个游标模式时也会发生同样的事情。
在函数的尾部添加(redisplay t)无助于提高速度。
按照此函数使用(force-mode-line-update)不会提高速度。
(defun my-modeline-face-function ()
(cond
((minibufferp)
(set-face-attribute 'mode-line nil :height 140 :foreground "gray70"
:background "black" :box '(:line-width 1 :color "black"))
(set-face-attribute 'minibuffer-prompt nil :background "black"
:foreground "cyan" :bold t)
(set (make-local-variable 'face-remapping-alist)
'((default :background "black" :foreground "yellow"))))
(save-as-variable
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "#eab700" :box nil))
(insert-variable
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "orange" :box nil))
((or multi-extract-variable multi-attach-variable)
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "magenta" :box nil))
(open-with-variable
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "ForestGreen" :box nil))
(mc-mode
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "cyan" :box nil))
(isearch-mode
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "yellow" :box nil))
((eq major-mode 'lawlist-calculator-mode)
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "firebrick" :box nil))
(t
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "gray70" :box nil)
(set-face-attribute 'minibuffer-prompt nil
:background "black" :foreground "white"))) )编辑(2014年8月5日):
使用measure-time宏(即http://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087.html ),我验证了set-face-attribute中的函数internal-set-lisp-face-attribute的运行时仅在一秒内发生。然而,我需要整整一秒的时间才能看到视觉效果。无论是函数的初始调用还是相同缓冲区中的后续调用,都是如此。
至于缓冲区内face-remapping-alist的第一次调用,视觉效果会占用我整整一秒的时间。但是,在同一缓冲区中使用face-remapping-alist的后续调用发生在第二个缓冲区的几个部分中。我无法消除在第一次调用之后看到视觉效果所需的时间。这可能是最好的--即,第一次呼叫最多可达1秒,在同一缓冲区内,后续呼叫的光速也是如此。
(defun my-modeline-face-function ()
(cond
((minibufferp)
(set 'face-remapping-alist '(
(mode-line modeline-inactive-face)
(minibuffer-prompt minibuffer-prompt-active-face))) )
(save-as-variable
(set 'face-remapping-alist '((mode-line save-as-modeline-face))))
(insert-variable
(set 'face-remapping-alist '((mode-line insert-modeline-face))))
((or multi-extract-variable multi-attach-variable)
(set 'face-remapping-alist '((mode-line multi-attach-extract-modeline-face))))
(open-with-variable
(set 'face-remapping-alist '((mode-line open-with-modeline-face))))
(mc-mode
(set 'face-remapping-alist '((mode-line mc-modeline-face))))
(isearch-mode
(set 'face-remapping-alist '((mode-line isearch-modeline-face))))
((eq major-mode 'lawlist-calculator-mode)
(set 'face-remapping-alist '((mode-line lawlist-calculator-modeline-face))))
(t
(set 'face-remapping-alist '(
(mode-line modeline-active-face)
(minibuffer-prompt minibuffer-prompt-inactive-face))) )))发布于 2014-08-06 00:53:31
动态地改变面孔将是缓慢的,因为重新显示代码是在假设faces不会改变的前提下编写的(如果它们改变了,我们基本上会重新做大量的工作)。使用face-remapping-alist将带来更好的性能,因为重新显示代码确实期望它发生变化,并且知道如何缓存结果。
https://stackoverflow.com/questions/25109011
复制相似问题