0

As the title. I have come so close but can't get past this last hurdle.

The below returns all time today that has been spent on headings where the tag is 'billable'. However it fails when there are also other tags. I've tried to replace string= with a test for the string containing billable, but for some reason it fails.

You can see some of my attempts commented out below.

Tia.

(defun my-broken-function ()
  (interactive)
  (let ((files (org-agenda-files))
        (total 0))
    (org-agenda-prepare-buffers files)
    (dolist (file files)
      (with-current-buffer (find-buffer-visiting file)
        (setq total (+ total (org-clock-sum-today (lambda ()
            (string= (org-entry-get (point) "TAGS") ":billable:")
            ;; (string-match  ":billable:" (org-entry-get (point) "TAGS"))
            ;; (not (not (string-match-p (regexp-quote "billable") (org-entry-get (point) "TAGS"))))
            ))))))
    (message (number-to-string total))
    ))
  • org-entry-get may return nil which is not a string, so it will cause any string functions to barf. Try replacing any such call with (or (org-entry-get (point) "TAGS") ""), effectively replacing the nil with the empty string. The string-match implementation should then work. If it does not, edit your question and add the error that you get - don't just tell us there is some error. And set debug-on-error so that errors will generate backtraces - then post the backtrace. – NickD Jul 10 at 13:46
  • Thanks for pointer, and thanks for the tip on useful info to include in questions. This is all still new to me, but I'll remember that for the future. What you suggested worked, I'll answer the question now. – randouser Jul 10 at 23:32
1

As per NickD's comment:

"org-entry-get may return nil which is not a string, so it will cause any string functions to barf. Try replacing any such call with (or (org-entry-get (point) "TAGS") ""), effectively replacing the nil with the empty string."

What worked is replacing the ninth line with:

(string-match  ":billable:" (or (org-entry-get (point) "TAGS") ""))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.