branch: externals/cursory commit 1b2d6416ac937cde7a22d43d8eac3d5b6c2efa18 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Implement fallback value for cursory-presets --- README.org | 49 ++++++++++++++++++++++++++++++------------------- cursory.el | 48 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/README.org b/README.org index 08a5094bec..ec82fc733e 100644 --- a/README.org +++ b/README.org @@ -95,6 +95,35 @@ built-in variables: ~cursor-type~, ~cursor-in-non-selected-windows~, The value each property accepts is the same as the variable it references. +[ The fallback =t= value for ~cursory-presets~ is part of {{{development-version}}} ] + +A preset whose car is =t= is treated as the default option. This makes +it possible to specify multiple presets without duplicating their +properties. The other presets beside =t= act as overrides of the +defaults and, as such, need only consist of the properties that change +from the default. See the original value of this variable for how that +is done: + +#+begin_src emacs-lisp +(defcustom cursory-presets + '((box + :blink-cursor-interval 0.8) + (bar + :cursor-type (bar . 2) + :blink-cursor-interval 0.5) + (underscore + :cursor-type (hbar . 3) + :blink-cursor-blinks 50) + (t ; the default values + :cursor-type box + :cursor-in-non-selected-windows hollow + :blink-cursor-blinks 10 + :blink-cursor-interval 0.2 + :blink-cursor-delay 0.2)) + ;; Omitting the doc string for demo purposes + ) +#+end_src + When called from Lisp, the ~cursory-set-preset~ command requires a PRESET argument, such as: @@ -179,25 +208,7 @@ Remember to read the doc string of each of these variables or functions. #+begin_src emacs-lisp (require 'cursory) -(setq cursory-presets - '((bar - :cursor-type (bar . 2) - :cursor-in-non-selected-windows hollow - :blink-cursor-blinks 10 - :blink-cursor-interval 0.5 - :blink-cursor-delay 0.2) - (box - :cursor-type box - :cursor-in-non-selected-windows hollow - :blink-cursor-blinks 10 - :blink-cursor-interval 0.5 - :blink-cursor-delay 0.2) - (underscore - :cursor-type (hbar . 3) - :cursor-in-non-selected-windows hollow - :blink-cursor-blinks 50 - :blink-cursor-interval 0.2 - :blink-cursor-delay 0.2))) +;; Check the `cursory-presets' for how to set your own preset styles. (setq cursory-latest-state-file (locate-user-emacs-file "cursory-latest-state")) diff --git a/cursory.el b/cursory.el index d61a8ec2b3..38c66a89aa 100644 --- a/cursory.el +++ b/cursory.el @@ -77,28 +77,32 @@ :group 'cursor) (defcustom cursory-presets - '((bar + '((box + :blink-cursor-interval 0.8) + (bar :cursor-type (bar . 2) - :cursor-in-non-selected-windows hollow - :blink-cursor-blinks 10 - :blink-cursor-interval 0.5 - :blink-cursor-delay 0.2) - (box - :cursor-type box - :cursor-in-non-selected-windows hollow - :blink-cursor-blinks 10 - :blink-cursor-interval 0.5 - :blink-cursor-delay 0.2) + :blink-cursor-interval 0.5) (underscore :cursor-type (hbar . 3) + :blink-cursor-blinks 50) + (t ; the default values + :cursor-type box :cursor-in-non-selected-windows hollow - :blink-cursor-blinks 50 + :blink-cursor-blinks 10 :blink-cursor-interval 0.2 :blink-cursor-delay 0.2)) "Alist of preset configurations for `blink-cursor-mode'. The car of each cons cell is an arbitrary, user-specified key -that broadly describes the set. +that broadly describes the set (e.g. slow-blinking-box or +fast-blinking-bar). + +A preset whose car is t is treated as the default option. This +makes it possible to specify multiple presets without duplicating +their properties. The other presets beside t act as overrides of +the defaults and, as such, need only consist of the properties +that change from the default. See the original value of this +variable for how that is done. The cdr is a plist which specifies the cursor type and blink properties. In particular, it accepts the following properties: @@ -144,6 +148,20 @@ Saving is done by the `cursory-store-latest-preset' function." (defvar cursory--style-hist '() "Minibuffer history of `cursory--set-cursor-prompt'.") +(defun cursory--preset-values (preset) + "Get properties of PRESET with relevant fallbacks." + (append (alist-get preset cursory-presets) + (alist-get t cursory-presets))) + +(defun cursory--presets-no-fallback () + "Return list of `cursory-presets', minus the fallback value." + (delete + nil + (mapcar (lambda (symbol) + (unless (eq (car symbol) t) + symbol)) + cursory-presets))) + (defun cursory--set-cursor-prompt () "Promp for `cursory-presets' (used by `cursory-set-preset')." (let* ((def (nth 1 cursory--style-hist)) @@ -151,8 +169,8 @@ Saving is done by the `cursory-store-latest-preset' function." (format "Apply cursor configurations from PRESET [%s]: " def) "Apply cursor configurations from PRESET: "))) (completing-read - (mapcar #'car cursory-presets) prompt + (cursory--presets-no-fallback) nil t nil 'cursory--style-hist def))) ;;;###autoload @@ -171,7 +189,7 @@ With optional LOCAL as a prefix argument, set the (cursory--set-cursor-prompt)) current-prefix-arg)) (when-let* ((styles (if (stringp style) (intern style) style)) - (properties (alist-get styles cursory-presets)) + (properties (cursory--preset-values styles)) (type (plist-get properties :cursor-type)) (type-no-select (plist-get properties :cursor-in-non-selected-windows)) (blinks (plist-get properties :blink-cursor-blinks))