1

Have the following code but want to use let in the function blink-cursor-timer-function. Have started doing the changes but do require some assistance with it. The variable names veak-indicator-point, veak-indicator-colour are long, and want to shorten them. A good way is to use local variables within a let construct, but keeping the long descriptive names present. I do not think I can remove the variable veak-indicator-point, replace it with a local variable, and still have the cursor change colour upon blinking.

    (defvar veak-indicator-point 0
      "Sets colour of cursor.")
(defvar veak-indicator-colour
  (list "#FFA500" "#8A8AFF" "#FF6161" "#61FF61"
    "#FFFF00" "#E859E8" "#FFFFFF" "#FFC370" "#C370FF")
  "Sets colours for cursor.")

(defun blink-cursor-timer-function ()
  "Blinks the cursor"

  (when (not (internal-show-cursor-p))
    (when (>= veak-indicator-point (length veak-indicator-colour)) 
    (setq veak-indicator-point 0))
    (set-cursor-color (nth veak-indicator-point veak-indicator-colour))
    (setq veak-indicator-point (+ 1 veak-indicator-point)))
  (internal-show-cursor nil (not (internal-show-cursor-p)) ))

I have started with the following


     (defun blink-cursor-timer-function ()
      "Blinks the cursor"
  (let ( (i veak-indicator-point)
         (n (length veak-indicator-colour)) )

    (when (not (internal-show-cursor-p))
      (when (>= i n) (setq i 0))
      (set-cursor-color (nth i veak-indicator-colour))
      (setq i (+ 1 i))
      (setq veak-indicator-point i))
    (internal-show-cursor nil (not (internal-show-cursor-p))) )))

Lindydancer
  • 6,150
  • 1
  • 15
  • 26
Dilna
  • 1
  • 3
  • 11

1 Answers1

1

let bindings are not aliases for variables. They are independent variable names (with either lexical or dynamic scope) to which you are assigning a value. If you were to subsequently assign a new value to your let-bound i variable, that would have no effect on any other variable.

Such bindings are only valid for "shortening" purposes in a purely read-only context.

In any case, the names are not that long, and I think (>= i n) is worse as you now need to look elsewhere in the code to find out what i and n are. I suggest not doing any of this.


Edit for comments:

I keep within 72 characters, which is more compact than usual

This is within 72 characters:

        (when (>= veak-indicator-point
                  (length veak-indicator-colour))

Actually, that's within 72 even on a single line, but you get the point -- you are always free to format code across multiple lines. Doing so is normal, and Emacs will indent appropriately.

phils
  • 50,977
  • 3
  • 79
  • 122
  • I keep within 72 characters, where is more compact that usual, You are correct, as what I am doing is basically shortening in a read-only context. – Dilna Mar 09 '22 at 23:09