简体   繁体   English

如何在Emacs Lisp中创建列视图?

[英]How to create a column view in Emacs Lisp?

I'm writing my own mode in Elisp. 我在Elisp中编写自己的模式。 It's basically a simple crud application showing rows of data which can be manipulated via the minibuffer. 它基本上是一个简单的crud应用程序,显示可以通过迷你缓冲区操作的数据行。 I'd like to create a view for these rows which looks like the emacs package manager: columns of data nicely aligned. 我想为这些行创建一个看起来像emacs包管理器的视图:数据列很好地对齐。 What's the best way to implement such a view? 实现这种观点的最佳方法是什么?

The answer from phils got me on track. phils的答案让我走上正轨。 There are no tutorials or simple examples anywhere though, so I created one. 虽然在任何地方都没有教程或简单的例子,所以我创建了一个。 Here is an example of a tabulated-list-mode derivative which has static data and can print the ID of the current column: 以下是具有静态数据并可打印当前列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))

If you look at the code for the package listing function you mention, you'll see that it employs package-menu-mode which derives from tabulated-list-mode . 如果你看一下你提到的软件包列表函数的代码,你会看到它采用了package-menu-mode ,它源自tabulated-list-mode

  • Mx find-function RET package-menu-mode RET Mx find-function RET package-menu-mode RET
  • Ch f tabulated-list-mode RET Ch f tabulated-list-mode RET

I use org-mode for this kind of task all the time. 我一直使用org-mode来完成这种任务。

This should be a starting point for your development, because you already have nice tables. 这应该是您开发的起点,因为您已经有了很好的表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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