I got the following snippet in my init.el:

(define-minor-mode sticky-buffer-mode
  "Make the current window always display this buffer."
  nil " locked" nil
  (set-window-dedicated-p (selected-window) sticky-buffer-mode))
(global-set-key [f11] 'sticky-buffer-mode)

So, I can use F11 to lock one window, but the minor mode indicator "locked" shows in the mode line is not easy to see when more than one windows exist in one frame, so I wonder how can I change the color of mode-line-buffer-id or something like filename(locked) in mode line(change color would be better).

Note: the original version is able to toggle the status with the same key, so the modified version should be so. Since the minor mode is unnecessary, it would be better to modify define-minor-mode to defun.


3 Answers 3


The following command toggles the dedicated status of a window and changes the color of the mode line:

(defun make-buffer-sticky ()
  "Make the current window always display this buffer."
  (let* ((window (get-buffer-window (current-buffer)))
         (dedicated (window-dedicated-p window)))
    (if (not dedicated)
        (face-remap-add-relative 'mode-line '(:background "#0000FF"))
      (face-remap-add-relative 'mode-line '(:background "#FF0000")))
    (set-window-dedicated-p window (not dedicated))))

Bind it to a convenient key sequence:

(global-set-key (kbd "C-c s") 'make-buffer-sticky)

Currently, the command toggles between a red (#FF0000) and a blue (#0000FF) background for the mode line. You'll have to adjust the colors to your liking.

If you want to use the default mode line color (of your theme) for non-sticky buffers, you can do

M-x describe-face RET mode-line RET

to check the current background color of the mode line.


You could install rich-minority from Melpa. It is a minor mode that can highlight or even hide certain minor modes from the mode line.

So you can configure it to highlight " locked" and to hide other stuff to make more space.

Here's an example.

(setq rm-text-properties '(("\\` locked\\'" 'face 'font-lock-warning-face))
(add-to-list 'rm-blacklist " company") ; company will be hidden.

You can also install smart-mode-line, which comes bundled with rich-minority.

  • 1
    Nice, did not know about rich-minority :)
    – itsjeyd
    Oct 17, 2014 at 16:56
  • rich-minority and smart-mode-line are nice, but I have configured defvar mode-line-cleaner-alist to clean/rename the modes names and all other configurations like mode line color which are better with my Emacs color theme already in my init.el, so the above packages are basically unnecessary for me.
    – CodyChan
    Oct 18, 2014 at 12:24
  • @CodyChan then the answer by itsjeyd should do what you want. He explains how to remap a face specifically in a buffer. Just use that to remap mode-line-buffer-id.
    – Malabarba
    Oct 18, 2014 at 12:37

I use make-buffer-sticky() function of @itsjeyd and change something. Here are i did:

I make new face by: (make-face 'mode-line-sticky-face) Then, in make-buffer-sticky() function i change to:

(defun make-buffer-sticky ()
  "Make the current window always display this buffer."
  (let* ((window (get-buffer-window (current-buffer)))
         (dedicated? (window-dedicated-p window)))
    (if (not dedicated?)
          (face-remap-add-relative 'mode-line-sticky-face
                                   '(:foreground "#8BE03C"))
          (message "Window '%s' is sticky now" (current-buffer))
        (face-remap-add-relative 'mode-line '(:background "#0D1011"))
        (message "window '%s' is normal" (current-buffer))
    (set-window-dedicated-p window (not dedicated?))))

I have a customization mode line:

   ;; Sticked mode line
    (let* ((window (get-buffer-window (current-buffer)))
           (sticky? (window-dedicated-p window)))
      (cond (sticky?
             (propertize "  ⚡" 'face 'mode-line-sticky-face))
            (t ""))))
   ;; Position, including warning for 78 columns
   (:propertize "%4l :" face mode-line-position-face)
   (:eval (propertize "%3c " 'face
                      (if (> (current-column) 78)
   ;; emacsclient [default -- keep?]
   "  "
   ;; read-only or modified status
    (cond (buffer-read-only
           (propertize " RO " 'face 'mode-line-read-only-face))
           (propertize " ** " 'face 'mode-line-modified-face))
          (t "      ")))
   "    "
   ;; directory and buffer/file name
   (:propertize (:eval (shorten-directory default-directory 30))
                face mode-line-folder-face)
   (:propertize "%b"
                face mode-line-filename-face)
   ;; narrow [default -- keep?]
   " %n "
   ;; mode indicators: vc, recursive edit, major mode, minor modes, process, global
   (vc-mode vc-mode)
   "  %["
   (:propertize mode-name
                face mode-line-mode-face)
   "%] "
   (:eval (propertize (format-mode-line minor-mode-alist)
                      'face 'mode-line-minor-mode-face))
   (:propertize mode-line-process
                face mode-line-process-face)
   (global-mode-string global-mode-string)
   "    "

You can see detail at the commit in my repo at here.


Not sticky: enter image description here Sticky: enter image description here

Hope it helped. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.