Subject: bug#77224: [PATCH] New minor mode 'cursor-indicators-mode'

From: Juri Linkov <[email-masked]>
Date: Tue, 25 Mar 2025 09:34:08 +0200

> +*** New minor mode 'cursor-indicators-mode'
> +This mode changes cursor appearance (color and/or type) to indicate
> +different buffer states.  This mode have cursor indicators for:
> +- Overwrite mode
> +- Read-only buffers
> +- Repeat mode
> +- Input method activation

What if users want to add more conditions?
Could you try to create only one defcustom that
contains a list of default conditions
plus a possible user-defined conditions.
For example:

#+begin_src emacs-lisp
(defcustom cursor-indicators nil
  :type `(alist :key-type
                  (choice :tag "Condition"
                    (const :tag "Overwrite mode" overwrite)
                    (const :tag "Read-only mode" read-only)
                    (const :tag "Repeat mode" repeat-in-progress)
                    (const :tag "Activated input method" input-method)
                    (function :tag "Matcher function")) ;; User-defined condition
                :value-type
                  (choice
                    (const :tag "None (do not change cursor)" nil)
                    (color :tag "Color")
                    (choice :tag "Type"
                            (const :tag "Filled box" box)
                            (const :tag "Vertical bar" bar)
                            (const :tag "Horizontal bar" hbar)
                            (const :tag "Hollow box" hollow))
                    (cons :tag "Color and Type"
                          (choice :tag "Type"
                                  (const :tag "Filled box" box)
                                  (const :tag "Vertical bar" bar)
                                  (const :tag "Horizontal bar" hbar)
                                  (const :tag "Hollow box" hollow))
                          (color :tag "Color")))))
#+end_src

Then I could replace:

#+begin_src emacs-lisp
(defun my-change-cursor (&rest _)
  "Change cursor color and type depending on insertion mode and input method."
  (set-cursor-color
   (cond (repeat-in-progress   "blue")
         (current-input-method "red3")
         (t                    "black")))
  (setq-default cursor-type
   (cond (overwrite-mode       'box)
         (t                    'bar))))
#+end_src

with just

#+begin_src emacs-lisp
(setopt cursor-indicators '((repeat-in-progress   "blue")
                            (current-input-method "red3")
                            (overwrite-mode       'box)
                            (default              'bar)))
#+end_src