]> code.delx.au - gnu-emacs-elpa/commitdiff
Fill out code. loc-changes-goto now updates loc-changes-alist. Some
authorrocky <rocky@sanchez.(none)>
Wed, 16 Dec 2009 10:27:12 +0000 (05:27 -0500)
committerrocky <rocky@sanchez.(none)>
Wed, 16 Dec 2009 10:27:12 +0000 (05:27 -0500)
names have changed. loc-changes-clear-buffer is now interactive.

loc-changes.el
test/Makefile [new file with mode: 0644]
test/sample.txt [new file with mode: 0644]
test/test-basic.el

index f038bb48b5672fdaea730b2695ad54812f2621b1..9044d85d783db40d5962e1f03ed9cd24cf0edf67 100644 (file)
@@ -22,29 +22,29 @@ proclaim is okay to use in a Lisp program."
        line-number last-line))
     (goto-char (point-min))
     (forward-line (1- line-number)))
-)
-
+  )
 
-(defun loc-changes-add (line-number &optional opt-buffer)
+(defun loc-changes-add-and-goto (line-number &optional opt-buffer)
   "Add a marker at LINE-NUMBER and record LINE-NUMBER and its
 marker association in `loc-changes-alist'."
   (let ((buffer (or opt-buffer (current-buffer))))
     (with-current-buffer buffer
-      (loc-changes-goto-line buffer)
+      (loc-changes-goto-line line-number)
       (setq loc-changes-alist 
-           (cons line-number (point-marker)) 
-           loc-changes-alist)
+           (cons (cons line-number (point-marker))
+                 loc-changes-alist))
       ))
-)
+  )
 
-(defun loc-changes-clear (&optional opt-buffer)
+(defun loc-changes-clear-buffer (&optional opt-buffer)
   "Remove all location-tracking associations in BUFFER."
+  (interactive "bbuffer: ")
   (let ((buffer (or opt-buffer (current-buffer)))
        )
     (with-current-buffer buffer
       (setq loc-changes-alist '())
       ))
-)
+  )
 
 (defun loc-changes-resync (&optional opt-buffer)
   "Take existing marks and use the current (updated) positions for each of those.
@@ -59,7 +59,20 @@ so that its positions are will be reflected."
 previous location marks. Normally if the position hasn't been
 seen before, we will add a new mark for this position. However if
 NO-UPDATE is set, no mark is added."
-  (error "To be continued....")
+  (unless (wholenump position)
+    (error "Expecting line-number parameter `%s' to be a whole number"
+          position))
+  (let ((elt (assq position loc-changes-alist)))
+    (if elt
+       (let ((marker (cdr elt)))
+         (unless (markerp marker)
+           (error "Internal error: loc-changes-alist is not a marker"))
+         (goto-char (marker-position marker)))
+      (if no-update
+         (loc-changes-goto-line position)
+       (loc-changes-add-and-goto position))
+      )
+    )
   )
 
 (provide 'loc-changes)
diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..bc80236
--- /dev/null
@@ -0,0 +1,7 @@
+# Whatever it is you want to do, it should be forwarded to the 
+# to top-level irectories
+PHONY=check all
+all: check
+
+%: 
+       $(MAKE) -C .. $@
diff --git a/test/sample.txt b/test/sample.txt
new file mode 100644 (file)
index 0000000..7f07c10
--- /dev/null
@@ -0,0 +1,14 @@
+This is line 1
+This is line 2
+This is line 3
+This is line 4
+This is line 5
+This is line 6
+This is line 7
+This is line 8
+This is line 9
+This is line 10
+This is line 11
+This is line 12
+This is line 13
+This is line 14
index 0958c16161e66a102dfc49907aa47e3879d3232e..0e8528fc94badb7cdfc5fe24a6c5698c70a17ba3 100644 (file)
@@ -4,18 +4,57 @@
 
 (test-unit-clear-contexts)
 
-;; Define a test named `foo'.
+(setq sample-buffer (find-file-noselect "./sample.txt"))
 (context "basic-tests"
         (tag basic-tests)
-        (specify "loc-changes-goto-line error conditions"
-                 (assert-raises error (loc-changes-goto-line "foo"))
-                 (assert-raises error (loc-changes-goto-line 0))
-                 (assert-raises error (loc-changes-goto-line 10000)))
-        (specify "loc-changes-goto-line"
-                 (save-excursion
-                   (loc-changes-goto-line 5)
-                   (assert-equal 5 (line-number-at-pos (point)))))
+          (specify "loc-changes-goto-line error conditions"
+                   (assert-raises error (loc-changes-goto-line "foo"))
+                   (message "buffer %s" (current-buffer))
+                   (assert-raises error (loc-changes-goto-line 0))
+                   (assert-raises error (loc-changes-goto-line 10000)))
+          (specify "loc-changes-goto-line"
+                   (save-excursion
+                     (set-buffer sample-buffer)
+                     (loc-changes-goto-line 5)
+                     (assert-equal 5 (line-number-at-pos (point)))))
+          (specify "loc-changes-clear-buffer null"
+                   (loc-changes-clear-buffer)
+                   (assert-equal '() loc-changes-alist))
 
-)
+          (specify "loc-changes-add-and-goto - update"
+                   (save-excursion
+                     (set-buffer sample-buffer)
+                     (loc-changes-add-and-goto 10)
+                     (assert-equal 10 (line-number-at-pos)
+                                   "point should be at line 10")
+                     (assert-t (assq 10 loc-changes-alist)
+                               "Should find 10 in loc-changes-alist")
+                     (assert-t (markerp (cdr (assq 10 loc-changes-alist)))
+                               "10 in loc-changes-alist should be a marker"))
+                   )
+
+          (specify "loc-changes-goto - update"
+                   (save-excursion
+                     (set-buffer sample-buffer)
+                     (loc-changes-goto 11)
+                     (assert-equal 11 (line-number-at-pos)
+                                   "point should be at line 11")
+                     (assert-t (assq 11 loc-changes-alist)
+                               "Should find 11 in loc-changes-alist")
+                     (assert-t (markerp (cdr (assq 11 loc-changes-alist)))
+                               "11 in loc-changes-alist should be a marker"))
+                   )
+
+          (specify "loc-changes-goto - no update"
+                   (save-excursion
+                     (set-buffer sample-buffer)
+                     (loc-changes-goto 12 nil 't)
+                     (assert-equal 12 (line-number-at-pos)
+                                   "point should be at line 12")
+                     (assert-nil (assq 12 loc-changes-alist)
+                                 "Should not find 12 in loc-changes-alist")
+                     )
+                   )
+          )
 
 (test-unit "basic-tests")