I'd like to create a way to toggle showing/hiding/changing text following a pattern in org-mode, but if it works generally, that's fine also.

A few examples of where this might be useful.

  • Hiding #+TITLE: and just leaving the actual title text in a larger font, or if there is no title text specified after the space, showing instead the text Insert Title Here:____. (the latter is an example of changing the text).
  • Hiding #OPTIONS:.* completely (would use other font changes to indicate heading).
  • Removing all headline *'s (simply having headlines in larger fonts), etc.
  • Highlighting text with a special character (e.g. @foo@ to highlight "foo").

Obviously, the underlying goal is to make a very clean org-mode environment for writing, but which you can easily toggle on and off to update the "metadata" and formatting info (perhaps just temporarily by entering shift-select-mode, but that's for another day!).

Based off of this answer: How to make my own org-mode text emphasis work again?, I am able to do some of this, but there isn't a clear way to toggle this on and off within a session without at least reloading org-mode (which loses lots of editor state). E.g.:

(defun org-add-my-extra-fonts ()
  (add-to-list 'org-font-lock-extra-keywords '("[^@\\w]\\(@\\)\\([^@\n\r\t]+\\)\\(@\\)[^@\\w]" (1 '(face irrelevant-face invisible t)) (2 'my-highlight-face t) (3 '(face irrelevant-face invisible t))) t))

(add-hook 'org-font-lock-set-keywords-hook #'org-add-my-extra-fonts)

So how can you bind this sort of behavior to a minor-mode in a way that plays nice with org? (assuming it's possible)

EDIT: I am not asking for how to do any of these individual things. I'm giving examples of where it is useful. I am asking for how to do the general thing of creating invisible/modified text in a way that can be toggled on and off. The ways I know how do this, as shown above, cannot be toggled. I provided the code above as a starting point, since that was where I got stuck (it doesn't appear toggle-able), and it might useful for those trying to help.

It's possible that org-font-lock-set-keywords-hook can somehow be toggled within a session without reloading org or other side effects, and would address all of these scenarios, in which case, showing how to do that would be a great answer!

  • Most of you're asking for is scattered here and there among themes, modules, and multiple blog posts related to beautifiying org-mode. The main question probably can be addressed with overlays and the techniques which org-bullets uses. Apart those pointers, I cannot help much. – Muihlinn Jun 8 '20 at 9:16
  • You say "showing/hiding/changing" but AFAICT you say nothing about "changing" text. Please either specify what you mean or remove "changing". And please explain how the usual Org showing/hiding does not do what you want. IOW, more specifics please, about what you're looking for. Thx. – Drew Jun 8 '20 at 14:36
  • @Muihlinn, I edited the question with a clarification that hopefully helps? I can also try to look at the source of org-bullets, but my elisp is still not super solid. I've looked at many such posts and tried to adopt some, but none that I've seen have directly addressed this issue. (toggleability within a session) – avv Jun 9 '20 at 1:06
  • @Drew, I added an edit (first bullet) which hopefully clarifies? – avv Jun 9 '20 at 1:07
  • 1
    You can hide keywords. See here. – jagrg Jun 10 '20 at 21:45

Your Answer

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

Browse other questions tagged or ask your own question.