diff options
| author | Vibhav Pant | 2017-04-24 11:57:46 +0530 |
|---|---|---|
| committer | Vibhav Pant | 2017-04-24 11:57:46 +0530 |
| commit | 2205546269bf5af01d766dc38720f71046b08dfa (patch) | |
| tree | 9759b460dcdda356875ac303056c870a769d1a3b | |
| parent | e589018b48f802d69f62ab1e7e266df1c7d8cf68 (diff) | |
| download | emacs-2205546269bf5af01d766dc38720f71046b08dfa.tar.gz emacs-2205546269bf5af01d766dc38720f71046b08dfa.zip | |
Add support for IRCv3 message tags.
* erc-backend.el:
erc-response: Add `tags' element.
Add (erc-parse-tags).
(erc-parse-server-response): Use (erc-parse-tags) to parse message
tags (if any), and store them in `erc-resopnse' struct.
* erc.el: (erc-display-message): Expose message tags with text
properties of the corresponding message line.
| -rw-r--r-- | lisp/erc/erc-backend.el | 30 | ||||
| -rw-r--r-- | lisp/erc/erc.el | 5 |
2 files changed, 29 insertions, 6 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 8eac2e18aee..3368d6701ae 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | ;; CONTENTS --- `erc-response.contents' | 53 | ;; CONTENTS --- `erc-response.contents' |
| 54 | ;; SENDER --- `erc-response.sender' | 54 | ;; SENDER --- `erc-response.sender' |
| 55 | ;; LINE --- `erc-response.unparsed' | 55 | ;; LINE --- `erc-response.unparsed' |
| 56 | ;; TAGS --- `erc-response.tags' | ||
| 56 | ;; | 57 | ;; |
| 57 | ;; WARNING, WARNING!! | 58 | ;; WARNING, WARNING!! |
| 58 | ;; It's probably not a good idea to destructively modify the list | 59 | ;; It's probably not a good idea to destructively modify the list |
| @@ -115,7 +116,8 @@ | |||
| 115 | (sender "" :type string) | 116 | (sender "" :type string) |
| 116 | (command "" :type string) | 117 | (command "" :type string) |
| 117 | (command-args '() :type list) | 118 | (command-args '() :type list) |
| 118 | (contents "" :type string)) | 119 | (contents "" :type string) |
| 120 | (tags '() :type list)) | ||
| 119 | 121 | ||
| 120 | ;;; User data | 122 | ;;; User data |
| 121 | 123 | ||
| @@ -955,16 +957,34 @@ See also `erc-server-send'." | |||
| 955 | 957 | ||
| 956 | ;;;; Handling responses | 958 | ;;;; Handling responses |
| 957 | 959 | ||
| 960 | (defun erc-parse-tags (string) | ||
| 961 | "Parse IRCv3 tags list in STRING to a (tag . value) alist." | ||
| 962 | (let ((tags) | ||
| 963 | (tag-strings (split-string string ";"))) | ||
| 964 | (dolist (tag-string tag-strings tags) | ||
| 965 | (let ((pair (split-string tag-string "="))) | ||
| 966 | (push (if (consp pair) | ||
| 967 | pair | ||
| 968 | `(,pair)) | ||
| 969 | tags))))) | ||
| 970 | |||
| 958 | (defun erc-parse-server-response (proc string) | 971 | (defun erc-parse-server-response (proc string) |
| 959 | "Parse and act upon a complete line from an IRC server. | 972 | "Parse and act upon a complete line from an IRC server. |
| 960 | PROC is the process (connection) from which STRING was received. | 973 | PROC is the process (connection) from which STRING was received. |
| 961 | PROCs `process-buffer' is `current-buffer' when this function is called." | 974 | PROCs `process-buffer' is `current-buffer' when this function is called." |
| 962 | (unless (string= string "") ;; Ignore empty strings | 975 | (unless (string= string "") ;; Ignore empty strings |
| 963 | (save-match-data | 976 | (save-match-data |
| 964 | (let ((posn (if (eq (aref string 0) ?:) | 977 | (let* ((tag-list (when (eq (aref string 0) ?@) |
| 965 | (string-match " " string) | 978 | (substring string 1 (string-match " " string)))) |
| 966 | 0)) | 979 | (msg (make-erc-response :unparsed string :tags (when tag-list |
| 967 | (msg (make-erc-response :unparsed string))) | 980 | (erc-parse-tags |
| 981 | tag-list)))) | ||
| 982 | (string (if tag-list | ||
| 983 | (substring string (+ 1 (string-match " " string))) | ||
| 984 | string)) | ||
| 985 | (posn (if (eq (aref string 0) ?:) | ||
| 986 | (string-match " " string) | ||
| 987 | 0))) | ||
| 968 | 988 | ||
| 969 | (setf (erc-response.sender msg) | 989 | (setf (erc-response.sender msg) |
| 970 | (if (eq posn 0) | 990 | (if (eq posn 0) |
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 7e19ebbf980..8c65016ed22 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el | |||
| @@ -2700,7 +2700,10 @@ See also `erc-format-message' and `erc-display-line'." | |||
| 2700 | (unless (erc-hide-current-message-p parsed) | 2700 | (unless (erc-hide-current-message-p parsed) |
| 2701 | (erc-put-text-property 0 (length string) 'erc-parsed parsed string) | 2701 | (erc-put-text-property 0 (length string) 'erc-parsed parsed string) |
| 2702 | (erc-put-text-property 0 (length string) 'rear-sticky t string) | 2702 | (erc-put-text-property 0 (length string) 'rear-sticky t string) |
| 2703 | (erc-display-line string buffer))))) | 2703 | (when (erc-response.tags parsed) |
| 2704 | (erc-put-text-property 0 (length string) 'tags (erc-response.tags parsed) | ||
| 2705 | string)) | ||
| 2706 | (erc-display-line string buffer))))) | ||
| 2704 | 2707 | ||
| 2705 | (defun erc-message-type-member (position list) | 2708 | (defun erc-message-type-member (position list) |
| 2706 | "Return non-nil if the erc-parsed text-property at POSITION is in LIST. | 2709 | "Return non-nil if the erc-parsed text-property at POSITION is in LIST. |