Skip to content

Commit

Permalink
Introduce an ee-app-info-function customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
tecosaur committed Apr 16, 2024
1 parent bdc0ec3 commit 8868b9e
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions emacs-everywhere.el
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ Make sure that it will be matched by `emacs-everywhere-file-patterns'."
:type 'function
:group 'emacs-everywhere)

(defcustom emacs-everywhere-app-info-function
(pcase emacs-everywhere--display-server
(`(quartz . ,_) #'emacs-everywhere--app-info-osx)
(`(windows . ,_) #'emacs-everywhere--app-info-windows)
(`(x11 . ,_) #'emacs-everywhere--app-info-linux-x11)
(`(wayland . KDE) #'emacs-everywhere--app-info-linux-kde))
"Function that asks the system for information on the current foreground app.
On most systems, this should be set to a sensible default, but it
may not be set on less common configurations. If unset, a custom
app-info function can be used — see the various
emacs-everywhere--app-info-* functions for reference."
:type 'function
:group 'emacs-everywhere)

;; Semi-internal variables

(defconst emacs-everywhere-osascript-accessibility-error-message
Expand Down Expand Up @@ -429,20 +443,19 @@ Never paste content when ABORT is non-nil."
id class title geometry)

(defun emacs-everywhere-app-info ()
"Return information on the active window."
(let ((w (pcase system-type
(`darwin (emacs-everywhere--app-info-osx))
((or `ms-dos `windows-nt `cygwin)
(emacs-everywhere--app-info-windows))
(_ (emacs-everywhere--app-info-linux)))))
(setf (emacs-everywhere-app-title w)
(replace-regexp-in-string
(format " ?-[A-Za-z0-9 ]*%s"
(regexp-quote (emacs-everywhere-app-class w)))
""
(replace-regexp-in-string
"[^[:ascii:]]+" "-" (emacs-everywhere-app-title w))))
w))
"Return information on the active window.
This runs `emacs-everywhere-app-info-function' and lightly reformats the app title."
(if (functionp emacs-everywhere-app-info-function)
(let ((w (funcall emacs-everywhere-app-info-function)))
(setf (emacs-everywhere-app-title w)
(replace-regexp-in-string
(format " ?-[A-Za-z0-9 ]*%s"
(regexp-quote (emacs-everywhere-app-class w)))
""
(replace-regexp-in-string
"[^[:ascii:]]+" "-" (emacs-everywhere-app-title w))))
w)
(user-error "No app-info function is set, see `emacs-everywhere-app-info-function'")))

(defun emacs-everywhere--call (command &rest args)
"Execute COMMAND with ARGS synchronously."
Expand Down

0 comments on commit 8868b9e

Please sign in to comment.