From 7570b35740915626e94c6038e3203374ce4267b1 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Fri, 25 Mar 2016 16:57:35 +0100 Subject: [PATCH] (shr-insert): Respect non-breaking space in non-
 text

* lisp/net/shr.el (shr-insert): Respect non-breaking space in
non-
 text.
---
 lisp/net/shr.el          | 26 +++++++++++++++-----------
 test/data/shr/nonbr.html |  1 +
 test/data/shr/nonbr.txt  | 12 ++++++++++++
 3 files changed, 28 insertions(+), 11 deletions(-)
 create mode 100644 test/data/shr/nonbr.html
 create mode 100644 test/data/shr/nonbr.txt

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 60794158024..3adc57397cf 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -554,6 +554,16 @@ size, and full-buffer size."
       (insert string)
       (shr-pixel-column))))
 
+(defsubst shr--translate-insertion-chars ()
+  ;; Remove soft hyphens.
+  (goto-char (point-min))
+  (while (search-forward "­" nil t)
+    (replace-match "" t t))
+  ;; Translate non-breaking spaces into real spaces.
+  (goto-char (point-min))
+  (while (search-forward " " nil t)
+    (replace-match " " t t)))
+
 (defun shr-insert (text)
   (when (and (not (bolp))
 	     (get-text-property (1- (point)) 'image-url))
@@ -564,14 +574,11 @@ size, and full-buffer size."
       (insert text)
       (save-restriction
 	(narrow-to-region start (point))
-	;; Remove soft hyphens.
-	(goto-char (point-min))
-	(while (search-forward "­" nil t)
-	  (replace-match "" t t))
+        (shr--translate-insertion-chars)
 	(goto-char (point-max)))))
    (t
     (let ((font-start (point)))
-      (when (and (string-match "\\`[ \t\n\r ]" text)
+      (when (and (string-match "\\`[ \t\n\r]" text)
 		 (not (bolp))
 		 (not (eq (char-after (1- (point))) ? )))
 	(insert " "))
@@ -581,14 +588,11 @@ size, and full-buffer size."
 	(save-restriction
 	  (narrow-to-region start (point))
 	  (goto-char start)
-	  (when (looking-at "[ \t\n\r ]+")
+	  (when (looking-at "[ \t\n\r]+")
 	    (replace-match "" t t))
-	  (while (re-search-forward "[ \t\n\r ]+" nil t)
+	  (while (re-search-forward "[ \t\n\r]+" nil t)
 	    (replace-match " " t t))
-	  ;; Remove soft hyphens.
-	  (goto-char (point-min))
-	  (while (search-forward "­" nil t)
-	    (replace-match "" t t))
+          (shr--translate-insertion-chars)
 	  (goto-char (point-max)))
 	;; We may have removed everything we inserted if if was just
 	;; spaces.
diff --git a/test/data/shr/nonbr.html b/test/data/shr/nonbr.html
new file mode 100644
index 00000000000..56282cf4ca5
--- /dev/null
+++ b/test/data/shr/nonbr.html
@@ -0,0 +1 @@
+
(progn
  (setq minibuffer-prompt-properties '(read-only t cursor-intangible t face minibuffer-prompt))

  (defun turn-on-cursor-intangible-mode ()
    "Turns on cursor-intangible-mode."
    (interactive)
    (cursor-intangible-mode 1))
  (define-globalized-minor-mode global-cursor-intangible-mode cursor-intangible-mode turn-on-cursor-intangible-mode)

  (global-cursor-intangible-mode 1))

diff --git a/test/data/shr/nonbr.txt b/test/data/shr/nonbr.txt new file mode 100644 index 00000000000..0c3cffa93f9 --- /dev/null +++ b/test/data/shr/nonbr.txt @@ -0,0 +1,12 @@ +(progn + (setq minibuffer-prompt-properties '(read-only t cursor-intangible t face +minibuffer-prompt)) + + (defun turn-on-cursor-intangible-mode () + "Turns on cursor-intangible-mode." + (interactive) + (cursor-intangible-mode 1)) + (define-globalized-minor-mode global-cursor-intangible-mode +cursor-intangible-mode turn-on-cursor-intangible-mode) + + (global-cursor-intangible-mode 1)) -- 2.39.2