all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How can I enter query-replace in GNU Emacs using a repeatable  function based on values in the line currently at point. - Super User
@ 2010-06-21 14:35 Tim Visher
  2010-06-21 15:00 ` Tim Landscheidt
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Visher @ 2010-06-21 14:35 UTC (permalink / raw)
  To: emacs

Hi Everyone,

I'd like to take the following data and query-replace occurences of
each word identifier with the corresponding numeric identifier using
some sort of repeatable function.

    -1 ACT/CNS
    -2 AG NFC
    -3 AID
    -4 BBG
    -5 BIA
    -6 BLM
    -7 BOC
    -8 BPD
    -9 CCC
    -10 CDC
    -11 Census

In other words, with point at

    -1 ACT/CNS
    ^

I'd like to be able to hit a key and launch into the following command

    query-replace RET ACT/CNS RET -1 RET

I tried defining a keyboard macro but there seems to be enough jumping
between buffers and M-x calls to confuse the kbmacro and make it
unusable.

Thoughts?

Write up also here:

http://superuser.com/questions/155017/how-can-i-enter-query-replace-in-gnu-emacs-using-a-repeatable-function-based-on-v



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

* Re: How can I enter query-replace in GNU Emacs using a repeatable function based on values in the line currently at point. - Super User
  2010-06-21 14:35 How can I enter query-replace in GNU Emacs using a repeatable function based on values in the line currently at point. - Super User Tim Visher
@ 2010-06-21 15:00 ` Tim Landscheidt
  2010-06-21 16:18   ` Tim Visher
       [not found]   ` <mailman.0.1277137734.5294.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Tim Landscheidt @ 2010-06-21 15:00 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Visher <tim.visher@gmail.com> wrote:

> I'd like to take the following data and query-replace occurences of
> each word identifier with the corresponding numeric identifier using
> some sort of repeatable function.

>     -1 ACT/CNS
>     -2 AG NFC
>     -3 AID
>     -4 BBG
>     -5 BIA
>     -6 BLM
>     -7 BOC
>     -8 BPD
>     -9 CCC
>     -10 CDC
>     -11 Census

> In other words, with point at

>     -1 ACT/CNS
>     ^

> I'd like to be able to hit a key and launch into the following command

>     query-replace RET ACT/CNS RET -1 RET
> [...]

From my experience, the easiest way to do that is to copy
the lines to a temporary buffer, hack up a small lisplet:

| (dolist (line '(("-1"  "ACT/CNS")
|                 ("-2"  "AG NFC")
|                 ("-3"  "AID")
|                 ("-4"  "BBG")
|                 ("-5"  "BIA")
|                 ("-6"  "BLM")
|                 ("-7"  "BOC")
|                 ("-8"  "BPD")
|                 ("-9"  "CCC")
|                 ("-10" "CDC")
|                 ("-11" "Census")))
|   (query-replace (car line) (cdr line) nil (point-min) (point-max)))

and then evaluate that in the original buffer with M-x :.

  While it is possible to create a proper "one-key command"
as you intended, chances are that it is very cumbersome and
that you will have to change it soon afterwards when your
requirements shift just a little bit. Directly programming
in Emacs Lisp is much easier and more flexible.

Tim




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

* Re: How can I enter query-replace in GNU Emacs using a repeatable  function based on values in the line currently at point. - Super User
  2010-06-21 15:00 ` Tim Landscheidt
@ 2010-06-21 16:18   ` Tim Visher
       [not found]   ` <mailman.0.1277137734.5294.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Tim Visher @ 2010-06-21 16:18 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon, Jun 21, 2010 at 11:00 AM, Tim Landscheidt
<tim@tim-landscheidt.de> wrote:
> Tim Visher <tim.visher@gmail.com> wrote:
>
>> I'd like to take the following data and query-replace occurences of
>> each word identifier with the corresponding numeric identifier using
>> some sort of repeatable function.
>
>>     -1 ACT/CNS
>>     -2 AG NFC
>>     -3 AID
>>     -4 BBG
>>     -5 BIA
>>     -6 BLM
>>     -7 BOC
>>     -8 BPD
>>     -9 CCC
>>     -10 CDC
>>     -11 Census
>
>> In other words, with point at
>
>>     -1 ACT/CNS
>>     ^
>
>> I'd like to be able to hit a key and launch into the following command
>
>>     query-replace RET ACT/CNS RET -1 RET
>> [...]
>
> From my experience, the easiest way to do that is to copy
> the lines to a temporary buffer, hack up a small lisplet:
>
> | (dolist (line '(("-1"  "ACT/CNS")
> |                 ("-2"  "AG NFC")
> |                 ("-3"  "AID")
> |                 ("-4"  "BBG")
> |                 ("-5"  "BIA")
> |                 ("-6"  "BLM")
> |                 ("-7"  "BOC")
> |                 ("-8"  "BPD")
> |                 ("-9"  "CCC")
> |                 ("-10" "CDC")
> |                 ("-11" "Census")))
> |   (query-replace (car line) (cdr line) nil (point-min) (point-max)))
>
> and then evaluate that in the original buffer with M-x :.
>
>  While it is possible to create a proper "one-key command"
> as you intended, chances are that it is very cumbersome and
> that you will have to change it soon afterwards when your
> requirements shift just a little bit. Directly programming
> in Emacs Lisp is much easier and more flexible.
>
> Tim

That worked perfectly. Thanks, Tim.

-- 

In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail



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

* Re: How can I enter query-replace in GNU Emacs using a repeatable  function based on values in the line currently at point. - Super User
       [not found]   ` <mailman.0.1277137734.5294.help-gnu-emacs@gnu.org>
