From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Re: Show presence of zero width spaces using overlay Date: Sat, 19 Sep 2015 02:15:14 -0400 Message-ID: References: <87twqrtou5.fsf@nicolasgoaziou.fr> <87io772n8w.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b33d318a056f30520139436 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdBRE-0003ez-KU for emacs-orgmode@gnu.org; Sat, 19 Sep 2015 02:15:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZdBRC-0004Mi-Iq for emacs-orgmode@gnu.org; Sat, 19 Sep 2015 02:15:56 -0400 Received: from mail-ob0-x236.google.com ([2607:f8b0:4003:c01::236]:36224) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdBRC-0004Ma-BF for emacs-orgmode@gnu.org; Sat, 19 Sep 2015 02:15:54 -0400 Received: by obbmp4 with SMTP id mp4so17747911obb.3 for ; Fri, 18 Sep 2015 23:15:53 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Abrahamsen , emacs-org list , Nicolas Goaziou --047d7b33d318a056f30520139436 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I got really interested in org-entities (to deal with the case I mentioned in the first email in this thread like \ast{}shrug\ast{}) and came up with this: =3D=3D=3D=3D=3D (defun modi/org-entity-get-name (char) "Return the entity name for CHAR. For example, return \"ast\" for *." (let ((ll (append org-entities-user org-entities)) e name utf8) (catch 'break (while ll (setq e (pop ll)) (when (not (stringp e)) (setq utf8 (nth 6 e)) (when (string=3D char utf8) (setq name (car e)) (throw 'break name))))))) (defun modi/org-insert-org-entity-maybe (orig-fun &rest args) "When the universal prefix C-u is used before entering any character, insert the character's `org-entity' name if available." (let ((pressed-key (this-command-keys)) entity-name) (when (and (listp args) (eq 4 (car args))) (setq entity-name (modi/org-entity-get-name pressed-key)) (when entity-name (setq entity-name (concat "\\" entity-name "{}")) (insert entity-name) (message (concat "Inserted `org-entity' " (propertize entity-name 'face 'font-lock-function-name-face) " for the symbol " (propertize pressed-key 'face 'font-lock-function-name-face) ".")))) (when (null entity-name) (apply orig-fun args)))) (advice-add 'org-self-insert-command :around #'modi/org-insert-org-entity-maybe) =3D=3D=3D=3D=3D After evaluating the above, whenever you do C-u *, C-u /, C-u =3D, etc, tha= t symbol's org-entity will be inserted (if available in either org-entities-user or org-entities). If an org-entity match is not found, that symbol will be inserted 4 times, as C-u would usually do. The message tells the user if the org-entity got inserted so that there is not confusion. The advised portion gets executed only if the below 2 conditions match: - User used C-u prefix (not M-4 or C-u C-u or anything else) - The entered character has a match in the org entities lists. Question to the list is: Does this advise mask any useful functionality of org-self-insert-command? -- Kaushal Modi On Sat, Sep 19, 2015 at 12:11 AM, Kaushal Modi wrote: > Here's the MWE once again with proper indication ([ZWS]) of where you nee= d > to insert the zero width space char. > > =3D=3D=3D=3D=3D > > * Escaping =3Dequal=3D sign in verbatim formatting. > =3Da\equal{}b+c=3D > ** Here's the same but using zero width spaces instead of /org entities/. > =3Da=3D[ZWS]b+c=3D > > * Here I am trying to have double quotes in verbatim formatting. > =3D\quot{}This is inbetween double quotes\quot{}=3D. > ** Here's the same but using zero width spaces instead of /org entities/. > =3D[ZWS]"This is inbetween double quotes"[ZWS]=3D. > > * And here's to escapes asterisks > This is *bold*. But this is \ast{}not bold\ast{}. > This works! > > =3D=3D=3D=3D=3D > > > > On Sat, Sep 19, 2015 at 12:07 AM Kaushal Modi > wrote: > >> Thanks for letting me know about org-entities. That is awesome. I now >> know how to escape various characters in general, but unfortunately this >> does not work within verbatim formatting (which makes sense). >> >> Here's a minimum working example: >> >> =3D=3D=3D=3D=3D >> >> * Escaping =3Dequal=3D sign in verbatim formatting. >> =3Da\equal{}b+c=3D >> ** Here's the same but using zero width spaces instead of /org entities/= . >> =3Da=3Db+c=3D >> >> * Here I am trying to have double quotes in verbatim formatting. >> =3D\quot{}This is inbetween double quotes\quot{}=3D. >> ** Here's the same but using zero width spaces instead of /org entities/= . >> =3D=E2=80=8B"This is inbetween double quotes"=E2=80=8B=3D. >> >> * And here's to escapes asterisks >> This is *bold*. But this is \ast{}not bold\ast{}. >> This works! >> >> =3D=3D=3D=3D=3D >> >> Here's what it looks like when exported: >> https://dl.dropboxusercontent.com/u/10985/escape-chars.pdf >> >> On Fri, Sep 18, 2015 at 9:48 PM Eric Abrahamsen >> wrote: >> >>> Kaushal Modi writes: >>> >>> > My most common uses are escaping double quotes (") and equals (=3D) >>> > within org verbatim blocks (=3DVERBATIM=3D) >>> > >>> > Examples: >>> > >>> > 1. =3Dvar=3D[ZWS]val=3D >>> > 2. =3D[ZWS]"something"[ZWS]=3D >>> > >>> > Here [ZWS] is the 0x200b zero width space unicode char. >>> > >>> > I found [ZWS] useful as a generic escape char for org mode. There are >>> > few other cases where this has been useful, but I can't recall right >>> > now. >>> > >>> > In any case, what would be the recommended way to escape " and =3D in >>> > the above 2 examples? >>> >>> Check out the variable `org-entities' for all the replaceable escape >>> codes. It's got quotes and equal! >>> >>> E >>> >>> >>> --047d7b33d318a056f30520139436 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I got really interested in org-e= ntities (to deal with the case I mentioned in the first email in this threa= d like \ast{}shrug\ast{}) and came up with this:

