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

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

[emacs-wiki-discuss] heaps of unnecessary loops in planner-sort-tasks


From: Angus Lees
Subject: [emacs-wiki-discuss] heaps of unnecessary loops in planner-sort-tasks
Date: Mon, 04 Apr 2005 12:42:07 +1000
User-agent: Wanderlust/2.10.1 (Watching The Wheels) XEmacs/21.4 (Jumbo Shrimp)

The `save-excursion' around `sort-fields-1' in `planner-sort-tasks'
doesn't do whats intended, since point is moved to follow the text
changes.  For me (XEmacs 21.4), even in cases where the tasks are
already sorted, this seems to result in the pathological "call
sort-fields-1 again for *every* task" every time.

Since sorting doesn't change the overall length of text, its an easy
fix to manually save the point offset and restore it afterwards (patch
is against Debian 3.27-1):

(I haven't tested, but I suspect the (unless (eobp) (forward-char 1)))
may have been an attempted workaround for this behaviour and is now
unnecessary)

--- /usr/share/emacs/site-lisp/planner-el/planner.el    2005-02-18 
12:51:29.000000000 +1100
+++ /tmp/planner.el     2005-04-04 12:30:06.145839708 +1000
@@ -2039,16 +2039,17 @@
     (goto-char (point-min))
     (while (re-search-forward "^#[A-C][0-9]*" nil t)
       (goto-char (match-beginning 0))
-      (let ((here (point)))
+      (let ((here (point)) there)
         (while (and (char-after) (= (char-after) ?#))
           (forward-line 1))
         ;;        (let ((paragraph-start (concat paragraph-start "\\|\\*.+")))
         ;;          (forward-paragraph))
         ;; Sort by priority and position on date pages
-        (save-excursion
-          (sort-fields-1 1 here (point)
-                         planner-sort-tasks-key-function
-                         nil)))
+       (setq there (point))
+       (sort-fields-1 1 here there
+                        planner-sort-tasks-key-function
+                        nil)
+       (goto-char there))
       (unless (eobp)
         (forward-char 1))) ; sort-fields
     (goto-char old-point))

-- 
 - Gus




reply via email to

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