all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marcin Borkowski <mbork@wmi.amu.edu.pl>
To: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: XKCD/541 compliance, anyone?
Date: Sun, 15 Mar 2015 02:40:47 +0100	[thread overview]
Message-ID: <871tkrghr4.fsf@wmi.amu.edu.pl> (raw)
In-Reply-To: <8761drazec.fsf@wmi.amu.edu.pl>

Hi all,

so finally I sat down and finished my smiley code.  I have still three
questions left, though.  But first – the (deceptively simple) code.

--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 – I think font-lock is better, especially that I also
want my smileys to be greyed out – 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’t it?  Shouldn’t it be just nil?

3. The mode works – 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’m writing this message).  Why might that be so?

Best,
Marcin




On 2014-12-04, at 22:16, Marcin Borkowski <mbork@wmi.amu.edu.pl> 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 in
> Elisp is possible, but there might be problems with performance.
>
> Did anyone try that?  Am I the only one with this problem, actually?


-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



  parent reply	other threads:[~2015-03-15  1:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-04 21:16 XKCD/541 compliance, anyone? Marcin Borkowski
2014-12-04 22:34 ` Stefan Monnier
2014-12-04 23:10   ` Marcin Borkowski
2014-12-05 22:33   ` Marcin Borkowski
2014-12-05 23:41     ` Artur Malabarba
2014-12-05 23:48       ` Marcin Borkowski
2014-12-31  9:19   ` Marcin Borkowski
2015-01-01 17:07     ` Stefan Monnier
2015-01-01 21:41       ` Marcin Borkowski
2015-01-02  4:07         ` Stefan Monnier
2015-01-02 10:09           ` Marcin Borkowski
2015-01-03  1:47             ` Stefan Monnier
2015-01-07 21:55               ` Marcin Borkowski
2015-01-02 14:39       ` Marcin Borkowski
2015-01-03  1:49         ` Stefan Monnier
2015-01-07 22:09       ` Marcin Borkowski
2015-01-07 22:37         ` Stefan Monnier
2015-01-08  1:09           ` Marcin Borkowski
2015-01-08  1:49             ` Stefan Monnier
2015-01-08  2:37               ` Marcin Borkowski
     [not found]               ` <mailman.17449.1420684651.1147.help-gnu-emacs@gnu.org>
2015-01-08  3:11                 ` Stefan Monnier
2015-01-08 14:10                   ` Marcin Borkowski
2015-03-15  1:40 ` Marcin Borkowski [this message]
2015-03-15 18:39   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871tkrghr4.fsf@wmi.amu.edu.pl \
    --to=mbork@wmi.amu.edu.pl \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.