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

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

[elpa] externals/hyperbole de9e60f 09/50: Fix bug#43692, failed to do su


From: Stefan Monnier
Subject: [elpa] externals/hyperbole de9e60f 09/50: Fix bug#43692, failed to do substitute fixed case for path variables
Date: Wed, 17 Mar 2021 18:44:13 -0400 (EDT)

branch: externals/hyperbole
commit de9e60fd665d43c174aaaf6e1d6972df12e7630d
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>

    Fix bug#43692, failed to do substitute fixed case for path variables
---
 Changes  | 24 +++++++++++++++++++-----
 hpath.el | 30 ++++++++++++++++++++----------
 hypb.el  | 12 ++++++++++--
 3 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/Changes b/Changes
index 9b0e86e..ef22b51 100644
--- a/Changes
+++ b/Changes
@@ -1,8 +1,22 @@
 2020-10-18  Bob Weiner  <rsw@gnu.org>
 
-* kotl/kotl-mode.el (kotl-mode:action-key): Add Org table support.
-                    (kotl-mode): Automatically enable orgtbl-mode
-    minor mode.  Force load of org-table and kotl-orgtbl for this.
+* hypb.el  (hypb:replace-match-string):
+  hpath.el (hpath:substitute-match-value):
+    Added optional 5th arg, fixedcase, which can be used to prevent
+    case changes in replaced strings.
+           (hpath:substitute-var-name, hpath:is-p,
+            hpath:substitute-match-value): Used fixedcase arg in
+    hypb:replace-match-string calls.
+           (hpath:substitute-value): Used fixedcase arg in
+    hpath:substitute-match-value call.
+           (hpath:is-p): Handle empty string return value from
+    hpath:substitute-value call.
+    These changes fixed improper path variable subst where the path
+    contains mixed case characters.
+
+* kotl/kotl-mode.el (kotl-mode:action-key): Added Org table support.
+                    (kotl-mode): Automatically enabled orgtbl-mode
+    minor mode.  Forced load of org-table and kotl-orgtbl for this.
                     (kotl-mode-map): Bound demotion and promotion of trees
     to all of the following (inside Org Table is when orgtbl-mode minor
     mode is active and point is in a table):
@@ -24,8 +38,8 @@
 * Makefile (EL_KOTL, ELC_COMPILE): Added kotl/kotl-orgtbl.{el,elc}.
   kotl/kotl-orgtbl.el (orgtbl-tab): Added to support Org Table minor-mode use
     in Koutlines.
-  kotl/kotl-mode.el (hsys-orgtbl): Require this new library.
-                    (kotl-mode-map): Bind M- arrow keys to closely match those
+  kotl/kotl-mode.el (hsys-orgtbl): Required this new library.
+                    (kotl-mode-map): Bound M- arrow keys to closely match those
     in Org mode for tree promotion/demotion and moving text lines up and down.
 
 2020-10-10  Bob Weiner  <rsw@gnu.org>
diff --git a/hpath.el b/hpath.el
index 8585d04..b6fb209 100644
--- a/hpath.el
+++ b/hpath.el
@@ -1147,7 +1147,9 @@ path form is what is returned for PATH."
                                             suffix)
                                suffix nil)
                          t)
-                (setq path (hpath:substitute-value path)))
+                (setq path (hpath:substitute-value path))
+                (unless (string-empty-p path)
+                  path))
             t)
           (not (string-match "[\t\n\r\"`'|{}\\]" path))
           (let ((rtn-path path))
@@ -1209,8 +1211,8 @@ path form is what is returned for PATH."
                      ;; Quote any % except for one %s at the end of the
                      ;; path part of rtn-path (immediately preceding a #
                      ;; or , character or the end of string).
-                     (setq rtn-path (hypb:replace-match-string "%" rtn-path 
"%%")
-                           rtn-path (hypb:replace-match-string 
"%%s\\([#,]\\|\\'\\)" rtn-path "%s\\1"))
+                     (setq rtn-path (hypb:replace-match-string "%" rtn-path 
"%%" nil t)
+                           rtn-path (hypb:replace-match-string 
"%%s\\([#,]\\|\\'\\)" rtn-path "%s\\1" nil t))
                      ;; Return path if non-nil return value.
                      (if (stringp suffix) ;; suffix could = t, which we ignore
                          (if (string-match (concat (regexp-quote suffix) "%s") 
rtn-path)
@@ -1330,7 +1332,7 @@ in-buffer path will not match."
                           (hpath:substitute-dir var-name rest-of-path)
                         (error rest-of-path)))
            var-group)))
