aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorEli Zaretskii2014-09-01 17:57:21 +0300
committerEli Zaretskii2014-09-01 17:57:21 +0300
commit0360ec583aa754eb746ca6772ca6ca0f0212d546 (patch)
treee6e94a7d099ac6d826f7045e11d7c280ac363992 /lisp
parent8d033ecb9d8189a7e6b1230e86dacb253dedb055 (diff)
downloademacs-0360ec583aa754eb746ca6772ca6ca0f0212d546.tar.gz
emacs-0360ec583aa754eb746ca6772ca6ca0f0212d546.zip
Use the new string-collate-lessp function in ls-lisp.el.
lisp/ls-lisp.el (ls-lisp-use-string-collate) (ls-lisp-UCA-like-collation): New defcustoms. (ls-lisp-string-lessp): Use them to control sorting by file names. etc/NEWS: Mention that ls-lisp uses string-collate-lessp. Fixes: debbugs:18051
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/ls-lisp.el58
2 files changed, 61 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7087cde6d44..47185e01f5e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12014-09-01 Eli Zaretskii <eliz@gnu.org>
2
3 * ls-lisp.el (ls-lisp-use-string-collate)
4 (ls-lisp-UCA-like-collation): New defcustoms.
5 (ls-lisp-string-lessp): Use them to control sorting by file
6 names. (Bug#18051)
7
12014-08-31 Christoph Scholtes <cschol2112@gmail.com> 82014-08-31 Christoph Scholtes <cschol2112@gmail.com>
2 9
3 * ibuffer.el: Replace mode-specific quit function with 10 * ibuffer.el: Replace mode-specific quit function with
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 2ff0a3a230b..410b44999f6 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -113,6 +113,47 @@ update the dependent variables."
113 :type 'boolean 113 :type 'boolean
114 :group 'ls-lisp) 114 :group 'ls-lisp)
115 115
116(defcustom ls-lisp-use-string-collate
117 (cond ((memq ls-lisp-emulation '(MacOS UNIX)) nil)
118 (t t)) ; GNU/Linux or MS-Windows emulate GNU ls
119 "Non-nil causes ls-lisp to sort files in locale-dependent collation order.
120
121A value of nil means use ordinary string comparison (see `compare-strings')
122for sorting files. A non-nil value uses `string-collate-lessp' instead,
123which more closely emulates what GNU `ls' does.
124
125On GNU/Linux systems, if the locale's codeset specifies UTF-8, as
126in \"en_US.UTF-8\", the collation order follows the Unicode
127Collation Algorithm (UCA), which places together file names that
128differ only in punctuation characters. On MS-Windows, customize
129the option `ls-lisp-UCA-like-collation' to a non-nil value to get
130similar behavior."
131 :version "24.5"
132 :set-after '(ls-lisp-emulation)
133 :type 'boolean
134 :group 'ls-lisp)
135
136(defcustom ls-lisp-UCA-like-collation t
137 "Non-nil means force ls-lisp use a collation order compatible with UCA.
138
139UCA is the Unicode Collation Algorithm. GNU/Linux systems automatically
140follow it in their string-collation routines if the locale specifies
141UTF-8 as its codeset. On MS-Windows, customize this option to a non-nil
142value to get similar behavior.
143
144When this option is non-nil, and `ls-lisp-use-string-collate' is also
145non-nil, the collation order produced on MS-Windows will ignore
146punctuation and symbol characters, which will, for example, place
147\`.foo' near `foo'. See the documentation of `string-collate-lessp'
148and `w32-collate-ignore-punctuation' for more details.
149
150This option is ignored on platforms other than MS-Windows; to
151control the collation ordering of the file names on those other
152systems, set your locale instead."
153 :version "24.5"
154 :type 'boolean
155 :group 'ls-lisp)
156
116(defcustom ls-lisp-dirs-first (eq ls-lisp-emulation 'MS-Windows) 157(defcustom ls-lisp-dirs-first (eq ls-lisp-emulation 'MS-Windows)
117 "Non-nil causes ls-lisp to sort directories first in any ordering. 158 "Non-nil causes ls-lisp to sort directories first in any ordering.
118\(Or last if it is reversed.) Follows Microsoft Windows Explorer." 159\(Or last if it is reversed.) Follows Microsoft Windows Explorer."
@@ -495,11 +536,20 @@ Responds to the window width as ls should but may not!"
495 result)) 536 result))
496 537
497(defsubst ls-lisp-string-lessp (s1 s2) 538(defsubst ls-lisp-string-lessp (s1 s2)
498 "Return t if string S1 is less than string S2 in lexicographic order. 539 "Return t if string S1 should sort before string S2.
499Case is significant if `ls-lisp-ignore-case' is nil. 540Case is significant if `ls-lisp-ignore-case' is nil.
500Unibyte strings are converted to multibyte for comparison." 541Uses `string-collate-lessp' if `ls-lisp-use-string-collate' is non-nil,
501 (let ((u (compare-strings s1 0 nil s2 0 nil ls-lisp-ignore-case))) 542\`compare-strings' otherwise.
502 (and (numberp u) (< u 0)))) 543On GNU/Linux systems, if the locale specifies UTF-8 as the codeset,
544the sorting order will place together file names that differ only
545by punctuation characters, like `.emacs' and `emacs'. To have a
546similar behavior on MS-Widnows, customize `ls-lisp-UCA-like-collation'
547to a non-nil value."
548 (let ((w32-collate-ignore-punctuation ls-lisp-UCA-like-collation))
549 (if ls-lisp-use-string-collate
550 (string-collate-lessp s1 s2 nil ls-lisp-ignore-case)
551 (let ((u (compare-strings s1 0 nil s2 0 nil ls-lisp-ignore-case)))
552 (and (numberp u) (< u 0))))))
503 553
504(defun ls-lisp-handle-switches (file-alist switches) 554(defun ls-lisp-handle-switches (file-alist switches)
505 "Return new FILE-ALIST sorted according to SWITCHES. 555 "Return new FILE-ALIST sorted according to SWITCHES.