summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <ricardo.wurmus@mdc-berlin.de>2014-10-24 15:01:55 +0200
committerRicardo Wurmus <ricardo.wurmus@mdc-berlin.de>2014-10-24 15:01:55 +0200
commitfe3439329826b72c86d11033ac95dc7dc2cb8c88 (patch)
treea8040256a4783de9cac410e8aa64b72e605858df
parent23b8841669cd990fb544745ad3081a2382c37596 (diff)
make columns in header variable
-rw-r--r--grid-engine-mode.el39
1 files changed, 27 insertions, 12 deletions
diff --git a/grid-engine-mode.el b/grid-engine-mode.el
index 988d4c5..ed198bb 100644
--- a/grid-engine-mode.el
+++ b/grid-engine-mode.el
@@ -65,12 +65,20 @@
(defun grid-engine-list-jobs ()
"List all jobs for the specified user in a new buffer."
- (setq row-pattern "%-10s %-10s %-15s %-10s\n")
- (setq header (format (concat row-pattern " \n")
- "Job-ID"
- "Priority"
- "User"
- "State"))
+ (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
@@ -80,11 +88,10 @@
text))
(defun format-job-record (job)
- (let ((text (format row-pattern
- (field-as-text 'job-id job)
- (field-as-text 'priority job)
- (field-as-text 'owner job)
- (field-as-text 'state job))))
+ (let* ((args (cons row-fmt (mapcar (lambda (key)
+ (field-as-text key job))
+ column-order)))
+ (text (apply 'format args)))
(put-text-property 0 (length text) 'grid-engine-job job text)
text))
@@ -116,7 +123,15 @@
(jobs (mapcar 'mkjob-alist (cddr (caddr tree)))))
(set-buffer (get-buffer-create title))
(erase-buffer)
- (insert header)
+ ;; 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))