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:23:43 -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 1440447867 968 80.91.229.3 (24 Aug 2015 20:24:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 24 Aug 2015 20:24:27 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 24 22:24:27 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 1ZTyHy-0006x5-0z for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 22:24:18 +0200 Original-Received: from localhost ([::1]:56604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyHx-00039P-Gs for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 16:24:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyHm-000397-70 for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:24:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTyHl-0004bh-Be for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:24:06 -0400 Original-Received: from mail-oi0-x22f.google.com ([2607:f8b0:4003:c06::22f]:33356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTyHl-0004bb-47 for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 16:24:05 -0400 Original-Received: by oieu205 with SMTP id u205so17645484oie.0 for ; Mon, 24 Aug 2015 13:24:04 -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 :content-type; bh=bxOYdsq+m65CYdz3nNDGhobiYNAzwVGT8vnP3yaNhYw=; b=DQflgF4g9tpusq6NlZ1+X2C86LUXq/Wokb3+tQqowNTgmVbYYJ7xfVdtyR1x2fSXbC o2FpmpOUIaMNW2cfGUvR7wEmuE58zRkwjh1xxWwee0FKSc4MJXGxmrbQKHRujSKOOEq/ DUhVW9TLqNt7jIF6z/2ej5Gkl4X8ItXyIKVjdIc8qihNAcBn7djAJM3Lof3eUrPBqd1v 3SnHyf/HyQqM8kFUp9nWcrh/cD6AiW3bFz+uaK5v1VyzpFKpKgu1HoUzua2pCE/HbJ3T yonk0NHv5ZOBqiqwfLaPCBwgISi1v74oZ3KDgHHdRxjmtjcc2bZc9lWlQofGz5KFoPZf 5yyQ== X-Received: by 10.202.77.207 with SMTP id a198mr6405415oib.94.1440447844662; Mon, 24 Aug 2015 13:24:04 -0700 (PDT) Original-Received: by 10.76.168.70 with HTTP; Mon, 24 Aug 2015 13:23:43 -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:c06::22f 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:106815 Archived-At: > Assume I have a string somewhere in Emacs-Lisp program. I want this > string to be propertized in such a way that when I display this string > somewhere, it should have identical highlighting as if it would have > been typed in Emacs-Lisp major mode (with `font-lock'). 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. -- john