rougier / nano-modeline

GNU Emacs / N Λ N O Modeline
GNU General Public License v3.0
170 stars 29 forks source link

[Question] Extending default modeline #40

Closed SalTor closed 1 year ago

SalTor commented 2 years ago

I'm new to emacs lisp and am wondering whether there's a better way to update the default modeline for my purposes

Right now the default one shows a primary and secondary section, usually a buffer name and git branch name

I'm a user of evil-mode and would like to have a representation of the current evil state in the modeline so I re-defined this function for the default mode line and currently have to execute it manually in order to have it show

The result is like this Screen Shot 2022-06-13 at 1 40 24 PM

The change is this (cond ...) portion at the end

(defun nano-modeline-default-mode (&optional icon)
    (let ((icon (or icon
                    (plist-get (cdr (assoc 'text-mode nano-modeline-mode-formats)) :icon)))
          ;; We take into account the case of narrowed buffers
          (buffer-name (cond
                        ((and (derived-mode-p 'org-mode)
                              (buffer-narrowed-p)
                              (buffer-base-buffer))
                         (format"%s [%s]" (buffer-base-buffer)
                                (org-link-display-format
                                (substring-no-properties (or (org-get-heading 'no-tags)
                                                         "-")))))
                        ((and (buffer-narrowed-p)
                              (buffer-base-buffer))
                         (format"%s [narrow]" (buffer-base-buffer)))
                        (t
                         (format-mode-line "%b"))))

          (mode-name   (nano-modeline-mode-name))
          (branch      (nano-modeline-vc-branch))
          (position    (format-mode-line "%l:%c")))
      (nano-modeline-render icon
                            buffer-name
                            (concat
                             (if branch
                                 (concat "(" branch ")")
                               "")
                             " "
                             (concat
                              "<"
                              (cond
                              (( eq evil-state 'visual) "V")
                              (( eq evil-state 'normal) "N")
                              (( eq evil-state 'insert) "I")
                              (( eq evil-state 'emacs) "E")
                              (t "*"))
                              ">"))
                            position)))

So:

rougier commented 2 years ago

If you add your mode at the end of nano-modeline-mode-formats, it should replace the default mode that is called when no other mode has been found. As for making a PR, I would prefer having something specific in default mode. One option could be to have an evil-defaut mode at the end of the list.

rougier commented 1 year ago

Should now be much easier with the new simpler branch.