CVS update by aidan packages/xemacs-packages/xemacs-base ...

xemacs-cvs at xemacs.org xemacs-cvs at xemacs.org
Tue Apr 22 14:07:01 EDT 2008


  User: aidan   
  Date: 08/04/22 20:07:01

  Modified:    packages/xemacs-packages/xemacs-base ChangeLog sort.el
Log:
Support `sort-numeric-base' in #'sort-regexp-fields-numerically.

Revision  Changes    Path
1.211     +11 -0     XEmacs/packages/xemacs-packages/xemacs-base/ChangeLog

Index: ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/xemacs-base/ChangeLog,v
retrieving revision 1.210
retrieving revision 1.211
diff -u -p -r1.210 -r1.211
--- ChangeLog	2008/02/25 20:08:43	1.210
+++ ChangeLog	2008/04/22 18:07:00	1.211
@@ -1,3 +1,14 @@
+2008-04-20  Aidan Kehoe  <kehoea at parhasard.net>
+
+	* sort.el (sort-regexp-fields-numerically): 
+	Support `sort-numeric-base' in #'s-r-f-n, implement the same
+	sniffing of a number's base used in #'sort-numeric-fields, correct
+	and extend the docstring (`sort-fold-case' is not used, the
+	example has been changed to one where numeric sorting is
+	relevant. 
+	(sort-numeric-base): 
+	Document its use in #'s-r-f-n. 
+
 2008-02-25  Norbert Koch  <viteno at xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 2.16 released.



1.6       +34 -11    XEmacs/packages/xemacs-packages/xemacs-base/sort.el

Index: sort.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/xemacs-base/sort.el,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -p -r1.5 -r1.6
--- sort.el	2004/11/07 23:43:09	1.5
+++ sort.el	2008/04/22 18:07:00	1.6
@@ -274,7 +274,7 @@ the sort order."
     (setq sort-fields-syntax-table table)))
 
 (defcustom sort-numeric-base 10
-  "*The default base used by `sort-numeric-fields'."
+  "*Fallback base for `sort-numeric-fields', `sort-regexp-fields-numerically'."
   :group 'sort
   :type 'integer)
 
@@ -500,21 +500,26 @@ For example: to sort lines in the region
 RECORD-REGEXP specifies the textual units which should be sorted.
   For example, to sort lines RECORD-REGEXP would be \"^.*$\"
 KEY specifies the part of each record (ie each match for RECORD-REGEXP)
-  is to be used for sorting.
+  which is to be used for sorting.
   If it is \"\\\\digit\" then the digit'th \"\\\\(...\\\\)\" match field from
   RECORD-REGEXP is used.
   If it is \"\\\\&\" then the whole record is used.
   Otherwise, it is a regular-expression for which to search within the record.
 If a match for KEY is not found within a record then that record is ignored.
 
-With a negative prefix arg sorts in reverse order.
+If the match for KEY starts with \"0x\", it specifies hexadecimal as the
+conversion base.  A match for KEY starting with \"0\" is interpreted as
+octal; otherwise `sort-numeric-base' is consulted for the conversion base to
+use.  You can avoid the automatic detection of a field's base by specifying
+RECORD-REGEXP appropriately; \"0*\" before the start of the KEY will prevent
+detection as octal, and including \"[^xX]\" in the group corresponding to
+KEY will prevent detection as hex.
 
-The variable `sort-fold-case' determines whether alphabetic case affects
-the sort order.
+With a negative prefix arg sorts in reverse order.
 
-For example: to sort lines in the region by the first word on each line
- starting with the letter \"f\",
- RECORD-REGEXP would be \"^.*$\" and KEY would be \"\\\\=\\<f\\\\w*\\\\>\""
+For example: to sort lines in the region by the numerical value of the first
+ C hexadecimal constant,
+ RECORD-REGEXP would be \"^.*$\" and KEY would be \"0[xX][0-9A-Fa-f]+\""
   ;; using negative prefix arg to mean "reverse" is now inconsistent with
   ;; other sort-.*fields functions but then again this was before, since it
   ;; didn't use the magnitude of the arg to specify anything.
@@ -529,9 +534,27 @@ For example: to sort lines in the region
 	   (read-string "Regexp specifying key within record: "
 			nil 'sort-regexp-history)
 	   beg end)))
-  (sort-regexp-fields reverse record-regexp key-regexp beg end
-		      #'(lambda (a b)
-			  (< (string-to-number a) (string-to-number b)))))
+  (let ((base-sniff-regexp "\\(0[xX]\\)[0-9a-fA-F]\\|\\(0\\)[0-7]"))
+    (sort-regexp-fields reverse record-regexp key-regexp beg end
+                        #'(lambda (a b)
+                            ;; If I replace #'< with #'max, the warning
+                            ;; 
+                            ;; ** variable base-sniff-regexp bound but not
+                            ;; referenced
+                            ;;
+                            ;; goes away. Byte compiler bug. 
+                            (< (string-to-number a
+                                (if (string-match base-sniff-regexp a)
+                                    (cond ((match-beginning 1) 16)
+                                          ((match-beginning 2) 8)
+                                          (t sort-numeric-base))
+                                  sort-numeric-base))
+                               (string-to-number b
+                                (if (string-match base-sniff-regexp b)
+                                    (cond ((match-beginning 1) 16)
+                                          ((match-beginning 2) 8)
+                                          (t sort-numeric-base))
+                                  sort-numeric-base)))))))
 
 
 (defvar sort-columns-subprocess t)





More information about the XEmacs-CVS mailing list