=3D=3D=3D=3D=3D

(defu= n modi/org-entity-get-name (char)
=C2=A0 "Return the = entity name for CHAR. For example, return \"ast\" for *."
=C2=A0 (let ((ll (append org-entities-user
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 org-e= ntities))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 e name utf8)<= /div>
=C2=A0 =C2=A0 (catch 'break
=C2=A0 =C2=A0 = =C2=A0 (while ll
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq e (pop = ll))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (not (stringp e))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq utf8 (nth 6 e))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (string=3D char utf= 8)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq name (c= ar e))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (throw &#= 39;break name)))))))

(defun modi/org= -insert-org-entity-maybe (orig-fun &rest args)
=C2= =A0 "When the universal prefix C-u is used before entering any charact= er,
insert the character's `org-entity' name if av= ailable."
=C2=A0 (let ((pressed-key (this-command-key= s))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 entity-name)
<= div class=3D"gmail_default" style=3D"">=C2=A0 =C2=A0 (when (and (listp args) (eq 4 (car args)))
=C2=A0 =C2=A0 =C2=A0 (setq entity-name (modi/org-entity-get-name pressed= -key))
=C2=A0 =C2=A0 =C2=A0 (when entity-name
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq entity-name (concat "\\" e= ntity-name "{}"))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (= insert entity-name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (message (= concat "Inserted `org-entity' "
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(propertize entity-name
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'face 'font-lock-function-name-face)=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0" for the symbol "
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(propertize pressed-key
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'face 'font-lock-funct= ion-name-face)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"."))))
=C2=A0 =C2=A0 (when (null entity-name)
=C2=A0 =C2= =A0 =C2=A0 (apply orig-fun args))))

= (advice-add 'org-self-insert-command :around #'modi/org-insert-org-= entity-maybe)

=3D=3D=3D=3D=3D

= After evaluating the above, whenever you do C-u *, C-u /, C-u =3D, etc, tha= t symbol's org-entity will be inserted (if available in either org-enti= ties-user or org-entities).
If an org-entity match is not found, tha= t symbol will be inserted 4 times, as C-u would usually do.

The message tells the user if the org-entity got inserted so that there= is not confusion.

The advised portion gets executed onl= y if the below 2 conditions match:
- User used C-u prefix (not M-4 o= r C-u C-u or anything else)
- The entered character has a match in t= he org entities lists.

Question to the list is: Does thi= s advise mask any useful functionality of org-self-insert-command?


--
= Kaushal Modi

On Sat, Sep 19, 2015 at 12:11 AM, Kaushal Mo= di <kaushal.modi@gmail.com> wrote:
Here's the MWE once again with proper = indication ([ZWS]) of where you need to insert the zero width space char.
=3D=3D=3D=3D=3D

* Escaping =3Dequal=3D sign in verbatim formatting.
= =3Da\equal{}b+c=3D
** Here's the same but using zero width sp= aces instead of /org entities/.
=3Da=3D[ZWS]b+c=3D

* Here I am trying to have double quotes= in verbatim formatting.
=3D\quot{}This is inbetween double quote= s\quot{}=3D.
** Here's the same but using zero width spaces i= nstead of /org entities/.
=3D[ZWS]"This is inbetween doub= le quotes"[ZWS]=3D.

* And here's to escapes asterisks
This is *bold*. But this = is \ast{}not bold\ast{}.
This works!

<= /div>
=3D=3D=3D=3D=3D



On Sat, Sep 19, 2015 at 12:07 AM Kaushal Modi <kaushal.modi@gmail.com>= ; wrote:
Thanks fo= r letting me know about org-entities. That is awesome. I now know how to es= cape various characters in general, but unfortunately this does not work wi= thin verbatim formatting (which makes sense).

Here's= a minimum working example:

=3D=3D=3D=3D=3D
<= div>
* Escaping =3Dequal=3D sign in verbatim formatting.=
=3Da\equal{}b+c=3D
** Here's the same but using ze= ro width spaces instead of /org entities/.
=3Da=3Db+c=3D

* Here I am trying to have double quotes in verbatim forma= tting.
=3D\quot{}This is inbetween double quotes\quot{}=3D.
=
** Here's the same but using zero width spaces instead of /org ent= ities/.
=3D=E2=80=8B"This is inbetween double quotes"= =E2=80=8B=3D.

* And here's to escapes asterisk= s
This is *bold*. But this is \ast{}not bold\ast{}.
Thi= s works!

=3D=3D=3D=3D=3D

Here's what it looks like when exported:=C2=A0https= ://dl.dropboxusercontent.com/u/10985/escape-chars.pdf

On Fri, Sep 18, 2015 at 9:48 PM E= ric Abrahamsen <eric@ericabrahamsen.net> wrote:
Kaushal Modi <kaushal.modi@gmail.com> writes:

> My most common uses are escaping double quotes (") and equals (= =3D)
> within org verbatim blocks (=3DVERBATIM=3D)
>
> Examples:
>
> 1. =3Dvar=3D[ZWS]val=3D
> 2. =3D[ZWS]"something"[ZWS]=3D
>
> Here [ZWS] is the 0x200b zero width space unicode char.
>
> I found [ZWS] useful as a generic escape char for org mode. There are<= br> > few other cases where this has been useful, but I can't recall rig= ht
> now.
>
> In any case, what would be the recommended way to escape " and = =3D in
> the above 2 examples?

Check out the variable `org-entities' for all the replaceable escape codes. It's got quotes and equal!

E



--047d7b33d318a056f30520139436--