unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35331: [PATCH] Neater html table of old versions in ELPA
@ 2019-04-19 21:36 Mattias Engdegård
  2019-04-21 16:09 ` Basil L. Contovounesios
  0 siblings, 1 reply; 9+ messages in thread
From: Mattias Engdegård @ 2019-04-19 21:36 UTC (permalink / raw)
  To: 35331

[-- Attachment #1: Type: text/plain, Size: 129 bytes --]

This patch sorts the "old versions" table for each ELPA package in reverse chronological order, and uses correct unit prefixes.

[-- Attachment #2: 0001-Neater-html-table-of-old-versions.patch --]
[-- Type: application/octet-stream, Size: 2374 bytes --]

From 5fecea5da0cd87f73d77a78a80496f8aaf4a62dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Fri, 19 Apr 2019 23:27:47 +0200
Subject: [PATCH] Neater html table of old versions

* admin/archive-contents.el (archive--html-bytes-format): Use IEC prefixes.
(archive--html-make-pkg): Sort old versions in newest-to-oldest order.
---
 admin/archive-contents.el | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/admin/archive-contents.el b/admin/archive-contents.el
index 30245437f..c7cac6e40 100644
--- a/admin/archive-contents.el
+++ b/admin/archive-contents.el
@@ -388,15 +388,15 @@ Rename DIR/ to PKG-VERS/, and return the descriptor."
 (defun archive--html-bytes-format (bytes) ;Aka memory-usage-format.
   (setq bytes (/ bytes 1024.0))
   (let ((units '(;; "B"
-                 "kB" "MB" "GB" "TB")))
+                 "KiB" "MiB" "GiB" "TiB")))
     (while (>= bytes 1024)
       (setq bytes (/ bytes 1024.0))
       (setq units (cdr units)))
     (cond
-     ;; ((integerp bytes) (format "%4d%s" bytes (car units)))
-     ((>= bytes 100) (format "%4.0f%s" bytes (car units)))
-     ((>= bytes 10) (format "%4.1f%s" bytes (car units)))
-     (t (format "%4.2f%s" bytes (car units))))))
+     ;; ((integerp bytes) (format "%4d %s" bytes (car units)))
+     ((>= bytes 100) (format "%4.0f %s" bytes (car units)))
+     ((>= bytes 10) (format "%4.1f %s" bytes (car units)))
+     (t (format "%4.2f %s" bytes (car units))))))
 
 (defun archive--get-prop (prop name srcdir mainsrcfile)
   (let ((kprop (intern (format ":%s" (downcase prop)))))
@@ -536,7 +536,10 @@ Rename DIR/ to PKG-VERS/, and return the descriptor."
                   "\n</pre>\n")))
       (unless (< (length files) (if (zerop (length latest)) 1 2))
         (insert (format "<h2>Old versions</h2><table>\n"))
-        (dolist (file files)
+        (dolist (file 
+                 (sort files (lambda (f1 f2)
+                               (version-list-< (version-to-list (car f2))
+                                               (version-to-list (car f1))))))
           (unless (equal (pop file) latest)
             (let ((attrs (file-attributes file)))
               (insert (format "<tr><td><a href=%S>%s</a></td><td>%s</td><td>%s</td>\n"
-- 
2.20.1 (Apple Git-117)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-04-19 21:36 bug#35331: [PATCH] Neater html table of old versions in ELPA Mattias Engdegård
@ 2019-04-21 16:09 ` Basil L. Contovounesios
  2019-04-22 13:17   ` Mattias Engdegård
  0 siblings, 1 reply; 9+ messages in thread
From: Basil L. Contovounesios @ 2019-04-21 16:09 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 35331

Mattias Engdegård <mattiase@acm.org> writes:

> @@ -536,7 +536,10 @@ Rename DIR/ to PKG-VERS/, and return the descriptor."
>                    "\n</pre>\n")))
>        (unless (< (length files) (if (zerop (length latest)) 1 2))
>          (insert (format "<h2>Old versions</h2><table>\n"))
> -        (dolist (file files)
> +        (dolist (file 
> +                 (sort files (lambda (f1 f2)
> +                               (version-list-< (version-to-list (car f2))
> +                                               (version-to-list (car f1))))))

AKA

  (dolist (file (sort files (lambda (f1 f2)
                              (version< (car f2) (car f1)))))
    ...)

Thanks,

-- 
Basil





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-04-21 16:09 ` Basil L. Contovounesios
@ 2019-04-22 13:17   ` Mattias Engdegård
  2019-05-13 13:42     ` Mattias Engdegård
  0 siblings, 1 reply; 9+ messages in thread
