From baf0de7ca9fb9886aa67dc688324417b0051e8c1 Mon Sep 17 00:00:00 2001 From: "wojciech.meyer" Date: Sat, 3 Mar 2012 23:41:56 +0100 Subject: [PATCH] provide tabulated-list for the older versions of emacs Ignore-this: 385310d27c8b7812fd914ad4125ef252 darcs-hash:20120303224156-33bd9-b2f09d35cf79bc530512bd4ed34b2a64f86f4e03 --- src/top/utop.el | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/top/utop.el b/src/top/utop.el index 6a01528..38f10ac 100644 --- a/src/top/utop.el +++ b/src/top/utop.el @@ -7,6 +7,9 @@ (require 'easymenu) +;; tabulated-list is a part of Emacs 24 +(require 'tabulated-list nil t) + ;; +-----------------------------------------------------------------+ ;; | License | ;; +-----------------------------------------------------------------+ @@ -177,6 +180,55 @@ before the end of prompt.") "The position of the cursor in the phrase sent to OCaml (where to add the newline character if it is not accepted).") +;; +-----------------------------------------------------------------+ +;; | Compability | +;; +-----------------------------------------------------------------+ + +(unless (featurep 'tabulated-list) + ;; tabulated-list.el is part of Emacs 24 + ;; This is a thin layer building compability with previous versions + (defvar tabulated-list-format nil) + (defvar tabulated-list-sort-key nil) + (defvar tabulated-list-printer nil) + (defvar tabulated-list-revert-hook nil) + (defvar tabulated-list-entries nil) + (define-derived-mode tabulated-list-mode special-mode "Mini-tabulated list mode" + "Tabulated list" + (make-local-variable 'tabulated-list-format) + (make-local-variable 'tabulated-list-sort-key) + (make-local-variable 'tabulated-list-printer) + (set (make-local-variable 'revert-buffer-function) 'tabulated-list-revert) + + (defun tabulated-list-init-header () + (save-excursion + (let ((inhibit-read-only t)) + ;; Find the longest package name + (mapc + (lambda (entry) + (let* ((name (nth 0 entry)) + (size (length name)) + (padding (- (nth 1 entry) size))) + (insert name) + (insert-char ?\s padding) + )) tabulated-list-format) + (insert-string "\n")))) + + (defun tabulated-list-print (dummy) + (save-excursion + (let ((inhibit-read-only t)) + (mapc (lambda (entry) + (goto-char (point-max)) + (apply tabulated-list-printer entry)) + tabulated-list-entries)) + t)) + + (defun tabulated-list-revert (ignore-auto noconfirm) + (let ((inhibit-read-only t)) + (delete-region (point-min) (point-max)) + (tabulated-list-init-header) + (tabulated-list-print t)))) +) + ;; +-----------------------------------------------------------------+ ;; | Utils | ;; +-----------------------------------------------------------------+