From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id yCBiBd7uPl9bWwAA0tVLHw (envelope-from ) for ; Thu, 20 Aug 2020 21:45:02 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id +MkeAd7uPl/NZAAAbx9fmQ (envelope-from ) for ; Thu, 20 Aug 2020 21:45:02 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 44FDA9403CA for ; Thu, 20 Aug 2020 21:45:01 +0000 (UTC) Received: from localhost ([::1]:54034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8sMl-00051I-O9 for larch@yhetil.org; Thu, 20 Aug 2020 17:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8sMQ-00050r-JS for emacs-orgmode@gnu.org; Thu, 20 Aug 2020 17:44:38 -0400 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]:44840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k8sMO-0000Cn-SR for emacs-orgmode@gnu.org; Thu, 20 Aug 2020 17:44:38 -0400 Received: by mail-qk1-x744.google.com with SMTP id j187so2871245qke.11 for ; Thu, 20 Aug 2020 14:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:subject:in-reply-to:date:message-id :mime-version; bh=kFty5+OpVnh26vZGaE9/7W6vYMG/1ol56ISSabfIPgY=; b=p7aKoaBkAlBOvfZLuKUV9mPKAA0JUY3GFMASVYB/0912qDTY8NWUdh+DucX7faCdYn bC9KAgSy84luC6jzVKbrs+zGecv38RnT9TF3MJUu4VWybnVMgU7xZnwOYuC+1qjAXyjQ 1CFh/8nnVYpSwhZUYjLh7HGDYaT6HkQJW7iu2ikqgzpa/b5BLaRi1vLD6XYYpauTU6Xy cBDZwvxavHOgRJs/ane1sR3M0UscB9JJ+9wDW/2NE8mH9WJa0Wx4F06I3PnQPnEUJ7pO PN8u+iz1SSfjcJAig0Tc8SSMiN6GqVxBqf/nzfQpQ7OGzkCURsSNfO3l07aNSJlrpVKo /wqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:subject :in-reply-to:date:message-id:mime-version; bh=kFty5+OpVnh26vZGaE9/7W6vYMG/1ol56ISSabfIPgY=; b=ip9osGOuTWoI7dVvp0FbGn9JwiiFzDlmMVF04kk6XEM1jOc0YTjc3MkFYMzOVSN96H jSfM8JDJdNgGoigSVWokeTK3YloFGxfsx2uddS+8ogxIU+re1/iLsXEfjJT5sSojmXJ1 Nk8QBLYVPIw33nAdJRuscx73s0DjgUMeAZ3BcUc5Oh1JOX7ohJO5c+8stapRsExazKOl i2oVutFXzl7rj2kXfQXzLyIctfRH8zlXieeQsPrjGFYfv+P/6fGxza7LXuwORMZrhxkb a1uQWUemcXpOFf98FbLik10IPBtL1M4hHmLT+zJaVhy+W9KEs/2BA+o9riZV0/F1Ya/f yVcA== X-Gm-Message-State: AOAM530hzCI5+/0TjSCdZNDOGcvhvMZ0iHi87migmpp5mY0k76qTjglo 9mmGtE6Nn9qx2XdUj5tnOFdDcxX1ihKhhA== X-Google-Smtp-Source: ABdhPJytAnckerooWMkHb0Kg7p5UdONUtB9JRrw29wcx2MLbp6P06leuipjJjfLNbVdP+BcMCHdZQg== X-Received: by 2002:ae9:dc03:: with SMTP id q3mr12329qkf.276.1597959875458; Thu, 20 Aug 2020 14:44:35 -0700 (PDT) Received: from arch ([2601:8b:c300:1024:1266:d0ff:1635:f964]) by smtp.gmail.com with ESMTPSA id n85sm3381394qkn.80.2020.08.20.14.44.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 14:44:33 -0700 (PDT) References: <87k0xt5fd6.fsf@gmail.com> User-agent: mu4e 1.5.5; emacs 28.0.50 From: No Wayman To: emacs-orgmode@gnu.org Subject: Re: [PATCH] org-habit: custom consistency graph placement [9.3.7 (release_9.3.7-716-g6d5cab @ /home/n/.emacs.d/straight/build/org/)] In-reply-to: <87k0xt5fd6.fsf@gmail.com> Date: Thu, 20 Aug 2020 17:44:33 -0400 Message-ID: <87tuwxyou6.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::744; envelope-from=iarchivedmywholelife@gmail.com; helo=mail-qk1-x744.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=p7aKoaBk; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.71 X-TUID: EJ3m1pIFolDO --=-=-= Content-Type: text/plain; format=flowed No Wayman 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-habit-add-custom-option-for-placing-consistency-grap.patch Content-Description: org-habit-insert-graph-function.0.0.2 >From 93496b6b86d73a95512c277a1321005d5f1995d1 Mon Sep 17 00:00:00 2001 From: Nicholas Vollmer 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 --=-=-=--