unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Paul Eggert <eggert@cs.ucla.edu>, emacs-devel@gnu.org
Subject: Re: Escaping quotes in docstrings, Was: A simple solution to "Upcoming loss of usability ..."
Date: Thu, 2 Jul 2015 03:09:30 +0300	[thread overview]
Message-ID: <5594813A.3000705@yandex.ru> (raw)
In-Reply-To: <559356D2.4000103@cs.ucla.edu>

On 07/01/2015 05:56 AM, Paul Eggert wrote:

> I tried it out.  One thing I noticed right away is odd behavior that
> results from storing grave accent and apostrophe in the buffer and
> displaying them as curved quotes.  For example, run 'emacs -Q -nw', then
> read the documentation for the 'length' function and copy it to a new
> file /tmp/foo by typing "C-h f length RET C-x o C-x h M-w C-x 4 f
> /tmp/foo RET C-y C-s".  On the screen you'll see a buffer 'foo'
> containing curved quotes.  Now, revisit /tmp/foo by typing "C-x C-v
> RET".  The buffer will contain the same contents as before, except the
> curved quotes are magically transformed to grave accent and apostrophe
> on the display.  It's weird that copied text mysteriously changes its
> display representation at a seemingly unrelated moment.

It's the same if you copy some syntax-highlighted text (say, from 
src/doc.c) to /tmp/foo and save it. Kill the buffer, reopen - the 
highlighting is gone! :)

That may seem counter-intuitive, but it's something Emacs users are 
generally familiar with.

> How about the following idea instead.  Instead of displaying grave
> accent and apostrophe specially, have with-help-window transliterate
> these characters in place before displaying itself as usual.

That should work, too. In help-mode-finish, before help-make-xrefs.

> with-help-window should not transliterate characters that are marked as
> being escaped, or as being user data (not clear that we need two kinds
> of marks here; one should do, no?).

They're semantically different. I think we currently apply linkification 
(help-make-xrefs) to the contents of user data, and we might continue 
doing that.

On the other hand, we should probably avoid linkifying symbols inside 
quotes when at least one of the quotes is escaped.

> That's the big picture.  Here are a few more-minor remarks.
>
>> +  (font-lock-add-keywords
>> +   nil '(("\\(\\\\~\\)\\(?:\\\\~\\|.\\)"
>
> As already mentioned, the new \~ quoting syntax doesn't seem to be
> needed; we can get by with the existing \= quoting syntax.  So let's go
> that direction.

For us to go there, could you please make substitute-command-keys add 
the `escaped' property to the escaped characters in its output? And push 
it to scratch/quote-escaping.

> Also, this regexp string matches either (1) \~\~ or (2) \~ followed by
> any non-newline character.  But if \~ is supposed to escape the next
> character, the regexp string should simply implement that, i.e., the
> regexp string should be "\\\\~\\(.\\|\n\\)".

I guess so. Sorry, brain fart.

> I assume the extra complication is about escaping backslash itself,
> e.g., if the docstring is \~\ (which would look like "\\~\\" in the
> source code) this should stand for \ in the *Help* buffer.  But the
> above regexp doesn't do that.

Doesn't it? Works for me. But anyway, let's try to reuse the quoting 
from substitute-command-keys first.

>> +               (unless (get-text-property mbeg 'help-value)
>
> Supposed the matched string is partly help-value, and partly not.  E.g.,
> mbeg has help-value but mbeg+1 does not but mbeg+2 does.  Shouldn't this
> test that all the matched characters are not help-value characters?

Why? I'm assuming the value is separated from the other contents by 
whitespace or newlines. IMHO, that would too defensive. We're throwing 
that code out anyway.

On the other hand, we could encounter a value between ` and ', in 
help--translate-quotes, if the value is shown at the end of the buffer.

Should be taken care of in f9f3aa5 (as well as another nearby bug).

>> +                 ;; If we use "" as the third argument, cursor
>> +                 ;; stumbles once when moving over its position.
>
> I don't understand this comment.  Can you explain?  For example, does
> the comment apply to the just the compose-region call, or to the rest of
> the 'unless'?

Only to the compose-region call. If we pass "" to it as COMPOSITION, the 
result will still be considered a valid position for the cursor, even 
though it has zero width. Anyway, we're going a different route: no 
compose-region calls.

>> +                                 (buffer-substring-no-properties
>> +                                  mend (1+ mend)))
>
> This may go haywire if it returns "\t", because a TAB is special to
> compose-region.  Also, what if the buffer has some properties other than
> help-value that should be preserved?

