Subject: bug#20177: 24.4: bookmark.el: show all annotations does not display in proper order (FIX INCLUDED)

From: Boruch Baum <[email-masked]>
Date: Mon, 23 Mar 2015 06:21:49 -0400

When `bookmark-sort-flag' is set, the bmenu list displays in sorted
order, but the function `bookmark-show-all-annotations' (keybinding
`A'), does not.

The first attached patch file, `simple.patch', is just that.

The second attached patch file, `fancy.patch', adds an option to display
the list of all annotations as a pre-formatted org-mode buffer, based
upon the setting of a new variable,
`bookmark-show-all-annotations-in-org-mode'.

-- 
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0

--- bookmark.el	2015-03-23 04:52:30.503739608 -0400
+++ bookmark-new.el	2015-03-23 05:15:50.763694210 -0400
@@ -1756,7 +1756,7 @@
   (save-selected-window
     (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
     (delete-region (point-min) (point-max))
-    (dolist (full-record bookmark-alist)
+    (dolist (full-record (bookmark-maybe-sort-alist))
       (let* ((name (bookmark-name-from-full-record full-record))
              (ann  (bookmark-get-annotation full-record)))
         (insert (concat name ":\n"))
--- bookmark.el	2015-03-23 04:52:30.503739608 -0400
+++ bookmark-new.el	2015-03-23 06:08:22.399592029 -0400
@@ -1751,15 +1751,30 @@
           (switch-to-buffer-other-window old-buf))))))

+
+(defvar bookmark-show-all-annotations-in-org-mode nil
+"When not `nil', the command `bookmark-show-all-annotations' will
+format its display as an org-mode buffer")
+
 (defun bookmark-show-all-annotations ()
   "Display the annotations for all bookmarks in a buffer."
   (save-selected-window
     (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
     (delete-region (point-min) (point-max))
-    (dolist (full-record bookmark-alist)
+    (unless (null bookmark-show-all-annotations-in-org-mode)
+      (org-mode))
+    (let* ((heading-text "Bookmark annotations for ALL bookmarks")
+           (heading (if (null bookmark-show-all-annotations-in-org-mode)
+                      (concat "# " heading-text "\n----------------------------------------\n")
+                     (concat "* " heading-text "\n")))
+           (prefix (unless (null bookmark-show-all-annotations-in-org-mode)
+                     "** ")))
+      (insert heading)
+
+    (dolist (full-record (bookmark-maybe-sort-alist))
       (let* ((name (bookmark-name-from-full-record full-record))
              (ann  (bookmark-get-annotation full-record)))
-        (insert (concat name ":\n"))
+        (insert (concat prefix name ":\n"))
         (if (and ann (not (string-equal ann "")))
             ;; insert the annotation, indented by 4 spaces.
             (progn
@@ -1769,10 +1784,9 @@
                 (beginning-of-line)     ; paranoia
                 (insert "    ")
                 (forward-line)
-                (end-of-line))))))
+                (end-of-line)))))))
     (goto-char (point-min))))
 
-
 (defun bookmark-bmenu-mark ()
   "Mark bookmark on this line to be displayed by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-select]."
   (interactive)