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
    Commented Dec 17, 2015 at 18:17

1 Answer 1


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
    Commented Dec 17, 2015 at 15:51
  • @Marco Wahl: I edit my post with your proposition.
    – djangoliv
    Commented Dec 17, 2015 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
    Commented Dec 18, 2015 at 13:08
  • @Name Maybe you are on Windows. Sorry this function only work on linux...
    – djangoliv
    Commented Dec 18, 2015 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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