branch: externals/gpastel
commit 9362fee65c7a5f14d178353cc5ca9ce74de6e2f3
Author: Damien Cassou <[email protected]>
Commit: Damien Cassou <[email protected]>
Add a global minor mode (idea from Stefan Monnier)
---
README.org | 4 ++--
gpastel.el | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/README.org b/README.org
index a53bd7e..02d6f39 100644
--- a/README.org
+++ b/README.org
@@ -48,11 +48,11 @@ Add the following to your initialization file:
#+END_SRC
You also have to tell gpastel to start listening for GPaste events. If
-you are using EXWM, add ~gpastel-start-listening~ to
+you are using EXWM, add ~gpastel-mode~ to
~exwm-init-hook~. Otherwise, just add this line to your initialization file:
#+BEGIN_SRC emacs-lisp
- (gpastel-start-listening)
+ (gpastel-mode)
#+END_SRC
** Usage
diff --git a/gpastel.el b/gpastel.el
index c67cc8b..4381c35 100644
--- a/gpastel.el
+++ b/gpastel.el
@@ -138,5 +138,24 @@ all text in the GPaste clipboard."
(setq gpastel--dbus-object
(gpastel-dbus-call #'dbus-register-signal "Update"
#'gpastel--update-handler))))
+(defun gpastel-stop-listening ()
+ "Stop listening for GPaste events."
+ (interactive)
+ (when (dbus-unregister-object gpastel--dbus-object)
+ (setq gpastel--dbus-object nil)
+ (setq save-interprogram-paste-before-kill
gpastel--save-interprogram-paste-before-kill-orig)
+ (advice-remove interprogram-paste-function #'ignore)))
+
+;;;###autoload
+(define-minor-mode gpastel-mode
+ "Listen to GPaste events."
+ :group 'gpastel
+ :global t
+ :init-value nil
+ :require 'gpastel
+ (if gpastel-mode
+ (gpastel-start-listening)
+ (gpastel-stop-listening)))
+
(provide 'gpastel)
;;; gpastel.el ends here