]> code.delx.au - gnu-emacs/commitdiff
Prefer ‘format’ to ‘substitute-command-keys’
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 14 Aug 2015 22:50:35 +0000 (15:50 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 14 Aug 2015 22:55:58 +0000 (15:55 -0700)
* src/character.h (uLSQM, uRSQM): Move here ...
* src/doc.c (uLSQM, uRSQM): ... from here.
* src/doc.c (Fsubstitute_command_keys):
* src/syntax.c (Finternal_describe_syntax_value):
* lisp/cedet/mode-local.el (mode-local-print-binding)
(mode-local-describe-bindings-2):
* lisp/cedet/srecode/srt-mode.el (srecode-macro-help):
* lisp/cus-theme.el (describe-theme-1):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/emacs-lisp/cl-extra.el (cl--describe-class):
* lisp/emacs-lisp/cl-generic.el (cl--generic-describe):
* lisp/emacs-lisp/eieio-opt.el (eieio-help-constructor):
* lisp/emacs-lisp/package.el (describe-package-1):
* lisp/faces.el (describe-face):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--parent-mode)
(help-fns--obsolete, help-fns--interactive-only)
(describe-function-1, describe-variable):
* lisp/help.el (describe-mode):
Prefer ‘format’ to ‘substitute-command-keys’ when either will do
to implement quoting style.  This generally makes the code simpler.

14 files changed:
lisp/cedet/mode-local.el
lisp/cedet/srecode/srt-mode.el
lisp/cus-theme.el
lisp/descr-text.el
lisp/emacs-lisp/cl-extra.el
lisp/emacs-lisp/cl-generic.el
lisp/emacs-lisp/eieio-opt.el
lisp/emacs-lisp/package.el
lisp/faces.el
lisp/help-fns.el
lisp/help.el
src/character.h
src/doc.c
src/syntax.c

