emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Eduardo Suarez-Santana <esuarez@itccanarias.org>
Cc: emacs-orgmode@gnu.org
Subject: [PATCH] Re: Escaping org mode date properties
Date: Sun, 02 Jan 2022 10:51:54 +0800	[thread overview]
Message-ID: <8735m626k5.fsf@localhost> (raw)
In-Reply-To: <20220101200103.GB29829@itccanarias.org>

[-- Attachment #1: Type: text/plain, Size: 1379 bytes --]

Eduardo Suarez-Santana <esuarez@itccanarias.org> writes:

>> I am unable to reproduce. What are your Org and Emacs versions?
>
> I'm using Spacemacs (develop branch).
>
> - Emacs 27.2
> - Org 9.5.1
>
> I get a weird behaviour about it. These events appear when I start emacs. If I
> edit somehow these entries they disappear from the agenda view (until I start
> emacs again).

Confirmed

Thanks for the hint! I was able to reproduce entries disappearing from
agenda view.

The culprit is org-in-src-block-p. It relies on fontification to
determine if we are inside a code block. However, when you strip a code
block with SCHEDULED inside from begin/end lines, the fontification
properties do not get removed.

The attached patch should fix the issue. However, I need several people
to test it first - the patch will make things slower without cache.

>> Depending what you want, you may use org-agenda-todo-list-sublevels or
>> add agenda filter excluding specific tags that you can then use to mark
>> undesired subtrees.
>
> Could be a workaround. Thanks a lot.
>
> Anyway it looks like a bug to me.

For future. You will make things much easier if you provide a clear
sequence of steps to reproduce the problem. Your original report is not
reproducible if I just copy-paste your code into a new org file. I had
to guess what you did in order to see the problem.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-in-src-block-p-Do-not-rely-on-fontification.patch --]
[-- Type: text/x-diff, Size: 2088 bytes --]

From 0f046ebe94bbe84ac2f167feda527022bfac4e6e Mon Sep 17 00:00:00 2001
Message-Id: <0f046ebe94bbe84ac2f167feda527022bfac4e6e.1641091542.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sun, 2 Jan 2022 10:30:03 +0800
Subject: [PATCH] org-in-src-block-p: Do not rely on fontification

* lisp/org.el (org-in-src-block-p): New optional argument ELEMENT.
The code now relies on org-element API to check if we are inside
src-block.

Fixes https://list.orgmode.org/20220101200103.GB29829@itccanarias.org/T/#t
---
 lisp/org.el | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 8c09a057c..7ea8d65f3 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18731,17 +18731,19 @@ (defun org-uuidgen-p (s)
   "Is S an ID created by UUIDGEN?"
   (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
 
-(defun org-in-src-block-p (&optional inside)
+(defun org-in-src-block-p (&optional inside element)
   "Whether point is in a code source block.
 When INSIDE is non-nil, don't consider we are within a source
-block when point is at #+BEGIN_SRC or #+END_SRC."
-  (let ((case-fold-search t))
-    (or (and (eq (get-char-property (point) 'src-block) t))
-	(and (not inside)
-	     (save-match-data
-	       (save-excursion
-		 (beginning-of-line)
-		 (looking-at ".*#\\+\\(begin\\|end\\)_src")))))))
+block when point is at #+BEGIN_SRC or #+END_SRC.
+When ELEMENT is provided, it is considered to be element at point."
+  (save-match-data (setq element (or element (org-element-at-point))))
+  (when (eq 'src-block (org-element-type element))
+    (or (not inside)
+        (not (or (= (line-beginning-position)
+                  (org-element-property :post-affiliated element))
+               (= (1+ (line-end-position))
+                  (- (org-element-property :end element)
+                     (org-element-property :post-blank element))))))))
 
 (defun org-context ()
   "Return a list of contexts of the current cursor position.
-- 
2.34.1


  reply	other threads:[~2022-01-02  2:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-01 12:24 Escaping org mode date properties Eduardo Suarez
2022-01-01 15:10 ` Ihor Radchenko
2022-01-01 20:01   ` Eduardo Suarez-Santana
2022-01-02  2:51     ` Ihor Radchenko [this message]
2022-01-02 21:04       ` [PATCH] " Eduardo Suarez-Santana
2022-01-03  3:39         ` Ihor Radchenko
2022-01-03 10:39           ` Eduardo Suarez-Santana
2022-01-12 13:14             ` Ihor Radchenko

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=8735m626k5.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=esuarez@itccanarias.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).