2

In emacs I can replace function ( with #( in javascript with the following.

(font-lock-add-keywords
 'js2-mode `(("\\(function *\\)(" ;; \\(function *\\
              (0 (progn (compose-region (match-beginning 1) (match-end 1) "#") ;;ƒ
                        nil)))))

It's neat. But how would go about making the replacement # ( or something like fn (.

I've tried hacking away at this to understand it... but not yet.

Ross
  • 14,266
  • 12
  • 60
  • 91
  • Are you perhaps interested in folding what's there and placing an overlay instead? Font-lock is not going to hide and replace. Or, do you want to permanently replace the text within the file. – lawlist Nov 26 '14 at 17:35
  • I don't want to permanently change the text in the file. Just how it is rendering to the buffer. The above example is great... but it only replaces the found text with a single character. It would be great to replace it with more than one char. – Ross Nov 26 '14 at 17:46
  • The folding and overlay sounds good. _Away to google..._ – Ross Nov 26 '14 at 17:47
  • It looks like I may have spoken too soon -- here is a link to an example of using `compose-region`: http://stackoverflow.com/a/4513933/2112489 So, it appears there are more than one way to handle this type of issue. – lawlist Nov 26 '14 at 18:06
  • Yeah. The linked example similarly replaces all the php content with a single character... – Ross Nov 26 '14 at 18:18

0 Answers0