* [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)]
@ 2020-08-20 18:41 No Wayman
2020-08-20 18:46 ` No Wayman
2020-08-20 21:44 ` No Wayman
0 siblings, 2 replies; 5+ messages in thread
From: No Wayman @ 2020-08-20 18:41 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 677 bytes --]
I like seeing a month long habit consistency graph, but this
usually overwrites most of the information on each agenda habit
line unless the window is particularly wide.
The attached patch adds a customizable option to place the graph.
I'm using it now to place each habit's graph on a new line below
the habit at `org-habit-graph-column'. It makes this sort of
customization very simple, e.g.
(setq org-habit-insert-graph-function
(lambda (graph)
(goto-char (point-at-eol))
(insert "\n")
(move-to-column org-habit-graph-column t)
(insert graph)))
Would love to see it included in org-habit.
Thanks,
Nicholas Vollmer
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-habit-insert-graph-function --]
[-- Type: text/x-patch, Size: 3123 bytes --]
From 6d5cabcbe15e67873a7ce489e59cff642357d8e6 Mon Sep 17 00:00:00 2001
From: Nicholas Vollmer <iarchivedmywholelife@gmail.com>
Date: Thu, 20 Aug 2020 13:46:49 -0400
Subject: [PATCH] habit: add custom option for placing consistency graph
* lisp/org-habit.el (org-habit-insert-consistency-graphs): Add
`org-habit-insert-graph-function' defcustom.
Allow user to control consistency graph placement with a customizable
function. See `org-habit-insert-graph-function` docstring for an
example.
---
lisp/org-habit.el | 42 +++++++++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/lisp/org-habit.el b/lisp/org-habit.el
index f76f0f213..64d265448 100644
--- a/lisp/org-habit.el
+++ b/lisp/org-habit.el
@@ -104,6 +104,24 @@ means of creating calendar-based reminders."
:package-version '(Org . "9.3")
:safe (lambda (v) (or (integerp v) (null v))))
+(defcustom org-habit-insert-graph-function nil
+ "Function called to place each consistency graph.
+It must accept the graph string as its sole argument.
+It is invoked with point on the current habit's line in the agenda buffer.
+
+For example, to insert graphs on a new line below the habit:
+
+ (setq org-habit-insert-graph-function
+ (lambda (graph)
+ (goto-char (point-at-eol))
+ (insert \"\\n\")
+ (move-to-column org-habit-graph-column t)
+ (insert graph)))
+
+If nil, the graph is inserted on the current habit's line at `org-habit-graph-column'."
+ :group 'org-habit
+ :type 'function)
+
(defface org-habit-clear-face
'((((background light)) (:background "#8270f9"))
(((background dark)) (:background "blue")))
@@ -430,17 +448,19 @@ current time."
(while (not (eobp))
(let ((habit (get-text-property (point) 'org-habit-p)))
(when habit
- (move-to-column org-habit-graph-column t)
- (delete-char (min (+ 1 org-habit-preceding-days
- org-habit-following-days)
- (- (line-end-position) (point))))
- (insert-before-markers
- (org-habit-build-graph
- habit
- (time-subtract moment (days-to-time org-habit-preceding-days))
- moment
- (time-add moment (days-to-time org-habit-following-days))))))
- (forward-line)))))
+ (let ((graph (org-habit-build-graph
+ habit
+ (time-subtract moment (days-to-time org-habit-preceding-days))
+ moment
+ (time-add moment (days-to-time org-habit-following-days)))))
+ (if (functionp org-habit-insert-graph-function)
+ (save-excursion (funcall org-habit-insert-graph-function graph))
+ (move-to-column org-habit-graph-column t)
+ (delete-char (min (+ 1 org-habit-preceding-days
+ org-habit-following-days)
+ (- (line-end-position) (point))))
+ (insert-before-markers graph))))
+ (forward-line))))))
(defun org-habit-toggle-habits ()
"Toggle display of habits in an agenda buffer."
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)]
2020-08-20 18:41 [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)] No Wayman
@ 2020-08-20 18:46 ` No Wayman
2020-08-20 21:44 ` No Wayman
1 sibling, 0 replies; 5+ messages in thread
From: No Wayman @ 2020-08-20 18:46 UTC (permalink / raw)
To: emacs-orgmode
No Wayman <iarchivedmywholelife@gmail.com> writes:
> I'm using it now to place each habit's graph on a new line below
> the habit at `org-habit-graph-column'.
Forgot to mention, this also has the added benefit of not
displacing the tags on each habit's line.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)]
2020-08-20 18:41 [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)] No Wayman
2020-08-20 18:46 ` No Wayman
@ 2020-08-20 21:44 ` No Wayman
2020-08-20 22:29 ` Ihor Radchenko
1 sibling, 1 reply; 5+ messages in thread
From: No Wayman @ 2020-08-20 21:44 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
No Wayman <iarchivedmywholelife@gmail.com> writes:
> It makes this sort of customization very simple
Famous last words. I forgot the agenda relies on text-properties
for much of its functionality.
I've attached a patch that addresses this and also removes the
`save-excursion` around the funcall to the custom insertion
function.
I've noted in the documentation that if the function is moving
point, it is responsible for making sure it ends up on the line
before the next habit.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-habit-insert-graph-function.0.0.2 --]
[-- Type: text/x-patch, Size: 3425 bytes --]
From 93496b6b86d73a95512c277a1321005d5f1995d1 Mon Sep 17 00:00:00 2001
From: Nicholas Vollmer <iarchivedmywholelife@gmail.com>
Date: Thu, 20 Aug 2020 13:46:49 -0400
Subject: [PATCH] habit: add custom option for placing consistency graph
* lisp/org-habit.el (org-habit-insert-consistency-graphs): Add
`org-habit-insert-graph-function' defcustom.
Allow user to control consistency graph placement with a customizable
function. See `org-habit-insert-graph-function` docstring for an
example.
---
lisp/org-habit.el | 45 ++++++++++++++++++++++++++++++++++-----------
1 file changed, 34 insertions(+), 11 deletions(-)
diff --git a/lisp/org-habit.el b/lisp/org-habit.el
index f76f0f213..99dfe8def 100644
--- a/lisp/org-habit.el
+++ b/lisp/org-habit.el
@@ -104,6 +104,27 @@ means of creating calendar-based reminders."
:package-version '(Org . "9.3")
:safe (lambda (v) (or (integerp v) (null v))))
+(defcustom org-habit-insert-graph-function nil
+ "Function called to place each consistency graph.
+It must accept the graph string as its sole argument.
+It is invoked with point on the current habit's line in the agenda buffer,
+and is responsible for placing point on the line before the next habit if point is moved.
+
+For example, to insert graphs on a new line below the habit:
+
+ (setq org-habit-insert-graph-function
+ (lambda (graph)
+ (let ((props (text-properties-at (point))))
+ (end-of-line)
+ ;; org-agenda functionality depends on current line's text properties
+ (insert (concat \"\\n\" (make-string (1+ (or org-habit-graph-column 0)) ? )))
+ (add-text-properties (line-beginning-position) (line-end-position) props)
+ (insert graph))))
+
+If nil, the graph is inserted on the current habit's line at `org-habit-graph-column'."
+ :group 'org-habit
+ :type 'function)
+
(defface org-habit-clear-face
'((((background light)) (:background "#8270f9"))
(((background dark)) (:background "blue")))
@@ -430,17 +451,19 @@ current time."
(while (not (eobp))
(let ((habit (get-text-property (point) 'org-habit-p)))
(when habit
- (move-to-column org-habit-graph-column t)
- (delete-char (min (+ 1 org-habit-preceding-days
- org-habit-following-days)
- (- (line-end-position) (point))))
- (insert-before-markers
- (org-habit-build-graph
- habit
- (time-subtract moment (days-to-time org-habit-preceding-days))
- moment
- (time-add moment (days-to-time org-habit-following-days))))))
- (forward-line)))))
+ (let ((graph (org-habit-build-graph
+ habit
+ (time-subtract moment (days-to-time org-habit-preceding-days))
+ moment
+ (time-add moment (days-to-time org-habit-following-days)))))
+ (if (functionp org-habit-insert-graph-function)
+ (funcall org-habit-insert-graph-function graph)
+ (move-to-column org-habit-graph-column t)
+ (delete-char (min (+ 1 org-habit-preceding-days
+ org-habit-following-days)
+ (- (line-end-position) (point))))
+ (insert-before-markers graph)))))
+ (forward-line)))))
(defun org-habit-toggle-habits ()
"Toggle display of habits in an agenda buffer."
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)]
2020-08-20 21:44 ` No Wayman
@ 2020-08-20 22:29 ` Ihor Radchenko
2020-08-21 3:12 ` No Wayman
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2020-08-20 22:29 UTC (permalink / raw)
To: No Wayman, emacs-orgmode
> Famous last words. I forgot the agenda relies on text-properties
> for much of its functionality.
> I've attached a patch that addresses this and also removes the
> `save-excursion` around the funcall to the custom insertion
> function.
As I remember, last time I played with multi-line agenda entries, there
were issues with org-agenda-next/previous-item. You may consider
checking if your patch breaks those.
Best,
Ihor
No Wayman <iarchivedmywholelife@gmail.com> writes:
> No Wayman <iarchivedmywholelife@gmail.com> writes:
>
>> It makes this sort of customization very simple
>
> Famous last words. I forgot the agenda relies on text-properties
> for much of its functionality.
> I've attached a patch that addresses this and also removes the
> `save-excursion` around the funcall to the custom insertion
> function.
> I've noted in the documentation that if the function is moving
> point, it is responsible for making sure it ends up on the line
> before the next habit.
>
> From 93496b6b86d73a95512c277a1321005d5f1995d1 Mon Sep 17 00:00:00 2001
> From: Nicholas Vollmer <iarchivedmywholelife@gmail.com>
> Date: Thu, 20 Aug 2020 13:46:49 -0400
> Subject: [PATCH] habit: add custom option for placing consistency graph
>
> * lisp/org-habit.el (org-habit-insert-consistency-graphs): Add
> `org-habit-insert-graph-function' defcustom.
>
> Allow user to control consistency graph placement with a customizable
> function. See `org-habit-insert-graph-function` docstring for an
> example.
> ---
> lisp/org-habit.el | 45 ++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 34 insertions(+), 11 deletions(-)
>
> diff --git a/lisp/org-habit.el b/lisp/org-habit.el
> index f76f0f213..99dfe8def 100644
> --- a/lisp/org-habit.el
> +++ b/lisp/org-habit.el
> @@ -104,6 +104,27 @@ means of creating calendar-based reminders."
> :package-version '(Org . "9.3")
> :safe (lambda (v) (or (integerp v) (null v))))
>
> +(defcustom org-habit-insert-graph-function nil
> + "Function called to place each consistency graph.
> +It must accept the graph string as its sole argument.
> +It is invoked with point on the current habit's line in the agenda buffer,
> +and is responsible for placing point on the line before the next habit if point is moved.
> +
> +For example, to insert graphs on a new line below the habit:
> +
> + (setq org-habit-insert-graph-function
> + (lambda (graph)
> + (let ((props (text-properties-at (point))))
> + (end-of-line)
> + ;; org-agenda functionality depends on current line's text properties
> + (insert (concat \"\\n\" (make-string (1+ (or org-habit-graph-column 0)) ? )))
> + (add-text-properties (line-beginning-position) (line-end-position) props)
> + (insert graph))))
> +
> +If nil, the graph is inserted on the current habit's line at `org-habit-graph-column'."
> + :group 'org-habit
> + :type 'function)
> +
> (defface org-habit-clear-face
> '((((background light)) (:background "#8270f9"))
> (((background dark)) (:background "blue")))
> @@ -430,17 +451,19 @@ current time."
> (while (not (eobp))
> (let ((habit (get-text-property (point) 'org-habit-p)))
> (when habit
> - (move-to-column org-habit-graph-column t)
> - (delete-char (min (+ 1 org-habit-preceding-days
> - org-habit-following-days)
> - (- (line-end-position) (point))))
> - (insert-before-markers
> - (org-habit-build-graph
> - habit
> - (time-subtract moment (days-to-time org-habit-preceding-days))
> - moment
> - (time-add moment (days-to-time org-habit-following-days))))))
> - (forward-line)))))
> + (let ((graph (org-habit-build-graph
> + habit
> + (time-subtract moment (days-to-time org-habit-preceding-days))
> + moment
> + (time-add moment (days-to-time org-habit-following-days)))))
> + (if (functionp org-habit-insert-graph-function)
> + (funcall org-habit-insert-graph-function graph)
> + (move-to-column org-habit-graph-column t)
> + (delete-char (min (+ 1 org-habit-preceding-days
> + org-habit-following-days)
> + (- (line-end-position) (point))))
> + (insert-before-markers graph)))))
> + (forward-line)))))
>
> (defun org-habit-toggle-habits ()
> "Toggle display of habits in an agenda buffer."
> --
> 2.28.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)]
2020-08-20 22:29 ` Ihor Radchenko
@ 2020-08-21 3:12 ` No Wayman
0 siblings, 0 replies; 5+ messages in thread
From: No Wayman @ 2020-08-21 3:12 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]
Ihor Radchenko <yantar92@gmail.com> writes:
> As I remember, last time I played with multi-line agenda
> entries, there
> were issues with org-agenda-next/previous-item. You may consider
> checking if your patch breaks those.
Thanks for the heads up, Ihor. The patch itself shouldn't break
anything and is completely optional behavior, though the example I
gave in the docstring does.
I ended up faking the newline with the display text-property:
(defun +org-habit-graph-on-own-line (graph)
"Place org habit consitency graph below the habit."
(add-text-properties
(line-beginning-position)
(line-end-position)
`(display ,(concat (when-let ((icon (car
(org-agenda-get-category-icon
(org-agenda-get-category)))))
(format " %s " icon))
(string-trim-left (thing-at-point 'line))
(make-string (or org-habit-graph-column 0) ?
)
(propertize graph 'display '(height (+
1)))))))
This works well for me so far.
I've revised the docstring attachment in the attached patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-habit-insert-graph-function.0.0.3 --]
[-- Type: text/x-patch, Size: 3620 bytes --]
From 41ee2b974a98e0beac00a8012eab91cec948e6d5 Mon Sep 17 00:00:00 2001
From: Nicholas Vollmer <iarchivedmywholelife@gmail.com>
Date: Thu, 20 Aug 2020 13:46:49 -0400
Subject: [PATCH] habit: add custom option for placing consistency graph
* lisp/org-habit.el (org-habit-insert-consistency-graphs): Add
`org-habit-insert-graph-function' defcustom.
Allow user to control consistency graph placement with a customizable
function. See `org-habit-insert-graph-function` docstring for an
example.
---
lisp/org-habit.el | 51 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 40 insertions(+), 11 deletions(-)
diff --git a/lisp/org-habit.el b/lisp/org-habit.el
index f76f0f213..55577f442 100644
--- a/lisp/org-habit.el
+++ b/lisp/org-habit.el
@@ -104,6 +104,33 @@ means of creating calendar-based reminders."
:package-version '(Org . "9.3")
:safe (lambda (v) (or (integerp v) (null v))))
+(defcustom org-habit-insert-graph-function nil
+ "Function called to place each consistency graph.
+It must accept the graph string as its sole argument.
+It is invoked with point on the current habit's line in the agenda
+buffer, and is responsible for placing point on the line before the
+next habit if point is moved.
+
+For example, to insert graphs on a new line below each habit:
+
+\(setq org-habit-insert-graph-function
+ (lambda (graph)
+ \"Place org habit consitency on its own line below the habit.\"
+ (add-text-properties
+ (line-beginning-position) (line-end-position)
+ \\=`(display ,(concat
+ (when-let ((icon (car (org-agenda-get-category-icon
+ (org-agenda-get-category)))))
+
+ (format \" %s \" icon))
+ (string-trim-left (thing-at-point \\='line))
+ (make-string (or org-habit-graph-column 0) ? )
+ (insert graph))))))
+
+If nil, the graph is inserted on the current habit's line at `org-habit-graph-column'."
+ :group 'org-habit
+ :type 'function)
+
(defface org-habit-clear-face
'((((background light)) (:background "#8270f9"))
(((background dark)) (:background "blue")))
@@ -430,17 +457,19 @@ current time."
(while (not (eobp))
(let ((habit (get-text-property (point) 'org-habit-p)))
(when habit
- (move-to-column org-habit-graph-column t)
- (delete-char (min (+ 1 org-habit-preceding-days
- org-habit-following-days)
- (- (line-end-position) (point))))
- (insert-before-markers
- (org-habit-build-graph
- habit
- (time-subtract moment (days-to-time org-habit-preceding-days))
- moment
- (time-add moment (days-to-time org-habit-following-days))))))
- (forward-line)))))
+ (let ((graph (org-habit-build-graph
+ habit
+ (time-subtract moment (days-to-time org-habit-preceding-days))
+ moment
+ (time-add moment (days-to-time org-habit-following-days)))))
+ (if (functionp org-habit-insert-graph-function)
+ (funcall org-habit-insert-graph-function graph)
+ (move-to-column org-habit-graph-column t)
+ (delete-char (min (+ 1 org-habit-preceding-days
+ org-habit-following-days)
+ (- (line-end-position) (point))))
+ (insert-before-markers graph)))))
+ (forward-line)))))
(defun org-habit-toggle-habits ()
"Toggle display of habits in an agenda buffer."
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-21 3:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-20 18:41 [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)] No Wayman
2020-08-20 18:46 ` No Wayman
2020-08-20 21:44 ` No Wayman
2020-08-20 22:29 ` Ihor Radchenko
2020-08-21 3:12 ` No Wayman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).