4

是否可以在 Emacs org-mode 中对给定的表或文件强制执行表排序?

当我说“强制”时,我的意思是表格应该在重新对齐时自动排序(例如当我点击<TAB> 或时C-c C-c)。我希望它根据第一行按字母顺序排序。

我可以设置一些属性来实现这一点吗?

4

1 回答 1

4

一种选择是“建议”您通过按键调用的功能。
http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/elisp/Defining-Advice.html

;; advise a functions called by <TAB>
(defadvice org-table-next-field (around auto-sort-advice)
  "Sort table alphabetically according to the first rows"
  (progn
    ad-do-it
    (let ((pos (point)))
      ;; to to the first column
      (goto-char (org-table-begin))
      ;; one can change SORTING-TYPE (?a ?A ?n ?N ?t ?T)
      (org-table-sort-lines nil ?a)
      ;; restore position
      (goto-char pos))))

(ad-activate 'org-table-next-field)
于 2012-07-20T18:57:53.003 回答