.emacs: c-set-style will delay display of new style until I change the buffer (type a key)

Viewed 29

Dealing with files of different C flavours, I defined the following function and a keyboard mapping to invoke it:

(defun my-c-set-gnu-style ()
  "doc string"
  (interactive)
  (setq tab-width 8
        indent-tabs-mode t)
  (c-set-style "gnu")
  )

(global-set-key (kbd "C-x :") 'my-c-set-gnu-style)

Now when I open a C file with emacs, and then type C-x: then nothing happens. Only after I hit some key (and thus I change the code, which is really bad), emacs will re-draw the code according to the new style.

How can I achieve that emacs will re-indent the code right after the respective command has been issued? The need to change the file is really bad.

Version is GNU Emacs 26.3.

1 Answers

The issue isn't related to c-set-style. Changing the TABs mode like in (setq tab-width 8 indent-tabs-mode t) should also have an immediate visual effect — which it does not have.

Using (redisplay t) didn't solve the problem, but what worked is (force-window-update) at the end of the defun. Dunno if that's supposed to be issued by hand or whether the requirement is an Emacs bug, though.

Related