From 0fba6ef10cf2ad3b833754a48b543bd5f66b953b Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 12 Feb 2008 19:58:21 +0100 Subject: [PATCH] Allow relative completion cookies for column view summation. Requested by Daniel J. Sinder. --- ChangeLog | 1 + org.el | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2758e9fa..8c18a379c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ (org-export-as-html): Join unsorted lists when they directly follow each other. Such lists may be created by headlines that are converted to lists. + (org-nofm-to-completion): New function. 2008-02-12 Bastien Guerry diff --git a/org.el b/org.el index 06ce45dcf..503c1be9b 100644 --- a/org.el +++ b/org.el @@ -16756,9 +16756,10 @@ Where possible, use the standard interface for changing this line." x)) org-columns-overlays))) (allowed (or (org-property-get-allowed-values pom key) - (and (equal + (and (memq (nth 4 (assoc key org-columns-current-fmt-compiled)) - 'checkbox) '("[ ]" "[X]")))) + '(checkbox checkbox-n-of-m checkbox-percent)) + '("[ ]" "[X]")))) nval) (when (equal key "ITEM") (error "Cannot edit item headline from here")) @@ -17160,11 +17161,19 @@ display, or in the #+COLUMNS line of the current buffer." (cond ((= n (floor n)) "[X]") ((> n 1.) "[-]") (t "[ ]"))) + ((memq fmt '(checkbox-n-of-m checkbox-percent)) + (let* ((n1 (floor n)) (n2 (floor (+ .5 (* 1000000 (- n n1)))))) + (org-nofm-to-completion n1 (+ n2 n1) (eq fmt 'checkbox-percent)))) (printf (format printf n)) ((eq fmt 'currency) (format "%.2f" n)) (t (number-to-string n)))) +(defun org-nofm-to-completion (n m &optional percent) + (if (not percent) + (format "[%d/%d]" n m) + (format "[%d%%]"(floor (+ 0.5 (* 100. (/ (* 1.0 n) m))))))) + (defun org-column-string-to-number (s fmt) "Convert a column value to a number that can be used for column computing." (cond @@ -17173,7 +17182,7 @@ display, or in the #+COLUMNS line of the current buffer." (while l (setq sum (+ (string-to-number (pop l)) (/ sum 60)))) sum)) - ((eq fmt 'checkbox) + ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent)) (if (equal s "[X]") 1. 0.000001)) (t (string-to-number s)))) @@ -17190,6 +17199,8 @@ display, or in the #+COLUMNS line of the current buffer." (cond ((eq fmt 'add_times) (setq op ":")) ((eq fmt 'checkbox) (setq op "X")) + ((eq fmt 'checkbox-n-of-m) (setq op "X/")) + ((eq fmt 'checkbox-percent) (setq op "X%")) ((eq fmt 'add_numbers) (setq op "+")) ((eq fmt 'currency) (setq op "$"))) (if (and op printf) (setq op (concat op ";" printf))) @@ -17232,8 +17243,8 @@ printf a printf format for computed values" ((equal op "$") (setq f 'currency)) ((equal op ":") (setq f 'add_times)) ((equal op "X") (setq f 'checkbox)) - ((equal op "X/") (setq f 'checkbox)) - ((equal op "X%") (setq f 'checkbox)) + ((equal op "X/") (setq f 'checkbox-n-of-m)) + ((equal op "X%") (setq f 'checkbox-percent)) ) (push (list prop title width op f printf) org-columns-current-fmt-compiled)) (setq org-columns-current-fmt-compiled -- 2.11.4.GIT