emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: No Wayman <iarchivedmywholelife@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)]
Date: Thu, 20 Aug 2020 14:41:57 -0400	[thread overview]
Message-ID: <87k0xt5fd6.fsf@gmail.com> (raw)

[-- 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


             reply	other threads:[~2020-08-20 18:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-20 18:41 No Wayman [this message]
2020-08-20 18:46 ` [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 21:44 ` No Wayman
2020-08-20 22:29   ` Ihor Radchenko
2020-08-21  3:12     ` No Wayman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k0xt5fd6.fsf@gmail.com \
    --to=iarchivedmywholelife@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).