Skip to main content
Share Your Experience: Take the 2024 Developer Survey
15 votes

dired - sort and hide by default

Thanks to Dan's comment on the original question. This seems to work: (add-hook 'dired-mode-hook (lambda () (dired-hide-details-mode) (dired-sort-toggle-or-edit)))
dharmatech's user avatar
  • 1,274
8 votes
Accepted

How to alphabetize strings with diacritics?

If your system locale is set to something that will properly collate diacritics (not POSIX), this should work for you: (let ((letters '("é" "a" "à" "c" "â" "b" "á" "e" "ê"))) (sort letters #'string-...
eeowaa's user avatar
  • 372
6 votes
Accepted

How to sort an association list (alist)?

At the excellent ergo emacs on hash tables (http://ergoemacs.org/emacs/elisp_hash_table.html) I found out this also works for alists: (sort my-alist (lambda (a b) (string< (car a) (car b)))) ......
Erik's user avatar
  • 153
6 votes
Accepted

Ivy: sort candidates by most recently used

I would suggest using ivy-prescient. It is a package that provides sorting and filtering for ivy. After installing it, you enable it with ivy-prescient-mode. For more details on it's usage see its ...
Aquaactress's user avatar
  • 1,453
5 votes
Accepted

Sort list by decreasing length of the strings

See DoMiNeLa10's answer for the canonical answer. On Emacs 25 and later, however, and if you don't care about sheer performance, there is a way to save yourself some typing: (require 'seq) (seq-sort-...
Basil's user avatar
  • 12.5k
5 votes

How to sort comma separated (or otherwise) text?

Use M-x sort-lines for the first example. For the second example, change it into z, a, c, g, then use M-x sort-regexp-fields <RET> ., <RET> \& <RET>.
xuchunyang's user avatar
  • 14.6k
4 votes
Accepted

sorting paragraphs of a document by paragraph numbers (not lexicographically)

Like sort-paragraphs but set sort-subr's PREDICATE argument to meet your needs (defun my-sort-paragraphs (reverse beg end) (interactive "P\nr") (save-excursion (save-restriction (narrow-...
xuchunyang's user avatar
  • 14.6k
4 votes

Randomize headers in Org mode

I found the answer here. All I had to do was creating a function and call it once I got into org-sort f(function).
stacko's user avatar
  • 1,597
4 votes

Sort js object by name

If your JavaScript code happened to also be valid JSON like: { "method": "GET", "url": "asd", "headers": { "Content": "application/json", "Authorization": "token" } } ...
ebpa's user avatar
  • 7,499
4 votes
Accepted

Incorporate a list of floats, into another list of floats, in numerical order, with remainders

(require 'cl-lib) (defun incorporate (master orphans) (let* (;; remove call to `cl-sort' if `master' is already sorted (master (cl-sort (cl-copy-list master) #'<)) ;; remove ...
d125q's user avatar
  • 1,443
4 votes
Accepted

Display completion options from top to bottom in alphabetical order?

It is described at the end of the Completion options section in the Emacs manual. To get vertical ordering, just set completions-format to vertical by either setting it via the customize interface, or ...
dalanicolai's user avatar
  • 7,855
3 votes
Accepted

Custom function to map through nested lists sorting by time-stamp

Generate a complete (rassoc-) map assigning time-stamps to nodes at first. Afterwards sort and then locate time-stamp in the sorted list. From there you can go forward and backward. (defvar goto-node-...
Tobias's user avatar
  • 33.3k
3 votes

Find files with find-dired sorting by date and by size

After doing some googling for the Linux find parameters and looking at the find-dired function, I came with these two functions that seem to work. Not sure if this is the optimal way, but at least ...
nephewtom's user avatar
  • 2,261
3 votes
Accepted

Reverse suggestions from hippie-expand

I'm a bit confused by your question, because hippie-expand doesn't provide results in longest-to-shortest order, and it also doesn't provide "lowest common denominator" results which aren't actual ...
phils's user avatar
  • 51.5k
3 votes

org: How to sort headings by TODO and then by priority?

You can also define a org-agenda-cmp-user-defined function and add it to org-agenda-sorting-strategy. This is the one I created as an example. (setq org-todo-sort-order '("WAIT" "TODO" "DOING" "...
Prgrm.celeritas's user avatar
3 votes
Accepted

How does sorting work within habits?

The key function is org-habit-get-priority which provides a numerical priority value for a habit. This value is then used as part of the sorting habit-down and will take higher precedence than your ...
Andrew Swann's user avatar
  • 3,556
3 votes
Accepted

How to sort lines ignoring a pattern?

You can try M-x sort-regexp-fields ^.*$ \_<.+?\_> ^.*$ is the record regexp, it splits the region into lines \_<.+?\_> is the key regexp, it matches the first symbol in the line
xuchunyang's user avatar
  • 14.6k
3 votes

org-mode error: Region to sort contains a level above the first entry

Take an example like this, with a TAB before the 'd' - if you call org-sort-entries on the 'a', you'll get the error - the '*[TAB]d' seems to confuse the function. * a ** c * d ** b You can do a ...
Brian Burns's user avatar
  • 1,647
3 votes
Accepted

Is there a timsort implementation in Emacs Lisp?

There is no implementation of timsort for Elisp, AFAIK. The implementation of sort is a "plain" mergesort. I can't see any reason why we wouldn't be happy to change sort to use timsort, so feel free ...
Stefan's user avatar
  • 26.5k
3 votes
Accepted

is there a way to sort only on second level headlines in org mode?

As we have already discussed in the comments second level headings are probably the wrong structural means for an alternative sorting of the first level headings. There could be two subheadings 2.1, 2....
Tobias's user avatar
  • 33.3k
3 votes

Is there a way to change order of the key in a hashtable?

No, you cannot change the order of the keys in a hash table. As @xuchunyang's comment points out, hash tables do not have an order in the way you're thinking about them. From the elisp manual node ...
Dan's user avatar
  • 33.1k
3 votes
Accepted

Sort Chinese Characters in Emacs

My code is beyond stackoverflow characters limit. So see https://gist.github.com/redguardtoo/78a68fb6ac914bd89b6f04314819d24b for full code. Here is a short version, (defconst my-chinese-pinyin-...
chen bin's user avatar
  • 4,877
3 votes
Accepted

How to add a string at nth position of an ordered list of strings

Here's one way to do this: (let ((l (list "%(binary)" "-f" "%(ledger-file)" "--empty" "--depth=...
Basil's user avatar
  • 12.5k
3 votes
Accepted

Sort lines omitting a prefix of a certain length?

C-h f sort-columns: sort-columns is an interactive autoloaded compiled Lisp function in sort.el. It is bound to menu-bar edit sort sort-columns. (sort-columns REVERSE &optional BEG END) Sort ...
Drew's user avatar
  • 77.9k
3 votes

How to ignore accents (À Â É Ê etc.) when sorting?

Depending on your locale, you can try (sort '("Always" "Emerald" "Yesterday" "Zoo" "À la campagne" "Âge" "Écarlate" &...
gigiair's user avatar
  • 2,186
2 votes

Change field separator for sort-fields

Just use sort-regexp-fields. (Don't change sort.el or redefine any of its functions.)
John's user avatar
  • 21
2 votes
Accepted

Sort Dewey Decimal list?

Use command sort-numeric-fields. C-h f sort-numeric-fields tells you: sort-numeric-fields is an interactive autoloaded Lisp function in sort.el. It is bound to menu-bar edit sort sort-...
Drew's user avatar
  • 77.9k
2 votes

shuffling the paragraphs in a buffer

In a comment, @politza provided the best answer (and hopefully @politza will post it as an answer): use sort-paragraphs. In addition, you can use transpose-paragraphs to move the previous paragraph ...
Drew's user avatar
  • 77.9k
2 votes

Is there a way to sort buffers alphabetically in speedbar

(require 'speedbar) (defun speedbar-buffer-buttons-engine (temp) "Create speedbar buffer buttons. If TEMP is non-nil, then clicking on a buffer restores the previous display." (speedbar-insert-...
lawlist's user avatar
  • 19.2k

Only top scored, non community-wiki answers of a minimum length are eligible