From: Mattias Engdegård @ 2019-04-22 13:17 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35331

21 apr. 2019 kl. 18.09 skrev Basil L. Contovounesios <contovob@tcd.ie>:
> 
>  (dolist (file (sort files (lambda (f1 f2)
>                              (version< (car f2) (car f1)))))
>    ...)

Thank you, I obviously didn't do my homework properly.
Please consider the patch as if it had that improvement.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-04-22 13:17   ` Mattias Engdegård
@ 2019-05-13 13:42     ` Mattias Engdegård
  2019-05-13 14:25       ` Basil L. Contovounesios
  0 siblings, 1 reply; 9+ messages in thread
From: Mattias Engdegård @ 2019-05-13 13:42 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35331

[-- Attachment #1: Type: text/plain, Size: 213 bytes --]

> 21 apr. 2019 kl. 18.09 skrev Basil L. Contovounesios <contovob@tcd.ie>:
>> 
>> (dolist (file (sort files (lambda (f1 f2)
>>                             (version< (car f2) (car f1)))))
>>   ...)

Revised patch.


[-- Attachment #2: 0001-Neater-HTML-table-of-old-package-versions-bug-35331.patch --]
[-- Type: application/octet-stream, Size: 2219 bytes --]

From f9a3ca2c0e76b93394bf20e7dba9912376da8f4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Fri, 19 Apr 2019 23:27:47 +0200
Subject: [PATCH] Neater HTML table of old package versions (bug#35331)

* admin/archive-contents.el (archive--html-bytes-format): Use IEC prefixes.
(archive--html-make-pkg): Sort old versions in newest-to-oldest order.
---
 admin/archive-contents.el | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/admin/archive-contents.el b/admin/archive-contents.el
index de444e381..c4c2e5af1 100644
--- a/admin/archive-contents.el
+++ b/admin/archive-contents.el
@@ -387,16 +387,14 @@ Rename DIR/ to PKG-VERS/, and return the descriptor."
 
 (defun archive--html-bytes-format (bytes) ;Aka memory-usage-format.
   (setq bytes (/ bytes 1024.0))
-  (let ((units '(;; "B"
-                 "kB" "MB" "GB" "TB")))
+  (let ((units '("KiB" "MiB" "GiB" "TiB")))
     (while (>= bytes 1024)
       (setq bytes (/ bytes 1024.0))
       (setq units (cdr units)))
     (cond
-     ;; ((integerp bytes) (format "%4d%s" bytes (car units)))
-     ((>= bytes 100) (format "%4.0f%s" bytes (car units)))
-     ((>= bytes 10) (format "%4.1f%s" bytes (car units)))
-     (t (format "%4.2f%s" bytes (car units))))))
+     ((>= bytes 100) (format "%4.0f&nbsp;%s" bytes (car units)))
+     ((>= bytes 10) (format "%4.1f&nbsp;%s" bytes (car units)))
+     (t (format "%4.2f&nbsp;%s" bytes (car units))))))
 
 (defun archive--get-prop (prop name srcdir mainsrcfile)
   (let ((kprop (intern (format ":%s" (downcase prop)))))
@@ -536,7 +534,8 @@ Rename DIR/ to PKG-VERS/, and return the descriptor."
                   "\n</pre>\n")))
       (unless (< (length files) (if (zerop (length latest)) 1 2))
         (insert (format "<h2>Old versions</h2><table>\n"))
-        (dolist (file files)
+        (dolist (file
+                 (sort files (lambda (f1 f2) (version< (car f2) (car f1)))))
           (unless (equal (pop file) latest)
             (let ((attrs (file-attributes file)))
               (insert (format "<tr><td><a href=%S>%s</a></td><td>%s</td><td>%s</td>\n"
-- 
2.20.1 (Apple Git-117)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-05-13 13:42     ` Mattias Engdegård
@ 2019-05-13 14:25       ` Basil L. Contovounesios
  2019-05-13 15:18         ` Mattias Engdegård
  2019-05-15 20:16         ` Mattias Engdegård
  0 siblings, 2 replies; 9+ messages in thread
From: Basil L. Contovounesios @ 2019-05-13 14:25 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 35331

Mattias Engdegård <mattiase@acm.org> writes:

> diff --git a/admin/archive-contents.el b/admin/archive-contents.el
> index de444e381..c4c2e5af1 100644
> --- a/admin/archive-contents.el
> +++ b/admin/archive-contents.el
> @@ -387,16 +387,14 @@ Rename DIR/ to PKG-VERS/, and return the descriptor."
>  
>  (defun archive--html-bytes-format (bytes) ;Aka memory-usage-format.
>    (setq bytes (/ bytes 1024.0))
> -  (let ((units '(;; "B"
> -                 "kB" "MB" "GB" "TB")))
> +  (let ((units '("KiB" "MiB" "GiB" "TiB")))
>      (while (>= bytes 1024)
>        (setq bytes (/ bytes 1024.0))
>        (setq units (cdr units)))
>      (cond
> -     ;; ((integerp bytes) (format "%4d%s" bytes (car units)))
> -     ((>= bytes 100) (format "%4.0f%s" bytes (car units)))
> -     ((>= bytes 10) (format "%4.1f%s" bytes (car units)))
> -     (t (format "%4.2f%s" bytes (car units))))))
> +     ((>= bytes 100) (format "%4.0f&nbsp;%s" bytes (car units)))
> +     ((>= bytes 10) (format "%4.1f&nbsp;%s" bytes (car units)))
> +     (t (format "%4.2f&nbsp;%s" bytes (car units))))))

Is it possible to reuse file-size-human-readable here?

Does the no-break space have to be a HTML entity,
or can it be Unicode ?\u00A0?

Thanks,

-- 
Basil





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-05-13 14:25       ` Basil L. Contovounesios
@ 2019-05-13 15:18         ` Mattias Engdegård
  2019-05-15 20:16         ` Mattias Engdegård
  1 sibling, 0 replies; 9+ messages in thread