@ 2010-06-24  7:38     ` bolega
  2010-06-28  7:32       ` Fren Zeee
  0 siblings, 1 reply; 5+ messages in thread
From: bolega @ 2010-06-24  7:38 UTC (permalink / raw)
  To: help-gnu-emacs

On Jun 21, 9:18 am, Tim Visher <tim.vis...@gmail.com> wrote:
> On Mon, Jun 21, 2010 at 11:00 AM, Tim Landscheidt
>
>
>
> <t...@tim-landscheidt.de> wrote:
> > Tim Visher <tim.vis...@gmail.com> wrote:
>
> >> I'd like to take the following data and query-replace occurences of
> >> each word identifier with the corresponding numeric identifier using
> >> some sort of repeatable function.
>
> >>     -1 ACT/CNS
> >>     -2 AG NFC
> >>     -3 AID
> >>     -4 BBG
> >>     -5 BIA
> >>     -6 BLM
> >>     -7 BOC
> >>     -8 BPD
> >>     -9 CCC
> >>     -10 CDC
> >>     -11 Census
>
> >> In other words, with point at
>
> >>     -1 ACT/CNS
> >>     ^
>
> >> I'd like to be able to hit a key and launch into the following command
>
> >>     query-replace RET ACT/CNS RET -1 RET
> >> [...]
>
> > From my experience, the easiest way to do that is to copy
> > the lines to a temporary buffer, hack up a small lisplet:
>
> > | (dolist (line '(("-1"  "ACT/CNS")
> > |                 ("-2"  "AG NFC")
> > |                 ("-3"  "AID")
> > |                 ("-4"  "BBG")
> > |                 ("-5"  "BIA")
> > |                 ("-6"  "BLM")
> > |                 ("-7"  "BOC")
> > |                 ("-8"  "BPD")
> > |                 ("-9"  "CCC")
> > |                 ("-10" "CDC")
> > |                 ("-11" "Census")))
> > |   (query-replace (car line) (cdr line) nil (point-min) (point-max)))
>
> > and then evaluate that in the original buffer with M-x :.
>
> >  While it is possible to create a proper "one-key command"
> > as you intended, chances are that it is very cumbersome and
> > that you will have to change it soon afterwards when your
> > requirements shift just a little bit. Directly programming
> > in Emacs Lisp is much easier and more flexible.
>
> > Tim
>
> That worked perfectly. Thanks, Tim.
>
> --
>
> In Christ,
>

Its new for me so I write the documentation here

