From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id yHpRLwjxlGXpawAAkFu2QA (envelope-from ) for ; Wed, 03 Jan 2024 06:30:48 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 6OocKQjxlGVZJQAA62LTzQ (envelope-from ) for ; Wed, 03 Jan 2024 06:30:48 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1704259848; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=zpRKRT+j4FP+qvbP9dNxMlF5M2sAaTTAApahARU3dPw=; b=NySPiGQqMqVGRNZAlRigGOvCT2DM9GFjdhl/u0Bwes+6Te8lQRcMb8QLLxeF88JrYIu02y 9bVzk9I/QXhg9PegKKa9WYmbujveolK82n7QqdhOAc0RvEzmcvO5Y/zfiASMlbJIf4tEJz iQIRy6ZAtxlsXhhCULPyzmphvhW+18bbgBQLyuwEbJZ3YkrHtqsCHBMxJ/K3pVghXNu7t6 Di+JBjt5wnM6W8/xuA7pXgV9uDO+GVwk49USrkhKzP2Q6Md/Hn0aIXmZqk7HjJnYPHr9pv g7BsP/dKqRBk9U5zt6PR3nZOwpxg3iCCSKgN55uw9yNq36DDgAc8ufbbDVDKrA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1704259848; a=rsa-sha256; cv=none; b=kq69ybQnomyoQ3EZMLQTOdKt5EiI7qzg1YjuZ44uAQdW16jTtMCcS3F72wTvQKOmfHwV9a N7sKZOBNN36wv4KxxFJphu0Jr50dV4cwxfEnBO2DICXgpxdHH9FmaYpDVzG92MvdtXD4in SN2sb+G0fTzvmUvcZQdukfDMnEl/AKbh5CnjhQJHm5LK0isVN/yz6UuaC0BSdklg980y4X z8J8COHDyaxhiK3C8uqkDC/x3xB+ewuBjoogPF8ei19Fdvbzqz1CXoQaLTkl42z93HyVBZ RM4Pul8yoS+zOzuHisOu0XEANk7VyDZ9RhYyHhOp+178Vt92NuuIJ66Ggqq0SA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none 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 0C8E03A734 for ; Wed, 3 Jan 2024 06:30:48 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rKtpO-0002Ji-5x; Wed, 03 Jan 2024 00:30:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rKtpM-0002JA-3P for emacs-orgmode@gnu.org; Wed, 03 Jan 2024 00:30:04 -0500 Received: from smtpout1.mo11.mail-out.ovh.ca ([51.161.45.253]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rKtpJ-0007Xg-Gn for emacs-orgmode@gnu.org; Wed, 03 Jan 2024 00:30:03 -0500 Received: from mxplan1.mail.ovh.ca (unknown [10.111.58.210]) by mo11.mail-out.ovh.ca (Postfix) with ESMTPS id D4F512010A2 for ; Wed, 3 Jan 2024 01:29:51 -0400 (AST) Received: from rodrigomorales.site (54.39.251.57) by DAG2EX1.mxpca1.local (172.16.2.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 3 Jan 2024 00:29:50 -0500 X-OVh-ClientIp: 181.65.25.226 From: Rodrigo Morales To: Subject: Re: Elisp function to get the upcoming event with the closest scheduled date In-Reply-To: <355194690966e37531b8643292fe2b86@rodrigomorales.site> References: <355194690966e37531b8643292fe2b86@rodrigomorales.site> Date: Wed, 3 Jan 2024 00:29:49 -0500 Message-ID: <87sf3f56ia.fsf@rodrigomorales.site> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [54.39.251.57] X-ClientProxiedBy: DAG2EX1.mxpca1.local (172.16.2.11) To DAG2EX1.mxpca1.local (172.16.2.11) X-Ovh-Tracer-GUID: 40171f31-c753-426e-b302-c894e574ea07 X-Ovh-Tracer-Id: 17352087889399782935 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrvdeggedgkeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvffujghffffkgggtihesthdtredttddttdenucfhrhhomheptfhoughrihhgohcuofhorhgrlhgvshcuoehmvgesrhhoughrihhgohhmohhrrghlvghsrdhsihhtvgeqnecuggftrfgrthhtvghrnhephedvtdejudetgeeiuddvfeekvdffueeffeffvefgvdekgefhiedvudeggeejfeetnecuffhomhgrihhnpeifihhkihhmvgguihgrrdhorhhgnecukfhppeduvdejrddtrddtrddupdehgedrfeelrddvhedurdehjedpudekuddrieehrddvhedrvddvieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehmvgesrhhoughrihhgohhmohhrrghlvghsrdhsihhtvgeqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepvghmrggtshdqohhrghhmohguvgesghhnuhdrohhrghdpoffvtefjohhsthepmhhouddupdhmohguvgepshhmthhpohhuth Received-SPF: pass client-ip=51.161.45.253; envelope-from=me@rodrigomorales.site; helo=smtpout1.mo11.mail-out.ovh.ca X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, FROM_FMBLA_NEWDOM28=0.798, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, WIKI_IMG=1.898 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.26 X-Spam-Score: -6.26 X-Migadu-Queue-Id: 0C8E03A734 X-Migadu-Scanner: mx11.migadu.com X-TUID: d4Hyi6WtOLOG Rodrigo Morales writes: I managed to show the entry with the nearest upcoming scheduled date in the tab bar with the following utilities (see code block below). Here's an screenshot: https://upload.wikimedia.org/wikipedia/commons/f/f3/Show_information_of_Org_Agenda_in_tab-bar.png Here are some notes of the code: + The function my/org-agenda-nearest-upcoming-scheduled-search performs linear search through all headings in all files listed in org-agenda-files in order to search the entry with the nearest upcoming scheduled date. + The variable my/org-agenda-nearest-upcoming-scheduled stores the information of the event. + I added my/org-agenda-nearest-upcoming-scheduled-display to tab-bar-format in order to display the information that I requested. Because my/org-agenda-nearest-upcoming-scheduled-search uses linear search it is a rather expensive operation if there are many entries to look up. I haven't decided yet when this functino should be called so that it is called the fewer amount of times and it actually shows th entry with the nearest upcoming scheduled date. It is necessary that it is called in the proper times so that the my/org-agenda-nearest-upcoming-scheduled is updated accordingly when setting the scheduled date for new entries. #+BEGIN_SRC elisp (defvar my/org-agenda-nearest-upcoming-scheduled nil "Store entry with the nearest upcoming scheduled date. The value should store a CONS CELL whose CAR is the title of the entry and the CDR is the date of the entry.") (defun my/org-agenda-nearest-upcoming-scheduled-search () "Set the value for variable that store the entry with the nearest upcoming scheduled date." (let (nearest-entry ;; Store the scheduled date in seconds of the current entry. entry-scheduled (current-time (float-time))) ;; Iterate through all files in `org-agenda-files' (dolist (file org-agenda-files) (with-current-buffer (find-file-noselect file) ;; Iterate through all headings (org-map-entries (lambda () (when (and ;; Check the current entry has SCHEDULED (setq entry-scheduled (org-entry-get nil "SCHEDULED")) ;; If the currenty entry has SCHEDULED, we proceed ;; to convert it to seconds using org-2ft. We cannot ;; write org-entry-get and org-2ft in the same ;; expression because it is possible that ;; org-entry-get returns nil and org-2ft returns 0 ;; when nil is passed, so we won't be checking that ;; the entry has SCHEDULED. (setq entry-scheduled (org-2ft entry-scheduled)) ;; Check time of the entry is greater than the current time (> entry-scheduled current-time)) ;; If there's no nearest entry yet, then store the ;; current entry as the nearest entry. ;; ;; We use an if conditional because for plist-put to ;; work, it is needed that the property list is not nil. (if (null nearest-entry) (setq nearest-entry `(:item ,(org-entry-get nil "ITEM") :scheduled ,entry-scheduled :scheduled-string ,(org-entry-get nil "SCHEDULED") :marker ,(point-marker))) ;; If a nearest entry has been found previously, ;; compare their scheduled time. (when (> (plist-get nearest-entry :scheduled) entry-scheduled) (plist-put nearest-entry :item (org-entry-get nil "ITEM")) (plist-put nearest-entry :scheduled entry-scheduled) (plist-put nearest-entry :scheduled-string (org-entry-get nil "SCHEDULED")) (plist-put nearest-entry :marker (point-marker))))))))) (setq my/org-agenda-nearest-upcoming-scheduled nearest-entry) (unless nearest-entry (error "No event with scheduled date than the current date was found.")))) (defun my/org-agenda-nearest-upcoming-scheduled-display () (if my/org-agenda-nearest-upcoming-scheduled (progn ;; If the previously found entry has an scheduled date that has ;; already passed, let's search for a new upcoming scheduled. (when (< (plist-get my/org-agenda-nearest-upcoming-scheduled :scheduled) (float-time)) (my/org-agenda-nearest-upcoming-scheduled-search)) (let* ((time-difference (truncate (- (plist-get my/org-agenda-nearest-upcoming-scheduled :scheduled) (float-time)))) (days (/ time-difference 86400)) (hours (/ (% time-difference 86400) 3600)) (minutes (/ (% time-difference 3600) 60))) ;; TODO: The following is a list of menu items. I still ;; don't know the meaning of the first item in the menu item ;; definition, so I've written foo. `((foo menu-item ,(propertize (concat (plist-get my/org-agenda-nearest-upcoming-scheduled :item) " | " (string-join (delq nil (funcall 'append (unless (eq days 0) (list (number-to-string days) "days")) (unless (eq hours 0) (list (number-to-string hours) "hours")) (unless (eq minutes 0) (list (number-to-string minutes) "minutes")))) " ")) 'face `(:background ,(face-attribute 'default :background) :foreground ,(face-attribute 'default :foreground) :box (:line-width (1 . 1) :color ,(face-attribute 'default :foreground)))) my/org-agenda-nearest-upcoming-scheduled-jump :help (plist-get my/org-agenda-nearest-upcoming-scheduled :scheduled-string))))) `((foo menu-item ,(propertize "No entry found" 'face `(:background ,(face-attribute 'default :background) :foreground ,(face-attribute 'default :foreground) :box (:line-width (1 . 1) :color ,(face-attribute 'default :foreground)))) ignore :help "No entry with the nearest upcoming scheduled date found.")))) (defun my/org-agenda-nearest-upcoming-scheduled-jump () (interactive) (with-current-buffer (switch-to-buffer (marker-buffer (plist-get my/org-agenda-nearest-upcoming-scheduled :marker))) (goto-char (plist-get my/org-agenda-nearest-upcoming-scheduled :marker)))) #+END_SRC