* [PATCH] Add support for IRCv3 message tags
@ 2016-10-09 13:43 Vibhav Pant
2016-12-31 13:12 ` Vibhav Pant
0 siblings, 1 reply; 2+ messages in thread
From: Vibhav Pant @ 2016-10-09 13:43 UTC (permalink / raw)
To: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1740 bytes --]
The following patch adds support for IRCv3(.2) message tags
(http://ircv3.net/specs/core/message-tags-3.2.html), by adding a 'tags' memember
to the `erc-response` struct. Also, (erc-parse-server-response) is modified
so as to detect if the raw message has any tags preset, and if so, adds them to
the parsed message. Feedback would be appreciated.
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index bbb7ccb..f210e29 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -115,7 +115,8 @@ erc-server-responses
(sender "" :type string)
(command "" :type string)
(command-args '() :type list)
- (contents "" :type string))
+ (contents "" :type string)
+ (tags '() :type list))
;;; User data
@@ -961,10 +962,16 @@ erc-parse-server-response
PROCs `process-buffer' is `current-buffer' when this function is called."
(unless (string= string "") ;; Ignore empty strings
(save-match-data
- (let ((posn (if (eq (aref string 0) ?:)
- (string-match " " string)
- 0))
- (msg (make-erc-response :unparsed string)))
+ (let* ((tag-list (when (eq (aref string 0) ?@)
+ (split-string
+ (substring string 1 (string-match " " string)) ";")))
+ (msg (make-erc-response :unparsed string :tags tag-list))
+ (string (if tag-list
+ (substring string (+ 1 (string-match " " string)))
+ string))
+ (posn (if (eq (aref string 0) ?:)
+ (string-match " " string)
+ 0)))
(setf (erc-response.sender msg)
(if (eq posn 0)
--
Vibhav Pant
vibhavp@gmail.com
[-- Attachment #2: tags.diff --]
[-- Type: text/plain, Size: 1359 bytes --]
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index bbb7ccb..f210e29 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -115,7 +115,8 @@ erc-server-responses
(sender "" :type string)
(command "" :type string)
(command-args '() :type list)
- (contents "" :type string))
+ (contents "" :type string)
+ (tags '() :type list))
;;; User data
@@ -961,10 +962,16 @@ erc-parse-server-response
PROCs `process-buffer' is `current-buffer' when this function is called."
(unless (string= string "") ;; Ignore empty strings
(save-match-data
- (let ((posn (if (eq (aref string 0) ?:)
- (string-match " " string)
- 0))
- (msg (make-erc-response :unparsed string)))
+ (let* ((tag-list (when (eq (aref string 0) ?@)
+ (split-string
+ (substring string 1 (string-match " " string)) ";")))
+ (msg (make-erc-response :unparsed string :tags tag-list))
+ (string (if tag-list
+ (substring string (+ 1 (string-match " " string)))
+ string))
+ (posn (if (eq (aref string 0) ?:)
+ (string-match " " string)
+ 0)))
(setf (erc-response.sender msg)
(if (eq posn 0)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Add support for IRCv3 message tags
2016-10-09 13:43 [PATCH] Add support for IRCv3 message tags Vibhav Pant
@ 2016-12-31 13:12 ` Vibhav Pant
0 siblings, 0 replies; 2+ messages in thread
From: Vibhav Pant @ 2016-12-31 13:12 UTC (permalink / raw)
To: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 5176 bytes --]
I've further modified the patch to expose these message tags through
text-properties of the PRIVMSG they were sent with, thus they can be
accessed by ERC hooks. Also, the code for this feature rests in the
`features/erc-message-tags` branch.
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 288e8efe73..eed56174a8 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -53,6 +53,7 @@
;; CONTENTS --- `erc-response.contents'
;; SENDER --- `erc-response.sender'
;; LINE --- `erc-response.unparsed'
+;; TAGS --- `erc-response.tags'
;;
;; WARNING, WARNING!!
;; It's probably not a good idea to destructively modify the list
@@ -115,7 +116,8 @@ erc-server-responses
(sender "" :type string)
(command "" :type string)
(command-args '() :type list)
- (contents "" :type string))
+ (contents "" :type string)
+ (tags '() :type list))
;;; User data
@@ -955,16 +957,34 @@ erc-send-ctcp-notice
;;;; Handling responses
+(defun erc-parse-tags (string)
+ "Parse IRCv3 tags list in STRING to a (tag . value) alist."
+ (let ((tags)
+ (tag-strings (split-string string ";")))
+ (dolist (tag-string tag-strings tags)
+ (let ((pair (split-string tag-string "=")))
+ (push (if (consp pair)
+ pair
+ `(,pair))
+ tags)))))
+
(defun erc-parse-server-response (proc string)
"Parse and act upon a complete line from an IRC server.
PROC is the process (connection) from which STRING was received.
PROCs `process-buffer' is `current-buffer' when this function is called."
(unless (string= string "") ;; Ignore empty strings
(save-match-data
- (let ((posn (if (eq (aref string 0) ?:)
- (string-match " " string)
- 0))
- (msg (make-erc-response :unparsed string)))
+ (let* ((tag-list (when (eq (aref string 0) ?@)
+ (substring string 1 (string-match " " string))))
+ (msg (make-erc-response :unparsed string :tags (when tag-list
+ (erc-parse-tags
+ tag-list))))
+ (string (if tag-list
+ (substring string (+ 1 (string-match " " string)))
+ string))
+ (posn (if (eq (aref string 0) ?:)
+ (string-match " " string)
+ 0)))
(setf (erc-response.sender msg)
(if (eq posn 0)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 8501e2cba7..c66f9f56ec 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2700,7 +2700,10 @@ erc-display-message
(unless (erc-hide-current-message-p parsed)
(erc-put-text-property 0 (length string) 'erc-parsed parsed string)
(erc-put-text-property 0 (length string) 'rear-sticky t string)
- (erc-display-line string buffer)))))
+ (when (erc-response.tags parsed)
+ (erc-put-text-property 0 (length string) 'tags (erc-response.tags parsed)
+ string))
+ (erc-display-line string buffer)))))
(defun erc-message-type-member (position list)
"Return non-nil if the erc-parsed text-property at POSITION is in LIST.
On Sun, Oct 9, 2016 at 7:13 PM, Vibhav Pant <vibhavp@gmail.com> wrote:
> The following patch adds support for IRCv3(.2) message tags
> (http://ircv3.net/specs/core/message-tags-3.2.html), by adding a 'tags' memember
> to the `erc-response` struct. Also, (erc-parse-server-response) is modified
> so as to detect if the raw message has any tags preset, and if so, adds them to
> the parsed message. Feedback would be appreciated.
>
> diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
> index bbb7ccb..f210e29 100644
> --- a/lisp/erc/erc-backend.el
> +++ b/lisp/erc/erc-backend.el
> @@ -115,7 +115,8 @@ erc-server-responses
> (sender "" :type string)
> (command "" :type string)
> (command-args '() :type list)
> - (contents "" :type string))
> + (contents "" :type string)
> + (tags '() :type list))
>
> ;;; User data
>
> @@ -961,10 +962,16 @@ erc-parse-server-response
> PROCs `process-buffer' is `current-buffer' when this function is called."
> (unless (string= string "") ;; Ignore empty strings
> (save-match-data
> - (let ((posn (if (eq (aref string 0) ?:)
> - (string-match " " string)
> - 0))
> - (msg (make-erc-response :unparsed string)))
> + (let* ((tag-list (when (eq (aref string 0) ?@)
> + (split-string
> + (substring string 1 (string-match " " string)) ";")))
> + (msg (make-erc-response :unparsed string :tags tag-list))
> + (string (if tag-list
> + (substring string (+ 1 (string-match " " string)))
> + string))
> + (posn (if (eq (aref string 0) ?:)
> + (string-match " " string)
> + 0)))
>
> (setf (erc-response.sender msg)
> (if (eq posn 0)
>
> --
> Vibhav Pant
> vibhavp@gmail.com
--
Vibhav Pant
vibhavp@gmail.com
[-- Attachment #2: tags.diff --]
[-- Type: text/plain, Size: 3010 bytes --]
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 288e8efe73..eed56174a8 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -53,6 +53,7 @@
;; CONTENTS --- `erc-response.contents'
;; SENDER --- `erc-response.sender'
;; LINE --- `erc-response.unparsed'
+;; TAGS --- `erc-response.tags'
;;
;; WARNING, WARNING!!
;; It's probably not a good idea to destructively modify the list
@@ -115,7 +116,8 @@ erc-server-responses
(sender "" :type string)
(command "" :type string)
(command-args '() :type list)
- (contents "" :type string))
+ (contents "" :type string)
+ (tags '() :type list))
;;; User data
@@ -955,16 +957,34 @@ erc-send-ctcp-notice
;;;; Handling responses
+(defun erc-parse-tags (string)
+ "Parse IRCv3 tags list in STRING to a (tag . value) alist."
+ (let ((tags)
+ (tag-strings (split-string string ";")))
+ (dolist (tag-string tag-strings tags)
+ (let ((pair (split-string tag-string "=")))
+ (push (if (consp pair)
+ pair
+ `(,pair))
+ tags)))))
+
(defun erc-parse-server-response (proc string)
"Parse and act upon a complete line from an IRC server.
PROC is the process (connection) from which STRING was received.
PROCs `process-buffer' is `current-buffer' when this function is called."
(unless (string= string "") ;; Ignore empty strings
(save-match-data
- (let ((posn (if (eq (aref string 0) ?:)
- (string-match " " string)
- 0))
- (msg (make-erc-response :unparsed string)))
+ (let* ((tag-list (when (eq (aref string 0) ?@)
+ (substring string 1 (string-match " " string))))
+ (msg (make-erc-response :unparsed string :tags (when tag-list
+ (erc-parse-tags
+ tag-list))))
+ (string (if tag-list
+ (substring string (+ 1 (string-match " " string)))
+ string))
+ (posn (if (eq (aref string 0) ?:)
+ (string-match " " string)
+ 0)))
(setf (erc-response.sender msg)
(if (eq posn 0)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 8501e2cba7..c66f9f56ec 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2700,7 +2700,10 @@ erc-display-message
(unless (erc-hide-current-message-p parsed)
(erc-put-text-property 0 (length string) 'erc-parsed parsed string)
(erc-put-text-property 0 (length string) 'rear-sticky t string)
- (erc-display-line string buffer)))))
+ (when (erc-response.tags parsed)
+ (erc-put-text-property 0 (length string) 'tags (erc-response.tags parsed)
+ string))
+ (erc-display-line string buffer)))))
(defun erc-message-type-member (position list)
"Return non-nil if the erc-parsed text-property at POSITION is in LIST.
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-31 13:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-09 13:43 [PATCH] Add support for IRCv3 message tags Vibhav Pant
2016-12-31 13:12 ` Vibhav Pant
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).