From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexander Shukaev Newsgroups: gmane.emacs.help Subject: Re: Apply Emacs-Lisp `font-lock' rules to a string Date: Mon, 24 Aug 2015 22:29:50 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1440448209 6829 80.91.229.3 (24 Aug 2015 20:30:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 24 Aug 2015 20:30:09 +0000 (UTC) Cc: help-gnu-emacs To: John Mastro Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 24 22:30:08 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZTyNX-0002jx-LU for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 22:30:03 +0200 Original-Received: from localhost ([::1]:56637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyNW-00082V-VG for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 16:30:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyNM-00082P-Dd for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:29:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTyNL-0008H5-Hg for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:29:52 -0400 Original-Received: from mail-la0-x231.google.com ([2a00:1450:4010:c03::231]:35037) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyNL-0008G7-90 for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:29:51 -0400 Original-Received: by labgv11 with SMTP id gv11so17511095lab.2 for ; Mon, 24 Aug 2015 13:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=JQAtYw29HAko8klKqFNDki4HSZzR6N/kx7+JYLBol4k=; b=Tm/ZNQi9DWhI0Zo8u7QW35o4K+MuBOyzHHcMhv+SuEw3yRsugDkD53XiQOZKmMJcd4 AZDkM/XFrxz9NTIN3H409TBPfVclfneSAj18VO2QVjp7ulZ0kbUBats9fGQ+ENPHvGle rlZjzMQvst+WM3zZUUuzXs3vrgWY6aIUoK8n0IyLBEbOaUA0keACH49o+vQKw5q4sAev Vine11kTHj4WhkhZrmfa93q4Bf2Plv1iQmQXP+y4jmvTp8svxvw1U3U0OH+q6rEgtUBN eeZBBtxwj1kC3gDqbbXSxUY1qTFAQJpLX2bJ5KNFkjvD4AGLK9drcxJir6Ak214SKXF0 yswQ== X-Received: by 10.152.18.164 with SMTP id x4mr17793392lad.35.1440448190164; Mon, 24 Aug 2015 13:29:50 -0700 (PDT) Original-Received: by 10.112.34.17 with HTTP; Mon, 24 Aug 2015 13:29:50 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::231 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106817 Archived-At: > 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) Nice! >> 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.