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

Disable elcord's rich presence when editing *scratch* #17

Open
ralsei opened this issue Jan 6, 2020 · 7 comments
Open

Disable elcord's rich presence when editing *scratch* #17

ralsei opened this issue Jan 6, 2020 · 7 comments

Comments

@ralsei
Copy link

ralsei commented Jan 6, 2020

I use emacs --daemon, and frequently get queries about why "I've been playing Emacs for two days".
When I'm not actively editing a file, Discord shows me as editing the scratchpad.
Hence, I'd like to have functionality where Elcord disables rich presence when editing the buffer *scratch*, possibly only if the daemon is enabled, which can be checked via (daemonp).

@Zulu-Inuoe
Copy link
Collaborator

Funny you bring this up. I was considering something like this the other day when somebody asked me.

Here's one thing I considered: Have elcord disable itself when all visible* frames are closed, and have it automatically start up again on new frame creation. This way we get to keep using the daemon while having non-daemon-like behaviour.

Let me know what you think.

* visible because iirc running daemon mode has an invisible frame that always exists).

@ralsei
Copy link
Author

ralsei commented Jan 6, 2020

That seems pretty reasonable, especially compared to my proposal of disabling *scratch* (since there are valid reasons to be editing that buffer).

@Zulu-Inuoe
Copy link
Collaborator

Cool.

I didn't have much time to work on it today but I hacked this up pretty quick (emphasis on the word "hack")

(defun elcord--disable-elcord-if-no-frames (f)
    (declare (ignore f))
    (when (let ((frames (delete f (visible-frame-list))))
            (or (null frames)
                (and (null (cdr frames))
                     (eq (car frames) terminal-frame))))
      (elcord-mode -1)
      (add-hook 'after-make-frame-functions 'elcord--enable-on-frame-created)))

  (defun elcord--enable-on-frame-created (f)
    (declare (ignore f))
    (elcord-mode +1))

  (defun my/elcord-mode-hook ()
    (if elcord-mode
        (add-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)
      (remove-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)))

  (add-hook 'elcord-mode-hook 'my/elcord-mode-hook)

should work in practical use-cases, though it looks like there's no hook for detecting when a frame goes invisible (without deleting it)

If I get time I'll do more on it

@g0rdonL
Copy link

g0rdonL commented Apr 10, 2021

I'm using doom emacs and I keep on getting editing doom which is quite annoying :(

TheGreatMcPain added a commit to TheGreatMcPain/dotfiles that referenced this issue Sep 3, 2021
Basically it disables elcord if no frames are visible, and will
re-enable elcord if a new frame get created.

Code is based on: Mstrodl/elcord#17
@g0rdonL
Copy link

g0rdonL commented Mar 18, 2022

the above code works but it still shows scratch . Is the a way to filter it in (when (let ((frames (delete f (visible-frame-list)))) ?

@donCESAR12345
Copy link

Cool.

I didn't have much time to work on it today but I hacked this up pretty quick (emphasis on the word "hack")

(defun elcord--disable-elcord-if-no-frames (f)
    (declare (ignore f))
    (when (let ((frames (delete f (visible-frame-list))))
            (or (null frames)
                (and (null (cdr frames))
                     (eq (car frames) terminal-frame))))
      (elcord-mode -1)
      (add-hook 'after-make-frame-functions 'elcord--enable-on-frame-created)))

  (defun elcord--enable-on-frame-created (f)
    (declare (ignore f))
    (elcord-mode +1))

  (defun my/elcord-mode-hook ()
    (if elcord-mode
        (add-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)
      (remove-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)))

  (add-hook 'elcord-mode-hook 'my/elcord-mode-hook)

should work in practical use-cases, though it looks like there's no hook for detecting when a frame goes invisible (without deleting it)

If I get time I'll do more on it

Friendly reminder to ask if you got time for this :)

@nezia1
Copy link

nezia1 commented Apr 25, 2023

Cool.

I didn't have much time to work on it today but I hacked this up pretty quick (emphasis on the word "hack")

(defun elcord--disable-elcord-if-no-frames (f)
    (declare (ignore f))
    (when (let ((frames (delete f (visible-frame-list))))
            (or (null frames)
                (and (null (cdr frames))
                     (eq (car frames) terminal-frame))))
      (elcord-mode -1)
      (add-hook 'after-make-frame-functions 'elcord--enable-on-frame-created)))

  (defun elcord--enable-on-frame-created (f)
    (declare (ignore f))
    (elcord-mode +1))

  (defun my/elcord-mode-hook ()
    (if elcord-mode
        (add-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)
      (remove-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)))

  (add-hook 'elcord-mode-hook 'my/elcord-mode-hook)

should work in practical use-cases, though it looks like there's no hook for detecting when a frame goes invisible (without deleting it)

If I get time I'll do more on it

Thanks a lot, I've been searching for a way to do this 🙏🏻

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

5 participants