Hot answers tagged

21

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


16

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


13

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


9

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

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

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

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


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

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 usage README section.


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

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

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

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

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)))) ...which sorts by the colors in the example, and consequently: (sort my-alist (lambda (a b) (< (cdr a) (cdr b)))) ...which sorts by the numbers in the example.


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


3

Here's one way to do this: (let ((l (list "%(binary)" "-f" "%(ledger-file)" "--empty" "--depth=3" "--no-total" "--amount" "'($1,000.00*a)/$1,000.00'" "--...


3

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 lines in region alphabetically by a certain range of columns. For the purpose of this command, the region BEG...END includes the entire line that point is in and ...


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