我需要对表格中的一列进行时间排序,但是目前的时间是类似2016-02
, Mar 2016
这样的格式. 试了下,这样是没法正常排序的, org mode不能正常识别为时间戳. 怎么让排序正常工作呢? 必须添加上日期么
首先 2016-02
和 Mar 2016
不是正常的时间戳(至少 Org 是这样认为的)。
不是必须的,org-table-sort-lines
支持自定义排序,甚至写成“二零一六年三月”都能排序,C-h f org-table-sort-lines
中有解释(看 GETKEY-FUNC
参数)
(org-table-sort-lines WITH-CASE &optional SORTING-TYPE GETKEY-FUNC COMPARE-FUNC)
Sort table lines according to the column at point.
....
If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies
a function to be called to extract the key. It must return either
a string or a number that should serve as the sorting key for that
row.
....
比如这样一个表
| 2017-01 | Jan 2017 |
| 2016-01 | Jan 2016 |
| 2016-03 | Mar 2016 |
- 需要排第一列的话:M-x org-table-sort-lines f my-year-month-to-number
- 需要排第二列的话:M-x org-table-sort-lines f my-month-year-to-number
;; "2016-03" => 201603
(defun my-year-month-to-number (s)
"Used as GETKEY-FUNC of `org-table-sort-lines'."
(string-to-number (replace-regexp-in-string "-" "" s)))
;; "Mar 2016" => 201603
(defun my-month-year-to-number (s)
(cl-destructuring-bind (m y) (split-string s " ")
(string-to-number
(concat y (format "%02d" (cl-position m calendar-month-abbrev-array :test 'string=))))))
P.S. 这个问题与
一样,假如这两个问题都是你问的话,以后请注意不要短时间内在不同的地方问同样的问题。
1 个赞
回答非常详细 好的,下次先读读手册了.很多东西我也基本上发现手册里面都有说了… 但是当然还是没有谷歌直接给出答案快. 另外那个问题也确实是我问的.