Skip to content

Commit

Permalink
emacs: Add workaround for elcord when using emacs as a daemon.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TheGreatMcPain committed Sep 3, 2021
1 parent dc35a56 commit 0524000
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
25 changes: 22 additions & 3 deletions .config/emacs/Emacs.org
Original file line number Diff line number Diff line change
Expand Up @@ -1179,15 +1179,34 @@ In order for this to work properly emacs needs to start a daemon on launch.
Some stuff that hasn't been covered by Emacs from Scratch yet, or just some personal emacs stuff.

** Elcord
elcord is a package that adds Discord Rich Presence to Emacs. It basically updates your Discord status to let everyone know your currently using Emacs.
[[https://github.com/Mstrodl/elcord][elcord]] is a package that adds Discord Rich Presence to Emacs. It basically updates your Discord status to let everyone know your currently using Emacs.

#+begin_src emacs-lisp
I've added the code from [[https://github.com/Mstrodl/elcord/issues/17][this issue]] which tells elcord to stop when no frames are visible. This allows using emacs as a daemon without elcord from constantly telling Discord that you're editing the stratch buffer dispite not having any frames open.

#+begin_src emacs-lisp

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

(defun elcord--disable-elcord-if-no-frames (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 jimjam/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)))

(use-package elcord
:config
(setq elcord-quiet t)
(add-hook 'elcord-mode-hook 'jimjam/elcord-mode-hook)
(elcord-mode 1))

#+end_src

** Ebuild Mode
Expand Down
17 changes: 17 additions & 0 deletions .config/emacs/init.el
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,24 @@
;; Make current emacs session a daemon if a server isn't already running.
(unless (server-running-p) (server-start))

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

(defun elcord--disable-elcord-if-no-frames (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 jimjam/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)))

(use-package elcord
:config
(setq elcord-quiet t)
(add-hook 'elcord-mode-hook 'jimjam/elcord-mode-hook)
(elcord-mode 1))

0 comments on commit 0524000

Please sign in to comment.