From 280fece769a9fd30e12e5823ab329e7d0e64d7c2 Mon Sep 17 00:00:00 2001 From: Yoni Rabkin Date: Tue, 17 Nov 2020 17:32:36 -0500 Subject: * rt-liberation-viewer.el: section parsing --- rt-liberation-viewer.el | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'rt-liberation-viewer.el') diff --git a/rt-liberation-viewer.el b/rt-liberation-viewer.el index 359e600..327e79f 100644 --- a/rt-liberation-viewer.el +++ b/rt-liberation-viewer.el @@ -31,6 +31,12 @@ (require 'rt-liberation) +(defvar rt-liber-viewer-section-header-regexp + "^# [0-9]+/[0-9]+ (id/[0-9]+/total)") + +(defvar rt-liber-viewer-section-field-regexp + "^\\(.+\\): \\(.+\\)$") + (defconst rt-liber-viewer-font-lock-keywords (let ((header-regexp (regexp-opt '("id: " "Ticket: " "TimeTaken: " "Type: " "Field: " "OldValue: " @@ -53,6 +59,25 @@ (car section-list) (cadr section-list)))))))) +(defun rt-liber-viewer-parse-section (start end) + (goto-char start) + (when (not (re-search-forward rt-liber-viewer-section-header-regexp + end t)) + (error "invalid section")) + (forward-line 2) + (let (section-field-alist + section-field-end) + (save-excursion + (setq section-field-end + (re-search-forward "\n\n" end nil))) + (while (looking-at rt-liber-viewer-section-field-regexp) + (setq section-field-alist + (append section-field-alist + `((,(match-string-no-properties 1) . + ,(match-string-no-properties 2))))) + (forward-line)) + ( + ;; According to: ;; "https://rt-wiki.bestpractical.com/wiki/REST#Ticket_History" is of ;; the form: "# / (id//total)" @@ -65,16 +90,24 @@ (goto-char (point-min)) ;; find history detail sections and procude a list of section ;; (start . end) pairs - (let (section-point-list) - (while (re-search-forward "^# [0-9]+/[0-9]+ (id/[0-9]+/total)" (point-max) t) + (let (section-point-list + section-list) + (while (re-search-forward rt-liber-viewer-section-header-regexp (point-max) t) (setq section-point-list (append section-point-list - (list (point))))) + (list (point-at-bol))))) (when (not section-point-list) (error "no history detail sections found")) (setq section-point-list (append section-point-list (list (point-max))) section-point-list (rt-liber-viewer-reduce section-point-list #'cons nil)) - section-point-list))) + ;; collect the sections + (setq section-list + (mapcar + (lambda (section-points) + (rt-liber-viewer-parse-section + (car section-points) + (cdr section-points))) + section-point-list))))) (defun rt-liber-display-ticket-history (ticket-alist &optional assoc-browser) "Display history for ticket. -- cgit v1.2.3