[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: Alexander Shukaev
Subject: Re: Apply Emacs-Lisp `font-lock' rules to a string
Date: Mon, 24 Aug 2015 22:29:50 +0200

> This seems to work here:
> (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)


>> To expand on the problem, I have a string which contains regular
>> expression, which I display in the echo area.  It would be nice to
>> apply standard highlighting to it.  Is there any way to achieve this
>> smoothly (preferably with one or a few calls to built-in functions)?
>> Thanks.
> 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.

reply via email to

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