[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#10998: Allow movements in bookmark-bmenu-search.
From: |
Thierry Volpiatto |
Subject: |
bug#10998: Allow movements in bookmark-bmenu-search. |
Date: |
Mon, 12 Mar 2012 07:08:04 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (gnu/linux) |
Hi,
there is no cursor in the prompt of bookmark-bmenu-search, and it is not
possible to move and edit it actually, this patch allow this.
--8<---------------cut here---------------start------------->8---
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -169,6 +169,11 @@
:group 'bookmark
:version "22.1")
+(defface bookmark-cursor
+ '((t (:foreground "green")))
+ "Face for cursor color in `bookmark-bmenu-search' prompt."
+ :group 'bookmark)
+
;;; No user-serviceable parts beyond this point.
@@ -2008,20 +2013,57 @@
;; Store keyboard input for incremental search.
(defvar bookmark-search-pattern)
+(defun bookmark-set-cursor-in-prompt (str pos)
+ "Add a cursor in string STR at index position POS."
+ (setq pos (min index (1- (length tmp-list))))
+ (when (not (string= str ""))
+ (let* ((real-index (- (1- (length tmp-list)) pos))
+ (cur-str (substring str real-index (1+ real-index))))
+ (concat (substring str 0 real-index)
+ (propertize cur-str 'display
+ (if (= index (length tmp-list))
+ (concat
+ (propertize "|" 'face 'bookmark-cursor)
+ cur-str)
+ (concat
+ cur-str
+ (propertize "|" 'face 'bookmark-cursor))))
+ (substring str (1+ real-index))))))
+
(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 ()))
+ (tmp-list ())
+ (index 0))
(while
- (let ((char (read-key (concat prompt bookmark-search-pattern))))
+ (let ((char (read-key (concat prompt (bookmark-set-cursor-in-prompt
+ bookmark-search-pattern
index)))))
(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
+ (?\d (with-no-warnings ; Delete last char of pattern with DEL.
+ (pop (nthcdr index tmp-list))) t)
+ ;; Movements in minibuffer.
+ (?\C-b ; backward-char.
+ (setq index (min (1+ index) (length tmp-list))) t)
+ (?\C-f ; forward-char.
+ (setq index (max (1- index) 0)) t)
+ (?\C-a ; move bol.
+ (setq index (length tmp-list)) t)
+ (?\C-e ; move eol.
+ (setq index 0) t)
+ (?\C-k
+ (kill-new (substring bookmark-search-pattern
+ (- (length tmp-list) index)))
+ (setq tmp-list (nthcdr index tmp-list)) (setq index 0) t)
+ (?\C-y
+ (let ((str (car kill-ring)))
+ (loop for char across str
+ do (push char (nthcdr index tmp-list)))) t)
(t
(if (characterp char)
- (push char tmp-list)
+ (push char (nthcdr index tmp-list))
(setq unread-command-events
(nconc (mapcar 'identity
(this-single-command-raw-keys))
--8<---------------cut here---------------end--------------->8---
--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
- bug#10998: Allow movements in bookmark-bmenu-search.,
Thierry Volpiatto <=