index 3bdc3ea615534dc45f30c39483487c90d59e1fe9..aa1dd65068f9f3d877f461b2afb7eb6a700ff83c 100644 (file)
@@ -629,10 +629,9 @@ SYMBOL is a function that can be overridden."
 (defun mode-local-print-binding (symbol)
   "Print the SYMBOL binding."
   (let ((value (symbol-value symbol)))
-    (princ (format (substitute-command-keys "\n     ‘%s’ value is\n       ")
-                   symbol))
+    (princ (format "\n     ‘%s’ value is\n       " symbol))
     (if (and value (symbolp value))
-        (princ (format (substitute-command-keys "‘%s’") value))
+        (princ (format "‘%s’" value))
       (let ((pt (point)))
         (pp value)
         (save-excursion
@@ -690,7 +689,7 @@ SYMBOL is a function that can be overridden."
       )
      ((symbolp buffer-or-mode)
       (setq mode buffer-or-mode)
-      (princ (format (substitute-command-keys "‘%s’\n") buffer-or-mode))
+      (princ (format "‘%s’\n" buffer-or-mode))
       )
      ((signal 'wrong-type-argument
               (list 'buffer-or-mode buffer-or-mode))))
@@ -700,7 +699,7 @@ SYMBOL is a function that can be overridden."
     (while mode
       (setq table (get mode 'mode-local-symbol-table))
       (when table
-        (princ (format (substitute-command-keys "\n- From ‘%s’\n") mode))
+        (princ (format "\n- From ‘%s’\n" mode))
         (mode-local-print-bindings table))
       (setq mode (get-mode-local-parent mode)))))
 
index 48f055561ea39332966d913075a990a8590d26c2..efcfe4ba51dd05ecd7dcfeb4db898b0aaffb629b 100644 (file)
@@ -258,9 +258,9 @@ we can tell font lock about them.")
            (when (class-abstract-p C)
              (throw 'skip nil))
 
-           (princ (substitute-command-keys "‘"))
+           (princ (format "‘"))
            (princ name)
-           (princ (substitute-command-keys "’"))
+           (princ (format "’"))
            (when (slot-exists-p C 'key)
              (when key
                (princ " - Character Key: ")
index bc221e17c4bf7c909647a632f830379e7a44042c..f8e5650db785f17863ff6ceeb8edbd5de9f2cac1 100644 (file)
@@ -492,10 +492,10 @@ It includes all faces in list FACES."
                         '("" "c")))
        doc)
     (when fn
-      (princ (substitute-command-keys " in ‘"))
+      (princ (format " in ‘"))
       (help-insert-xref-button (file-name-nondirectory fn)
                               'help-theme-def fn)
-      (princ (substitute-command-keys "’")))
+      (princ (format "’")))
     (princ ".\n")
     (if (custom-theme-p theme)
        (progn
index 71233d406e190696661854cba076c0b1b03b2254..579278ceaa0316ba1b2575c2020e017ad8f78b80 100644 (file)
@@ -161,11 +161,8 @@ otherwise."
       ;; Buttons
       (when (and button (not (widgetp wid-button)))
        (newline)
-       (insert (substitute-command-keys "Here is a ‘")
-               (format "%S" button-type)
-               (substitute-command-keys "’ button labeled ‘")
-               button-label
-               (substitute-command-keys "’.\n\n")))
+       (insert (format "Here is a ‘%S’ button labeled ‘%s’.\n\n"
+                       button-type button-label)))
       ;; Overlays
       (when overlays
        (newline)
@@ -739,9 +736,7 @@ relevant to POS."
                       (when face
                         (insert (propertize " " 'display '(space :align-to 5))
                                 "face: ")
-                        (insert (substitute-command-keys "‘")
-                                (symbol-name face)
-                                (substitute-command-keys "’\n"))))))
+                        (insert (format "‘%s’\n" face))))))
               (insert "these terminal codes:\n")
               (dotimes (i (length disp-vector))
                 (insert (car (aref disp-vector i))
index 9742014db0cd40d47f2d1112f5a93d7d9893c43e..132aaa5cfce40c3cc7ab05158fd1f401d88216b5 100644 (file)
@@ -752,16 +752,16 @@ including `cl-block' and `cl-eval-when'."
         ;; FIXME: Add a `cl-class-of' or `cl-typeof' or somesuch.
         (metatype (cl--class-name (symbol-value (aref class 0)))))
     (insert (symbol-name type)
-            (substitute-command-keys " is a type (of kind ‘"))
+            (format " is a type (of kind ‘"))
     (help-insert-xref-button (symbol-name metatype)
                              'cl-help-type metatype)
-    (insert (substitute-command-keys "’)"))
+    (insert (format "’)"))
     (when location
-      (insert (substitute-command-keys " in ‘"))
+      (insert (format " in ‘"))
       (help-insert-xref-button
        (help-fns-short-filename location)
        'cl-type-definition type location 'define-type)
-      (insert (substitute-command-keys "’")))
+      (insert (format "’")))
     (insert ".\n")
 
     ;; Parents.
@@ -771,10 +771,10 @@ including `cl-block' and `cl-eval-when'."
         (insert " Inherits from ")
         (while (setq cur (pop pl))
           (setq cur (cl--class-name cur))
-          (insert (substitute-command-keys "‘"))
+          (insert (format "‘"))
           (help-insert-xref-button (symbol-name cur)
                                    'cl-help-type cur)
-          (insert (substitute-command-keys (if pl "’, " "’"))))
+          (insert (format (if pl "’, " "’"))))
         (insert ".\n")))
 
     ;; Children, if available.  ¡For EIEIO!
@@ -785,10 +785,10 @@ including `cl-block' and `cl-eval-when'."
       (when ch
         (insert " Children ")
         (while (setq cur (pop ch))
-          (insert (substitute-command-keys "‘"))
+          (insert (format "‘"))
           (help-insert-xref-button (symbol-name cur)
                                    'cl-help-type cur)
-          (insert (substitute-command-keys (if ch "’, " "’"))))
+          (insert (format (if ch "’, " "’"))))
         (insert ".\n")))
 
     ;; Type's documentation.
@@ -804,10 +804,10 @@ including `cl-block' and `cl-eval-when'."
       (when generics
         (insert (propertize "Specialized Methods:\n\n" 'face 'bold))
         (dolist (generic generics)
-          (insert (substitute-command-keys "‘"))
+          (insert (format "‘"))
           (help-insert-xref-button (symbol-name generic)
                                    'help-function generic)
-          (insert (substitute-command-keys "’"))
+          (insert (format "’"))
           (pcase-dolist (`(,qualifiers ,args ,doc)
                          (cl--generic-method-documentation generic type))
             (insert (format " %s%S\n" qualifiers args)
index a138697a18b3f990267c0cddfcd1b9b18b2c9f22..7ae63b1e6b1bca46981965683747ea06af79a77d 100644 (file)
@@ -864,11 +864,11 @@ MET-NAME is a cons (SYMBOL . SPECIALIZERS)."
                                    (cl--generic-method-specializers method)))
                    (file (find-lisp-object-file-name met-name 'cl-defmethod)))
               (when file
-                (insert (substitute-command-keys " in ‘"))
+                (insert (format " in ‘"))
                 (help-insert-xref-button (help-fns-short-filename file)
                                          'help-function-def met-name file
                                          'cl-defmethod)
-                (insert (substitute-command-keys "’.\n"))))
+                (insert (format "’.\n"))))
             (insert "\n" (or (nth 2 info) "Undocumented") "\n\n")))))))
 
 (defun cl--generic-specializers-apply-to-type-p (specializers type)
index 0b003360ed5a2f0cf2908612910f4cdefc779ad2..c4d6d35a13b9f5eb11c039fe6f26a1478aa18bbb 100644 (file)
@@ -141,11 +141,11 @@ are not abstract."
        (setq location
              (find-lisp-object-file-name ctr def)))
       (when location
-       (insert (substitute-command-keys " in ‘"))
+       (insert (format " in ‘"))
        (help-insert-xref-button
         (help-fns-short-filename location)
         'cl-type-definition ctr location 'define-type)
-       (insert (substitute-command-keys "’")))
+       (insert (format "’")))
       (insert ".\nCreates an object of class " (symbol-name ctr) ".")
       (goto-char (point-max))
       (if (autoloadp def)
index 967720881f652f29b6abc1fbb95f6040dc7094cb..863a02df252ea21af8067b193c81241f3ade68d1 100644 (file)
@@ -2204,7 +2204,7 @@ Otherwise no newline is inserted."
                                    "Installed"
                                  (capitalize status))
                                'font-lock-face 'package-status-builtin-face))
-           (insert (substitute-command-keys " in ‘"))
+           (insert (format " in ‘"))
            (let ((dir (abbreviate-file-name
                        (file-name-as-directory
                         (if (file-in-directory-p pkg-dir package-user-dir)
@@ -2213,11 +2213,10 @@ Otherwise no newline is inserted."
              (help-insert-xref-button dir 'help-package-def pkg-dir))
            (if (and (package-built-in-p name)
                     (not (package-built-in-p name version)))
-               (insert (substitute-command-keys
-                        "’,\n             shadowing a ")
+               (insert (format "’,\n             shadowing a ")
                        (propertize "built-in package"
                                    'font-lock-face 'package-status-builtin-face))
-             (insert (substitute-command-keys "’")))
+             (insert (format "’")))
            (if signed
                (insert ".")
              (insert " (unsigned)."))
index 511b35412655bc485d37e02f78c76ed0a4372b15..125b14d8085e2387bc97ef0b4ce7968fbdf8a77b 100644 (file)
@@ -1435,12 +1435,10 @@ If FRAME is omitted or nil, use the selected frame."
                  (when alias
                    (setq face alias)
                    (insert
-                    (format (substitute-command-keys
-                              "\n  %s is an alias for the face ‘%s’.\n%s")
+                    (format "\n  %s is an alias for the face ‘%s’.\n%s"
                             f alias
                             (if (setq obsolete (get f 'obsolete-face))
-                                (format (substitute-command-keys
-                                          "  This face is obsolete%s; use ‘%s’ instead.\n")
+                                (format "  This face is obsolete%s; use ‘%s’ instead.\n"
                                         (if (stringp obsolete)
                                             (format " since %s" obsolete)
                                           "")
@@ -1458,13 +1456,11 @@ If FRAME is omitted or nil, use the selected frame."
                    (help-xref-button 1 'help-customize-face f)))
                (setq file-name (find-lisp-object-file-name f 'defface))
                (when file-name
-                 (princ (substitute-command-keys "Defined in ‘"))
-                 (princ (file-name-nondirectory file-name))
-                 (princ (substitute-command-keys "’"))
+                 (princ (format "Defined in ‘%s’"
+                                 (file-name-nondirectory file-name)))
                  ;; Make a hyperlink to the library.
                  (save-excursion
-                   (re-search-backward
-                     (substitute-command-keys "‘\\([^‘’]+\\)’") nil t)
+                   (re-search-backward (format "‘\\([^‘’]+\\)’") nil t)
                    (help-xref-button 1 'help-face-def f file-name))
                  (princ ".")
                  (terpri)
index 0836c7f6710cbea3f2e7f7ab92aab2e83befec2e..c97647c2d41e0801fdf9dd0f16fbaa07f9dc201f 100644 (file)
@@ -297,9 +297,7 @@ suitable file is found, return nil."
             (when remapped
               (princ "Its keys are remapped to ")
               (princ (if (symbolp remapped)
-                        (concat (substitute-command-keys "‘")
-                                (symbol-name remapped)
-                                (substitute-command-keys "’"))
+                         (format "‘%s’" remapped)
                       "an anonymous command"))
               (princ ".\n"))
 
@@ -333,18 +331,16 @@ suitable file is found, return nil."
       (insert "\nThis function has a compiler macro")
       (if (symbolp handler)
           (progn
-            (insert (format (substitute-command-keys " ‘%s’") handler))
+            (insert (format " ‘%s’" handler))
             (save-excursion
-              (re-search-backward (substitute-command-keys "‘\\([^‘’]+\\)’")
-                                  nil t)
+              (re-search-backward (format "‘\\([^‘’]+\\)’") nil t)
               (help-xref-button 1 'help-function handler)))
         ;; FIXME: Obsolete since 24.4.
         (let ((lib (get function 'compiler-macro-file)))
           (when (stringp lib)
-            (insert (format (substitute-command-keys " in ‘%s’") lib))
+            (insert (format " in ‘%s’" lib))
             (save-excursion
-              (re-search-backward (substitute-command-keys "‘\\([^‘’]+\\)’")
-                                  nil t)
+              (re-search-backward (format "‘\\([^‘’]+\\)’") nil t)
               (help-xref-button 1 'help-function-cmacro function lib)))))
       (insert ".\n"))))
 
@@ -399,13 +395,13 @@ suitable file is found, return nil."
                           (get function
                                'derived-mode-parent))))
     (when parent-mode
-      (insert (substitute-command-keys "\nParent mode: ‘"))
+      (insert (format "\nParent mode: ‘"))
       (let ((beg (point)))
         (insert (format "%s" parent-mode))
         (make-text-button beg (point)
                           'type 'help-function
                           'help-args (list parent-mode)))
-      (insert (substitute-command-keys "’.\n")))))
+      (insert (format "’.\n")))))
 
 (defun help-fns--obsolete (function)
   ;; Ignore lambda constructs, keyboard macros, etc.
@@ -421,9 +417,7 @@ suitable file is found, return nil."
       (when (nth 2 obsolete)
         (insert (format " since %s" (nth 2 obsolete))))
       (insert (cond ((stringp use) (concat ";\n" use))
-                    (use (format (substitute-command-keys
-                                  ";\nuse ‘%s’ instead.")
-                                 use))
+                    (use (format ";\nuse ‘%s’ instead." use))
                     (t "."))
               "\n"))))
 
@@ -459,8 +453,7 @@ FILE is the file where FUNCTION was probably defined."
                           (format ";\nin Lisp code %s" interactive-only))
                          ((and (symbolp 'interactive-only)
                                (not (eq interactive-only t)))
-                          (format (substitute-command-keys
-                                   ";\nin Lisp code use ‘%s’ instead.")
+                          (format ";\nin Lisp code use ‘%s’ instead."
                                   interactive-only))
                          (t "."))
                    "\n")))))
@@ -529,8 +522,7 @@ FILE is the file where FUNCTION was probably defined."
                 ;; Aliases are Lisp functions, so we need to check
                 ;; aliases before functions.
                 (aliased
-                 (format (substitute-command-keys "an alias for ‘%s’")
-                          real-def))
+                 (format "an alias for ‘%s’" real-def))
                 ((autoloadp def)
                  (format "%s autoloaded %s"
                          (if (commandp def) "an interactive" "an")
@@ -564,24 +556,22 @@ FILE is the file where FUNCTION was probably defined."
       (with-current-buffer standard-output
        (save-excursion
          (save-match-data
-           (when (re-search-backward (substitute-command-keys
-                                       "alias for ‘\\([^‘’]+\\)’")
+           (when (re-search-backward (format "alias for ‘\\([^‘’]+\\)’")
                                       nil t)
              (help-xref-button 1 'help-function real-def)))))
 
       (when file-name
-       (princ (substitute-command-keys " in ‘"))
+       (princ (format " in ‘"))
        ;; We used to add .el to the file name,
        ;; but that's completely wrong when the user used load-file.
        (princ (if (eq file-name 'C-source)
                   "C source code"
                 (help-fns-short-filename file-name)))
-       (princ (substitute-command-keys "’"))
+       (princ (format "’"))
        ;; Make a hyperlink to the library.
        (with-current-buffer standard-output
          (save-excursion
-           (re-search-backward (substitute-command-keys "‘\\([^‘’]+\\)’")
-                                nil t)
+           (re-search-backward (format "‘\\([^‘’]+\\)’") nil t)
            (help-xref-button 1 'help-function-def function file-name))))
       (princ ".")
       (with-current-buffer (help-buffer)
@@ -714,17 +704,14 @@ it is displayed along with the global value."
 
              (if file-name
                  (progn
-                   (princ (substitute-command-keys
-                            " is a variable defined in ‘"))
+                   (princ (format " is a variable defined in ‘"))
                    (princ (if (eq file-name 'C-source)
                               "C source code"
                             (file-name-nondirectory file-name)))
-                   (princ (substitute-command-keys "’.\n"))
+                   (princ (format "’.\n"))
                    (with-current-buffer standard-output
                      (save-excursion
-                       (re-search-backward (substitute-command-keys
-                                             "‘\\([^‘’]+\\)’")
-                                            nil t)
+                       (re-search-backward (format "‘\\([^‘’]+\\)’") nil t)
                        (help-xref-button 1 'help-variable-def
                                          variable file-name)))
                    (if valvoid
@@ -854,8 +841,7 @@ if it is given a local binding.\n")))
              ;; Mention if it's an alias.
               (unless (eq alias variable)
                 (setq extra-line t)
-                (princ (format (substitute-command-keys
-                                "  This variable is an alias for ‘%s’.\n")
+                (princ (format "  This variable is an alias for ‘%s’.\n"
                                alias)))
 
               (when obsolete
@@ -864,8 +850,7 @@ if it is given a local binding.\n")))
                 (if (nth 2 obsolete)
                     (princ (format " since %s" (nth 2 obsolete))))
                (princ (cond ((stringp use) (concat ";\n  " use))
-                            (use (format (substitute-command-keys
-                                           ";\n  use ‘%s’ instead.")
+                            (use (format ";\n  use ‘%s’ instead."
                                           (car obsolete)))
                             (t ".")))
                 (terpri))
@@ -896,7 +881,7 @@ if it is given a local binding.\n")))
                               ;; Otherwise, assume it was set directly.
                               (setq file (car file)
                                     dir-file nil)))
-                       (princ (substitute-command-keys
+                       (princ (format
                                 (if dir-file
                                     "by the file\n  ‘"
                                   "for the directory\n  ‘")))
@@ -904,7 +889,7 @@ if it is given a local binding.\n")))
                          (insert-text-button
                           file 'type 'help-dir-local-var-def
                           'help-args (list variable file)))
-                       (princ (substitute-command-keys "’.\n"))))
+                       (princ (format "’.\n"))))
                  (princ "  This variable's value is file-local.\n")))
 
              (when (memq variable ignored-local-variables)
@@ -928,8 +913,7 @@ file-local variable.\n")
                (princ "if its value\n  satisfies the predicate ")
                (princ (if (byte-code-function-p safe-var)
                           "which is a byte-compiled expression.\n"
-                        (format (substitute-command-keys "‘%s’.\n")
-                                 safe-var))))
+                        (format "‘%s’.\n" safe-var))))
 
               (if extra-line (terpri))
              (princ "Documentation:\n")
index 46136d91003748479e533cad36edd69290ab9d73..461a8ab898627d827b84d686279f963378243e9a 100644 (file)
@@ -964,14 +964,12 @@ documentation for the major and minor modes of that buffer."
        (let* ((mode major-mode)
               (file-name (find-lisp-object-file-name mode nil)))
          (when file-name
-           (princ (concat (substitute-command-keys " defined in ‘")
-                           (file-name-nondirectory file-name)
-                           (substitute-command-keys "’")))
+           (princ (format " defined in ‘%s’"
+                           (file-name-nondirectory file-name)))
            ;; Make a hyperlink to the library.
            (with-current-buffer standard-output
              (save-excursion
-               (re-search-backward (substitute-command-keys "‘\\([^‘’]+\\)’")
-                                    nil t)
+               (re-search-backward (format "‘\\([^‘’]+\\)’") nil t)
                (help-xref-button 1 'help-function-def mode file-name)))))
        (princ ":\n")
        (princ (documentation major-mode)))))
index 0b2c419de9911ba1b7abeee4c5d8767fc41ef475..67d4bca4a239ba29e48807ce8f40f2b5182b195b 100644 (file)
@@ -78,6 +78,11 @@ enum
   OBJECT_REPLACEMENT_CHARACTER = 0xFFFC,
 };
 
+/* UTF-8 encodings.  Use \x escapes, so they are portable to pre-C11
+   compilers and can be concatenated with ordinary string literals.  */
+#define uLSQM "\xE2\x80\x98" /* U+2018 LEFT SINGLE QUOTATION MARK */
+#define uRSQM "\xE2\x80\x99" /* U+2019 RIGHT SINGLE QUOTATION MARK */
+
 /* Nonzero iff C is a character that corresponds to a raw 8-bit
    byte.  */
 #define CHAR_BYTE8_P(c) ((c) > MAX_5_BYTE_CHAR)
index 9f0ddbc5260e833eebe1e49859a57cc3b0c2b8b2..977953d53e5b13f9f3ff8afe180f976070e45dba 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -687,8 +687,6 @@ the same file name is found in the `doc-directory'.  */)
 /* Curved quotation marks.  */
 static unsigned char const LSQM[] = { uLSQM0, uLSQM1, uLSQM2 };
 static unsigned char const RSQM[] = { uRSQM0, uRSQM1, uRSQM2 };
-#define uLSQM "\xE2\x80\x98"
-#define uRSQM "\xE2\x80\x99"
 
 /* Return the current effective text quoting style.  */
 enum text_quoting_style
@@ -922,14 +920,13 @@ Otherwise, return a new string.  */)
          if (NILP (tem))
            {
              name = Fsymbol_name (name);
-             insert1 (Fsubstitute_command_keys
-                      (build_string ("\nUses keymap "uLSQM)));
+             insert1 (CALLN (Fformat, build_string ("\nUses keymap "uLSQM)));
              insert_from_string (name, 0, 0,
                                  SCHARS (name),
                                  SBYTES (name), 1);
-             insert1 (Fsubstitute_command_keys
-                      (build_string
-                       (uRSQM", which is not currently defined.\n")));
+             insert1 (CALLN (Fformat,
+                             (build_string
+                              (uRSQM", which is not currently defined.\n"))));
              if (start[-1] == '<') keymap = Qnil;
            }
          else if (start[-1] == '<')
index d45936b2b28d267594eaedce34565f18c1c35826..d543a5f9823610c6af30412967b1325604c6e387 100644 (file)
@@ -1333,9 +1333,10 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
     insert_string (" (nestable)");
 
   if (prefix)
-    insert1 (Fsubstitute_command_keys
-            (build_string
-             (",\n\t  is a prefix character for `backward-prefix-chars'")));
+    insert1 (CALLN (Fformat,
+                   (build_string
+                    (",\n\t  is a prefix character for "
+                     uLSQM"backward-prefix-chars"uRSQM))));
 
   return syntax;
 }