Hot answers tagged

20

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


14

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


12

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


8

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


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


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

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

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

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


4

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

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

Add the following to your file: #+ARCHIVE: :: * Completed. And shuffling becomes archiving Rather than sort the entries, how about a sorted view? (setq org-agenda-custom-commands '(("cx" "TODOs sorted by state, priority, effort" todo "*" ((org-agenda-overriding-header "\nTODOs sorted by state, priority, effort") (org-...


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

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 later keys. The default definition of org-habit-get-priority takes into account the consistency graph in a number of ways: it starts at 1000, adjusts by 10 for ...


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


3

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 on hash tables: The correspondences in a hash table are in no particular order. You may wish to order the keys in some form (say, for the purposes of ...


3

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-order-hash #s(hash-table size 30 test equal data ( "一" 375 ;; 375 corresponds to pinyin of one hanzi "乙" 381 "二" ...


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


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