Mstrodl / elcord

Discord Rich Presence / Gamebridge support for Emacs!
MIT License
196 stars 44 forks source link

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

Open ralsei opened 4 years ago

ralsei commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

Zulu-Inuoe commented 4 years ago

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 commented 3 years ago

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

g0rdonL commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 🙏🏻