简体   繁体   中英

Org Mode. Sorting in column view

How do we sort in a column view. In specific, I have a list of estimated taks, along with their priority, I want to be able to sort them based on any field, dynamically or atleast by specifying a field as a property.

AFAIK, you can't sort while you are in column view. But you exit column view (by typing "q"). They you can sort the entries by property with Mx org-sort (Cc ^). Type r for property and then enter the property you want to sort by.

Eg, let's say we begin with this:

* Test
** First task
   :PROPERTIES:
   :Effort:   1:30
   :END:
** Second task
   :PROPERTIES:
   :Effort:   0:30
   :END:

Navigate to "* Test" and type Cc ^ (or Mx org-sort). In this case, type "r" and then enter "Effort" to get the resulting order:

* Test
** Second task
   :PROPERTIES:
   :Effort:   0:30
   :END:
** First task
   :PROPERTIES:
   :Effort:   1:30
   :END:

Then enter column view again. (Note, you can also sort by priority --- you'll see the option when you invoke org-sort.)

Additionally, you can export your column view to a table and then sort the table by column:

http://orgmode.org/manual/Capturing-column-view.html

Wanting to sort in column view quite often, I wrote a command which does it by exiting column view, sorting, and then reentering column view:

(defun org-columns-sort (&optional arg)
  "Sort entries from column view by value in current column.

This only sorts the children of the column view top level,
which is the entry with the current column view specification.

When ARG is non-nil (interactively with prefix), sort in
reverse order."
  (interactive "P")
  (let ((colname (get-char-property (point) 'org-columns-key))
        (colnum (org-current-text-column)))
    (org-columns-goto-top-level)
    (org-columns-quit)
    (org-sort-entries nil (if arg ?R ?r) nil nil colname)
    (org-columns)
    (outline-hide-sublevels
     (1+ (org-current-level)))
    (forward-char colnum)))

(org-defkey org-columns-map "^" #'org-columns-sort)

Suggestions for improvement are welcome. It doesn't quite restore the original folding and position. I tried storing (point-marker) and then use goto-char but somehow the marker gets lost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM