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

Added project name display using projectile #89

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ For creating an 'Application':

After you've created your application, Customize `elcord-client-id` to be the new application's client ID,
and set the value of `elcord-mode-icon-alist` as appropriate to reference your new icons.

## Projectile Integration

elcord supports displaying which project you're currently working on by using [Projectile](https://github.com/bbatsov/projectile). Simply make sure that projectile is loaded before elcord, and enable the "Elcord Display Project Name" custimization via `M-x package-install RET elcord RET`, or `(setq elcord-display-project-name t)`.
Please note that line numbers and the project name cannot be displayed at the same time. Displaying line numbers will take precedence if both have been enabled.
48 changes: 36 additions & 12 deletions elcord.el
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ The mode text is the same found by `elcord-mode-text-alist'"
:type 'boolean
:group 'elcord)

(defcustom elcord-display-project-name 't
"When enabled, Discord status will display the project name the current buffer is part of:
\"Editing <buffer-name>\"
\"Working on <project-name>\"

When both elcord-display-line-numbers and elcord-display-project-name are enabled, displaying line numbers takes
precedence.

Requires Projectile.")

(defcustom elcord-display-line-numbers 't
"When enabled, shows the total line numbers of current buffer.
Including the position of the cursor in the buffer."
Expand All @@ -207,6 +217,12 @@ Swap this with your own function if you want a custom buffer-details message."
:type 'function
:group 'elcord)

(defcustom elcord-project-name-format-function 'elcord-project-name-format
"Function to return the project name string shown on discord.
Swap this with your own function if you want a custom project-name message."
:type 'function
:group 'elcord)

(defcustom elcord-use-major-mode-as-main-icon 'nil
"When enabled, the major mode determines the main icon, rather than it being the editor."
:type 'boolean
Expand Down Expand Up @@ -288,6 +304,9 @@ Unused on other platforms.")
(defvar elcord--idle-status nil
"Current idle status.")

(defvar elcord--projectile-present (when (require 'projectile nil 'noerror) t)
"Whether projectile is present or not.")

(defun elcord--make-process ()
"Make the asynchronous process that communicates with Discord IPC."
(let ((default-directory "~/"))
Expand Down Expand Up @@ -578,20 +597,25 @@ If no text is available, use the value of `mode-name'."
"Return the buffer details string shown on discord."
(format "Editing %s" (buffer-name)))

(defun elcord-project-name-format ()
"Return the project name as shown on discord."
(format "Working on %s" (projectile-project-name)))

(defun elcord--details-and-state ()
"Obtain the details and state to use for Discord's Rich Presence."
(let ((activity (if elcord-display-buffer-details
(if elcord-display-line-numbers
(list
(cons "details" (funcall elcord-buffer-details-format-function))
(cons "state" (format "Line %s of %S"
(format-mode-line "%l")
(+ 1 (count-lines (point-min) (point-max))))))
(list
(cons "details" (funcall elcord-buffer-details-format-function))))
(list
(cons "details" "Editing")
(cons "state" (elcord--mode-text))))))
(let ((activity (list
(if elcord-display-buffer-details
(cons "details" (funcall elcord-buffer-details-format-function))
(cons "details" "Editing")))))

(if elcord-display-line-numbers
(push (cons "state" (format "Line %s of %S"
(format-mode-line "%l")
(+ 1 (count-lines (point-min) (point-max)))))
activity)
(when (and elcord-display-project-name elcord--projectile-present (not (string= (projectile-project-name) "-")))
(push (cons "state" (funcall elcord-project-name-format-function)) activity)))

(when elcord-display-elapsed
(push (list "timestamps" (cons "start" elcord--startup-time)) activity))
activity))
Expand Down