From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: XKCD/541 compliance, anyone? Date: Sun, 15 Mar 2015 02:40:47 +0100 Message-ID: <871tkrghr4.fsf@wmi.amu.edu.pl> References: <8761drazec.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1426383682 11570 80.91.229.3 (15 Mar 2015 01:41:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 15 Mar 2015 01:41:22 +0000 (UTC) To: Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 15 02:41:14 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 1YWxYH-0005ET-79 for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Mar 2015 02:41:13 +0100 Original-Received: from localhost ([::1]:42262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWxYF-0000VU-NT for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Mar 2015 21:41:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWxY3-0000VH-MW for help-gnu-emacs@gnu.org; Sat, 14 Mar 2015 21:41:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YWxY0-0002Yy-EO for help-gnu-emacs@gnu.org; Sat, 14 Mar 2015 21:40:59 -0400 Original-Received: from msg.wmi.amu.edu.pl ([2001:808:114:2::50]:54559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWxY0-0002YL-37 for help-gnu-emacs@gnu.org; Sat, 14 Mar 2015 21:40:56 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by msg.wmi.amu.edu.pl (Postfix) with ESMTP id CCC1C5A744 for ; Sun, 15 Mar 2015 02:40:52 +0100 (CET) Original-Received: from msg.wmi.amu.edu.pl ([127.0.0.1]) by localhost (msg.wmi.amu.edu.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cD4LQjVYzLh6 for ; Sun, 15 Mar 2015 02:40:52 +0100 (CET) Original-Received: from localhost (117-116.echostar.pl [213.156.117.116]) by msg.wmi.amu.edu.pl (Postfix) with ESMTPSA id 30CA55A740 for ; Sun, 15 Mar 2015 02:40:52 +0100 (CET) In-reply-to: <8761drazec.fsf@wmi.amu.edu.pl> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:808:114:2::50 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:103168 Archived-At: Hi all, so finally I sat down and finished my smiley code. I have still three questions left, though. But first =E2=80=93 the (deceptively simple) cod= e. --8<---------------cut here---------------start------------->8--- (defvar smiley-regex "[:;>B][,']?-?[][()]" "This regex should match smileys, and only them.") (defface smiley '((t :foreground "gray")) "Face for displaying smileys.") (setq parse-sexp-lookup-properties t) (add-to-list 'font-lock-extra-managed-props 'syntax-table) (defconst smiley-props `(face smiley syntax-table ,(string-to-syntax ".")= )) (define-minor-mode xkcd-541-mode "Toggle XKCD/541 mode. In this mode, smileys (as defined by smiley-regex) are treated as punctuation by Emacs movement commands etc. In particular, parens in smileys are skipped by paren-matching commands." :lighter " :)" (if xkcd-541-mode (font-lock-add-keywords nil `((,smiley-regex . smiley-props))) (font-lock-remove-keywords nil `((,smiley-regex . smiley-props))))) --8<---------------cut here---------------end--------------->8--- And now the questions. 1. In this post: http://lists.gnu.org/archive/html/help-gnu-emacs/2015-01/msg00005.html I noticed that syntax-propertize makes parse-sexp-lookup-properties buffer-local. OTOH, in the next post (http://lists.gnu.org/archive/html/help-gnu-emacs/2015-01/msg00008.html), Stefan Monnier confirmed my suspicion that the performance hit from setting it globally to t is negligible. Since I ended up not using syntax-propertize =E2=80=93 I think font-lock is better, especially that = I also want my smileys to be greyed out =E2=80=93 I have to set parse-sexp-lookup-properties manually. Should I do it in my mode toggle function, remembering the previous value and resetting it after disabling the mode? (More or less the same question concerns font-lock-extra-managed-props.) 2. After enabling xkcd-541-mode, I have ,---- | (t | (("[:;>B][,']?-?[][()]" . smiley-props)) | ("[:;>B][,']?-?[][()]" | (0 smiley-props))) `---- as the value of font-lock-keywords. Why does that look that strange? Moreover, after /disabling/ the mode, the value of font-lock-keywords is (t nil). Strange, isn=E2=80=99t it? Shouldn=E2=80=99t it be just nil? 3. The mode works =E2=80=93 sort of, since there is one (a bit annoying) = thing. When I turn it on, and type this: (hello world;-)) sometimes the opening paren is highlighted when typing the smiley (this happens e.g. in emacs -Q after loading that mode), and sometimes not (e.g. while I=E2=80=99m writing this message). Why might that be so? Best, Marcin On 2014-12-04, at 22:16, Marcin Borkowski wrote: > Hi there, > > it is so frustrating to be unable to use paren matching (like in > show-paren mode, or C-M-f & friends) when I use smileys. And this > *does* happen; comments in, say, elisp-mode seem to be safe, but in > LaTeX smileys do break my workflow. Try entering this in AUCTeX: > > \textbf{Hello :-)} > > then put the point at the EOL and press C-M-b. > > I have a dream: to have the s-exp functions ignore closing parens, > brackets etc. /after/, say, things matching > > [;:B]-? > > (this regex should probably cover the most basic cases). > > AFAIK, these functions are deeply hardcoded in Emacs; its behavior here > seems to be inborn and instinctive rather than learned and reflective, > so to speak. (I.e., it is based on the `scan-sexp' function, which is > written in C rather than Elisp.) I imagine that redefining scan-sexp i= n > Elisp is possible, but there might be problems with performance. > > Did anyone try that? Am I the only one with this problem, actually? --=20 Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University