-      t)))
+      t t)))
 
 (defun hpath:substitute-var (path)
   "Replace up to one match in PATH with the first variable from 
`hpath:variables' whose value contain a string match to PATH.
@@ -1775,13 +1777,22 @@ local pathname."
                      (concat "$\{" var-name "\}/" rest-of-path)))))
          (t (error "(hpath:substitute-dir): Value of VAR-NAME, \"%s\", must be 
a string or list" var-name)))))
 
-(defun hpath:substitute-match-value (regexp str newtext &optional literal)
+(defun hpath:substitute-match-value (regexp str newtext &optional literal 
fixedcase)
   "Replace all matches for REGEXP in STR with NEWTEXT string and return the 
result.
+
 Optional LITERAL non-nil means do a literal replacement.
 Otherwise treat \\ in NEWTEXT string as special:
   \\& means substitute original matched text,
   \\N means substitute match for \(...\) number N,
   \\\\ means insert one \\.
+
+If optional fifth arg FIXEDCASE is non-nil, do not alter the case of
+the replacement text.  Otherwise, maybe capitalize the whole text, or
+maybe just word initials, based on the replaced text.  If the replaced
+text has only capital letters and has at least one multiletter word,
+convert NEWTEXT to all caps.  Otherwise if all words are capitalized
+in the replaced text, capitalize each word in NEWTEXT.
+
 NEWTEXT may instead be a function of one argument (the string to replace in)
 that returns a replacement string."
   (unless (stringp str)
@@ -1803,7 +1814,7 @@ that returns a replacement string."
              (cond ((functionp newtext)
                     (hypb:replace-match-string
                      regexp (substring str match start)
-                     (funcall newtext str) literal))
+                     (funcall newtext str) literal fixedcase))
                    (literal newtext)
                    (t (mapconcat
                         (lambda (c)
@@ -1813,8 +1824,7 @@ that returns a replacement string."
                                        ((eq c ?&)
                                         (match-string 0 str))
                                        ((and (>= c ?0) (<= c ?9))
-                                        (if (> c (+ ?0 (length
-                                                        (match-data))))
+                                        (if (> c (+ ?0 (length (match-data))))
                                             ;; Invalid match num
                                             (error 
"(hypb:replace-match-string) Invalid match num: %c" c)
                                           (setq c (- c ?0))
@@ -1830,13 +1840,13 @@ that returns a replacement string."
 (defun hpath:substitute-var-name (var-symbol var-dir-val path)
   "Replace with VAR-SYMBOL any occurrences of VAR-DIR-VAL in PATH.
 Replacement is done iff VAR-DIR-VAL is an absolute path.
-If PATH is modified, returns PATH, otherwise returns nil."
+If PATH is modified, return PATH, otherwise return nil."
   (when (and (stringp var-dir-val) (file-name-absolute-p var-dir-val))
     (let ((new-path (hypb:replace-match-string
                     (regexp-quote (file-name-as-directory
                                    (or var-dir-val default-directory)))
                     path (concat "$\{" (symbol-name var-symbol) "\}/")
-                    t)))
+                    t t)))
       (if (equal new-path path) nil new-path))))
 
 
diff --git a/hypb.el b/hypb.el
index 5522c33..a2b8ac5 100644
--- a/hypb.el
+++ b/hypb.el
@@ -523,13 +523,21 @@ WINDOW pixelwise."
        ((symbolp object)
         (get object 'hyperbole))))
 
-(defun hypb:replace-match-string (regexp str newtext &optional literal)
+(defun hypb:replace-match-string (regexp str newtext &optional literal 
fixedcase)
   "Replace all matches for REGEXP in STR with NEWTEXT string and return the 
result.
 Optional LITERAL non-nil means do a literal replacement.
 Otherwise treat \\ in NEWTEXT string as special:
   \\& means substitute original matched text,
   \\N means substitute match for \(...\) number N,
   \\\\ means insert one \\.
+
+If optional fifth arg FIXEDCASE is non-nil, do not alter the case of
+the replacement text.  Otherwise, maybe capitalize the whole text, or
+maybe just word initials, based on the replaced text.  If the replaced
+text has only capital letters and has at least one multiletter word,
+convert NEWTEXT to all caps.  Otherwise if all words are capitalized
+in the replaced text, capitalize each word in NEWTEXT.
+
 NEWTEXT may instead be a function of one argument (the string to replace in)
 that returns a replacement string."
   (unless (stringp str)
@@ -537,7 +545,7 @@ that returns a replacement string."
   (unless (or (stringp newtext) (functionp newtext))
     (error "(hypb:replace-match-string): 3rd arg must be a string or function: 
%s"
           newtext))
-  (replace-regexp-in-string regexp newtext str nil literal))
+  (replace-regexp-in-string regexp newtext str fixedcase literal))
 
 (defun hypb:return-process-output (program &optional infile &rest args)
   "Return as a string the output from external PROGRAM with INFILE for input.



reply via email to

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