宏定义期间的 Emacs 模式行突出显示

Emacs mode-line highlight during macro definition

当我定义键盘宏 (kmacro-start-macro-or-insert-counter) 时,是否有简单的方法来获得清晰的指示符,例如通过更改模式行背景或类似的东西?

"Def" 指示器很难解析,有时由于许多次要模式 indicators/narrow 屏幕不可见。

非常感谢!

我使用绑定到 f3f4 的标准函数并通过添加 my-modeline-face-function 修改它们,并将这些键重新绑定到新函数。您可以根据需要更改 my-modeline-face-function 中面孔的颜色。我选择使用cond是因为你可能会发现你对各种主次模式还有其他类似的需求,你可以为那些模式插入类似的条件。 [例如,您可以为 isearch 模式或计算器模式等执行此操作]

face-remap-add-relative 返回的值存储在我命名为 my-face-remap-cookie 的自定义变量中,该变量又在宏录制阶段结束时用作函数 face-remap-remove-relative.

(defun my-kmacro-start-macro-or-insert-counter (arg)
  "Record subsequent keyboard input, defining a keyboard macro.
The commands are recorded even as they are executed.

Sets the `kmacro-counter' to ARG (or 0 if no prefix arg) before defining the
macro.

With \[universal-argument], appends to current keyboard macro (keeping
the current value of `kmacro-counter').

When defining/executing macro, inserts macro counter and increments
the counter with ARG or 1 if missing.  With \[universal-argument],
inserts previous `kmacro-counter' (but do not modify counter).

The macro counter can be modified via \[kmacro-set-counter] and \[kmacro-add-counter].
The format of the counter can be modified via \[kmacro-set-format]."
  (interactive "P")
  (if (or defining-kbd-macro executing-kbd-macro)
      (progn
        (my-modeline-face-function)
        (kmacro-insert-counter arg))
    (kmacro-start-macro arg)
    (my-modeline-face-function)))

(defun my-kmacro-end-or-call-macro (arg &optional no-repeat)
  "End kbd macro if currently being defined; else call last kbd macro.
With numeric prefix ARG, repeat macro that many times.
With \[universal-argument], call second macro in macro ring."
  (interactive "P")
  (cond
   (defining-kbd-macro
     (if kmacro-call-repeat-key
   (kmacro-call-macro arg no-repeat t)
       (kmacro-end-macro arg)))
   ((and (eq this-command 'kmacro-view-macro)  ;; We are in repeat mode!
   kmacro-view-last-item)
    (kmacro-exec-ring-item (car kmacro-view-last-item) arg))
   ((and arg (listp arg))
    (kmacro-call-ring-2nd 1))
   (t
    (kmacro-call-macro arg no-repeat)))
  (my-modeline-face-function))

(defface my-recording-macro-face
  '((t (:background "yellow" :foreground "black")))
  "Face for `my-recording-macro-face`."
  :group 'my-faces)

(defvar my-face-remap-cookie nil
"The return value of `face-remap-add-relative` is a Lisp object that
serves as a `cookie`; you can pass this object as an argument to
`face-remap-remove-relative` if you need to remove the remapping later.")
(make-variable-buffer-local 'my-face-remap-cookie)

(defun my-modeline-face-function ()
"Doc-string."
  (require 'face-remap)
  (cond
    (defining-kbd-macro
      (setq my-face-remap-cookie
        (face-remap-add-relative 'mode-line 'my-recording-macro-face)))
    (t
      (face-remap-remove-relative my-face-remap-cookie)
      (setq my-face-remap-cookie nil))))

(define-key global-map [f3] 'my-kmacro-start-macro-or-insert-counter)

(define-key global-map [f4] 'my-kmacro-end-or-call-macro)
(setq minor-mode-alist
      `((abbrev-mode " Abbrev")
        (overwrite-mode overwrite-mode)
        (auto-fill-function " Fill")
        ;; not really a minor mode...
        (defining-kbd-macro ,(propertize " Def" 'face 'highlight))))

我所做的只是调整 bindings.el 的原始代码,将 " Def" 替换为 (propertize " Def" 'face 'highlight) 的值。

使用您喜欢的任何面部或面部规格代替 highlight