Is there a straightforward way to make all text with a given face invisible? I don't believe I can make invisibility be intrinsic to the face, but can I perhaps specify a minor mode that makes sure all appropriate text is invisible?

By "invisible" here I mean the text works as if you'd set the invisible property, so the text in question doesn't even take up an horizontal space.

  • Yes, set the :foreground of the applicable face to be the same color as the 'default :background. – lawlist Jun 22 '15 at 16:12
  • Thanks @lawlist, but I mean invisible in the Emacs sense, in which the text in question doesn't even take up any space on the screen. I'll edit the question to clarify. – kuzzooroo Jun 22 '15 at 16:21
  • 1
    You can write font-lock rules to apply any property, including :invisible. Instead of a plain face name, you can use a code block, which should return the name of the face to apply. This code block can contain side effects, like (set-property ...). Also, you will need to include :invisible in font-lock-extra-managed-props. – Lindydancer Jun 22 '15 at 16:55

OK, here's a simple demonstration of @Lindydancer's technique, which in this case turns the whole buffer invisible.

(defun my-mode () "my-mode" (interactive)
  (make-local-variable 'font-lock-defaults)
  (setq font-lock-defaults  '(my-mode-font-lock-keywords t)))

(defvar my-mode-font-lock-keywords nil 
  "Keywords/Regexp for fontlocking of my-mode")

(setq my-mode-font-lock-keywords
       '(".*" 0
         (progn (add-text-properties (match-beginning 0) 
                                     (match-end 0) 
                                     '(invisible t))

(add-to-list 'font-lock-extra-managed-props 'invisible)
  • Spot on! Yes, it should be 'invisible since that is the property Emacs use to hide text. the :xxx form is used to specify face properties (I got them mixed up). – Lindydancer Jun 22 '15 at 20:17

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.