;; -*- coding: utf-8 -*-
;; buffer-file-coding-system: utf-8

;; Actually GNU Emacs doesn't support localized sorting
;; The function sort-lines-according-locale calls GNU sort
;; for this purpose

;; Copyright (C) 2004 Sebastian Nagel
;; License: GPL

(provide 'sortLocale)

(defun sort-lines-according-locale (locale options)
;;   "Sort the lines according the (current) locale using GNU `sort'.
;; Locale and buffer-file-coding-system should harmonize or
;; you have to specifiy the coding with the prefix `C-x RET c'
;; (see documentation for shell-command-on-region)."
  (interactive
    "MEnter your locale (LANG) [default: current locale] \nMEnter additional options for the sort command ")
;  (print locale)
;  (print options)
  (let ((start (mark))
        (end (point))
        (command
          (if (string-equal locale "\"\"") ; empty locale is ""
            (concat "LANG=" locale " sort " options)
            (concat "sort " options))))
    (save-excursion
      (shell-command-on-region start end command t t
			       shell-command-default-error-buffer))))

;;;; Test: unicode
;; асд
;; дллс
;; вьс
;; hallo
;; абас
;; zebra
;; hybernation
;; abakadabra
;; ćder
;; chyb
;; ĉed
;; abakadabra
;; česky

;;;; Test for cs_CZ resp. cs_CZ.utf8 (czech -- chyba comes after hybernace!)
;; chyba
;; halo
;; abakadabra
;; hybernace
;; zebra
;; česky



