all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, David Kastrup <dak@gnu.org>,
	emacs-devel@gnu.org
Subject: Re: port x-symbol to GNU emacs 24.
Date: Wed, 19 Aug 2015 14:33:43 +0200	[thread overview]
Message-ID: <87oai34fvc.fsf@gnu.org> (raw)
In-Reply-To: <87r3mz91h2.fsf@gnu.org> (Tassilo Horn's message of "Wed, 19 Aug 2015 09:33:29 +0200")

Tassilo Horn <tsdh@gnu.org> writes:

> Well, it's actually not as simple as I've thought before.  It does in
> fact handle some non-symbol things but it depends on the syntax before
> and after the matched thing.
>
> With `prettify-symbols-alist' set to just (("\\alpha" . ?α) ("\\beta"
> . ?β)), that's what I get when using AUCTeX (yes means that the greek
> letter is displayed, no means the literal tex macro is displayed):
>
> \alpha                %% yes
> \[\alpha\]            %% yes
> $\alpha$              %% no
> $ \alpha$             %% no
> $ \alpha $            %% no
> \(\alpha\)            %% no
> \( \alpha\)           %% yes
> \( \alpha \)          %% yes
> \(\alpha\cdot\beta\)  %% alpha: no, beta: yes
> \( \alpha\cdot\beta\) %% alpha: yes, beta: yes
>
> With Emacs' built-in (la)tex-mode, all occurrences are displayed with
> the greek letters, so it seems to be more or less an AUCTeX problem.
>
> The only syntax differences I could find between the standard
> (la)tex-mode and AUCTeX's modes is that in the former, ?\\ has charquote
> syntax whereas it has escape syntax in the latter.  And $ has "math
> syntax, matches $" in the former and only math syntax in the latter.
> However, even after
>
>   (modify-syntax-entry ?\\ "/")
>   (modify-syntax-entry ?$ "$$")
>
> in the AUCTeX buffer and disabling and re-enabling
> `prettify-symbols-mode', the results stay the same as above...

Ok, it seems like these char syntax differences are not the culprit.  At
least the control flow thru `prettify-symbols--compose-symbol' is the
same no matter if the built-in (la)tex-modes or the AUCTeX ones are
used.  For all of the \alpha / \beta occurrences above,

  (compose-region start end (cdr (assoc match alist)))

is called.  So I defined this command to figure out what's going on:

(defun th/pretty-compose-region (start end)
  (interactive "r")
  (let* ((str  (buffer-substring-no-properties start end))
         (char (cdr (assoc str prettify-symbols-alist))))
    (if (null char)
        (message "Won't compose when there's no character defined.")
      (message "Composing %qs to be displayed as %qs." str (string char))
      (compose-region start end char))))

Now in my example test.tex file with `prettify-symbols-mode' enabled,
when I mark some \alpha still displayed literally in any of the samples
above and invoke my command, it messages

  Composing ‘\alpha’ to be displayed as ‘α’.

but the \alpha stays displayed as \alpha, and no composition text
property is added.  Why?

To make things more mysterious: when I disable `prettify-symbols-mode',
I can call my `th/pretty-compose-region' on any \alpha and \beta
occurrence, and then it'll be displayed as greek letter!

I thought that might be caused by `composition' being added to
`font-lock-extra-managed-props' by `prettify-symbols-mode', but the
behavior stays the same even when I remove it there.

So all in all: `prettify-symbols-mode' calls `compose-region' for all
occurrences of the tex macros I've defined in `prettify-symbols-alist'
with the corresponding unicode character.  The call always has the
desired effect in the built-in (la)tex-mode and in fundamental-mode [1],
but with AUCTeX modes the invocation of `compose-region' on some
occurrences has no effect when `prettify-symbols-mode' is enabled.  When
I disable it, I can manually compose the occurrences that didn't work.

When I set AUCTeX `TeX-install-font-lock' to `tex-font-setup' so that
the standard font-lock rules are used instead of AUCTeX's font-latex.el,
two more \alpha occurrences are displayed as the greek letter (the ones
with YES!), but still not all.

\alpha %% yes
\[\alpha\] %% yes
$\alpha$ %% no
$ \alpha$ %% no
$ \alpha $ %% no
\(\alpha\) %% YES!
\( \alpha\) %% yes
\( \alpha \) %% yes
\(\alpha\cdot\beta\) %% alpha: YES!, beta: yes
\( \alpha\cdot\beta\) %% alpha: yes, beta: yes

Well, the actual `font-lock-keywords' are not identical in the case of
the built-in (la)tex-mode and AUCTeX with `tex-font-setup' and it's not
really possible to figure out the differences given all those
regexp-opt-ed regexps.  Maybe in the AUCTeX version there's some
additional font-lock that would interfer with the composition, i.e.,
immediately undos what the `compose-region' calls did?

Or what else might be the culprit of rendering `compose-region'
non-functional?

Bye,
Tassilo

[1] With the exception of $\alpha$ because there the trailing $ is part
of the word.



  reply	other threads:[~2015-08-19 12:33 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-14 14:43 port x-symbol to GNU emacs 24 Uwe Brauer
2015-08-14 14:58 ` Eli Zaretskii
2015-08-14 15:16   ` Uwe Brauer
2015-08-14 15:30     ` David Kastrup
2015-08-14 18:15       ` Uwe Brauer
2015-08-14 16:05     ` Tassilo Horn
2015-08-14 17:21       ` Stefan Monnier
2015-08-14 18:19       ` Uwe Brauer
2015-08-17  7:29         ` Tassilo Horn
2015-08-17 15:10           ` Eli Zaretskii
2015-08-17 15:20             ` David Kastrup
2015-08-17 15:36               ` Eli Zaretskii
2015-08-18  8:38               ` Tassilo Horn
2015-08-18 15:52                 ` Stefan Monnier
2015-08-19  7:33                   ` Tassilo Horn
2015-08-19 12:33                     ` Tassilo Horn [this message]
2015-08-19 16:34                       ` Tassilo Horn
2015-08-19 17:29                     ` Stefan Monnier
2015-08-19 19:05                       ` Tassilo Horn
2015-08-19 21:43                         ` Stefan Monnier
2015-08-21  6:21                           ` Tassilo Horn
2015-08-21  7:28                             ` David Kastrup
2015-08-21  8:44                               ` Tassilo Horn
2015-08-21  9:51                                 ` David Kastrup
2015-08-21 13:08                                   ` Tassilo Horn
2015-08-20  8:11                       ` Generalizing prettify-symbols-mode (was: port x-symbol to GNU emacs 24.) Tassilo Horn
2015-08-20 14:15                         ` Generalizing prettify-symbols-mode Stefan Monnier
2015-08-21  6:48                           ` Tassilo Horn
2015-08-21  7:43                             ` Tassilo Horn
2015-08-21 13:19                               ` Stefan Monnier
2015-08-14 18:38       ` port x-symbol to GNU emacs 24 Uwe Brauer
2015-08-17  1:59     ` Stephen J. Turnbull
2015-08-17  9:20       ` Uwe Brauer
2015-08-17 10:50         ` Stephen J. Turnbull
2015-08-17 11:12           ` David Kastrup

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=87oai34fvc.fsf@gnu.org \
    --to=tsdh@gnu.org \
    --cc=dak@gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.