2012-06-30 42 views
13

我在Elisp寫我自己的模式。它基本上是一個簡單的crud應用程序,顯示可以通過minibuffer操縱的數據行。我想爲這些行創建一個看起來像emacs包管理器的視圖:數據列很好地對齊。實現這種觀點的最佳方式是什麼?如何在Emacs Lisp中創建列視圖?

回答

18

從菲爾斯的回答讓我走上軌道。雖然任何地方都沒有教程或簡單的例子,所以我創建了一個。這裏是一個具有靜態數據,並可以打印當前列的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)) 
1

如果您查看您提到的軟件包列表功能的代碼,您會發現它使用了package-menu-mode,它源自tabulated-list-mode

  • M-Xfind-functionRETpackage-menu-modeRET
  • C-H˚Ftabulated-list-modeRET
0

我用組織模式爲這種任務的所有時間。

這應該是您開發的起點,因爲您已經有了很好的表格。