From: Kaushal Modi <kaushal.modi@gmail.com>
To: Eric Abrahamsen <eric@ericabrahamsen.net>,
emacs-org list <emacs-orgmode@gnu.org>,
Nicolas Goaziou <mail@nicolasgoaziou.fr>
Subject: Re: Show presence of zero width spaces using overlay
Date: Sat, 19 Sep 2015 02:15:14 -0400 [thread overview]
Message-ID: <CAFyQvY1F0PX__QzKM=qHKkkKrWPWtQh3dtbLfN9pLZuhXHvP3g@mail.gmail.com> (raw)
In-Reply-To: <CAFyQvY18tU8-FXnz-17OGtVyOCEx5_zgKfTycDgm6O7H5bTygg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4975 bytes --]
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:
=====
(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= 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)
=====
After evaluating the above, whenever you do C-u *, C-u /, C-u =, etc, that
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 <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.
>
> =====
>
> * Escaping =equal= sign in verbatim formatting.
> =a\equal{}b+c=
> ** Here's the same but using zero width spaces instead of /org entities/.
> =a=[ZWS]b+c=
>
> * Here I am trying to have double quotes in verbatim formatting.
> =\quot{}This is inbetween double quotes\quot{}=.
> ** Here's the same but using zero width spaces instead of /org entities/.
> =[ZWS]"This is inbetween double quotes"[ZWS]=.
>
> * And here's to escapes asterisks
> This is *bold*. But this is \ast{}not bold\ast{}.
> This works!
>
> =====
>
>
>
> On Sat, Sep 19, 2015 at 12:07 AM Kaushal Modi <kaushal.modi@gmail.com>
> 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:
>>
>> =====
>>
>> * Escaping =equal= sign in verbatim formatting.
>> =a\equal{}b+c=
>> ** Here's the same but using zero width spaces instead of /org entities/.
>> =a=b+c=
>>
>> * Here I am trying to have double quotes in verbatim formatting.
>> =\quot{}This is inbetween double quotes\quot{}=.
>> ** Here's the same but using zero width spaces instead of /org entities/.
>> ="This is inbetween double quotes"=.
>>
>> * And here's to escapes asterisks
>> This is *bold*. But this is \ast{}not bold\ast{}.
>> This works!
>>
>> =====
>>
>> 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 <eric@ericabrahamsen.net>
>> wrote:
>>
>>> Kaushal Modi <kaushal.modi@gmail.com> writes:
>>>
>>> > My most common uses are escaping double quotes (") and equals (=)
>>> > within org verbatim blocks (=VERBATIM=)
>>> >
>>> > Examples:
>>> >
>>> > 1. =var=[ZWS]val=
>>> > 2. =[ZWS]"something"[ZWS]=
>>> >
>>> > 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 = in
>>> > the above 2 examples?
>>>
>>> Check out the variable `org-entities' for all the replaceable escape
>>> codes. It's got quotes and equal!
>>>
>>> E
>>>
>>>
>>>
[-- Attachment #2: Type: text/html, Size: 11568 bytes --]
next prev parent reply other threads:[~2015-09-19 6:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-18 18:44 Show presence of zero width spaces using overlay Kaushal Modi
2015-09-18 21:11 ` Nicolas Goaziou
2015-09-18 22:39 ` Kaushal Modi
2015-09-19 1:47 ` Eric Abrahamsen
2015-09-19 4:07 ` Kaushal Modi
2015-09-19 4:11 ` Kaushal Modi
2015-09-19 6:15 ` Kaushal Modi [this message]
2015-09-19 7:22 ` Eric Abrahamsen
2015-09-19 13:46 ` Kaushal Modi
2015-09-19 11:37 ` Nicolas Goaziou
-- strict thread matches above, loose matches on Subject: below --
2015-09-22 15:13 timor
2015-09-27 9:41 ` Nicolas Goaziou
2016-04-19 9:23 ` timor
2016-04-19 10:16 ` Nicolas Goaziou
2016-04-19 11:38 timor
2016-04-19 19:21 ` Nicolas Goaziou
2016-04-19 23:20 ` timor
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFyQvY1F0PX__QzKM=qHKkkKrWPWtQh3dtbLfN9pLZuhXHvP3g@mail.gmail.com' \
--to=kaushal.modi@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=eric@ericabrahamsen.net \
--cc=mail@nicolasgoaziou.fr \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).