diff options
| author | Visuwesh <visuweshm@gmail.com> | 2022-01-29 20:01:23 +0530 |
|---|---|---|
| committer | Vedang Manerikar <ved.manerikar@gmail.com> | 2022-07-22 17:32:11 -0700 |
| commit | efd4ceee1a00df80a6e5815148e300ef50ec5d41 (patch) | |
| tree | 6d7290cce60844958881bfb1ce0a11fd4707ed5e | |
| parent | 0b8d47ddddbf2e41a446df847701d00a9de01745 (diff) | |
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
| -rw-r--r-- | lisp/pdf-annot.el | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lisp/pdf-annot.el b/lisp/pdf-annot.el index 86b483e..4a8c2e9 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 |