From: Mattias Engdegård @ 2019-05-13 15:18 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35331

[-- Attachment #1: Type: text/plain, Size: 598 bytes --]

13 maj 2019 kl. 16.25 skrev Basil L. Contovounesios <contovob@tcd.ie>:
> 
> Is it possible to reuse file-size-human-readable here?

That either requires modifying that function to (optionally) put a hard space between the number and unit, or post-processing its return value to achieve the same effect. The former is obviously the heroic way to go. Patch attached!

> Does the no-break space have to be a HTML entity,
> or can it be Unicode ?\u00A0?

Probably either would do, but since we don't control the web browser interpreting it, I went with what I thought was the safer option.


[-- Attachment #2: 0001-Optional-space-in-file-size-human-readable.patch --]
[-- Type: application/octet-stream, Size: 6505 bytes --]

From 35a8001e6293748876ce0e1a5929222fedb696d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Mon, 13 May 2019 17:05:24 +0200
Subject: [PATCH] Optional space in `file-size-human-readable'

Readability and correct usage requires a space between a number and
its unit of measurement; add an optional argument to
`file-size-human-readable' to provide the desired string to put in
that place.  For compatibility, the default is an empty string.

* lisp/files.el (file-size-human-readable): Add optional SPACE argument.
(files--ask-user-about-large-file, warn-maybe-out-of-memory):
Use the new argument.
* lisp/url/url-http.el (url-http-simple-after-change-function)
(url-http-content-length-after-change-function):
Use the new argument.
* etc/NEWS (Lisp Changes): Mention the change.
---
 etc/NEWS             |  7 +++++++
 lisp/files.el        | 21 ++++++++++++++-------
 lisp/url/url-http.el | 11 ++++++-----
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 43ad8be1cc..e2bffe7a2b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1983,6 +1983,13 @@ returns a regexp that never matches anything, which is an identity for
 this operation.  Previously, the empty string was returned in this
 case.
 
++++
+** The function 'file-size-human-readable' accepts another optional argument.
+The new third argument is a string put between the number and unit;
+if nil or omitted, the empty string is used.  It is recommended to use
+a single space or non-breaking space for readability and correct
+usage.
+
 \f
 * Changes in Emacs 27.1 on Non-Free Operating Systems
 
diff --git a/lisp/files.el b/lisp/files.el
index 8477c227bc..a2f160fdae 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1358,7 +1358,7 @@ it means chase no more than that many links and then stop."
 
 ;; A handy function to display file sizes in human-readable form.
 ;; See http://en.wikipedia.org/wiki/Kibibyte for the reference.
-(defun file-size-human-readable (file-size &optional flavor)
+(defun file-size-human-readable (file-size &optional flavor space)
   "Produce a string showing FILE-SIZE in human-readable form.
 
 Optional second argument FLAVOR controls the units and the display format:
@@ -1368,7 +1368,12 @@ Optional second argument FLAVOR controls the units and the display format:
  If FLAVOR is `si', each kilobyte is 1000 bytes and the produced suffixes
     are \"k\", \"M\", \"G\", \"T\", etc.
  If FLAVOR is `iec', each kilobyte is 1024 bytes and the produced suffixes
-    are \"KiB\", \"MiB\", \"GiB\", \"TiB\", etc."
+    are \"KiB\", \"MiB\", \"GiB\", \"TiB\", etc.
+
+Optional third argument SPACE is a string put between the number and unit.
+If nil or omitted, the empty string is used.
+Recommended value is a single space or non-breaking space, unless other
+constraints prohibit a space in that position."
   (let ((power (if (or (null flavor) (eq flavor 'iec))
 		   1024.0
 		 1000.0))
@@ -1379,9 +1384,10 @@ Optional second argument FLAVOR controls the units and the display format:
       (setq file-size (/ file-size power)
 	    post-fixes (cdr post-fixes)))
     (format (if (> (mod file-size 1.0) 0.05)
-		"%.1f%s%s"
-	      "%.0f%s%s")
+		"%.1f%s%s%s"
+	      "%.0f%s%s%s")
 	    file-size
+            (or space "")
 	    (if (and (eq flavor 'iec) (string= (car post-fixes) "k"))
 		"K"
 	      (car post-fixes))
@@ -2054,7 +2060,7 @@ think it does, because \"free\" is pretty hard to define in practice."
 (defun files--ask-user-about-large-file (size op-type filename offer-raw)
   (let ((prompt (format "File %s is large (%s), really %s?"
 		        (file-name-nondirectory filename)
-		        (file-size-human-readable size) op-type)))
+		        (file-size-human-readable size 'iec " ") op-type)))
     (if (not offer-raw)
         (if (y-or-n-p prompt) nil 'abort)
       (let* ((use-dialog (and (display-popup-menus-p)
@@ -2106,9 +2112,10 @@ returns nil or exits non-locally."
 exceeds the %S%% of currently available free memory (%s).
 If that fails, try to open it with `find-file-literally'
 \(but note that some characters might be displayed incorrectly)."
-	     (file-size-human-readable size)
+	     (file-size-human-readable size 'iec " ")
 	     out-of-memory-warning-percentage
-	     (file-size-human-readable (* total-free-memory 1024)))))))))
+	     (file-size-human-readable (* total-free-memory 1024)
+                                       'iec " "))))))))
 
 (defun files--message (format &rest args)
   "Like `message', except sometimes don't print to minibuffer.
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 662b6664b1..3baf5c6b19 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -999,7 +999,8 @@ should be shown to the user."
 (defun url-http-simple-after-change-function (_st _nd _length)
   ;; Function used when we do NOT know how long the document is going to be
   ;; Just _very_ simple 'downloaded %d' type of info.
-  (url-lazy-message "Reading %s..." (file-size-human-readable (buffer-size))))
+  (url-lazy-message "Reading %s..."
+                    (file-size-human-readable (buffer-size) 'iec " ")))
 
 (defun url-http-content-length-after-change-function (_st nd _length)
   "Function used when we DO know how long the document is going to be.
@@ -1012,16 +1013,16 @@ the callback to be triggered."
        (url-percentage (- nd url-http-end-of-headers)
 		       url-http-content-length)
        url-http-content-type
-       (file-size-human-readable (- nd url-http-end-of-headers))
-       (file-size-human-readable url-http-content-length)
+       (file-size-human-readable (- nd url-http-end-of-headers) 'iec " ")
+       (file-size-human-readable url-http-content-length 'iec " ")
        (url-percentage (- nd url-http-end-of-headers)
 		       url-http-content-length))
     (url-display-percentage
      "Reading... %s of %s (%d%%)"
      (url-percentage (- nd url-http-end-of-headers)
 		     url-http-content-length)
-     (file-size-human-readable (- nd url-http-end-of-headers))
-     (file-size-human-readable url-http-content-length)
+     (file-size-human-readable (- nd url-http-end-of-headers) 'iec " ")
+     (file-size-human-readable url-http-content-length 'iec " ")
      (url-percentage (- nd url-http-end-of-headers)
 		     url-http-content-length)))
 
-- 
2.20.1 (Apple Git-117)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-05-13 14:25       ` Basil L. Contovounesios
  2019-05-13 15:18         ` Mattias Engdegård
@ 2019-05-15 20:16         ` Mattias Engdegård
  2019-06-26 11:41           ` Basil L. Contovounesios
  1 sibling, 1 reply; 9+ messages in thread
From: Mattias Engdegård @ 2019-05-15 20:16 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35331

13 maj 2019 kl. 16.25 skrev Basil L. Contovounesios <contovob@tcd.ie>:
> 
> Is it possible to reuse file-size-human-readable here?

There turned out to be more things to fix in that function, so I opened a new bug for it (bug#35756).

I'm not sure what Emacs version elpa.gnu.org is using, so it is perhaps unwise to depend on a very recent addition to Emacs master.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-05-15 20:16         ` Mattias Engdegård
@ 2019-06-26 11:41           ` Basil L. Contovounesios
  2019-06-26 17:11             ` Mattias Engdegård
  0 siblings, 1 reply; 9+ messages in thread
From: Basil L. Contovounesios @ 2019-06-26 11:41 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 35331

Mattias Engdegård <mattiase@acm.org> writes:

> 13 maj 2019 kl. 16.25 skrev Basil L. Contovounesios <contovob@tcd.ie>:
>> 
>> Is it possible to reuse file-size-human-readable here?
>
> There turned out to be more things to fix in that function, so I
> opened a new bug for it (bug#35756).
>
> I'm not sure what Emacs version elpa.gnu.org is using, so it is perhaps unwise
> to depend on a very recent addition to Emacs master.

Indeed.

I'd feel free to push the patch for archive-contents.el, given the lack
of objections in the last 6 weeks.

Thanks,

-- 
Basil





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#35331: [PATCH] Neater html table of old versions in ELPA
  2019-06-26 11:41           ` Basil L. Contovounesios
@ 2019-06-26 17:11             ` Mattias Engdegård
  0 siblings, 0 replies; 9+ messages in thread
From: Mattias Engdegård @ 2019-06-26 17:11 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35331-done

26 juni 2019 kl. 13.41 skrev Basil L. Contovounesios <contovob@tcd.ie>:
> 
> I'd feel free to push the patch for archive-contents.el, given the lack
> of objections in the last 6 weeks.

Thank you, pushed.






^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-06-26 17:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-19 21:36 bug#35331: [PATCH] Neater html table of old versions in ELPA Mattias Engdegård
2019-04-21 16:09 ` Basil L. Contovounesios
2019-04-22 13:17   ` Mattias Engdegård
2019-05-13 13:42     ` Mattias Engdegård
2019-05-13 14:25       ` Basil L. Contovounesios
2019-05-13 15:18         ` Mattias Engdegård
2019-05-15 20:16         ` Mattias Engdegård
2019-06-26 11:41           ` Basil L. Contovounesios
2019-06-26 17:11             ` Mattias Engdegård

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).