Change sorting algorithm v1 SUPERSEDED

Ivan Sokolov: 1
 Change sorting algorithm

 1 files changed, 17 insertions(+), 19 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~brettgilio/org-webring/patches/12015/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Change sorting algorithm Export this patch

- use cl-sort
- remove org-webring-sort-items-by-pub-date (uncomposable)
- rename org-webring--pub-date-to-time to org-webring--date->time
- add type for org-webring-attribution
- require org (for org-time-stamp-formats)
 org-webring.el | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/org-webring.el b/org-webring.el
index c4e3211..5af2817 100644
--- a/org-webring.el
+++ b/org-webring.el
@@ -50,6 +50,7 @@

(require 'cl-lib)
(require 'dom)
(require 'org)
(require 'seq)
(require 'url)
(require 'xml)
@@ -75,7 +76,8 @@
generate the webring to its URL to be displayed at the bottom
of the webring."
  :group 'org-webring
  :type 'sexp)
  :type '(cons (string :tag "Name")
               (string :tag "URL")))

(defcustom org-webring-urls '()
  "The links for the RSS feeds to be scraped for items."
@@ -120,10 +122,6 @@ FEED, ignoring the items."
		(url-insert-file-contents link)

(defun org-webring--pub-date-to-time (pub-date)
  "Convert the a 'pubDate' string to a time value."
  (apply 'encode-time (parse-time-string pub-date)))

(defun org-webring--get-items-from-urls (urls)
  "Create a list of all the items contained in the URLS list of
RSS feed links."
@@ -142,14 +140,6 @@ RSS feed links."

(defun org-webring--sort-items-by-pub-date (items)
  "Sort a list of parsed RSS feed items by newest."
  (sort items
	(lambda (x y)
	  (let ((t1 (org-webring--pub-date-to-time (org-webring--feed-text-prop x 'pubDate)))
		(t2 (org-webring--pub-date-to-time (org-webring--feed-text-prop y 'pubDate))))
	    (not (time-less-p t1 t2))))))

(defun org-webring--string-truncate (len s elipsis)
  "If S is longer than LEN, cut it down and add ELIPSIS at the
end. Taken from the s.el library."
@@ -183,17 +173,25 @@ end. Taken from the s.el library."
						  (org-webring--feed-text-prop item 'pubDate)

(defun org-webring--date->time (date)
  "Convert DATE string to a time value."
  (apply 'encode-time (parse-time-string date)))

(defun org-webring--pub-time (item)
  "Get ITEM's publication time."
   (org-webring--feed-text-prop item 'pubDate)))

(defun org-webring-generate-webring ()
  "Generate the entire webring and return it as HTML."
  (let ((items (org-webring--sort-items-by-pub-date
		(org-webring--get-items-from-urls org-webring-urls))))
  (let* ((items (org-webring--get-items-from-urls org-webring-urls))
         (sorted-items (cl-sort items #'time-less-p :key #'org-webring--pub-time))
         (most-recent (last sorted-items org-webring-items-total))
         (articles (mapcar #'org-webring--article-instance most-recent)))
     `(section :class "feed"
	       (h4 feed-header)
	       (section :class "articles"
			,@(cl-loop repeat org-webring-items-total
				   for item in items
				   collect (org-webring--article-instance item)))
	       (section :class "articles" ,@articles)
	       (p :class "attribution"
		  (span :class "timestamp-wrapper"
			(span :class "timestamp"