The following code will hide the "array[" and "]" parts using the
invisible text property. It is a different approach compared to using
compose-region, as suggested in the question.
(defun my-hide-array ()
(add-to-list 'font-lock-extra-managed-props 'invisible)
(1 '(face nil invisible t))
(2 '(face nil invisible t))))))
You can add this function to a suitable major mode hook.
compose-region would probably not be a good idea -- the replacement text would probably not be editable, so you would have to disable the font-lock rule from time to time to edit your source code.
Note that the function matched only simple cases, where the array is indexed by a simple variable or constant. If you would like to handle the case with complex expression (maybe even nested occurrences of
array), you would need to replace the regexp with an elisp function to do the match (using tools like
forward-sexp). It can either apply the
invisible text property itself or set up a "fake" match data structure and continue using the font-lock rule as is.