When sorting the lines by sort-lines the lines beginning with ä comes after the lines starting with z. It would be nice if the lines could be sorted ignoring the accents, Umlauts, etc, like in a dictionary. Ideally a line starting with ändern should be come after a line starting with anderen.

There is simple solution for searching accented characters mentioned in https://superuser.com/a/675172/ but can not be used here. I am wondering if that solution can be adapted in this situation.

  • 1
    FYI, folding and grouping based on extended characters has been implemented in isearch and query-replace in the next version of emacs.
    – Emacs User
    Dec 17 '15 at 18:17

I use this function for that

(defun my-sort-lines ()
    (shell-command-on-region (point-min) (point-max) "LC_COLLATE=en_US.UTF-8 sort" (buffer-name) t ))

EDIT: To sort region or buffer:

  (defun my-sort-lines-buffer ()
    (shell-command-on-region (point-min) (point-max) "LC_COLLATE=en_US.UTF-8 sort" (buffer-name) t ))
  (defun my-sort-lines-region (start end) 
    (interactive "r") 
    (shell-command-on-region start end "LC_COLLATE=en_US.UTF-8 sort" (buffer-name) t))
  (defun my-sort-lines-region-or-buffer ()
      (if (region-active-p)
            (my-sort-lines-region (region-beginning) (region-end))
            (message "Sorted selected region"))
          (message "Sorted buffer")))))
  • Thanks for sharing! What about renaming to my-sort-lines-buffer? Or rewrite to (defun my-sort-lines (start end) (interactive "r") (shell-command-on-region start end "LC_COLLATE=en_US.UTF-8 sort" (buffer-name) t))?
    – Marco Wahl
    Dec 17 '15 at 15:51
  • @Marco Wahl: I edit my post with your proposition.
    – djangoliv
    Dec 17 '15 at 16:18
  • When running this I get the error 'LC_COLLATE' is not recognized as a internal or external command nor an executable program.
    – Name
    Dec 18 '15 at 13:08
  • @Name Maybe you are on Windows. Sorry this function only work on linux...
    – djangoliv
    Dec 18 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.