[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pdf-tools efd4ceee1a: pdf-annot: Add function to sort the
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pdf-tools efd4ceee1a: pdf-annot: Add function to sort the date field |
Date: |
Fri, 22 Jul 2022 20:58:58 -0400 (EDT) |
branch: elpa/pdf-tools
commit efd4ceee1a00df80a6e5815148e300ef50ec5d41
Author: Visuwesh <visuweshm@gmail.com>
Commit: Vedang Manerikar <ved.manerikar@gmail.com>
pdf-annot: Add function to sort the date field
Previously, the `date` field was sorted alphabetically, instead of
according to date.
Changes:
* lisp/pdf-annot.el (pdf-annot--make-entry-formatter): Propertize
string to include the lisp date.
(pdf-annot-list-mode): Add function to sort date.
Notes:
- Why use `propertize` instead of parsing the string back?
+ Because there are annotations with no associated dates. In this
case, we display the string "No date". Our parsing code would have
to handle that, `propertize` is just simpler and covers all edge-cases
correctly.
- What can we do better?
+ Currently, the index of the field we are looking up is hard-coded.
So any change in the fields will impact this code silently. We need
to add tests to ensure this is caught.
Closes: #75
---
lisp/pdf-annot.el | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/lisp/pdf-annot.el b/lisp/pdf-annot.el
index 86b483ed3d..4a8c2e9c71 100644
--- a/lisp/pdf-annot.el
+++ b/lisp/pdf-annot.el
@@ -1642,7 +1642,9 @@ pretty-printed output."
(lambda (str)
(replace-regexp-in-string "\n" " " str t t))))
(cl-ecase entry-type
- (date (pdf-annot-print-property a 'modified))
+ (date (propertize (pdf-annot-print-property a 'modified)
+ 'date
+ (pdf-annot-get a 'modified)))
(page (pdf-annot-print-property a 'page))
(label (funcall prune-newlines
(pdf-annot-print-property a 'label)))
@@ -1669,19 +1671,38 @@ pretty-printed output."
pdf-annot-list-format))))
(define-derived-mode pdf-annot-list-mode tablist-mode "Annots"
+ ;; @TODO: Remove the hard-coded index values here, and figure out a
+ ;; way to properly link this to the index values of
+ ;; `pdf-annot-list-format'.
+
+ ;; @TODO: Add tests for annotation formatting and display
(let* ((page-sorter
(lambda (a b)
(< (string-to-number (aref (cadr a) 0))
(string-to-number (aref (cadr b) 0)))))
+ (date-sorter
+ (lambda (a b)
+ (time-less-p (get-text-property 0 'date (aref (cadr a) 3))
+ (get-text-property 0 'date (aref (cadr b) 3)))))
(format-generator
(lambda (format)
(let ((field (car format))
(width (cdr format)))
(cl-case field
- (page `("Pg." 3 ,page-sorter :read-only t :right-alight t))
+ (page `("Pg."
+ ,width
+ ,page-sorter
+ :read-only t
+ :right-align t))
+ (date `("Date"
+ ,width
+ ,date-sorter
+ :read-only t))
(t (list
(capitalize (symbol-name field))
- width t :read-only t)))))))
+ width
+ t
+ :read-only t)))))))
(setq tabulated-list-entries 'pdf-annot-list-entries
tabulated-list-format (vconcat
(mapcar
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/pdf-tools efd4ceee1a: pdf-annot: Add function to sort the date field,
ELPA Syncer <=