0

The intention of the following code is to toggle the display of the mode-line when called repeatedly. Although the mode-line is removed when first called, the mode-line does not show up again. I want the function to toggle the mode-line properly.

(defvar-local ramona-mode-line-rflog nil
  "Toggle switch for mode-line display.")

(defun ramona-mode-line ()
  "TODO."
  (interactive)

  (setq-local mode-line-format
               (if ramona-mode-line-rflog
                   (progn
                     (setq mode-line-format ramona-mode-line-rflog)
                     (setq ramona-mode-line-rflog nil))
                 (setq ramona-mode-line-rflog mode-line-format)
                 (setq mode-line-format nil)))

  (force-mode-line-update t))
1
  • You are setting mode-line-format inside the if and then you are setting it again to the result of the if. Lose the outer setq-local: just keep the if.
    – NickD
    Dec 1, 2022 at 20:04

1 Answer 1

0

I commented:

You are setting mode-line-format inside the if and then you are setting it again to the result of the if. Lose the outer setq-local: just keep the if.

Just in case my comment is not clear, here's what I mean:

(defun ramona-mode-line ()
  "TODO."
  (interactive)

  (if ramona-mode-line-rflog
      (setq mode-line-format ramona-mode-line-rflog
            ramona-mode-line-rflog nil)
    (setq ramona-mode-line-rflog mode-line-format
          mode-line-format nil))
  (force-mode-line-update t))

And BTW, you can set multiple variables with one setq: you don't need progn here. Do C-h f setq for the details.

Your Answer

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

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