emacs-wiki-discuss
[Top][All Lists]
Advanced

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

[emacs-wiki-discuss] [patch] Counting bug in muse-publish-escape-special


From: Sacha Chua
Subject: [emacs-wiki-discuss] [patch] Counting bug in muse-publish-escape-specials
Date: Thu, 29 Dec 2005 16:23:52 +0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

muse-publish-escape-specials limits itself to beg and end. However,
inserting characters without updating end causes this function to
occasionally miss later characters that need to be escaped. Solution A
is to use save-restriction and then narrow to the region, checking
against (point-max).

--- orig/lisp/muse-publish.el
+++ mod/lisp/muse-publish.el
@@ -755,17 +755,18 @@
           ((symbolp specials)
            (setq specials (symbol-value specials))))
     (save-excursion
-      (goto-char beg)
-      (while (< (point) end)
-        (if (and (not ignore-read-only) (get-text-property (point) 'read-only))
-            (goto-char (next-single-property-change (point) 'read-only))
-          (let (repl)
-            (setq repl (or (assoc (char-after) specials)
-                           (assoc (char-after) muse-publish-markup-specials)))
-            (if (null repl)
-                (forward-char 1)
-              (delete-char 1)
-              (insert-before-markers (cdr repl)))))))))
+      (save-restriction
+        (narrow-to-region beg end)
+        (while (not (eobp))
+          (if (and (not ignore-read-only) (get-text-property (point) 
'read-only))
+              (goto-char (next-single-property-change (point) 'read-only))
+            (let (repl)
+              (setq repl (or (assoc (char-after) specials)
+                             (assoc (char-after) 
muse-publish-markup-specials)))
+              (if (null repl)
+                  (forward-char 1)
+                (delete-char 1)
+                (insert-before-markers (cdr repl))))))))))
 
 (defun muse-publish-markup-word ()
   (let* ((beg (match-beginning 2))

Solution B is to do some arithmetic.

--- orig/lisp/muse-publish.el
+++ mod/lisp/muse-publish.el
@@ -765,6 +765,7 @@
             (if (null repl)
                 (forward-char 1)
               (delete-char 1)
+              (setq end (+ end (length (cdr repl)) -1))
               (insert-before-markers (cdr repl)))))))))
 
 (defun muse-publish-markup-word ()

Other functions might have the same bug. muse-publish-verse-tag and
muse-publish-surround-text look a bit suspicious.
-- 
Sacha Chua <address@hidden> - open source, free software geekette
http://sacha.free.net.ph/ - PGP Key ID: 0xE7FDF77C
interests: emacs, gnu/linux, personal information management, public speaking
sachac on irc.freenode.net#emacs . YM: sachachua83




reply via email to

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