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

It doesn't work when treemacs is activated #17

Closed
IceAsteroid opened this issue Dec 6, 2023 · 5 comments
Closed

It doesn't work when treemacs is activated #17

IceAsteroid opened this issue Dec 6, 2023 · 5 comments

Comments

@IceAsteroid
Copy link

IceAsteroid commented Dec 6, 2023

It's shown as follows:

perfect-margin-issue2.mp4

Is it by design, or an unexpected effect?

It may not be clear, since the example shown is in a small size, but when I full screen emacs, it'd become so apparent as the text is still too wide in the buffer. since perfect-margin doesn't work at all when treemacs is activated.


Here's the configuration:

  (use-package perfect-margin
    :ensure t
    :init
    (defcustom perfect-margin-ignore-regexps
      '("^minibuf" "^[[:space:]]*\\*")
      ;;'("^minibuf" "^[[:space:]]*\\*" "*Treemacs*")
      "List of strings to determine if window is ignored.
       Each string is used as regular expression to match the window buffer name."
      :group 'perfect-margin)
    (defcustom perfect-margin-ignore-filters
      '(window-minibuffer-p)
      "List of functions to determine if window is ignored.
       Each function is called with window as its sole arguemnt,
       returning a non-nil value indicate to ignore the window."
      :group 'perfect-margin)
    :custom
    (perfect-margin-visible-width 128)
    :config
    ;; enable perfect-mode
    (perfect-margin-mode t)
    ;; auto-center minibuffer windows
    (setq perfect-margin-ignore-filters nil)
    ;; auto-center special windows
    (setq perfect-margin-ignore-regexps nil)
    ;; add additinal bding on margin area
    (dolist (margin '("<left-margin> " "<right-margin> "))
      (global-set-key (kbd (concat margin "<mouse-1>")) 'ignore)
      (global-set-key (kbd (concat margin "<mouse-3>")) 'ignore)
      (dolist (multiple '("" "double-" "triple-"))
	(global-set-key (kbd (concat margin "<" multiple "wheel-up>")) 'mwheel-scroll)
	(global-set-key (kbd (concat margin "<" multiple "wheel-down>")) 'mwheel-scroll))))

Any ideas?

@mpwang
Copy link
Owner

mpwang commented Dec 7, 2023

Thank you for the feedback! Unfortunately, pefect-margin is not compatible with treemcs at the moment because treemacs manages its own windows.

In order for pefect-margin to work with treemacs, it would need to incorporate special logic to adapt to the treemacs window on the left side. This is feasible since similar logic has already been implemented for the minimap's special window. I will need some time to investigate this further.

@IceAsteroid
Copy link
Author

IceAsteroid commented Dec 7, 2023

@mpwang Got it. Thanks for the great work!

Also may I ask, how can perfect-margin be disabled completely when treemacs is opened, and to re-enable it when treemacs is closed?

It somtimes makes the "display-line-numbers" columns too wide with spaces right near between treemacs & the buffer.

Like this:

perfect-margin-issue3.mp4

The following code just can't work

  (use-package treemacs
    :ensure t
    :defer t
    :hook
    (treemacs-mode . (lambda () (perfect-margin-mode -1)))
    (treemacs-quit . (lambda () (perfect-margin-mode 1)))
	;; Omitted lines.

I have also tried to add these two lines outside of use-pacakge, like follows, but it still can't work. When treemacs is closed, the hook doesn't bring the (perfect-margin-mode) back at all, as I type M-x perfect-margin-mode, it shows it's just enabled by the command I've typed

    (add-hook 'treemacs-mode-hook (lambda () (perfect-margin-mode -1)))
    (add-hook 'treemacs-quit-hook (lambda () (perfect-margin-mode 1)))

Later I also delete the keyword ":defer t" for treemacs, but the hooks still can't work either in use-pacakge section of either treemacs or perfect-margin nor outside of use-package. So, it's the issue with these hooks


Shall I repost this issue as a new issue for everyone to be able to see?

@mpwang
Copy link
Owner

mpwang commented Dec 13, 2023

Please try downloading the latest version to see if the issue still persists. This version should have support for Treemacs.

@IceAsteroid
Copy link
Author

IceAsteroid commented Dec 13, 2023

Thank you so much for the improvement. It works pefectly with treemacs now!

With a sidebar like org-side-tree opened, the perfect-margin also can't work. Maybe adding a more general solution to sidebar windows like 'treemacs" and others would be more acceptable.

I'm sorry, I didn't mean to describe the issue not comprehensively. The "org-side-tree" was just a package that I just tried in a recent few days.

The config used is same as above.

perfect-margin-issue4.mp4

@mpwang
Copy link
Owner

mpwang commented Dec 15, 2023

Thanks for the feedback!

I'm afraid that for every package that manage its left split window perfect-margin has to adapt special logic.

Even if I use a generic mechanism to allow user to specify the package they want to work with perfect-margin, user still have to look at the package source code and inspect what buffer name or special window they want to corporate then they can write the code to inject to perfect-margin to make it work. I think this is way too complicated for the end user.

As there is no common standard for package writers to specify their special window/buffer name. I think there might not be a general solution. Adding support to widely used packages is fine for me.

Please close this issue and re-post the org-side-tree support into a new issue. Thanks.

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

2 participants