0

I am using this function to toggle the mode-line display. But it does not always function when I call it repeatedly.

(defvar-local ramona-mode-line-rflog nil)

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

  (setq-local mode-line-format
               (if ramona-mode-line-rflog
                   (setq mode-line-format ramona-mode-line-rflog)
                 (setq ramona-mode-line-rflog mode-line-format)
                 (setq mode-line-format nil))))
8
  • 1
    lists.gnu.org/archive/html/help-gnu-emacs/2022-11/msg00699.html - that was part of the discussion arising from your question.
    – NickD
    Nov 30, 2022 at 23:30
  • force-mode-line-update with the optional argument set to non-nil if so desired.
    – lawlist
    Dec 1, 2022 at 3:49
  • Still does not work when I call (force-mode-line-update t) everytime I reset mode-line-format.
    – konmi
    Dec 1, 2022 at 11:39
  • Did you add the resetting of ramona-mode-line-rflog back to nil as pointed out in the link I pointed you to above?
    – NickD
    Dec 1, 2022 at 15:59
  • 1
    So you are making changes to your program and we are supposed to follow along using your descriptions? This is one reason that this is NOT A CONVERSATION SITE - as I have mentioned before and repeatedly: ask your question, accept or not accept any answer, but when you modify your program, you are now asking a new question - so make it a new question.
    – NickD
    Dec 1, 2022 at 18:54

1 Answer 1

0

Inasmuch as the variable mode-line-format is always buffer-local, it does not need to be set with setq-local. Either the variable ramona-mode-line-rflog or the buffer-local value of mode-line-format should be compared to something that does not change, such as the (default-value 'mode-line-format). The default value of a buffer-local variable can be set with setq-default.

(defvar-local ramona-mode-line-rflog "foo")

(defun ramona-mode-line ()
  "TODO."
  (interactive)
  (setq mode-line-format
          (if (equal mode-line-format (default-value 'mode-line-format))
             ramona-mode-line-rflog
           (default-value 'mode-line-format)))
  (force-mode-line-update))
4
  • Have resetted ramona-mode-line-rflog back to nil. But the modeline is gone and never toggles.
    – konmi
    Dec 1, 2022 at 18:11
  • Then ramona-mode-line-rflog is not needed.
    – konmi
    Dec 1, 2022 at 19:55
  • Did you even try the suggested solution? Starting from emacs -Q - a clean slate so to speak? You are randomly combining bits and pieces from previous attempts with this answer: don't! Start with emacs -Q, copy the answer to the *scratch* buffer, evaluate the two expressions with C-j after the closing paren, then keep evaluating (ramona-mode-line): it toggles between the default value and a mode line with just foo in it. Again, you are wasting everybody's time (and yours) by not reading carefully what people write and not following advice.
    – NickD
    Dec 1, 2022 at 20:26
  • I know it will have but am asking if using the variable can be avoided and just have the function.
    – konmi
    Dec 1, 2022 at 21:05

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.