17

我正在用 Elisp 编写自己的模式。它基本上是一个简单的 crud 应用程序,显示可以通过 minibuffer 操作的数据行。我想为这些行创建一个看起来像 emacs 包管理器的视图:数据列很好地对齐。实现这种观点的最佳方式是什么?

4

3 回答 3

24

菲尔斯的回答让我走上了正轨。虽然没有教程或简单的例子,所以我创建了一个。下面是一个表格列表模式导数的示例,它具有静态数据并且可以打印当前列的 ID:

(define-derived-mode mymode tabulated-list-mode "mymode" "Major mode My Mode, just a test"
  (setq tabulated-list-format [("Col1" 18 t)
                               ("Col2" 12 nil)
                               ("Col3"  10 t)
                               ("Col4" 0 nil)])
  (setq tabulated-list-padding 2)
  (setq tabulated-list-sort-key (cons "Col3" nil))
  (tabulated-list-init-header))

(defun print-current-line-id ()
  (interactive)
   (message (concat "current line ID is: " (tabulated-list-get-id))))

(defun my-listing-command ()
  (interactive)
  (pop-to-buffer "*MY MODE*" nil)
  (mymode)
  (setq tabulated-list-entries (list 
                (list "1" ["1" "2" "3" "4"])
                (list "2" ["a" "b" "c" "d"])))
  (tabulated-list-print t))
于 2012-07-17T19:42:58.673 回答
1

如果您查看您提到的包列表功能的代码,您会发现它使用package-menu-mode了源自tabulated-list-mode.

  • M-x find-function RET package-menu-mode RET
  • C-hf tabulated-list-mode RET
于 2012-06-30T08:53:09.177 回答
0

我一直使用 org-mode 来完成这类任务。

This should be a starting point for your development, because you already have nice tables.

于 2012-07-17T19:58:25.943 回答