Subject: bug#35141: closed (Re: bug#35141: Add a default action to erc-desktop-notifications to switch to the originating buffer)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 12 Apr 2019 12:17:02 +0000

Your bug report

#35141: Add a default action to erc-desktop-notifications to switch to the originating buffer

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
35141: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=35141
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#35141: Add a default action to erc-desktop-notifications to switch to the originating buffer
From: "Basil L. Contovounesios" <[email-masked]>
To: Alex Murray <[email-masked]>
Cc: [email-masked]
Date: Fri, 12 Apr 2019 13:16:41 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Alex Murray <[email-masked]> writes:

> Done - see attached. Thanks again for your help.
>
> On Fri, 5 Apr 2019 at 21:52, Basil L. Contovounesios <[email-masked]> wrote:
>
>  Otherwise LGTM, but we'll have to wait a few days to give others a
>  chance to comment.

Thanks, pushed to master[1].  I made minor edits to the commit message
to follow CONTRIBUTE guidelines and to make it slightly more accurate
and less redundant.

[1: 6dc4c722af]: Pop to originating erc buffer when clicking desktop notification
  2019-04-12 13:08:28 +0100
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=6dc4c722af4e5f9f189631638700cd1fb3cc2edb

If you're interested in making further contributions, I would recommend
starting the copyright assignment process.  See CONTRIBUTE and (info
"(emacs) Copyright Assignment") for details.

Thanks,

-- 
Basil

Subject: Add a default action to erc-desktop-notifications to switch to the originating buffer
From: Alex Murray <[email-masked]>
To: [email-masked]
Date: Thu, 4 Apr 2019 17:02:24 +1030
List-Id: <debbugs-submit.debbugs.gnu.org>

Attached is a patch which converts erc-desktop-notifications.el to
lexical-binding and adds a default action to the generated notifications so
that when they are clicked we automatically switch to the originating
buffer.
From 52b63272eed8aaafcd931e833ad006dd425d6512 Mon Sep 17 00:00:00 2001
From: Alex Murray <[email-masked]>
Date: Thu, 4 Apr 2019 16:49:48 +1030
Subject: [PATCH] Switch to originating erc buffer when clicking desktop
 notification

* lisp/erc/erc-desktop-notifications.el: Switch to lexical-binding and
  add a default action to the desktop notification which switches to
  the buffer from which the notification originated. As such clicking
  on the notification now automatically switches to that buffer.
---
 ChangeLog.3                           |  7 +++++++
 lisp/erc/erc-desktop-notifications.el | 18 ++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/ChangeLog.3 b/ChangeLog.3
index 235c8bb180..3819d6b4fe 100644
--- a/ChangeLog.3
+++ b/ChangeLog.3
@@ -1,3 +1,10 @@
+2019-04-04  Alex Murray  <[email-masked]>
+
+	* lisp/erc/erc-desktop-notifications.el: Use lexical-binding.
+	(erc-notifications-notify): Add a default action to
+	notifications which switches to the buffer from which the
+	notification originated.
+
 2019-03-20  Eli Zaretskii  <[email-masked]>
 
 	Improve indexing of the user manual
diff --git a/lisp/erc/erc-desktop-notifications.el b/lisp/erc/erc-desktop-notifications.el
index 56b93925ce..c1b812c119 100644
--- a/lisp/erc/erc-desktop-notifications.el
+++ b/lisp/erc/erc-desktop-notifications.el
@@ -1,4 +1,4 @@
-;; erc-desktop-notifications.el -- Send notification on PRIVMSG or mentions
+;; erc-desktop-notifications.el -- Send notification on PRIVMSG or mentions -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2012-2019 Free Software Foundation, Inc.
 
@@ -59,11 +59,17 @@
 This will replace the last notification sent with this function."
   (dbus-ignore-errors
     (setq erc-notifications-last-notification
-          (notifications-notify :bus erc-notifications-bus
-				:title (xml-escape-string nick)
-                                :body (xml-escape-string msg)
-                                :replaces-id erc-notifications-last-notification
-                                :app-icon erc-notifications-icon))))
+          (let ((channel (current-buffer)))
+            (notifications-notify :bus erc-notifications-bus
+                                  :title (format "%s in %s"
+                                                 (xml-escape-string nick)
+                                                 (buffer-name channel))
+                                  :body (xml-escape-string msg)
+                                  :replaces-id erc-notifications-last-notification
+                                  :app-icon erc-notifications-icon
+                                  :actions '("default" "Switch to buffer")
+                                  :on-action #'(lambda (id action)
+                                                 (switch-to-buffer channel)))))))
 
 (defun erc-notifications-PRIVMSG (proc parsed)
   (let ((nick (car (erc-parse-user (erc-response.sender parsed))))
-- 
2.17.1