emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 7570b35: (shr-insert): Respect non-breaking space i


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 7570b35: (shr-insert): Respect non-breaking space in non-<pre> text
Date: Fri, 25 Mar 2016 15:57:49 +0000

branch: master
commit 7570b35740915626e94c6038e3203374ce4267b1
Author: Lars Magne Ingebrigtsen <address@hidden>
Commit: Lars Magne Ingebrigtsen <address@hidden>

    (shr-insert): Respect non-breaking space in non-<pre> text
    
    * lisp/net/shr.el (shr-insert): Respect non-breaking space in
    non-<pre> 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(-)

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 6079415..3adc573 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 0000000..56282cf
--- /dev/null
+++ b/test/data/shr/nonbr.html
@@ -0,0 +1 @@
+<div class="gmail_extra">(progn</div><div class="gmail_extra">  (setq 
minibuffer-prompt-properties &#39;(read-only t cursor-intangible t face 
minibuffer-prompt))</div><div class="gmail_extra"><br></div><div 
class="gmail_extra">  (defun turn-on-cursor-intangible-mode ()</div><div 
class="gmail_extra">    &quot;Turns on cursor-intangible-mode.&quot;</div><div 
class="gmail_extra">    (interactive)</div><div class="gmail_extra">    
(cursor-intangible-mode 1))</div><div class="gmail_extra">  ( [...]
diff --git a/test/data/shr/nonbr.txt b/test/data/shr/nonbr.txt
new file mode 100644
index 0000000..0c3cffa
--- /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))



reply via email to

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