Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard frame not centered with emacsclient #430

Open
ThibaultGH opened this issue Jan 5, 2023 · 17 comments
Open

Dashboard frame not centered with emacsclient #430

ThibaultGH opened this issue Jan 5, 2023 · 17 comments

Comments

@ThibaultGH
Copy link

Hi there,

I launch an emacs server when my computer boots and launch new frame with emacsclient.
Don't know exactly why but a new frame with emacsclient -c bounded to CTRL-Alt-e (or C-M-e) will end up with a dashboard frame that is pushed to the right and not centered. Not very important but dont look good and looking good is the point of this package ^^'
How could I fix that issue ?

Here is my config for dashboard in my init.el :

;; Dashboard and its configuration
(use-package dashboard
  :ensure t
  :config
  (dashboard-setup-startup-hook))

(setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")))

;; Set the title
(setq dashboard-banner-logo-title "Welcome to Emacs Dashboard")
;; Set the banner
(setq dashboard-startup-banner 'logo)
;; Value can be
;; - nil to display no banner
;; - 'official which displays the official emacs logo
;; - 'logo which displays an alternative emacs logo
;; - 1, 2 or 3 which displays one of the text banners
;; - "path/to/your/image.gif", "path/to/your/image.png" or "path/to/your/text.txt" which displays whatever gif/image/text you would prefer
;; - a cons of '("path/to/your/image.png" . "path/to/your/text.txt")

;; Content is not centered by default. To center, set
(setq dashboard-center-content t)

;; To disable shortcut "jump" indicators for each section, set
(setq dashboard-show-shortcuts t)

;; What widget to show
(setq dashboard-items '((recents  . 5)
                        (projects . 5)))

And here is an image of the rendering :

DashboardNotCentered

@jcs090218
Copy link
Member

So it does work in regular startup but not with emacsclient? Can you write down steps to reproduce this bug? 🙏

@ThibaultGH
Copy link
Author

So it does work in regular startup but not with emacsclient? Can you write down steps to reproduce this bug? pray

Yep, well not very complicated I guess you just :
1). add the lines of my dashboard configuration from the first message of this issue
2). kill any emacs server or session you might have running
3). launch a emacs session from the terminal with emacs (the dashboard should appear clean and centered) then kill it
4). launch an emacs daemon from the terminal with emacs --daemon and launch a new frame with emacsclient -c and then you should have a dashboard that is not centered

Or at least that's what I have...

@ThibaultGH
Copy link
Author

Could it have something to do with how I set up dependencies for dashboard ??

It might so here are also the setup in my init.el file for page-break-lines and projectile :

(use-package page-break-lines)

