Skip to content

Commit

Permalink
Sometimes project names have trailing spaces
Browse files Browse the repository at this point in the history
org-gtd-agenda--prefix-format sometimes receives a project name with a trailing space.
Trim both sides to remove whitespace.
(perhaps that is something to look for and remove where it is extracted)

Also, remove spurious messages in testing code.
  • Loading branch information
gitmsr committed May 24, 2023
1 parent 03dfffe commit 23d1ef3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions org-gtd-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,25 @@ This assumes all GTD files are also agenda files."

(defun org-gtd-agenda--prefix-format ()
"Format prefix for items in agenda buffer."
(defun truncate (st)
(truncate-string-to-width (string-trim st) org-gtd-agenda-width-project-name nil ?\s "")
)
(let* ((elt (org-element-at-point))
(level (org-element-property :level elt))
(category (org-entry-get (point) "CATEGORY" t))
(parent-title (org-element-property
:raw-value
(org-element-property :parent elt)))
(tally-cookie-regexp "\[[[:digit:]]+/[[:digit:]]+\][[:space:]]*"))
(truncate-string-to-width
(truncate
;; if level 3, use the parent
;; otherwise if it has category, use category
;; else "no project" so we avoid failing
(cond
((eq level 3) (replace-regexp-in-string tally-cookie-regexp "" parent-title))
(category category)
(t "no project")
)
org-gtd-agenda-width-project-name nil ?\s ""
)))
))))

;;;; Footer

Expand Down
12 changes: 6 additions & 6 deletions test/agenda-width-project-name.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(it "can have a specific agenda width"
(ogt-capture-and-process-project "My long project name which needs shortening") ;; see test/helpers/processing.el
(org-gtd-engage)
(expect (message (ogt--buffer-string org-agenda-buffer))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"My long project …")
))
Expand All @@ -35,7 +35,7 @@
(it "can have a specific agenda width"
(ogt-capture-and-process-project "P234567890")
(org-gtd-engage)
(expect (message (ogt--buffer-string org-agenda-buffer))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"P234…")
))
Expand All @@ -53,7 +53,7 @@
(it "can have a specific agenda width"
(ogt-capture-and-process-project "P234567890")
(org-gtd-engage)
(expect (message (ogt--buffer-string org-agenda-buffer))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"")
))
Expand All @@ -71,7 +71,7 @@
(it "can have a specific agenda width"
(ogt-capture-and-process-project "P234567890")
(org-gtd-engage)
(expect (message (ogt--buffer-string org-agenda-buffer))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"P234567890")
))
Expand All @@ -89,7 +89,7 @@
(it "can have a specific agenda width"
(ogt-capture-and-process-project "P234567890")
(org-gtd-engage)
(expect (message (ogt--buffer-string org-agenda-buffer))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"P234567890 ")
))
Expand All @@ -107,7 +107,7 @@
(it "can have a specific agenda width"
(ogt-capture-and-process-project "P234567890")
(org-gtd-engage)
(expect (message (ogt--buffer-string org-agenda-buffer))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"P234567890 ")
))

0 comments on commit 23d1ef3

Please sign in to comment.