+ (let ((bmrk (bookmark-bmenu-bookmark))
+ (thispoint (point)))
+ (bookmark-relocate bmrk)
+ (goto-char thispoint)))
+
+;;; Bookmark-bmenu search
+
+;; Store keyboard input for incremental search.
+(defvar bookmark-search-pattern)
+
+(defun bookmark-read-search-input ()
+ "Read each keyboard input and add it to `bookmark-search-pattern'."
+ (let ((prompt (propertize "Pattern: " 'face 'minibuffer-prompt))
+ ;; (inhibit-quit t) ; inhibit-quit is evil. Use it with extreme care!
+ (tmp-list ()))
+ (while
+ (let ((char (read-key (concat prompt bookmark-search-pattern))))
+ (case char
+ ((?\e ?\r) nil) ; RET or ESC break the search loop.
+ (?\C-g (setq bookmark-quit-flag t) nil)
+ (?\d (pop tmp-list) t) ; Delete last char of pattern with DEL
+ (t
+ (if (characterp char)
+ (push char tmp-list)
+ (setq unread-command-events
+ (nconc (mapcar 'identity
+ (this-single-command-raw-keys))
+ unread-command-events))
+ nil))))
+ (setq bookmark-search-pattern
+ (apply 'string (reverse tmp-list))))))
+
+
+(defun bookmark-bmenu-filter-alist-by-regexp (regexp)
+ "Filter `bookmark-alist' with bookmarks matching REGEXP and rebuild list."
+ (let ((bookmark-alist
+ (loop for i in bookmark-alist
+ when (string-match regexp (car i)) collect i into new
+ finally return new)))
+ (bookmark-bmenu-list)))
+
+
+;;;###autoload
+(defun bookmark-bmenu-search ()
+ "Incremental search of bookmarks, hiding the non-matches as we go."
+ (interactive)
+ (let ((bmk (bookmark-bmenu-bookmark))
+ (bookmark-search-pattern "")
+ (timer (run-with-idle-timer
+ bookmark-search-delay 'repeat
+ #'(lambda ()
+ (bookmark-bmenu-filter-alist-by-regexp
+ bookmark-search-pattern)))))
+ (unwind-protect
+ (bookmark-read-search-input)
+ (cancel-timer timer)
+ (message nil)
+ (when bookmark-quit-flag ; C-g hit restore menu list.
+ (bookmark-bmenu-list) (bookmark-bmenu-goto-bookmark bmk))
+ (setq bookmark-quit-flag nil))))
+
+(defun bookmark-bmenu-goto-bookmark (name)
+ "Move point to bookmark with name NAME."
+ (goto-char (point-min))
+ (while (not (equal name (bookmark-bmenu-bookmark)))
+ (forward-line 1))
+ (forward-line 0))
+