期待一种让光标像Emacs中的心跳一样闪烁的方法

lou*_*xiu 5 emacs elisp

如何让Emacs中的光标像心跳一样闪烁.就像计算机暂停时笔记本电脑前面板上的LED一样.

有一个变量blink-cursor-alist控制光标的闪烁,但我不知道如何使用它来满足我的要求.

可能吗?

use*_*342 8

这个简单的次要模式实现了心跳式闪烁光标.您可以调整heartbeat-cursor-colors以获得不同的色调或其变体.

该代码在Emacs 24.2.1中进行了测试,但很容易移植到较旧的Emacsen.

(require 'cl)
(require 'color)

(defvar heartbeat-fps 16)
(defvar heartbeat-period 5)

(defun heartbeat-range (from to cnt)
  (let ((step (/ (- to from) (float cnt))))
    (loop for i below cnt collect (+ from (* step i)))))

(defun heartbeat-cursor-colors ()
  (let ((cnt (* heartbeat-period heartbeat-fps)))
    (mapcar (lambda (r)
              (color-rgb-to-hex r 0 0))
            (nconc (heartbeat-range .2 1 (/ cnt 2))
                   (heartbeat-range 1 .2 (/ cnt 2))))))

(defvar heartbeat-cursor-timer nil)
(defvar heartbeat-cursor-old-color)

(define-minor-mode heartbeat-cursor-mode
  "Change cursor color with the heartbeat effect."
  nil "" nil
  :global t
  (when heartbeat-cursor-timer
    (cancel-timer heartbeat-cursor-timer)
    (setq heartbeat-cursor-timer nil)
    (set-face-background 'cursor heartbeat-cursor-old-color))
  (when heartbeat-cursor-mode
    (setq heartbeat-cursor-old-color (face-background 'cursor)
          heartbeat-cursor-timer
          (run-with-timer
           0 (/ 1 (float heartbeat-fps))
           (lexical-let ((colors (heartbeat-cursor-colors)) tail)
             (lambda ()
               (setq tail (or (cdr tail) colors))
               (set-face-background 'cursor (car tail))))))))
Run Code Online (Sandbox Code Playgroud)


Omr*_*rel 4

您猜测该选项与“眨眼”一词有关。所以你按 Ch a(apropos)并输入“blink”。在我的 emacs 上,我有两个选项:blink-cursor-modeblink-matching-open。第一个看起来是对的。描述说:“切换闪烁光标模式”。

我的 emacs 上的快捷方式是:<menu-bar> <options> <blink-cursor-mode>。所以我猜想该选项位于菜单中的某个位置,可能在“选项”下。我打开“选项”菜单,看到的是:带有复选框的“闪烁光标”。

这听起来也像是一个可以定制的选项。所以我输入M-x customize-option然后blink-cursor-mode。这允许我切换该值并将其保存以供将来的会话使用。

编辑:要设置光标 ON 和 OFF 之间的间隔,有一个名为 的变量blink-cursor-interval。您可以使用M-x customize-variable和 thenblink-cursor-interval设置间隔。该变量blink-cursor-alist将OFF状态光标类型与ON状态光标类型相匹配,并且与闪烁速度无关。

EDIT2:据我所知,没有办法使光标逐渐关闭和打开,因为打开状态下的光标形状可能与关闭状态下的形状不同(因此形状的逐渐变化将是必需的)。