3

当我定义一个键盘宏kmacro-start-macro-or-insert-counter

由于许多次要模式指示器/窄屏幕,“Def”指示器难以解析并且有时不可见。

非常感谢!

4

2 回答 2

1

我使用绑定到的标准函数,f3f4通过添加修改它们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)
于 2015-04-14T01:55:41.150 回答
1
(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.

于 2015-04-14T02:04:30.827 回答