From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: Apply Emacs-Lisp `font-lock' rules to a string Date: Mon, 24 Aug 2015 13:39:05 -0700 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 1440448782 15714 80.91.229.3 (24 Aug 2015 20:39:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 24 Aug 2015 20:39:42 +0000 (UTC) Cc: Alexander Shukaev To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 24 22:39:41 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 1ZTyWr-0001IP-GS for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 22:39:41 +0200 Original-Received: from localhost ([::1]:56682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyWq-0000X7-WC for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 16:39:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyWc-0000Vi-AJ for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:39:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTyWb-0004C4-Ee for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:39:26 -0400 Original-Received: from mail-ob0-x235.google.com ([2607:f8b0:4003:c01::235]:33032) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyWb-0004Bc-A5 for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:39:25 -0400 Original-Received: by obbhe7 with SMTP id he7so124516087obb.0 for ; Mon, 24 Aug 2015 13:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Gfv7E919ZAhdj2sODUfJXaAwt/D4BvRRlQ2gxRIRpIE=; b=WZDSToMZ4o/ypU7uOFmcurrVmjz23SM9mVwbNF/DU4iaIE+iN9MB3n4KvJVGQzfb6k K2Mx7eylVPH+hyADtzM19a1iSpxevN7q+TV7xuIbYsfhidv14tB7rqy1rpFxrPLu397C hP6jN7xtZ8bqPlhv9WOzguUL++5RIxrIMpMoMSTJAF/338PRcgbEiB5bQiPfgLLYr5yy NmtQAR8fpcTFoXEFpvJoQnLKT+IiuGiBoSGml5gi4HcVemX2uNVY1FVrlt432nfoXlF1 B2gBow0xe5WX2cop3HnWuSjLay+WryLaSnvclFlgHuy7RULc7gpfW4jqvM2FfnK498OY MCNQ== X-Received: by 10.60.98.211 with SMTP id ek19mr22544174oeb.78.1440448764767; Mon, 24 Aug 2015 13:39:24 -0700 (PDT) Original-Received: by 10.76.168.70 with HTTP; Mon, 24 Aug 2015 13:39:05 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::235 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:106818 Archived-At: >> (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: (minibuffer-message (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. -- john