emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] scratch/quote-escaping d99e82d 1/2: Curlify quotes in help


From: Dmitry Gutov
Subject: [Emacs-diffs] scratch/quote-escaping d99e82d 1/2: Curlify quotes in help-mode buffers
Date: Sun, 28 Jun 2015 23:28:38 +0000

branch: scratch/quote-escaping
commit d99e82d36701fbed77586cb990409da206127b62
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Curlify quotes in help-mode buffers
---
 lisp/help-fns.el           |    3 ++-
 lisp/help-mode.el          |   40 ++++++++++++++++++++++++++++++++++++++++
 lisp/textmodes/texinfmt.el |    4 ++--
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 4982ee5..aaaf02b 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -746,7 +746,8 @@ it is displayed along with the global value."
                      (setq from (point))
                      (pp origval)
                      (if (< (point) (+ from 20))
-                         (delete-region (1- from) from)))))))
+                         (delete-region (1- from) from)))))
+                (put-text-property val-start-pos (point) 'help-value t)))
            (terpri)
            (when locus
              (cond
diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index f99e916..b5bf618 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -97,6 +97,18 @@ The format is (FUNCTION ARGS...).")
   "Hook run by `help-mode'."
   :type 'hook
   :group 'help)
+
+(defcustom help-quote-translation nil
+  "Style to use for single quotes in help.
+The value is a left single quote character of some style.
+Quote ‘like this’ if the value is ?‘ (left single quotation mark).
+Quote \\'like this\\' if the value is ?\\' (apostrophe).
+Quote \\`like this\\' if the value is ?\\` (grave accent).
+The default value is nil, which means quote with left single quotation mark
+if displayable, and with grave accent otherwise."
+  :type 'character
+  :group 'help)
+
 
 ;; Button types used by help
 
@@ -287,9 +299,37 @@ Commands:
 \\{help-mode-map}"
   (set (make-local-variable 'revert-buffer-function)
        'help-mode-revert-buffer)
+  (setq font-lock-defaults '(nil t))
+  (font-lock-add-keywords
+   nil '(("\\(?:\\=\\|[^\\]\\)\\(\\\\*\\)[`']"
+          (0 (let* ((mbeg (match-beginning 1))
+                    (mend (match-end 1))
+                    (escapes (- mend mbeg)))
+               (unless (get-text-property mend 'help-value)
+                 ;; Collapse all escaped backslashes.
+                 (compose-region mbeg (+ mbeg (- escapes (/ escapes 2))) "")
+                 ;; If there's an even number of backslashes,
+                 ;; translate the quote.
+                 (when (eq (logand escapes 1) 0)
+                   (help--translate-quote mend)))
+               nil)))))
   (set (make-local-variable 'bookmark-make-record-function)
        'help-bookmark-make-record))
 
+(defun help--translate-quote (beg)
+  (let* ((char (char-after beg))
+         (replacement
+          (cond
+           ((or (and (null help-quote-translation)
+                     (char-displayable-p ?‘))
+                (eq help-quote-translation ?‘))
+            (cdr (assq char '((?` . ?‘) (?' . ?’)))))
+           ((eq help-quote-translation ?')
+            ?')
+           (t char))))
+    (unless (eq char replacement)
+      (compose-region beg (1+ beg) replacement))))
+
 ;;;###autoload
 (defun help-mode-setup ()
   (help-mode)
diff --git a/lisp/textmodes/texinfmt.el b/lisp/textmodes/texinfmt.el
index e7b6835..392d45b 100644
--- a/lisp/textmodes/texinfmt.el
+++ b/lisp/textmodes/texinfmt.el
@@ -2493,8 +2493,8 @@ surrounded by in angle brackets."
 Enclose the verbatim text, including the delimiters, in braces.  Print
 text exactly as written (but not the delimiters) in a fixed-width.
 
-For example, @verb\{|@|\} results in @ and
address@hidden@'e?`!`+} results in @'e?`!`."
+For example, @verb{|@|} results in @ and
address@hidden@\\'e?\\`!\\`+} results in @\\'e?\\`!\\`."
 
   (let ((delimiter (buffer-substring-no-properties
                    (1+ texinfo-command-end) (+ 2 texinfo-command-end))))



reply via email to

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