Err, I don't think the current code deletes any existing properties, it 
only changes how the buffer looks.

On the other hand, if help-mode-finish performs the translations 
(destructively, I'm assuming), then we indeed might lose some properties.

I wouldn't worry too much about that, though. If help-mode doesn't know 
about them, no other code is likely to use them either.



  reply	other threads:[~2015-07-02  0:09 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25 14:59 A simple solution to "Upcoming loss of usability ..." Oleh Krehel
2015-06-25 15:37 ` Dmitry Gutov
2015-06-25 16:36 ` Paul Eggert
2015-06-25 17:00   ` Oleh Krehel
2015-06-25 20:48     ` Paul Eggert
2015-06-25 21:10       ` Dmitry Gutov
2015-06-25 22:15         ` Paul Eggert
2015-06-25 22:25           ` Dmitry Gutov
2015-06-25 22:41             ` Paul Eggert
2015-06-25 22:52               ` Dmitry Gutov
2015-06-27 15:00         ` raman
2015-06-25 18:32   ` Dmitry Gutov
2015-06-25 22:17     ` Paul Eggert
2015-06-25 22:38       ` Dmitry Gutov
2015-06-26  2:35         ` Paul Eggert
2015-06-26 12:06           ` Dmitry Gutov
2015-06-27 17:28             ` Paul Eggert
2015-06-27 17:53               ` Dmitry Gutov
2015-06-27 21:09                 ` Paul Eggert
2015-06-28  1:04                   ` Dmitry Gutov
2015-06-28 15:20                     ` Paul Eggert
2015-06-28 20:27                       ` Escaping quotes in docstrings, Was: " Dmitry Gutov
2015-06-28 23:29                         ` Dmitry Gutov
2015-07-01  2:56                           ` Paul Eggert
2015-07-02  0:09                             ` Dmitry Gutov [this message]
2015-07-02  6:57                               ` Paul Eggert
2015-07-02  9:46                                 ` Dmitry Gutov
2015-07-06  6:12                                 ` Paul Eggert
2015-07-06 12:07                                   ` Dmitry Gutov
2015-07-06 16:30                                     ` Paul Eggert
2015-07-06 22:10                                       ` Dmitry Gutov
2015-07-07  7:54                                         ` Paul Eggert
2015-07-07  8:39                                           ` Dmitry Gutov
2015-08-01  1:36                                             ` Paul Eggert
2015-08-01 21:05                                               ` Dmitry Gutov
2015-08-02  6:56                                                 ` Paul Eggert
2015-08-02 12:51                                                   ` Dmitry Gutov
2015-08-02 15:13                                                     ` Paul Eggert
2015-08-02 18:31                                                       ` Dmitry Gutov
2015-08-02  8:49                                                 ` Przemysław Wojnowski
2015-08-02 19:16                                                   ` Drew Adams
2015-06-27 17:57               ` Dmitry Gutov
2015-06-25 23:12       ` João Távora
2015-06-26  7:40       ` Oleh Krehel
2015-06-26 14:54         ` Paul Eggert
2015-06-26 15:03           ` Dmitry Gutov
2015-06-25 20:58   ` Alan Mackenzie
2015-06-25 22:34     ` Paul Eggert
2015-06-25 22:40       ` Dmitry Gutov
2015-06-25 22:45         ` Paul Eggert
2015-06-25 22:55           ` Dmitry Gutov

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=5594813A.3000705@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).