[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apply Emacs-Lisp `font-lock' rules to a string

From: John Mastro
Subject: Re: Apply Emacs-Lisp `font-lock' rules to a string
Date: Mon, 24 Aug 2015 13:39:05 -0700

>> (defun my-font-lock-string (string &optional mode)
>>   (let ((mode (or mode major-mode)))
>>     (with-temp-buffer
>>       (insert string)
>>       (funcall mode)
>>       (funcall font-lock-fontify-buffer-function)
>>       (buffer-string))))
>> (my-font-lock-string "\"\\\\(1\\\\|2\\\\)\"" #'emacs-lisp-mode)
>> Hm, maybe not. When I do (message (my-font-lock-string ...)) it prints
>> the string readably rather than colorized. Hopefully someone else will
>> know how to get around that.
> There surely must be one as I see that when cursor hovers different
> structures of Emacs Lisp code, echo area displays short summary of the
> corresponding structures, and that summary is obviously highlighted
> according to `font-lock' rules.

I may have found it. Try this:

 (my-font-lock-string #'emacs-lisp-mode "\"\\\\(1\\\\|2\\\\)\""))

Appears to work as intended, though hopefully someone will still
comment on whether it's the best way to do it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]