3

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.

3
  • Yes, set the :foreground of the applicable face to be the same color as the 'default :background.
    – lawlist
    Commented Jun 22, 2015 at 16:12
  • 1
    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
    Commented Jun 22, 2015 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. Commented Jun 22, 2015 at 16:55

1 Answer 1

5

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)
  (kill-all-local-variables)
  (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
      (list
       '(".*" 0
         (progn (add-text-properties (match-beginning 0) 
                                     (match-end 0) 
                                     '(invisible t))
                'bold))))

(add-to-list 'font-lock-extra-managed-props 'invisible)
1
  • 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). Commented Jun 22, 2015 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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