emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e611dbcc7c 3/3: Add rudimentary font-locking to edmacro-mode


From: Stefan Kangas
Subject: master e611dbcc7c 3/3: Add rudimentary font-locking to edmacro-mode
Date: Sun, 19 Jun 2022 08:32:22 -0400 (EDT)

branch: master
commit e611dbcc7c815d321199deb380df333737bab06a
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Add rudimentary font-locking to edmacro-mode
    
    * lisp/edmacro.el (edmacro-label): New face.
    (edmacro-mode-font-lock-keywords): New variable.
    (edit-kbd-macro): Use font-lock in 'edmacro-mode'.  Minor
    improvement to command substitution.
---
 lisp/edmacro.el | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/lisp/edmacro.el b/lisp/edmacro.el
index 11afb68883..debd76c43a 100644
--- a/lisp/edmacro.el
+++ b/lisp/edmacro.el
@@ -76,6 +76,32 @@ Default nil means to write characters above \\177 in octal 
notation."
   "C-c C-c" #'edmacro-finish-edit
   "C-c C-q" #'edmacro-insert-key)
 
+(defface edmacro-label
+  '((default :inherit bold)
+    (((class color) (background dark)) :foreground "light blue")
+    (((min-colors 88) (class color) (background light)) :foreground "DarkBlue")
+    (((class color) (background light)) :foreground "blue")
+    (t :inherit bold))
+  "Face used for labels in `edit-kbd-macro'."
+  :version "29.1"
+  :group 'kmacro)
+
+(defvar edmacro-mode-font-lock-keywords
+  `((,(rx bol (group (or "Command" "Key" "Macro") ":")) 0 'edmacro-label)
+    (,(rx bol
+          (group ";; Keyboard Macro Editor.  Press ")
+          (group (*? any))
+          (group  " to finish; press "))
+     (1 'font-lock-comment-face)
+     (2 'help-key-binding)
+     (3 'font-lock-comment-face)
+     (,(rx (group (*? any))
+           (group " to cancel" (* any)))
+      nil nil
+      (1 'help-key-binding)
+      (2 'font-lock-comment-face)))
+    (,(rx (one-or-more ";") (zero-or-more any)) 0 'font-lock-comment-face)))
+
 (defvar edmacro-store-hook)
 (defvar edmacro-finish-hook)
 (defvar edmacro-original-buffer)
@@ -151,11 +177,18 @@ With a prefix argument, format the macro in a more 
concise way."
         (setq-local edmacro-original-buffer oldbuf)
         (setq-local edmacro-finish-hook finish-hook)
         (setq-local edmacro-store-hook store-hook)
+        (setq-local font-lock-defaults
+                    '(edmacro-mode-font-lock-keywords nil nil nil nil))
+        (setq font-lock-multiline nil)
        (erase-buffer)
         (insert (substitute-command-keys
                  (concat
+                  ;; When editing this, make sure to update
+                  ;; `edmacro-mode-font-lock-keywords' to match.
                   ";; Keyboard Macro Editor.  Press \\[edmacro-finish-edit] "
-                  "to finish; press \\`C-x k RET' to cancel.\n")))
+                  "to finish; press \\[kill-buffer] \\`RET' to cancel.\n")
+                 ;; Use 'no-face argument to not conflict with font-lock.
+                 'no-face))
        (insert ";; Original keys: " fmt "\n")
        (unless store-hook
          (insert "\nCommand: " (if cmd (symbol-name cmd) "none") "\n")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]