有没有一种简单的方法,在我定义键盘宏(
kmacro-start-macro-or-insert-counter
)时有清晰的指示,例如通过更改模式行背景或类似的东西?“ Def”指示不易解析,并且由于许多小模式指示器/窄屏幕而有时不可见。非常感谢!(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
。
f3
和f4
的标准功能,并通过添加my-modeline-face-function
来修改它们,然后将这些键重新绑定到新函数。您可以更改my-modeline-face-function
中面的颜色以适应您的需要。我选择使用cond
,因为您可能会发现对于各种主要和次要模式有其他类似的需求,并且您可以为这些模式插入类似的条件。[例如,您可以为isearch-mode或calculcator-mode等执行此操作。]
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)
face-remap-add-relative
返回一个可以存储的值,例如在缓冲区局部变量中。该值稍后可以被函数 face-remap-remove-relative
使用。这将有效地满足您恢复 mode-line
默认值的需求。修订已纳入上述答案。 - lawlist
Def
指示器,这正是我认为你所请求的。但也许我误解了问题? - Drew