[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] master 9d35bb8: Fix minor quoting problems in doc stri

From: Dmitry Gutov
Subject: Re: [Emacs-diffs] master 9d35bb8: Fix minor quoting problems in doc strings
Date: Wed, 20 May 2015 15:25:10 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0

On 05/20/2015 05:49 AM, Paul Eggert wrote:

Although the quotes that we want to curl are paired, there are other
stray grave accents and apostrophes that we shouldn't curl.

Probably. But if they're rare enough, having to escape won't be too annoying.

Are you sure?  The first grave accent looks like a quasiquote, so there
shouldn't be a closing apostrophe.  Those commas are clues that it's a

Indeed (I corrected myself later). If this kind of quasiquote is a popular kind of exception, we can handle it programmatically:

- If there's a opening paren after the backtick,
- And there's no apostrophe after the matching closing paren,

don't turn the backtick into the curly quote, and continue matching right after the closing paren.

If could be implemented in the form FACENAME in font-lock-keywords while keeping the matcher to be a regexp, but a custom matching function seems more appropriate, to catch any apostrophes (straight quotes) inside the form. See the patch.

Here's my current draft regexp to catch the quotations we want to curl:


A bit tricky, but could be worse.  Newlines are allowed, as some doc
strings break these quotes across line boundaries (e.g., info node

Why not allow curly quotes inside? They don't introduce any syntax ambiguity.

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index f99e916..a0b7a6d 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -279,6 +279,19 @@ The format is (FUNCTION ARGS...).")
 (defvar bookmark-make-record-function)

+(defun help--match-quoted-code (limit)
+  (while (search-forward "`" limit t)
+    (let ((beg (point))
+          forward-sexp-function)
+      (when
+          (if (not (eq (char-after) ?\())
+ (re-search-forward "\\=\\([^[:space:]'`‘’][^'`‘’]*\\)?'" limit t)
+            (forward-sexp)
+            (eq (char-after) ?'))
+        (compose-region (1- beg) beg ?‘)
+        (compose-region (1- (point)) (point) ?’))))
+  nil)
 (define-derived-mode help-mode special-mode "Help"
   "Major mode for viewing help text and navigating references in it.
@@ -287,6 +300,7 @@ Commands:
   (set (make-local-variable 'revert-buffer-function)
+  (setq font-lock-defaults '(((help--match-quoted-code)) t))
   (set (make-local-variable 'bookmark-make-record-function)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]