Hi everybody!
there is an error in the last revision, this is a patch that correct
that and add the possibility to yank from one sublist to the other in 
dvc-bookmarks.
Here is the patch waiting the last revision.

# HG changeset patch
# User Thierry Volpiatto <thierry dot volpiatto hat gmail dot com>
# Date 1210684303 -7200
# Node ID 5f42b3641933c0e90c5c7cae6cf686247ec81805
# Parent  6742bff8851e03eccf3271d7a79ce3a54eb6f41f
Implement yank from sub to sub,keep point at the yank place.

Fixme ==> yank-index when yanking in the same sub

diff --git a/dvc-bookmarks.el b/dvc-bookmarks.el
--- a/dvc-bookmarks.el
+++ b/dvc-bookmarks.el
@@ -314,8 +314,8 @@
     (dolist (x dvc-bookmark-alist)
       (setq head (car x))
       (font-lock-add-keywords nil `((,head . font-lock-variable-name-face)))))
-  (font-lock-add-keywords nil '(("^  [a-zA-Z-_0-9\.]*" . font-lock-doc-face)))
-  (font-lock-add-keywords nil '(("^    [Partner]* [~/a-zA-Z-_\.\:/]*" . 
font-lock-function-name-face))))
+  (font-lock-add-keywords nil '(("^  [a-zA-Z\-_0-9\.]*" . font-lock-doc-face)))
+  (font-lock-add-keywords nil '(("^    [Partner]* [~/a-zA-Z\-_0-9\.\:/]*" . 
font-lock-function-name-face))))
 
 (defun dvc-bookmarks-quit ()
   "Clean dvc-bookmarks-hidden-subtree
@@ -612,7 +612,8 @@
                                              dvc-bookmark-alist)
                        (dvc-get-parent-elm (aref dvc-bookmarks-tmp-yank-item 1)
                                            dvc-bookmark-alist)))
-         (child-alist (cadr (assoc parent-elm dvc-bookmark-alist))))
+         (child-alist (cadr (assoc parent-elm dvc-bookmark-alist)))
+         (cur-pos (point)))
     (cond ((and (member killed-elm dvc-bookmark-alist)
                 (member yank-point dvc-bookmark-alist))
            (dvc-bookmarks-yank-from-list-to-list))
@@ -622,8 +623,11 @@
           ((and (member killed-elm child-alist)
                 (member yank-point dvc-bookmark-alist))
            (dvc-bookmarks-yank-from-sub-to-list))
-          (t (message "This yank is not implemented yet sorry!")))))
-
+          ((and (not (member killed-elm dvc-bookmark-alist))
+                (not (member yank-point dvc-bookmark-alist)))
+           (dvc-bookmarks-yank-from-sub-to-sub))
+          (t (message "This yank is not implemented yet sorry!")))
+      (goto-char cur-pos)))
 
 (defun dvc-bookmarks-yank-from-list-to-sub ()
   "Yank from list ==> sublist"
@@ -633,16 +637,22 @@
          (parent (dvc-get-parent-elm (aref (dvc-bookmarks-current-bookmark) 1)
                                      dvc-bookmark-alist))
          (sublist (assoc parent dvc-bookmark-alist))
-         ; get index of sub and store it
+         ;; get index of sub and store it
          (sub-index (dvc-get-index-el-list sublist dvc-bookmark-alist))
          (child-dvc-bookmark-alist (cadr sublist))
-         (alist-nosub (remove sublist dvc-bookmark-alist))
-         ; move elm at the root of sublist
+         (alist-nosub (remove sublist dvc-bookmark-alist)) 
+         (which-list (cond ((member elm-at-point child-dvc-bookmark-alist)
+                            child-dvc-bookmark-alist)
+                           ((member elm-at-point sublist)
+                            sublist)
+                           (t dvc-bookmark-alist)))
+         (yank-index (dvc-get-index-el-list elm-at-point which-list))
+         ;; move elm at the root of sublist
          (tmp-alist (dvc-move-elm-in-list-or-sublist elm-to-move
                                                      dvc-bookmark-alist
                                                      1
                                                      sublist)))
-    ; now move elm in the '(children)
+    ;; now move elm in the '(children)
     (setq sublist
           (dvc-move-elm-in-list-or-sublist elm-to-move
                                            (assoc parent tmp-alist)
@@ -650,7 +660,7 @@
                                            child-dvc-bookmark-alist))
     (when (not (consp (nth 1 sublist))) ; hack to fix a small bug in backend 
func
       (setq sublist (remove (nth 1 sublist) sublist)))
-    ; replace the sublist modified to initial place
+    ;; replace the sublist modified to initial place
     (setq dvc-bookmark-alist
           (dvc-add-to-list-at-ind sublist alist-nosub sub-index))
     (setq dvc-bookmark-alist
@@ -658,7 +668,6 @@
     (ewoc-refresh dvc-bookmarks-cookie))
   (dvc-bookmarks-save)
   (dvc-bookmarks))
-
 
 (defun dvc-bookmarks-yank-from-sub-to-list ()
   "Yank from sublist ==> list"
@@ -668,34 +677,27 @@
          (parent (dvc-get-parent-elm (aref dvc-bookmarks-tmp-yank-item 1)
                                      dvc-bookmark-alist))
          (sublist (assoc parent dvc-bookmark-alist))
-         ;get index of sublist and store it
+         ;; get index of sublist and store it
          (sub-index (dvc-get-index-el-list sublist dvc-bookmark-alist))
          (child-dvc-bookmark-alist (cadr sublist))
-         (alist-nosub (remove sublist dvc-bookmark-alist))
-         (which-list (cond ((member elm-at-point child-dvc-bookmark-alist)
-                            child-dvc-bookmark-alist)
-                           ((member elm-at-point sublist)
-                            sublist)
-                           ((member elm-at-point dvc-bookmark-alist)
-                            dvc-bookmark-alist)
-                           (t (message "no family %s for this elm" parent))))
-         (yank-index (dvc-get-index-el-list elm-at-point which-list))
-         ;now move elm out of '(children)
+         (alist-nosub (remove sublist dvc-bookmark-alist)) 
+         (yank-index (dvc-get-index-el-list elm-at-point dvc-bookmark-alist))
+         ;; now move elm out of '(children)
          (tmp-sublist (dvc-move-elm-in-list-or-sublist elm-to-move
                                                        sublist
                                                        1
                                                        
child-dvc-bookmark-alist))
          (tmp-alist nil))
-    ; replace the sublist modified to initial place
+    ;; replace the sublist modified to initial place
     (setq tmp-alist (dvc-add-to-list-at-ind tmp-sublist alist-nosub sub-index))
-    ; now move elm to root of dvc-bookmark-alist
+    ;; now move elm to root of dvc-bookmark-alist
     (if (member elm-to-move child-dvc-bookmark-alist)
-        ; elm-to-move was in child
+        ;; elm-to-move was in child
         (setq dvc-bookmark-alist (dvc-move-elm-in-list-or-sublist elm-to-move
                                                                   tmp-alist
                                                                   yank-index
                                                                   tmp-sublist))
-      ; elm-to-move was in sublist ("home-dir"...)
+      ;; elm-to-move was in sublist ("home-dir"...)
       (setq dvc-bookmark-alist (dvc-move-elm-in-list-or-sublist elm-to-move
                                                                 
dvc-bookmark-alist
                                                                 yank-index
@@ -704,10 +706,90 @@
   (dvc-bookmarks-save)
   (dvc-bookmarks))
 
-;; TODO create function to yank from sub to sub
-;; Two cases:
-;; - yank in the same sublist
-;; - yank from one sublist to another sublist
+(defun dvc-bookmarks-yank-from-sub-to-sub ()
+  "Yank from one sublist to another sublist,
+or in the same sublist"
+  (interactive)
+  (let* ((elm-to-move (aref dvc-bookmarks-tmp-yank-item 3))
+         (elm-at-point (aref (dvc-bookmarks-current-bookmark) 3))
+         (parent-from (dvc-get-parent-elm (aref dvc-bookmarks-tmp-yank-item 1)
+                                          dvc-bookmark-alist))
+         (parent-to (dvc-get-parent-elm (aref (dvc-bookmarks-current-bookmark) 
1)
+                                        dvc-bookmark-alist))
+         (sublist1 (assoc parent-from dvc-bookmark-alist))
+         (sublist2 (assoc parent-to dvc-bookmark-alist))
+         (sub-index (dvc-get-index-el-list sublist1 dvc-bookmark-alist))
+         (sub-index2 (dvc-get-index-el-list sublist2 dvc-bookmark-alist))
+         ;; index point (yank here + 1)
+         (yank-index (dvc-get-index-el-list elm-at-point (cadr sublist2)))
+         ;; dvc-bookmark-alist without sublist1
+         (alist-nosub (remove sublist1 dvc-bookmark-alist))
+         ;; initial sublist with elm-to-move at root of sublist
+         (tmp-sublist (dvc-move-elm-in-list-or-sublist elm-to-move
+                                                       sublist1
+                                                       1
+                                                       (cadr sublist1)))
+         ;; replace sublist1 modified to initial place
+         (tmp-alist (dvc-add-to-list-at-ind tmp-sublist
+                                            alist-nosub
+                                            sub-index))
+         ;; the new alist without sub2
+         (alist-nosub2 nil))
+    ;; check now if we yank in the same sub or an external one
+    (if (equal parent-from parent-to)
+        ;; we yank in the same sub
+        (progn
+          ;; move elm-to-move in child
+          ;; TODO: fix ==>yank-index + 1 produce nil.
+          (setq sublist1
+                (dvc-move-elm-in-list-or-sublist elm-to-move
+                                                 tmp-sublist
+                                                 yank-index
+                                                 (cadr tmp-sublist)))
+          (setq dvc-bookmark-alist
+                (dvc-add-to-list-at-ind sublist1
+                                        alist-nosub
+                                        sub-index)))
+      ;; else: we yank in another sub
+      ;; now move elm-to-move to root of dvc-bookmark-alist
+      (setq tmp-alist
+            (dvc-move-elm-in-list-or-sublist elm-to-move
+                                             tmp-alist
+                                             1
+                                             tmp-sublist))
+      ;; now move elm-to-move to root of sub2
+      (setq tmp-alist
+            (dvc-move-elm-in-list-or-sublist elm-to-move
+                                             tmp-alist
+                                             1
+                                             sublist2))
+      
+      ;; now move elm-to-move to child of sub2 at yank-index
+      (setq sublist2
+            (dvc-move-elm-in-list-or-sublist elm-to-move
+                                             (assoc parent-to tmp-alist)
+                                             (+ 1 yank-index)
+                                             (cadr sublist2)))
+      ;; create now a new dvc-bookmark-alist with the sub2 modified
+      (when (not (consp (nth 1 sublist2))) ; hack to fix a small bug in 
backend func
+        (setq sublist2 (remove (nth 1 sublist2) sublist2)))
+      ;; at this point we have just to remove elm-to-move from sub1
+      (setq dvc-bookmark-alist
+            (dvc-add-to-list-at-ind (remove elm-to-move (assoc parent-from 
tmp-alist))
+                                    alist-nosub
+                                    sub-index))
+      ;; set an alist without old sub2
+      (setq alist-nosub2
+            (remove (assoc parent-to dvc-bookmark-alist)
+                    dvc-bookmark-alist))
+      ;; add new sublist2 to the alist without sub2
+      (setq dvc-bookmark-alist
+            (dvc-add-to-list-at-ind sublist2
+                                    alist-nosub2
+                                    sub-index2)))
+    (ewoc-refresh dvc-bookmarks-cookie))
+  (dvc-bookmarks-save)
+  (dvc-bookmarks))
 
 (defun dvc-bookmarks-yank-from-list-to-list ()
   "Yank inside dvc-bookmark-alist: list ==> list"
@@ -773,6 +855,15 @@
         (dvc-bookmarks))
     (message "Please move first this element to root and then delete it")
     (dvc-bookmarks)))
+
+;; (defun dvc-bookmarks-kill ()
+;;   "kill or cut bookmark
+;; non destructive function
+;; use it to kill/yank"
+;;   (interactive)
+;;   (setq dvc-bookmarks-tmp-yank-item (dvc-bookmarks-current-bookmark))
+;;   (let ((buffer-read-only nil))
+;;     (dvc-ewoc-delete dvc-bookmarks-cookie (ewoc-locate 
dvc-bookmarks-cookie))))
 
 (defun dvc-bookmarks-kill ()
   "kill or cut bookmark

-- 
A + Thierry
Pub key: http://pgp.mit.edu


_______________________________________________
Dvc-dev mailing list
[email protected]
https://mail.gna.org/listinfo/dvc-dev

Reply via email to