0

I have a new win11 laptop, and have emacs 23.3 and 27.2 installed. Neither version will let me set the cursor to a blinking blue box in text files. This was not a problem with my previous win10 laptop.

I have the following in my init file (_emacs for 23.2 and .emacs for 27.2)

(setq default-cursor-type 'box) (set-cursor-color "blue") (blink-cursor-mode -1) 

All I get is a blinking vertical line.

Is there any way to describe the cursor settings? Is there any way to customize the cursor through the menu Options>Customize Emacs>Browse Customization groups ?

5
  • 1
    Try emacs -Q, cut and paste the forms you added to your init file (modified as per the answer below) into the *scratch* buffer and evaluate each one by putting the cursor after its closing parenthesis and typing C-j. You might try a more obvious color than "blue" (I suggest "red") for checking. If that works, cut and paste the working forms into your init file and try restarting emacs (without the -Q this time). If that does not work, then figure out why your init file is not being read. See gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html for hints. Commented Feb 4 at 15:20
  • Thanks for this suggestion. I tried this and evaluating (setq-default cursor-type 'box) returns box and doesn't change anything. Evaluating (set-cursor-color "blue") returns nil and doesn't change anything. Commented Feb 10 at 13:25
  • Did you start with emacs -Q? If not, please do so: it might be that something in your init is causing your emacs to behave differently from everybody else's, but both the above and the blink-cursor-mode setting behave differently in my case (and I presume in @amitp's case) than in yours, so my inclination is to blame your init file (or if you get the same behavior with -Q, your emacs build - where did you get your emacs and what is its version? Do M-x emacs-version to find out the version). Commented Feb 10 at 16:21
  • Unless there is some new information, your new question sounds to me similar (if not identical) to this one. Let's continue with this question until it is resolved, rather than working on two different questions. Commented Feb 10 at 16:38
  • I created a chat room for further discussion. Commented Feb 12 at 14:21

3 Answers 3

1

There isn't a default-cursor-type variable, I think.

You might try (setq-default cursor-type 'box).

(blink-cursor-mode -1) should turn off blinking, and (blink-cursor-mode +1) should turn on blinking. You say your cursor is still blinking, which makes me wonder if there's an error while running your .emacs. Check the *Messages* buffer to look for any errors.

6
  • pretty sure the causes the cursor to blink forever, as a count of -1 is never reached. I had the setq set to setq-default cursor-type 'box previously, and that didn't work either. Commented Feb 4 at 18:00
  • That number is not a count: it either enables (+1) or disables (-1) blink-cursor-mode, the minor mode that controls blinking. That's how all minor modes are enabled or disabled. Commented Feb 4 at 19:56
  • I just tested setting (blink-cursor-mode +1) and this causes the cursor to not blink. Setting it to -1 makes it blink. Commented Feb 10 at 13:26
  • 1
    That's interesting! It's the opposite for me. (blink-cursor-mode +1) makes it blink. -1 makes it not blink. At least when using gui emacs. When using terminal emacs, neither made a difference, since my terminal is controlling blinking. Some terminals allow apps to control the blinking, but it looks like mine does not. Commented Feb 10 at 16:14
  • To set the current cursor-type, use (setq cursor-type 'box) e.g. Using setq-default just changes the default value of the variable, which might not be applicable to whatever buffer you are in. C-h v cursor-type will tell you both the global value (which is what setq-default sets) and the buffer local value - if applicable. Commented Feb 10 at 16:33
1

You can check the settings by checking the various variables with C-h v:

  • C-h v cursor-type will tell you the value of that variable (both the global value and the value in the current buffer, if applicable).

  • C-h v blink-cursor-mode will tell you whether blink-cursor-mode is enabled (t) or disabled (nil). The name blink-cursor-mode (like the name of every minor mode) is the name of a function that can be used to enable/disable the mode and the value of a variable that indicates whether the mode is enabled or disabled currently. Emacs Lisp allows a single name to be the name of a function and a variable.

  • Cursor color is a frame parameter, not a simple variable, so it cannot be checked with C-h v. You can use M-: (frame-parameter nil 'cursor-color) to check it for the current frame.

All this assumes that you are using GUI Emacs: as @amitp pointed out in a comment, the terminal generally decides what cursor properties to use, so in terminal Emacs, it's the terminal that decides - Emacs is powerless.

As for Customize, you can type cursor in the Search box and come up with a multitude of options, but I would think twice before changing any of them, except the ones discussed already.

9
  • I have GNU Emacs 27.2 (build 1, x86_64-w64-mingw32) of 2021-03-26 installed on a new win11 laptop. I did not have this problem with my previous win10 laptop, and I do not have this problem when using the same .emacs file on a linux server . I invoked emacs with the -Q option and evaluated (setq cursor-type 'box) and it returned the value of box, even through the cursor is a non-blinking vertical line. If I do C-h v cursor-type I get the following: cursor-type is a variable defined in ‘C source code’. Its value is ‘box’ Original value was t Local in buffer scratch; global value is t Commented Feb 10 at 17:42
  • checking the blink-cursor-mode returns: blink-cursor-mode is a variable defined in ‘frame.el’. Its value is t However the cursor is unblinking. Sometimes I need to edit code on my laptop which is why I have emacs installed there. Commented Feb 10 at 17:51
  • I have now tried Emacs 29.4 on Windows 11 and I cannot reproduce any of your findings (even without -Q but without a personal init file). (blink-cursor-mode +1) turns on blinking, (blink-cursor-mode -1) turns it off, (setq cursor-type 'bar) turns it into a bar cursor, (setq cursor-type t) goes back to the (default) box cursor, (set-cursor-color "blue") turns the cursor blue. The only thing I changed was to make the blinking permanent: by default, after ten blinks, it stop blinking and you get a solid cursor. I customized the entry Blink Cursor Blinks and set it to 0. Commented Feb 10 at 21:59
  • The only thing I can think of is that Emacs 27.2 does not support these things, but I will not downgrade that far to test that. But searching through git logs, the last mention I find of blink-cursor-mode was in the Emacs 26.1 time frame. So I think that it is unlikely that 27.2 is the cause (although you might want to upgrade). I think you are doing something wrong, but I cannot venture a guess as to what. Commented Feb 10 at 22:03
  • 1
    @NickD My work laptop is on Windows 11 and has Emacs 27.1 on it and the code you describe works the same there as the Emacs 29 that I have on the Linux cluster. Commented Feb 12 at 0:08
0

One reason why it may not work which I discovered while preparing this answer: if you have customized it using customize interface, emacs will insert code that sets cursor-type in the custom-set-variables section of your init file. So first make sure nothing about the cursor is present in the custom-set-variables section of your init file.

For the cursor color, you have it right.

(set-cursor-color "blue") 

For the cursor type, the variable is cursor-type and you can set it using setq as shown here. You have more options that you can find with C-h v cursor-type RET

;; Empty box (setq cursor-type 'hollow) ;; Filled box (setq cursor-type 'box) ;; Thin bar (setq cursor-type '(bar . 2)) ;; Thick bar (setq cursor-type '(bar . 5)) 

For the blinking, there are two things that control it. The first one is the function blink-cursor-mode and the variable blink-cursor-blinks which are both described in the help for blink-cursor-mode:

If called interactively, enable Blink-Cursor mode if ARG is positive, and disable it if ARG is zero or negative. If called from Lisp, also enable the mode if ARG is omitted or nil, and toggle it if ARG is ‘toggle’; disable the mode otherwise. If the value of ‘blink-cursor-blinks’ is positive (10 by default), the cursor stops blinking after that number of blinks, if Emacs gets no input during that time. 

So for example:

;; Blink forever (setq blink-cursor-blinks 0) (blink-cursor-mode 1) ;; No blinking (blink-cursor-mode -1) 

This code in my init file on Emacs 27.1 on Windows 11 produces a cursor that is a blue box that blinks forever:

(set-cursor-color "blue") (setq cursor-type 'box) (setq blink-cursor-blinks 0) (blink-cursor-mode 1) 

If this is not working, I would try emptying your config file completely and putting just this code then restart Emacs. That is what I did for this answer since I normally use evil-mode which allows me to define different cursors for normal mode, insert mode, etc. I didn't want that to interfere with the results.

Remember that if you tried to customize it, then your init file will contain (custom-set-variables '(cursor-type 'bar)) and people usually add stuff in their config file before this code so that your code setting the cursor to a box will be run before the code that sets it to a bar thus making it seem like your code is not doing anything.

EDIT: I read the back-and-forth in the comments in @NickD's answer so I see you've made good efforts to isolate this from the rest of your config by doing emacs -Q so your problem is very interesting.

6
  • The problem is that the OP is (AFAICT) the only one who is having this problem (even with emacs -Q which should avoid init file and customization problems altogether). It works for everybody else. So the (almost) inescapable conclusion is that the OP is doing something wrong somehow, somewhere, but neither he nor anybody else has been able to figure out what that is. I suspect it will require an Emacs expert to physically get access to the OP's computer and debug it. Commented Feb 12 at 2:58
  • Thank you all for the help with this! I just changed my .emacs file to have only: (setq-default cursor-type 'box) (set-cursor-color "blue") The result is a black vertical line. If I do the steps to describe the cursor as explained in the above thread, the cursor-type returned is `box' and the color is blue. This is a Win11 work laptop configured with whatever extra security they add to make them 'safe'. Perhaps that has something to do with it. Commented Feb 14 at 15:23
  • How do I add line returns to format these comments better, I have tried ctrl-Enter and Alt-enter but those don't work, and Enter simply closes the comment Commented Feb 14 at 15:25
  • @user46811 You can't have returns in comments. Also, I have never seen your answer to the question "Are you running Emacs in a terminal?". Commented Feb 14 at 15:27
  • I am running this on Win11, from a shortcut on the desktop that points to C:\emacs-27p2\x86_64\bin\runemacs.exe so I don't believe it is running from a terminal. If I open a command prompt and run runemacs.exe I get the same behavior. Commented Feb 14 at 15:41

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.