emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/realgud 6706358 073/140: Add format specifier %q a la k


From: Rocky Bernstein
Subject: [elpa] externals/realgud 6706358 073/140: Add format specifier %q a la ksh...
Date: Sat, 25 May 2019 19:35:36 -0400 (EDT)

branch: externals/realgud
commit 6706358aa7adbfc6b551d8a2fd394287b01070e5
Author: rocky <address@hidden>
Commit: rocky <address@hidden>

    Add format specifier %q a la ksh...
    
    Used in nodejs exec(%q) for example
---
 realgud/common/send.el            | 23 +++++++++++++++++++----
 realgud/debugger/nodejs/init.el   |  2 +-
 realgud/debugger/trepanjs/init.el |  4 ++--
 test/gcd.js                       |  3 +--
 test/test-send.el                 |  3 +++
 5 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/realgud/common/send.el b/realgud/common/send.el
index 81edf16..4c112c1 100644
--- a/realgud/common/send.el
+++ b/realgud/common/send.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2015-2016 Free Software Foundation, Inc
+;; Copyright (C) 2015-2016, 2018 Free Software Foundation, Inc
 
 ;; Author: Rocky Bernstein <address@hidden>
 
@@ -140,6 +140,7 @@ taken from current buffer, or OPT-BUFFER if non-nil.  Some
   %c -- Fully qualified class name derived from the expression
         surrounding point.
   %p -- Value of OPT-STR, converted to string using `int-to-string'
+  %q -- Value of OPT-STR with string escapes (as ksh, bash, and zsh do).
   %s -- Value of OPT-STR.
 
 %p and %s are replaced by an empty string if OPT-STR is nil."
@@ -149,7 +150,7 @@ taken from current buffer, or OPT-BUFFER if non-nil.  Some
         result)
     (while (and fmt-str
                (let ((case-fold-search nil))
-                 (string-match "\\([^%]*\\)%\\([dfFlpxXs]\\)" fmt-str)))
+                 (string-match "\\([^%]*\\)%\\([dfFlpqxXs]\\)" fmt-str)))
       (let* ((key-str (match-string 2 fmt-str))
             (key (string-to-char key-str)))
        (setq result
@@ -179,20 +180,34 @@ taken from current buffer, or OPT-BUFFER if non-nil.  Some
                          (+ (count-lines (point-min) (point))
                             (if (bolp) 1 0)))))
                   "source-buffer-not-found-for-%l"))
+
+                ((eq key ?p) (if opt-str (int-to-string opt-str) ""))
+
+               ;; String with escapes. %q follows shell (ksh, bash, zsh)
+               ;; The other possibility was Python's %r, !r or "repr".
+               ;; That isn't as perfect a fit though.
+                ((eq key ?q) (if opt-str
+                                (let ((print-escape-newlines t))
+                                  (prin1-to-string opt-str))
+                                ""))
+
+               ;; String
+                ((eq key ?s) (or opt-str ""))
+
                ((eq key ?x)
                 (or (and src-file-name src-file-name)
                     "*source-file-not-found-for-%x"))
                ((eq key ?X)
                 (or (and src-file-name (expand-file-name src-file-name))
                     "*source-file-not-found-for-%X"))
+
                ;; ((eq key ?e)
                ;;  (gud-find-expr))
                ;; ((eq key ?a)
                ;;  (gud-read-address))
                ;; ((eq key ?c)
                ;;   (gud-find-class srcbuf))
-                ((eq key ?p) (if opt-str (int-to-string opt-str) ""))
-                ((eq key ?s) (or opt-str ""))
+
                 (t key)))))
       (setq fmt-str (substring fmt-str (match-end 2))))
     ;; There might be text left in FMT-STR when the loop ends.
diff --git a/realgud/debugger/nodejs/init.el b/realgud/debugger/nodejs/init.el
index 14b23ac..a095dec 100644
--- a/realgud/debugger/nodejs/init.el
+++ b/realgud/debugger/nodejs/init.el
@@ -167,7 +167,7 @@ realgud-loc-pat struct")
 (setf (gethash "quit"       realgud:nodejs-command-hash) "quit")
 (setf (gethash "finish"     realgud:nodejs-command-hash) "out")
 (setf (gethash "shell"      realgud:nodejs-command-hash) "repl")
-(setf (gethash "eval"       realgud:nodejs-command-hash) "exec('%s')")
+(setf (gethash "eval"       realgud:nodejs-command-hash) "exec(%q)")
 
 ;; We need aliases for step and next because the default would
 ;; do step 1 and nodejs doesn't handle this. And if it did,
diff --git a/realgud/debugger/trepanjs/init.el 
b/realgud/debugger/trepanjs/init.el
index 9f37b6f..881fcff 100644
--- a/realgud/debugger/trepanjs/init.el
+++ b/realgud/debugger/trepanjs/init.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2015-2016 Free Software Foundation, Inc
+;; Copyright (C) 2015-2016, 2018 Free Software Foundation, Inc
 
 ;; Author: Rocky Bernstein <address@hidden>
 
@@ -153,7 +153,7 @@ realgud-loc-pat struct")
 ;; We need aliases for step and next because the default would
 ;; do step 1 and trepanjs doesn't handle this. Or when it does,
 ;; it will probably look like step(1)
-(setf (gethash "eval"       realgud:trepanjs-command-hash) "eval('%s')")
+(setf (gethash "eval"       realgud:trepanjs-command-hash) "eval(%q)")
 (setf (gethash "quit"       realgud:trepanjs-command-hash) "quit()")
 
 ;; Unsupported features:
diff --git a/test/gcd.js b/test/gcd.js
index ee56555..901bb96 100644
--- a/test/gcd.js
+++ b/test/gcd.js
@@ -40,6 +40,5 @@ function gcd(a, b) {
 var a = parseInt(process.argv[0]) || 24,
     b = parseInt(process.argv[0]) || 5;
 
-console.log(util.format("The GCD of %d and %d is %d", a, b,
-                       gcd(a, b)));
+console.log(util.format("The GCD of %d and %d is %d", a, b, gcd(a, b)));
 process.exit();
diff --git a/test/test-send.el b/test/test-send.el
index 5eec304..5337a41 100644
--- a/test/test-send.el
+++ b/test/test-send.el
@@ -44,6 +44,9 @@
              (realgud-expand-format "h%s!" "i, rocky")
              "format %s")
 
+(assert-equal "\"\\\"fake\\\" news\"!"
+             (realgud-expand-format "%q!" "\"fake\" news"))
+
 (setup)
 ;; Current buffer is now set up as a source buffer
 (setq file-name (buffer-file-name))



reply via email to

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