diff options
author | Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> | 2014-10-27 11:36:29 +0100 |
---|---|---|
committer | Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> | 2014-10-27 11:36:29 +0100 |
commit | 4390a98f60133dbe5d1b7e2ec098fe9a11876a0c (patch) | |
tree | a4c2ecd811a9a984634b50fe9856ff2a1e5d1ac1 | |
parent | 0e3953c90cb3cee022ab56634619a717dd717ee1 (diff) |
use tabulated-list-mode functions to render list
-rw-r--r-- | grid-engine-mode.el | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/grid-engine-mode.el b/grid-engine-mode.el index a023f30..6de65c1 100644 --- a/grid-engine-mode.el +++ b/grid-engine-mode.el @@ -21,8 +21,6 @@ "The grid engine user. Defaults to the logged in user's name.") (defun grid-engine-setup () - (if grid-engine-map - nil (setq grid-engine-map (make-keymap)) ;; disable all key bindings (suppress-keymap grid-engine-map) @@ -38,7 +36,26 @@ (error "[Grid Engine] point is not on a field of a job record")) (grid-engine-job-details field job arg)))) (define-key grid-engine-map (kbd "g") - (lambda () (interactive) (grid-engine-list-jobs))))) + (lambda () (interactive) (grid-engine-list-jobs))) + + (grid-engine-update-list-format) + (tabulated-list-init-header)) + + +(setq column-order '(job-id time priority owner state)) +(defun grid-engine-update-list-format () + (setq columns '((job-id . ("Job-ID" 10 nil)) + (priority . ("Priority" 10 nil)) + (name . ("Job name" 10 nil)) + (owner . ("User" 15 nil)) + (state . ("State" 15 nil)) + (time . ("Time" 25 nil)) + (queue . ("Queue" 25 nil)) + (slots . ("Slots" 10 nil)))) + (setq tabulated-list-format + (vconcat (mapcar (lambda (key) + (cdr (assoc key columns))) + column-order)))) (defun grid-engine--raise-buffer (&optional buffer) (when buffer @@ -73,23 +90,8 @@ (grid-engine--cmd-to-buffer cmd) (libxml-parse-xml-region 1 (buffer-size)))) - (defun grid-engine-list-jobs () "List all jobs for the specified user in a new buffer." - (setq columns '((job-id . ("Job-ID" "%-10s")) - (priority . ("Priority" "%-10s")) - (name . ("Job name" "%-10s")) - (owner . ("User" "%-15s")) - (state . ("State" "%-15s")) - (time . ("Time" "%-25s")) - (queue . ("Queue" "%-25s")) - (slots . ("Slots" "%-10s")))) - (setq column-order '(job-id time priority owner state)) - (setq row-fmt (concat (mapconcat (lambda (key) - (caddr (assoc key columns))) - column-order " ") - "\n")) - (defun field-as-text (field obj &optional format-string) (let* ((value (cdr (assoc field obj))) (format-string (if format-string format-string @@ -97,12 +99,11 @@ (text (format format-string value))) (propertize text 'field value))) - (defun format-job-record (job) - (let* ((args (cons row-fmt (mapcar (lambda (key) - (field-as-text key job)) - column-order))) - (text (apply 'format args))) - (propertize text 'grid-engine-job job))) + (defun job-to-row (job) + (let ((contents (vconcat (mapcar (lambda (key) + (field-as-text key job)) + column-order)))) + (list job contents))) (defun mkjob-alist (subtree) "Convert a parsed XML subtree for a job entry to an alist." @@ -131,20 +132,13 @@ (let* ((tree (grid-engine--cmd-to-xmltree cmd)) (jobs (mapcar 'mkjob-alist (cddr (caddr tree))))) (set-buffer (get-buffer-create title)) - (erase-buffer) - ;; insert header - (insert (apply 'format - (cons row-fmt - (mapcar (lambda (key) - (cadr (assoc key columns))) - column-order)))) - ;; insert separator - (insert "\n") - ;; insert each row - (mapcar (lambda (job) - (insert (format-job-record job))) - jobs)) + (setq tabulated-list-entries + (mapcar (lambda (job) + (job-to-row job)) + jobs))) (grid-engine--raise-buffer) + ;; update list + (tabulated-list-print) (message nil))) (defun grid-engine-job-details (field job &optional new-buffer) |