summaryrefslogtreecommitdiff
path: root/lisp/bookmark.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2009-11-21 04:43:10 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2009-11-21 04:43:10 +0000
commit26d9285f3213af5175bc0d8dad2278b3b5506a0e (patch)
tree1fbee7be8f3afe146fd378ba416d6bacff5a69a8 /lisp/bookmark.el
parentd73a0317a0478d1b1ab11cfaf479fe08ea23c0e7 (diff)
downloademacs-26d9285f3213af5175bc0d8dad2278b3b5506a0e.tar.gz
(bookmark-search-prompt, bookmark-search-timer): Remove.
(bookmark-search-pattern): Move and leave unbound. (bookmark-bmenu-mode-map): Change binding. (bookmark-read-search-input): Simplify. Don't use text-char-description. Don't error on non-char events. (bookmark-filtered-alist-by-regexp-only): Remove by folding into the only caller (i.e. bookmark-bmenu-filter-alist-by-regexp). (bookmark-bmenu-search): Don't check we're in a bookmark-list buffer. Use a local var for the timer. (bookmark-bmenu-cancel-search): Remove by folding into the only caller (i.e. bookmark-bmenu-search).
Diffstat (limited to 'lisp/bookmark.el')
-rw-r--r--lisp/bookmark.el119
1 files changed, 44 insertions, 75 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index e9e4e727d9e..017eed8128a 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -196,19 +196,12 @@ following in your `.emacs' file:
:type 'integer
:group 'bookmark)
-
+;; FIXME: Is it really worth a customization option?
(defcustom bookmark-search-delay 0.2
- "*When searching bookmarks, redisplay every `bookmark-search-delay' seconds."
+ "Time before `bookmark-bmenu-search' updates the display."
:group 'bookmark
:type 'integer)
-
-(defcustom bookmark-search-prompt "Pattern: "
- "*Prompt used for `bookmark-bmenu-search'."
- :group 'bookmark
- :type 'string)
-
-
(defface bookmark-menu-heading
'((t (:inherit font-lock-type-face)))
"Face used to highlight the heading in bookmark menu buffers."
@@ -332,18 +325,8 @@ the source buffer for that information; see `bookmark-yank-word' and
This point is in `bookmark-curent-buffer'.")
-(defvar bookmark-search-pattern ""
- "Store keyboard input for incremental search.")
-
-
-(defvar bookmark-search-timer nil
- "Timer used for searching")
-
-
(defvar bookmark-quit-flag nil
"Non nil make `bookmark-bmenu-search' quit immediately.")
-
-
;; Helper functions.
@@ -1549,7 +1532,9 @@ method buffers use to resolve name collisions."
(define-key map "a" 'bookmark-bmenu-show-annotation)
(define-key map "A" 'bookmark-bmenu-show-all-annotations)
(define-key map "e" 'bookmark-bmenu-edit-annotation)
- (define-key map "\M-g" 'bookmark-bmenu-search)
+ ;; The original binding of M-g hides the M-g prefix map.
+ ;; If someone has a better idea than M-g s, I'm open to suggestions.
+ (define-key map [?\M-g ?s] 'bookmark-bmenu-search)
(define-key map [mouse-2] 'bookmark-bmenu-other-window-with-mouse)
map))
@@ -2099,69 +2084,58 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\
;;; 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'."
- (setq bookmark-search-pattern "") ; Always reset pattern to empty string
- (let ((prompt (propertize bookmark-search-prompt
- 'face '((:foreground "cyan"))))
- (inhibit-quit t)
- (tmp-list ())
- char)
- (catch 'break
- (while 1
- (catch 'continue
- (condition-case nil
- (setq char (read-char (concat prompt bookmark-search-pattern)))
- (error (throw 'break nil)))
+ (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
- ((or ?\e ?\r) ; RET or ESC break search loop and lead to [1].
- (throw 'break nil))
- (?\d (pop tmp-list) ; Delete last char of `bookmark-search-pattern'
- (setq bookmark-search-pattern
- (mapconcat 'identity (reverse tmp-list) ""))
- (throw 'continue nil))
- (?\C-g (setq bookmark-quit-flag t) (throw 'break nil))
+ ((?\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
- (push (text-char-description char) tmp-list)
- (setq bookmark-search-pattern
- (mapconcat 'identity (reverse tmp-list) ""))
- (throw 'continue nil))))))))
-
-
-(defun bookmark-filtered-alist-by-regexp-only (regexp)
- "Return a filtered `bookmark-alist' with bookmarks matching REGEXP."
- (loop for i in bookmark-alist
- when (string-match regexp (car i)) collect i into new
- finally return new))
+ (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 (bookmark-filtered-alist-by-regexp-only regexp)))
+ (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 ()
- "Incrementally search bookmarks matching `bookmark-search-pattern'.
-`bookmark-search-pattern' is built incrementally with
-`bookmark-read-search-input'."
+ "Incremental search of bookmarks, hiding the non-matches as we go."
(interactive)
- (when (string= (buffer-name (current-buffer)) "*Bookmark List*")
- (let ((bmk (bookmark-bmenu-bookmark)))
- (unwind-protect
- (progn
- (setq bookmark-search-timer
- (run-with-idle-timer
- bookmark-search-delay 'repeat
- #'(lambda ()
- (bookmark-bmenu-filter-alist-by-regexp
- bookmark-search-pattern))))
- (bookmark-read-search-input))
- (progn ; [1] Stop timer.
- (bookmark-bmenu-cancel-search)
- (when bookmark-quit-flag ; C-g hit restore menu list.
- (bookmark-bmenu-list) (bookmark-bmenu-goto-bookmark bmk))
- (setq bookmark-quit-flag nil))))))
+ (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)
+ (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."
@@ -2172,11 +2146,6 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\
(forward-line 0))
-(defun bookmark-bmenu-cancel-search ()
- "Cancel timer used for searching in bookmarks."
- (cancel-timer bookmark-search-timer)
- (setq bookmark-search-timer nil))
-
;;; Menu bar stuff. Prefix is "bookmark-menu".