From: Tom <adatgyujto@gmail.com>
To: Josh <josh@foxtail.org>
Cc: Juri Linkov <juri@jurta.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: History for query replace pairs
Date: Mon, 11 Aug 2014 20:34:33 +0200 [thread overview]
Message-ID: <CAON5ORr=VQpjEuNiBP-QFFbZGk72tm6prKpQp=rrdio9PppyLw@mail.gmail.com> (raw)
In-Reply-To: <CAON5ORraLMtxLcjRD8yfWh58rsn2VzyHj6aAC7fhOm_upLd8Uw@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1072 bytes --]
On Sun, Aug 10, 2014 at 7:59 AM, Tom <adatgyujto@gmail.com> wrote:
>
>
> Yes, that would be the full realization of the idea.
> Being able to select from FROM -> TO history pairs and quickly edit
> them in-place if needed.
>
> So the current FROM input field should provide access to previous
> FROM -> TO pairs and handle the case when such a pair is
> inputted instead of a simple FROM string.
>
>
I created a quick proof of concept implementation. It changes the behavior
of the arrow keys for the query-replace(-regexp) FROM prompt. You can stll
access the original behavior with M-p/n.
So when you start a query-replace and press the up arrow then
search/replace history is rendered as FROM -> TO pairs. The -> marker is
highlighted and intangible, the cursor jumps over it and you are free to
edit the search/replace string. If you submit a FROM->TO pair from the FROM
input field with RET then the replacement is started immediately. If you
submit a simple string (without the marker) then it behaves as usual and
asks for a TO string.
See the attached file.
[-- Attachment #1.2: Type: text/html, Size: 1798 bytes --]
[-- Attachment #2: hist.el --]
[-- Type: application/octet-stream, Size: 3620 bytes --]
(defvar histpairs-history nil)
(defvar histpairs-history-current nil)
(defun histpairs-query-replace-p ()
(string-match "Query replace\\( regexp\\)?\\( (\\|:\\)" (minibuffer-prompt)))
(defun histpairs-update-history-if-necessary ()
(unless (eq (cdr histpairs-history) command-history)
(setq histpairs-history
(cons
(delete-if 'null
(mapcar
(lambda (item)
(if (or (eq (car item) 'query-replace)
(eq (car item) 'query-replace-regexp))
(cons (second item) (third item))))
command-history))
command-history))))
(defun histpairs-update-minibuffer ()
(delete-minibuffer-contents)
(insert (caar histpairs-history-current)
(propertize " -> " 'face 'highlight
'intangible t 'rear-nonsticky t)
(if (stringp (cdar histpairs-history-current))
(cdar histpairs-history-current)
(concat "can't handle this history element yet, "
"probably a regexp lisp expression"))))
(defun histpairs-previous-history-element (n)
(interactive "p")
(if (not (histpairs-query-replace-p))
(previous-history-element n)
(histpairs-update-history-if-necessary)
(if (not histpairs-history-current)
(setq histpairs-history-current (car histpairs-history))
(setq histpairs-history-current (cdr histpairs-history-current)))
(if (not histpairs-history-current)
(message "No previous element.")
(histpairs-update-minibuffer))))
(defun histpairs-next-history-element (n)
(interactive "p")
(if (not (histpairs-query-replace-p))
(next-history-element n)
(histpairs-update-history-if-necessary)
(if histpairs-history-current
(let ((items (car histpairs-history)))
(while (and items
(not (eq (cdr items) histpairs-history-current)))
(setq items (cdr items)))
(setq histpairs-history-current items)))
(if (not histpairs-history-current)
(message "No next element.")
(histpairs-update-minibuffer))))
(defun histpairs-finish ()
(interactive)
(if (not (histpairs-query-replace-p))
(exit-minibuffer)
(setq histpairs-history-current nil)
(let ((pos (next-single-property-change 0 'intangible
(minibuffer-contents))))
(if (not pos)
(exit-minibuffer) ;; normal execution
(if (get-text-property 0 'intangible (minibuffer-contents))
(message "FROM is empty.")
(let* ((end (next-single-property-change pos 'intangible
(minibuffer-contents)))
(from (substring (minibuffer-contents) 0 pos))
(to (if end
(substring (minibuffer-contents) end)
"")))
(delete-minibuffer-contents)
(insert from)
(push 'return unread-command-events)
(dolist (c (nreverse (string-to-list to)))
(push c unread-command-events))
(exit-minibuffer)))))))
(define-key minibuffer-local-map
(kbd "<up>") 'histpairs-previous-history-element)
(define-key minibuffer-local-map
(kbd "<down>") 'histpairs-next-history-element)
(define-key minibuffer-local-map
(kbd "<return>") 'histpairs-finish)
next prev parent reply other threads:[~2014-08-11 18:34 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-08 20:20 History for query replace pairs Tom
2014-08-08 20:28 ` Drew Adams
2014-08-08 23:38 ` Juri Linkov
2014-08-09 5:35 ` Herring, Davis
2014-08-10 1:18 ` Josh
2014-08-10 5:59 ` Tom
2014-08-11 18:34 ` Tom [this message]
2014-10-04 21:45 ` Ted Zlatanov
2014-10-04 23:36 ` Juri Linkov
2014-10-05 1:52 ` Yuri Khan
2014-10-05 21:54 ` Juri Linkov
2014-10-05 7:09 ` Andreas Schwab
2014-10-05 1:52 ` Stefan Monnier
2014-10-05 5:59 ` Tom
2014-10-06 0:46 ` Ted Zlatanov
2014-10-06 20:17 ` Tom
2014-10-06 22:35 ` Juri Linkov
2014-10-07 22:11 ` Juri Linkov
2014-10-14 17:14 ` Stefan Monnier
2014-10-14 19:02 ` Juri Linkov
2014-10-14 19:13 ` Alan Mackenzie
2014-10-14 19:44 ` Juri Linkov
2014-10-14 20:15 ` Alan Mackenzie
2014-10-14 20:16 ` Drew Adams
2014-10-14 20:28 ` Juri Linkov
2014-10-14 21:19 ` Drew Adams
2014-10-14 20:05 ` Andreas Schwab
2014-10-14 20:09 ` Alan Mackenzie
2014-10-14 20:23 ` Andreas Schwab
2014-10-21 18:23 ` Stefan Monnier
2014-10-21 22:53 ` Juri Linkov
2014-10-22 12:58 ` Stefan Monnier
2014-10-23 9:06 ` Artur Malabarba
2014-10-25 20:57 ` Juri Linkov
2014-10-26 1:12 ` Artur Malabarba
2014-10-26 2:31 ` Stefan Monnier
2014-10-26 6:58 ` Andreas Schwab
2014-10-25 20:52 ` Juri Linkov
2014-10-26 2:29 ` Stefan Monnier
2014-10-26 23:27 ` Juri Linkov
2014-11-03 13:30 ` Ted Zlatanov
2014-11-03 23:46 ` Juri Linkov
2014-11-04 0:59 ` Ted Zlatanov
2014-11-04 23:09 ` Juri Linkov
2014-11-05 1:55 ` Stefan Monnier
2014-11-05 23:20 ` Juri Linkov
2014-11-06 2:35 ` Stefan Monnier
2014-11-07 23:34 ` Juri Linkov
2014-11-08 0:59 ` Ted Zlatanov
2014-11-08 8:46 ` Eli Zaretskii
2014-11-08 10:29 ` Juri Linkov
2014-11-08 11:24 ` Eli Zaretskii
2014-11-08 15:28 ` Stefan Monnier
2014-11-08 17:29 ` Eli Zaretskii
2014-11-08 22:52 ` Juri Linkov
2014-11-09 2:01 ` Stefan Monnier
2014-11-09 16:15 ` Eli Zaretskii
2014-11-09 17:11 ` Juri Linkov
2014-11-09 22:14 ` Stefan Monnier
2014-11-09 23:12 ` Juri Linkov
2014-11-09 22:10 ` Stefan Monnier
2014-11-09 2:29 ` Paul Eggert
2014-11-09 17:15 ` Juri Linkov
2014-11-08 22:51 ` Juri Linkov
2014-11-09 17:29 ` Eli Zaretskii
2014-11-08 10:15 ` Juri Linkov
2014-11-08 8:25 ` Eli Zaretskii
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAON5ORr=VQpjEuNiBP-QFFbZGk72tm6prKpQp=rrdio9PppyLw@mail.gmail.com' \
--to=adatgyujto@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=josh@foxtail.org \
--cc=juri@jurta.org \
/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 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.