all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#10998: Allow movements in bookmark-bmenu-search.
@ 2012-03-12  6:08 Thierry Volpiatto
  2012-03-12 12:31 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Thierry Volpiatto @ 2012-03-12  6:08 UTC (permalink / raw)
  To: 10998

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 






^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-06-12 20:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-12  6:08 bug#10998: Allow movements in bookmark-bmenu-search Thierry Volpiatto
2012-03-12 12:31 ` Stefan Monnier
2012-03-12 12:49   ` Thierry Volpiatto
2012-03-12 15:52     ` Stefan Monnier
2012-03-13 15:34       ` Thierry Volpiatto
2012-10-01  4:35 ` Karl Fogel
2012-10-01  7:45   ` Thierry Volpiatto
2012-10-01 14:53     ` Stefan Monnier
2012-10-01 15:11       ` Thierry Volpiatto
2012-10-02  2:47       ` Stefan Monnier
2019-06-12 16:28 ` Stefan Kangas
2019-06-12 20:30   ` npostavs

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.