Let's say I have an org file with this content (this is the Org Manual):

    *** System-wide header arguments
    #+vindex: org-babel-default-header-args

The file is opened normally, highlighted and everything.

Now, as a test I try to add a display property to the S character of System:

    (put-text-property (point) (1+ (point)) 'display "aaa")

It works. The S is replaced with aaa.

But if I try the same on a character on the vindex line then nothing happens.

Why is that?

  • 1
    Even if it is not obvious at the first glance. This question is directly related to Orgmode. – Tobias Mar 22 at 16:30

The text property is removed by font-lock in org-mode buffers.

The list org-font-lock-extra-keywords contains the function org-fontify-meta-lines-and-blocks as a matcher of a font lock keyword for meta lines, i.e., lines starting with #+ followed by a keyword.

That function calls org-fontify-meta-lines-and-blocks-1 which has the following lines for lines matching #+ at the beginning:

(t ;; just any other in-buffer setting, but not indented
      (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
      (remove-text-properties (match-beginning 0) (match-end 0)
                  '(display t invisible t intangible t))
      (add-text-properties beg (match-end 0)
                   '(font-lock-fontified t face org-meta-line))

One of the text properties removed there is the display property.

| improve this answer | |
  • 1
    Thanks. It's a bit strange org removes properties, because it prevents other packages, minor modes from modifying the org buffer's appearance. Org should only deal with adding its own stuff and not touching anything else. – Tom Mar 22 at 16:46
  • @Tom: A priori, I agree. Perhaps there is some special consideration that led to this exceptional behavior. If no one speaks to that here then you might want to ask about it on an Org mailing list. – Drew Mar 22 at 17:03

This complements the answer given by @Tobias, where it is explained how org-mode removes the display property.

One way to get around this is to use the variable char-property-alias-alist. It is used by Emacs to make one property to behave like another property. If you add (display my-display) to this list, you can set the property my-display on text and it would not be removed by org-mode.

The following is from the built-in documentation:

Alist of alternative properties for properties without a value. Each element should look like (PROPERTY ALTERNATIVE1 ALTERNATIVE2...). If a piece of text has no direct value for a particular property, then this alist is consulted. If that property appears in the alist, then the first non-nil value from the associated alternative properties is returned.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.