nex3 / perspective-el

Perspectives for Emacs.
MIT License
895 stars 71 forks source link

Current perspective name not being propertized in the mode-line #191

Closed mukundzare closed 3 months ago

mukundzare commented 2 years ago

Hi,

I am unable to see the current perspective name being highlighted in the modeline while using (setq persp-show-modestring t). It highlights correctly in the header when I use (setq persp-show-modestring 'header).

If it matters, I am using doom-modeline too. How do I fix this issue?

gcv commented 2 years ago

I'm not familiar with doom-modeline. What happens if you disable it?

It could be as simple as a hard-to-see face setting given your theme and modeline configuration. The highlight is controlled using persp-selected-face (https://github.com/nex3/perspective-el/blob/cb4083dfa91c336dbed0c330d629e256d86384f9/perspective.el#L500). What happens if you modify it?

mukundzare commented 2 years ago

Hi @gcv, disabling doom-modeline seems to make it work. Modifying the face has no effect when doom-modeline is active. To test that doom-modeline really is an issue, I ran emacs -Q and put the following config in it:

;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("elpa" . "https://elpa.gnu.org/packages/")
                         ("melpa-stable" . "https://stable.melpa.org/packages/")))

(add-to-list 'package-pinned-packages '(cider . "melpa-stable") t)
(add-to-list 'package-pinned-packages '(magit . "melpa-stable") t)

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(require 'use-package)
(defvar bootstrap-version)
  (let ((bootstrap-file
         (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
        (bootstrap-version 5))
    (unless (file-exists-p bootstrap-file)
      (with-current-buffer
          (url-retrieve-synchronously
           "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
           'silent 'inhibit-cookies)
        (goto-char (point-max))
        (eval-print-last-sexp)))
    (load bootstrap-file nil 'nomessage))
  (setq package-enable-at-startup nil)

(use-package perspective
  :straight t
  :bind
  ("C-x k" . persp-kill-buffer*)
  ("C-x C-b" . persp-list-buffers)   ; or use a nicer switcher, see below
  :init
  (setq persp-state-default-file "/home/zam4abt/my-emacs-stuff/perspectives"
    persp-sort 'access
    persp-show-modestring t
    persp-modestring-short nil
    persp-mode-prefix-key (kbd "C-x x"))
  (persp-mode)
  :hook ((kill-emacs . my-persp-save)
     (after-init . my-persp-load)))
(use-package doom-modeline
  :straight t
  :hook (after-init . doom-modeline-mode)
  :init
  (setq doom-modeline-minor-modes nil)
  ;; Prevent flash of unstyled modeline at startup
  (unless after-init-time
    (setq-default mode-line-format nil))
  :bind (:map doom-modeline-mode-map
              ("C-<f6>" . doom-modeline-hydra/body)))

After the following config was run, I tried to disable doom-modeline and re-enable it but the highlighting still seemed to work with and without doom-modeline.

Perhaps there is a problem with the themes interfering with it because that seems to be a thing I didn't test in emacs -Q . Do you have any hints for how to approach this problem other than trying to installing the themes and testing it?

gcv commented 2 years ago

Since it sounds like everything works with the minimal configuration above, then doom-modeline is not the problem? In that case, yes, I'm inclined to blame some interaction of themes and limitations of persp-selected-face, since it's just a :foreground "Blue" setting. Also, the face is used directly in the code, rather than through a variable indirection, so it's more difficult to adjust in conflicting situations.

I'd definitely install the conflicting theme and take it from there. It's tedious but not difficult to examine the faces defined by a theme (using M-x list-faces-display), and figure out what's going on. The raw mode line is in the mode-line-format variable, which I like to examine in ielm mode (pretty-printing is important for something that complicated) — it's usually possible to track down which faces are used where by looking at what it's doing.

If this is the case, then maybe a good fix would be to introduce a layer of indirection for persp-selected-face, which should make modifying it more theme-friendly:

(defface persp-selected-default-face
  '((t (:weight bold :foreground "Blue")))
  "The default face used to highlight the current perspective on the modeline.")

(defvar persp-selected-face persp-selected-default-face
  ;; or better yet: defcustom
  "The face actually used to highlight the current perspective on the modeline.")

An even smarter approach is to make the face dynamic, so it automatically adjusts its color to suit the theme. I've done this before for other code, it usually works. A bit more work required, though.

mukundzare commented 2 years ago

Yeah, I think hard coding persp-selected-face to blue might be causing some interactions with the themes and might need to have an indirection in the case of themes. Besides, I just declared emacs bankruptcy and the themes seemed to have played some part in it or my lack of sufficient knowledge. I have started over with my new config (without perspective.el as of now, but planned in the next few days). So, if the problem reappears, I will report back soon.

gcv commented 3 months ago

Not sure there’s anything to be done for this ticket.