Hot answers tagged

18

It would be great if there was something like org-agenda-sorting-stratagy that worked with org-sort-entries, but there doesn't seem to be. We can fake it since org-sort-entries can take an argument specifying a function assigning a (string or number) key to each heading, which will be used to sort the entries when the ?f sorting type is given. All we have ...


12

There is an org-sort command but you may need to tweak your file structure to get the results you want (if I am understanding the question properly). Use org-sort (C-c ^) to sort entries in the outline, rows in a table, or items in a list. For example from a heading you can call org-sort to sort all the child entries. In your example you want to sort the ...


11

Here's my config: (setq dired-listing-switches "-laGh1v --group-directories-first") The relevant part is -1v.


8

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-collate-lessp)) ;; => ("a" "á" "à" "â" "b" "c" "e" "é" "ê") If that doesn't work, you can supply a locale string as the third argument to string-collate-...


7

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)))


6

Just select the entire buffer and do C-c^ (it runs the command org-sort). It will prompt you for the type of sorting. To understand different types of sorting see the documentation of org-sort-entries (M-xorg-sort-entriesRET). I am quoting it here for completeness Sort entries on a certain level of an outline tree. If there is an active region, the ...


5

I use this function for that (defun my-sort-lines () (interactive) (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 () (interactive) (shell-command-on-region (point-min) (point-max) "LC_COLLATE=en_US.UTF-8 sort" (buffer-name) t )) ...


5

Besides @abo-abo answer, I just want to quote the documentation: dired-listing-switches is a variable defined in `dired.el'. Its value is "-Al --si --time-style long-iso" Documentation: Switches passed to ls for Dired. MUST contain the l option. May contain all other options that don't contradict -l; may contain even F, b, i and s. See also ...


4

I've managed to do it myself. Here's the code (defun company-transform-python (candidates) (let ((deleted)) (mapcar #'(lambda (c) (if (or (string-prefix-p "_" c) (string-prefix-p "._" c)) (progn (add-to-list 'deleted c) (setq candidates (delete c candidates))))) candidates) (append ...


4

See the code for sort-fields? Have you tried substituting a regexp that matches your preferred separators for the hard-coded regexp in sort-fields, which matches whitespace? Untested whether just changing that regexp does the trick - but that would be the place to start, I think. This the sort-fields code: (defun sort-fields (field beg end) "..." (...


4

Solution You can temporarily make - and _ be considered as part of the word in the syntax-table (defun sort-words (reverse beg end) "Sort words in region alphabetically, in REVERSE if negative. Prefixed with negative \\[universal-argument], sorts in reverse. The variable `sort-fold-case' determines whether alphabetic case affects the sort order. See `...


4

Dired relies on the ls command to do the listing and the sorting. The options for sorting are limited to what the ls command can do (via switches added with C-u s (dired-sort-toggle-or-edit)). On ELPA, I can find packages that make it easier to change the ls switches, but not packages that allow the sort order to be customized. It seems that the only way to ...


3

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).


3

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-to-region beg end) (goto-char (point-min)) (sort-subr reverse (function (lambda () (while (...


3

The most simple solution is to define your own key function that removes the comma before it transforms the string to a number for sorting: (defun string-to-number-remove-comma (str) "Convert string STR to number but remove commas beforehand." (string-to-number (replace-regexp-in-string "," "" str))) This function can be specified when you call org-...


3

Sort using symbol boundaries Here's a solution that came to me after reading OP's answer about what defines a "word": (defun sort-symbols (reverse beg end) (interactive "*P\nr") (sort-regexp-fields reverse "\\_<.*?\\_>" "\\&" beg end)) This version uses the symbol-boundary atoms (\_< and \_>). I think this solution makes the most sense,...


3

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 completions, so there's no way for you to achieve your aim by any kind of re-ordering process, so you're actually looking for a different kind of functionality. ...


3

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-timestamp-tolerance 1e-5 "Tolerance for testing equality of timestamps.") (defun goto-node (list time-stamp n) "Go to the desired node commencing from an ...


3

You can write a function which uses sort and pass it a predicate that comares lengths: (defun my-sort-decreasing-length (list) (sort list (lambda (a b) (> (length a) (length b)))))


3

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-by #'length #'> MYLIST) or (seq-sort-by #'string-width #'> MYLIST) should you care about displaying the strings.


3

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


3

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 to send a patch. In your use case, since the limiting factor is the number of calls to the comparison function, you could implement it in naive Elisp, which ...


2

The given answers are better for this precise problem because they hook directly into the behavior of Dired. However for generality's sake I want to mention the sort-numeric-fields command, which is specifically for sorting numbers by magnitude rather than lexicographically. (sort-numeric-fields FIELD BEG END) Sort lines in region numerically by the ...


2

Meanwhile I wrote a code to implement the hack that @glucas mentioned. It perhaps only suits the purpose of sorting headers in C, but I hope someone find it useful. (defun replace-char-after (character-number replacement) "Replaces char in the buffer after the `character-number' with `replacement'" (save-excursion (goto-char character-number) (...


2

You can use sort-regexp-fields. Mark the region and do: M-x sort-regexp-fields RET #include .\(.*\) RET \1 RET The regular expression group will capture everything after #include " or #include < and sort on that instead of the whole line. FYI, I believe the reason for the sorting you're seeing is because " is higher than < in ASCII.


2

Just use sort-regexp-fields. (Don't change sort.el or redefine any of its functions.)


2

The basic way to sort lists is with org-sort (C-c ^). It will offer you a number of different sorting options one of which (f) lets you call a custom sorting function. This function will be called on each entry and should return either a string or a number that will be used as a key to sort. You will need to write a custom function to order things the way ...


2

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-numeric-fields. (sort-numeric-fields FIELD BEG END) Sort lines in region numerically by the ARGth field of each line. Fields are separated by ...


2

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 down past the next one (or up, with a negative prefix arg). You can repeat transpose-paragraphs (easiest if bound to a key) to, essentially, drag a paragraph ...


2

I've convinced myself that my particular example should be treated as a bug since no explicitly recursive sorting mechanism appears to exist. In a pinch you can use the following: (org-map-entries (lambda () (condition-case x (org-sort-entries nil ?f 'my/sort-function) (user-...


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