unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Drew Adams <drew.adams@oracle.com>
Cc: 14742@debbugs.gnu.org
Subject: bug#14742: 24.3.50; enhancement request: be able to prepend stuff from buffer when search backward
Date: Fri, 05 Jul 2013 02:34:18 +0300	[thread overview]
Message-ID: <87y59lc32c.fsf@mail.jurta.org> (raw)
In-Reply-To: <9fa6642c-dbcb-47aa-a8a3-29ee892bd933@default> (Drew Adams's message of "Wed, 3 Jul 2013 17:17:38 -0700 (PDT)")

>> > Do you have this working already?  Have you described what you have in
>> > mind somewhere?  Did you bring this up in emacs-devel?  If not, please
>> > consider it - that is the best place to toss such an idea around.
>>
>> Yes, it is working and I described it on emacs-devel a month ago.
>> Now I'll prepare a minimal patch that implements low-level support, then
>> send separate high-level code to activate it, so everyone could try it.
>
> Sounds good; looking forward to it.

The following minimal patch implements low-level support
for the motion yanking feature that could be later enabled
by separate higher-level commands.

It adds a new option `isearch-allow-move' with the nil default value.
Like the user option `transient-mark-mode' having the certain special
value of (only . OLDVAL) that enables Transient Mark mode temporarily,
until any subsequent point motion command that is not shift-translated
sets the value of `transient-mark-mode' back to OLDVAL, the new option
`isearch-allow-move' does the same.

This patch relies on the previously sent patch that adds a new argument
`BEGINNING' to `isearch-yank-string' and `isearch-del-char'.

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el	2013-06-13 22:08:45 +0000
+++ lisp/isearch.el	2013-07-04 23:28:33 +0000
@@ -987,6 +1046,8 @@ (defun isearch-update ()
   ;; We must prevent the point moving to the end of composition when a
   ;; part of the composition has just been searched.
   (setq disable-point-adjustment t)
+  (when (eq (car-safe isearch-allow-move) 'only)
+    (setq isearch-allow-move (cdr isearch-allow-move)))
   (run-hooks 'isearch-update-post-hook))
 
 (defun isearch-done (&optional nopush edit)
@@ -2267,6 +2433,77 @@ (defun isearch-lookup-scroll-key (key-se
 	     (eq (get binding 'scroll-command) t))
          binding)))
 
+(defcustom isearch-allow-move nil
+  "Whether cursor movement is allowed to yank text in Isearch mode.
+If nil, point motion commands will exit Isearch mode immediately.
+If non-nil, point motion commands extend Isearch by yanking the text
+the cursor moves over in the buffer.  E.g., C-f yanks the next char,
+C-M-f yanks the next expression, etc. to the end of the search string
+in forward search.  In reverse search, C-b yanks the previous char,
+C-M-b yanks the previous expression, etc. to the beginning of the
+search string.  And conversely, backward cursor movements, e.g., C-b
+removes text from the end of the search string when searching forward.
+When searching backward, forward cursor movements, e.g., C-f removes
+text from the beginning of the search string.
+
+Lisp programs may give this variable a special value of
+\(only . OLDVAL) to enable motion yanking temporarily.
+After any subsequent Isearch command that is not point motion,
+the value of `isearch-allow-move' is set to OLDVAL."
+  :type 'boolean
+  :version "24.4"
+  :group 'isearch)
+
+(defun isearch-lookup-move-key (key-seq)
+  "If KEY-SEQ is bound to a motion command, return it as a symbol.
+Otherwise return nil."
+  (let* ((overriding-terminal-local-map nil)
+         (binding (key-binding key-seq)))
+    (and binding (symbolp binding) (commandp binding)
+         (eq (get binding 'isearch-move) t)
+         binding)))
+
 (defalias 'isearch-other-control-char 'isearch-other-meta-char)
 
 (defun isearch-other-meta-char (&optional arg)
@@ -2379,7 +2616,67 @@ (defun isearch-other-meta-char (&optiona
              (if ab-bel
                  (isearch-back-into-window (eq ab-bel 'above) isearch-point)
                (goto-char isearch-point)))
           (isearch-update))
+	  ;; Handle a motion function.
+	  ((and isearch-allow-move
+		(progn (setq key (isearch-reread-key-sequence-naturally keylist))
+		       (setq keylist (listify-key-sequence key))
+		       (setq main-event (aref key 0))
+		       (setq move-command (or
+					   (isearch-lookup-move-key key)
+					   (isearch-lookup-move-key
+					    ;; Use the last key in the sequence.
+					    (vector (aref key (1- (length key)))))))))
+	   (setq prefix-arg arg)
+	   (let* ((old-point (point))
+		  (new-point (save-excursion
+			       (condition-case ()
+				   (command-execute move-command)
+				 (error nil))
+			       (point))))
+	     ;; Change search direction between forward and backward.
+	     (when (if isearch-forward
+			 (< new-point old-point)
+		       (> new-point old-point))
+	       (setq isearch-forward (not isearch-forward))
+	       (setq isearch-string "" isearch-message "")
+	       (if isearch-other-end (setq old-point isearch-other-end)))
+	     (if (< old-point new-point)
+		 (if isearch-forward
+		     (isearch-yank-string
+		      (buffer-substring-no-properties old-point new-point))
+		   (isearch-del-char (- new-point old-point) t))
+	       (if isearch-forward
+		   (isearch-del-char (- old-point new-point))
+		 (isearch-yank-string
+		  (buffer-substring-no-properties old-point new-point) t))))
+	   (setq isearch-allow-move (cons 'only isearch-allow-move)))
 	  ;; A mouse click on the isearch message starts editing the search string
 	  ((and (eq (car-safe main-event) 'down-mouse-1)
 		(window-minibuffer-p (posn-window (event-start main-event))))



> What is the emacs-devel thread?  Somehow I must have missed it.

The emacs-devel thread is here:
http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00211.html





  reply	other threads:[~2013-07-04 23:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-28 18:17 bug#14742: 24.3.50; enhancement request: be able to prepend stuff from buffer when search backward Drew Adams
2013-06-28 21:43 ` Juri Linkov
2013-06-28 22:00   ` Drew Adams
2013-06-29 21:50     ` Juri Linkov
2013-06-29 23:02       ` Drew Adams
2013-07-02 22:39         ` Juri Linkov
2013-07-02 23:42           ` Drew Adams
2013-07-02 23:53             ` Juri Linkov
2013-07-03  1:07               ` Drew Adams
2013-07-03  5:40                 ` Drew Adams
2013-07-03 22:57                   ` Juri Linkov
2013-07-04  0:17                     ` Drew Adams
2013-07-04 23:34                       ` Juri Linkov [this message]
2013-07-05 10:37                         ` Stefan Monnier
2013-07-05 22:28                           ` Juri Linkov
2013-07-05 22:59                             ` Stefan Monnier
2013-07-05 23:17                               ` Juri Linkov
2013-07-06  0:40                                 ` Stefan Monnier
2020-09-18 14:30                             ` Lars Ingebrigtsen
2020-09-18 16:11                               ` Drew Adams
2020-09-21 19:07                                 ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y59lc32c.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=14742@debbugs.gnu.org \
    --cc=drew.adams@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).