From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KqOBMq/5Pl/dZwAA0tVLHw (envelope-from ) for ; Thu, 20 Aug 2020 22:31:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id ePjjLa/5Pl+TEgAAB5/wlQ (envelope-from ) for ; Thu, 20 Aug 2020 22:31:11 +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 0D42A94060F for ; Thu, 20 Aug 2020 22:31:11 +0000 (UTC) Received: from localhost ([::1]:41498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8t5R-0005z6-5B for larch@yhetil.org; Thu, 20 Aug 2020 18:31:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8t53-0005yw-JW for emacs-orgmode@gnu.org; Thu, 20 Aug 2020 18:30:45 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:47036) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k8t51-00059i-PC for emacs-orgmode@gnu.org; Thu, 20 Aug 2020 18:30:45 -0400 Received: by mail-pl1-x62f.google.com with SMTP id k13so1571090plk.13 for ; Thu, 20 Aug 2020 15:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=nFB9JjiVEmz50K0O6NLDw42TfNcQQRBZyDAs5dH9mIU=; b=hcV82Jl/ESIQ5IarCj7WS7z6aUH+wyhc1PAnz+1ZY59EeVSHE2LJ2gcDmqumBGtcFH 560n2dV0LNf86YmTUAOWx46wdoyKfxqrynEx+UQaAKG45o+8KKBnp/3/tbsTHjGPcU5C 3FIeCJOeGVoGLEjgDOUE7CEq1As3D14ko506vjQukVHD5cPzhmjeHG0v59okSTBS7JCX yZ8z2tO0fMhXJ2/9Gx7fLG2zj8/YnfZpx6SrRMQMGLSzu5tUbWT6YI2vqa0RFBdjHGqd 1g2KnYb86C/uEuTJtwf/vWXwSYMBGAup/uyJ3iIEAau/r5qK1uxJqYw4VEiSKqthfkII +lNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=nFB9JjiVEmz50K0O6NLDw42TfNcQQRBZyDAs5dH9mIU=; b=qC2MScKLWayCczRZAB+FoNkFwfBnEU3UgXiIRYuosj/JeTmyFlWQeutoTkDi92utG9 hB8NvTgXuvy8KUb6lNFVZozlK3gfddvTRUcjXJ8pV1y0PcqmXOAMoZ16y2NEtBvIySGH FTGmMJT7TUY4FNuNyM0UlG5a47c/cb1tUBswV9GGJ8fSwCdKovi8fke3U6WKhiQUR332 7VpTu1cJr6g9Zy3jnLztoKeZIlBPhrfrOdcOSwUTatwjtKBgM+pDim3tkkmur+6C6Q2U J6vOmFJBeM7ERY1gTsa5DNVuLtuewIvWGRx+TL23/JORSJjulkV8+9Eqmrk8DPr6Py5J cTVQ== X-Gm-Message-State: AOAM530ARNiaUmKZsGw/NzPzT2g6ZpDV2TI/qeP3d14wsfI2TN7wI3X9 0uuetk9Tt2M4UDRm6oK+ujw= X-Google-Smtp-Source: ABdhPJw3r4gMC806yPXEmPvOlgoXNRvxrSOywnOp7JjrPYffW/UOUgVFlytF9KB2rMZxDUIojlcswQ== X-Received: by 2002:a17:90a:8a87:: with SMTP id x7mr27256pjn.81.1597962641432; Thu, 20 Aug 2020 15:30:41 -0700 (PDT) Received: from localhost ([173.254.200.139]) by smtp.gmail.com with ESMTPSA id q18sm85873pfn.106.2020.08.20.15.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 15:30:39 -0700 (PDT) From: Ihor Radchenko To: No Wayman , 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: <87tuwxyou6.fsf@gmail.com> References: <87k0xt5fd6.fsf@gmail.com> <87tuwxyou6.fsf@gmail.com> Date: Fri, 21 Aug 2020 06:29:46 +0800 Message-ID: <87tuwx3q91.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=yantar92@gmail.com; helo=mail-pl1-x62f.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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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=hcV82Jl/; 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.21 X-TUID: eWV8He1YgBjW > 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 writes: > 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. > > 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