如何加速Emacs中的自定义模式行面部更改功能 [英] How to speed-up a custom mode-line face change function in Emacs

查看:104
本文介绍了如何加速Emacs中的自定义模式行面部更改功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下名为 my-modeline-face-function 的函数使Emacs暂停大约一半至一整秒,我正在寻找一些建议。可以大大提高速度。

The following function named my-modeline-face-function causes Emacs to pause for approximately one-half to one full second, and I'm looking for some suggestions please to significantly increase the speed.

它看起来并不多,但是使用了很多功能。例如,每次启用多光标模式(又称为mc-mode)时,我最终都会在不知所措之前就开始打了个手势-退出多光标模式时也会发生同样的事情。

It doesn't seem like much, but this function is used a lot. For example, every time I enable multiple-cursors mode (aka mc-mode), I end up twiddling my thumbs before I can get down to business -- the same thing happens when exiting multiple-cursors mode.

在函数的末尾添加(重新显示t)并没有提高速度。

Adding (redisplay t) at the tail end of the function does nothing to increase the speed.

使用(强制模式行更新)不会提高速度。

(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日):


EDIT (August 5, 2014):

●使用测量时间宏(即 http://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087 .html ),我验证了 set-face中函数 internal-set-lisp-face-attribute 的运行时-attribute 仅在几分之一秒内发生。但是,我最多需要一整秒钟才能看到视觉效果。无论是函数的初始调用还是同一缓冲区中的后续调用,都是如此。

● Using a measure-time macro (i.e., http://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087.html ), I verified that the run-time for the function internal-set-lisp-face-attribute within set-face-attribute occurs within mere fractions of a second. However, it takes up to one full second for me to see the visual effect. The same holds true whether it is the initial call of the function or subsequent calls within the same buffer.

●关于 face的第一次调用-remapping-alist 在缓冲区中,视觉效果最多需要一整秒钟才能让我看到。但是,随后在同一缓冲区中使用 face-remapping-alist 进行的调用发生在几分之一秒内。我无法消除第一次通话后看到视觉效果所需的时间。这可能会达到最好的效果-即,第一次呼叫的时间最长可达一整秒,而在同一缓冲区内后续呼叫的光速最高。

● As to the first call of face-remapping-alist within a buffer, the visual effect takes up to one full second for me to see. However, subsequent calls using the face-remapping-alist within that same buffer occur within fractions of the second. I have not been able to eliminate the time needed to see the visual effect following the first call. This may be as good as it gets -- i.e., up to one full second for the first call, and light speed for subsequent calls within that same buffer.

(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))) )))


推荐答案

动态更改人脸会很慢,因为重新显示代码是在假设人脸不变的情况下编写的(如果更改,基本上重做许多 工作)。使用 face-remapping-alist 会带来更好的性能,因为重新显示代码确实希望它会更改并知道如何缓存结果。

Changing faces dynamically is going to be slow because the redisplay code is written under the assumption that faces don't change (if they change, we basically redo a lot of work). Using face-remapping-alist will result in much better performance because the redisplay code does expect it to change and know how to cache the result.

这篇关于如何加速Emacs中的自定义模式行面部更改功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