(defmacro dolist (spec &rest body)
  "(dolist (VAR LIST [RESULT]) BODY...): loop over a list.
Evaluate BODY with VAR bound to each `car' from LIST, in turn.
Then evaluate RESULT to get return value, default nil."
  (let ((temp (gensym "--dolist-temp--")))
    (list 'block nil
	  (list* 'let (list (list temp (nth 1 spec)) (car spec))
		 (list* 'while temp (list 'setq (car spec) (list 'car temp))
			(append body (list (list 'setq temp
						 (list 'cdr temp)))))
		 (if (cdr (cdr spec))
		     (cons (list 'setq (car spec) nil) (cdr (cdr spec)))
		   '(nil))))))


I think the readability and rememberability would be improved by
writing it as

(dolist
 (foreach
  '( ("" "")
     ("" "")
     ("" "")))
  (save-excursion (replace-string (car foreach) (cdr foreach))))

Bolega




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

* Re: How can I enter query-replace in GNU Emacs using a repeatable  function based on values in the line currently at point. - Super User
  2010-06-24  7:38     ` bolega
@ 2010-06-28  7:32       ` Fren Zeee
  0 siblings, 0 replies; 5+ messages in thread
From: Fren Zeee @ 2010-06-28  7:32 UTC (permalink / raw)
  To: help-gnu-emacs

On Jun 24, 12:38 am, bolega <gnuist...@gmail.com> wrote:
> On Jun 21, 9:18 am, Tim Visher <tim.vis...@gmail.com> wrote:
>
>
>
> > On Mon, Jun 21, 2010 at 11:00 AM, Tim Landscheidt
>
> > <t...@tim-landscheidt.de> wrote:
> > > Tim Visher <tim.vis...@gmail.com> wrote:
>
> > >> I'd like to take the following data and query-replace occurences of
> > >> each word identifier with the corresponding numeric identifier using
> > >> some sort of repeatable function.
>
> > >>     -1 ACT/CNS
> > >>     -2 AG NFC
> > >>     -3 AID
> > >>     -4 BBG
> > >>     -5 BIA
> > >>     -6 BLM
> > >>     -7 BOC
> > >>     -8 BPD
> > >>     -9 CCC
> > >>     -10 CDC
> > >>     -11 Census
>
> > >> In other words, with point at
>
> > >>     -1 ACT/CNS
> > >>     ^
>
> > >> I'd like to be able to hit a key and launch into the following command
>
> > >>     query-replace RET ACT/CNS RET -1 RET
> > >> [...]
>
> > > From my experience, the easiest way to do that is to copy
> > > the lines to a temporary buffer, hack up a small lisplet:
>
> > > | (dolist (line '(("-1"  "ACT/CNS")
> > > |                 ("-2"  "AG NFC")
> > > |                 ("-3"  "AID")
> > > |                 ("-4"  "BBG")
> > > |                 ("-5"  "BIA")
> > > |                 ("-6"  "BLM")
> > > |                 ("-7"  "BOC")
> > > |                 ("-8"  "BPD")
> > > |                 ("-9"  "CCC")
> > > |                 ("-10" "CDC")
> > > |                 ("-11" "Census")))
> > > |   (query-replace (car line) (cdr line) nil (point-min) (point-max)))
>
> > > and then evaluate that in the original buffer with M-x :.
>
> > >  While it is possible to create a proper "one-key command"
> > > as you intended, chances are that it is very cumbersome and
> > > that you will have to change it soon afterwards when your
> > > requirements shift just a little bit. Directly programming
> > > in Emacs Lisp is much easier and more flexible.
>
> > > Tim
>
> > That worked perfectly. Thanks, Tim.
>
> > --
>
> > In Christ,
>
> Its new for me so I write the documentation here
>
> (defmacro dolist (spec &rest body)
>   "(dolist (VAR LIST [RESULT]) BODY...): loop over a list.
> Evaluate BODY with VAR bound to each `car' from LIST, in turn.
> Then evaluate RESULT to get return value, default nil."
>   (let ((temp (gensym "--dolist-temp--")))
>     (list 'block nil
>           (list* 'let (list (list temp (nth 1 spec)) (car spec))
>                  (list* 'while temp (list 'setq (car spec) (list 'car temp))
>                         (append body (list (list 'setq temp
>                                                  (list 'cdr temp)))))
>                  (if (cdr (cdr spec))
>                      (cons (list 'setq (car spec) nil) (cdr (cdr spec)))
>                    '(nil))))))
>
> I think the readability and rememberability would be improved by
> writing it as
>
> (dolist
>  (foreach
>   '( ("" "")
>      ("" "")
>      ("" "")))
>   (save-excursion (replace-string (car foreach) (cdr foreach))))
>
> Bolega

better to use

eachpair

than

foreach



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

end of thread, other threads:[~2010-06-28  7:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-21 14:35 How can I enter query-replace in GNU Emacs using a repeatable function based on values in the line currently at point. - Super User Tim Visher
2010-06-21 15:00 ` Tim Landscheidt
2010-06-21 16:18   ` Tim Visher
     [not found]   ` <mailman.0.1277137734.5294.help-gnu-emacs@gnu.org>
2010-06-24  7:38     ` bolega
2010-06-28  7:32       ` Fren Zeee

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.