(use-package projectile
  :diminish projectile-mode
  :config (projectile-mode)
  :custom ((projectile-completion-system 'ivy))
  :bind-keymap
  ("C-c p" . projectile-command-map)
  :init
  ;; NOTE: Set this to the folder where you keep your Git repos!
  (when (file-directory-p "~/Projects/Code")
    (setq projectile-project-search-path '("~/Projects/Code")))
  (setq projectile-switch-project-action #'projectile-dired))

(use-package counsel-projectile
  :config (counsel-projectile-mode))

@linwaytin
Copy link

I have the same issue and I also run the emacs daemon. However, the issue appears even if it is not in a daemon mode, in my case.

If dashboard-center-content is set to t, below the banner, "Welcome to Emacs!" and "xxx packages loaded in xxx seconds" start at the middle, making them shifted to the right. The same happens for the items below like recent file list, as shown in the figure posted above.

If dashboard-center-content is set to nil, "Welcome to Emacs!" and "xxx packages loaded in xxx seconds" still start at the middle, but the rest starts from the left margin.

@wjbg
Copy link

wjbg commented Jan 7, 2023

I have the same issue and I also run the emacs daemon. However, the issue appears even if it is not in a daemon mode, in my case.

If dashboard-center-content is set to t, below the banner, "Welcome to Emacs!" and "xxx packages loaded in xxx seconds" start at the middle, making them shifted to the right. The same happens for the items below like recent file list, as shown in the figure posted above.

If dashboard-center-content is set to nil, "Welcome to Emacs!" and "xxx packages loaded in xxx seconds" still start at the middle, but the rest starts from the left margin.

I have the same issue since updating the package to the latest version; I am not in daemon mode.

@ThibaultGH
Copy link
Author

ThibaultGH commented Jan 7, 2023

I have the same issue since updating the package to the latest version; I am not in daemon mode.

Can you give a version number of the package that did not have that bug pls ? And maybe a link to a dashboard.el and dashboard-widgets.el to look for difference ?

ThibaultGH referenced this issue Jan 7, 2023
* fix(centering): Caculate line length in pixel width

* changelog

* fix compile warnings
@ThibaultGH
Copy link
Author

I'm not entierly sure, but think the bug might here at this modification that is pretty rencent :
594f2d9#diff-c26fa000bfadfc4bb4a6f88e5d3d7e3d8c955f5d4f7b9e3d6693c7037b2e356aL499

I've left a comment for a maintainer of the package has more info and help, if it ever is help and not misleading !

@wjbg
Copy link

wjbg commented Jan 7, 2023

Can you give a version number of the package that did not have that bug pls ? And maybe a link to a dashboard.el and dashboard-widgets.el to look for difference ?

Sorry, I don't know. I just updated from Melpa and am currently on dashboard-20230103.501. As I auto-deleted the old package, I cannot check for the version number anymore. It is most probably the preceding version, as I tend to update quite regularly. Is there any other way to check which earlier versions were installed?

@jcs090218
Copy link
Member

I'm not entierly sure, but think the bug might here at this modification that is pretty rencent :
594f2d9#diff-c26fa000bfadfc4bb4a6f88e5d3d7e3d8c955f5d4f7b9e3d6693c7037b2e356aL499

The PR #427 calculate the length in pixels so it can correctly center characters like unicodes, emojis, etc.

The most relevant factor is (frame-char-width) in function dashboard-str-len. Is it not returning the correct value?

@fredericgiquel
Copy link

The problem is caused by a buggy string-pixel-width introduced by last compat package.

It will be fixed in the future compat release: emacs-compat/compat#8
It's also possible to patch dashboard to only use string-pixel-width with Emacs >= 29 as did doom-modeline (seagle0128/doom-modeline@fb516af)

See seagle0128/doom-modeline#601 for a long discussion about the problem.

@minad
Copy link

minad commented Jan 7, 2023

@fredericgiquel So it seems the string-pixel-width function wasn't only slow but also didn't compute the correct result. Interestingly the bug seems to only occur if one uses the Emacs daemon, so maybe one could work around this. Still, given the reports I don't have high hopes then that we can backport this function properly to Compat.

In any case, dropping it from Compat for now is the right approach given that @jcs090218 seems to use string-pixel-width in many of his packages (with a similar fboundp check as in doom-modeline).

@fredericgiquel
Copy link

@minad Here is what I see with Emacs 28.2 and Compat 29.1.0.1: string-pixel-width always return 0 whatever string is provided.

@minad
Copy link

minad commented Jan 8, 2023

@fredericgiquel Yes, that's obvious from the screenshot. Just update to the new version of Compat 29.1.1.0 released yesterday.

@jcs090218
Copy link
Member

Ah, okay. Now everything make sense. Since compat.el has dropped the function string-pixel-width (emacs-compat/compat@7c17c96), it should be good now.

@minad Thanks for taking care of this! 😄 👍

@ThibaultGH
Copy link
Author

ThibaultGH commented Jan 9, 2023

OK so an easy fix would be to update Compat to the 29.1.1.0 version.

Altough I did a M-x package-reinstall RET compat it seems that it did not fix the problem. As shown on the attached screenshot.
dashboard_notècentered

seagle0128 referenced this issue in emacs-compat/compat Jan 9, 2023
)

These functions seem to hangup from time to time on 28.2
(seagle0128/doom-modeline#601). By dropping the functions the hangup in
doom-modeline is resolved, since doom-modeline contains a runtime check for
string-pixel-width.

The compatibility function implementations do not contain any loops, this means
there is an underlying bug in `window-text-pixel-size' in 28.2 exposed by the
compatibility function. Either the compatibility function must be written in a
different form or we cannot provide them at all.
@jcs090218
Copy link
Member

Hmm... very strange. Can you try clean install the package? Maybe a quick hack is to replace the function dashboard-string-pixel-width to use shr-string-pixel-width, like:

(defun dashboard-string-pixel-width (str)
  "..."
  (require 'shr)
  (shr-string-pixel-width str))

eval- the above to override the function.

@ttybitnik
Copy link

OK so an easy fix would be to update Compat to the 29.1.1.0 version.

Altough I did a M-x package-reinstall RET compat it seems that it did not fix the problem. As shown on the attached screenshot. dashboard_notècentered

Disclaimer: I'm pretty new to Linux/Emacs/Git, meaning I can't evaluate well if it was a good approach, but I found a solution for that.

After doing some of the suggestions mentioned here, I realized that just refreshing the buffer fixes the problem. So all I did was adding the dashboard-refresh-buffer function to the dashboard's documentation daemon config.

(setq initial-buffer-choice (lambda () (dashboard-refresh-buffer)(get-buffer "*dashboard*")))

Now every emacsclient frame starts perfectly centralized (even some bugs I was having with the all-the-icons package were fixed). Hope it helps someway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants