Skip to content

Commit

Permalink
adjust code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevoke committed May 25, 2023
1 parent 23d1ef3 commit 12bad2a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 121 deletions.
26 changes: 18 additions & 8 deletions org-gtd-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,18 @@
(require 'org-gtd-core)
(require 'org-gtd-backward-compatibility)

(defvar org-gtd-agenda-width-project-name 12
"width of the project name in the agenda view. Name will be truncated to this length"
)
(defgroup org-gtd-engage nil
"Customize the engage views in the org-gtd package."
:group 'org-gtd
:package-version '(org-gtd . "3.1"))

(defcustom org-gtd-engage-prefix-width 12
"How many characters to dedicate to the agenda prefix in the engage view.
This is where the project name is displayed, on the left side."
:group 'org-gtd-engage
:package-version '(org-gtd . "3.1")
:type 'integer)

;;;; Commands

Expand All @@ -44,8 +53,9 @@
(interactive)
(org-gtd-core-prepare-agenda-buffers)
(with-org-gtd-context
(let* ((project-format-prefix (format " %%i %%-%d"
org-gtd-agenda-width-project-name) )
(let* ((project-format-prefix
(format " %%i %%-%d:(org-gtd-agenda--prefix-format) "
org-gtd-engage-prefix-width))
(org-agenda-custom-commands
`(("g" "Scheduled today and all NEXT items"
((agenda ""
Expand All @@ -55,12 +65,12 @@
(todo org-gtd-next
((org-agenda-overriding-header "All actions ready to be executed.")
(org-agenda-prefix-format
'((todo . ,(eval (concat project-format-prefix ":(org-gtd-agenda--prefix-format) ")))))))
'((todo . ,project-format-prefix)))))
(todo org-gtd-wait
((org-agenda-todo-ignore-with-date t)
(org-agenda-overriding-header "Delegated/Blocked items")
(org-agenda-prefix-format
'((todo . ,(eval (concat project-format-prefix " (org-gtd-agenda--prefix-format) "))))))))))))
'((todo . ,project-format-prefix))))))))))
(org-agenda nil "g")
(goto-char (point-min)))))

Expand Down Expand Up @@ -101,7 +111,7 @@ 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 "")
(truncate-string-to-width (string-trim st) org-gtd-engage-prefix-width nil ?\s "")
)
(let* ((elt (org-element-at-point))
(level (org-element-property :level elt))
Expand Down
113 changes: 0 additions & 113 deletions test/agenda-width-project-name.el

This file was deleted.

52 changes: 52 additions & 0 deletions test/engage-view-prefix-width-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(load "test/helpers/setup.el")
(require 'org-gtd)
(require 'buttercup)

(describe
"Engage view prefix width"

:var ((inhibit-message t))

(before-each (ogt--configure-emacs))
(after-each (ogt--close-and-delete-files))

(it "adds ellipses if name is too long"
(ogt-capture-and-process-project "My long project name which needs shortening")
(let ((org-gtd-engage-prefix-width 17))
(org-gtd-engage))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"My long project …"))

(it "shortens prefix words if necessary"
(ogt-capture-and-process-project "P234567890")
(let ((org-gtd-engage-prefix-width 5))
(org-gtd-engage))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"P234…"))

(it "only shows ellipses if width is 1"
(ogt-capture-and-process-project "P234567890")
(let ((org-gtd-engage-prefix-width 1))
(org-gtd-engage))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"^ …"))

(it "shows the full project name without ellipses if it can"
(ogt-capture-and-process-project "P234567890")
(let ((org-gtd-engage-prefix-width 10))
(org-gtd-engage))
(org-gtd-engage)
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"P234567890"))

(it "adds as many spaces as needed"
(ogt-capture-and-process-project "P234567890")
(let ((org-gtd-engage-prefix-width 50))
(org-gtd-engage))
(expect (ogt--buffer-string org-agenda-buffer)
:to-match
"P234567890 ")))

0 comments on commit 12bad2a

Please sign in to comment.