all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* keyboard macro create function from list
@ 2007-06-07  0:18 Patrick Drechsler
  2007-06-07 19:33 ` Peter Lee
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Drechsler @ 2007-06-07  0:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I often have a list of variable names and need to create similar code
from this list. Here is an example:

The List (imagine 6-10 myvar's):

--8<---------------cut here---------------start------------->8---
myvar_Asometext
myvar_B1foo
--8<---------------cut here---------------end--------------->8---


Lets say the code layout should look like:

--8<---------------cut here---------------start------------->8---
m_<listmember_n>.SetBounds(0, 0, m_<listmember_n>.Width, m_<listmember_n>.Height)
m_<listmember_n>.Show()
SplitContainer.Panel2.Controls.Add(m_<listmember_n>)
--8<---------------cut here---------------end--------------->8---

The output should look like this:

--8<---------------cut here---------------start------------->8---
m_Asometext.SetBounds(0, 0, m_Asometext.Width, m_Asometext.Height)
m_Asometext.Show()
SplitContainer.Panel2.Controls.Add(m_Asometext)

m_B1foo.SetBounds(0, 0, m_B1foo.Width, m_B1foo.Height)
m_B1foo.Show()
SplitContainer.Panel2.Controls.Add(m_B1foo)
--8<---------------cut here---------------end--------------->8---

At the moment I copy the list from another IDE into an Emacs scratch
buffer. Then I append one example layout to the scratch buffer. After
copying and marking the relevant region(s) I follow up by a multitude
of invocations of `M-x replace-string'. Although this is still faster
than working in the IDE I copy from, I feel that there is a better way
of using Emacs' abilities...

So, any ideas for accomplishing this more efficiently (using a current
Emacs version) are more than welcome ;-)

TIA

Patrick
-- 
I never used a logarithm in my life, and could not undertake to
extract the square root of four without misgivings.
	(Georg Bernhard Shaw)

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

* Re: keyboard macro create function from list
  2007-06-07  0:18 keyboard macro create function from list Patrick Drechsler
@ 2007-06-07 19:33 ` Peter Lee
  2007-06-09  7:54   ` Patrick Drechsler
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Lee @ 2007-06-07 19:33 UTC (permalink / raw)
  To: help-gnu-emacs

>>>> Patrick Drechsler writes:

    > So, any ideas for accomplishing this more efficiently (using a current
    > Emacs version) are more than welcome ;-)


You could use a regexp...

(defun name-me ()
  (interactive)
  (when mark-active
    (replace-regexp "myvar_\\(.*\\) *" "m_\\1.SetBounds(0, 0, m_\\1.Width, m_\\1.Height)\nm_\\1.Show()\nSplitContainer.Panel2.Controls.Add(m_\\1)\n" nil (region-beginning) (region-end))
    ))

Paste your var declarations..

myvar_Asometext
myvar_B1foo

Select them in a region... and run M-x name-me

You could probably use templates/skeletons for this as well.

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

* Re: keyboard macro create function from list
  2007-06-07 19:33 ` Peter Lee
@ 2007-06-09  7:54   ` Patrick Drechsler
  0 siblings, 0 replies; 3+ messages in thread
From: Patrick Drechsler @ 2007-06-09  7:54 UTC (permalink / raw)
  To: help-gnu-emacs

Peter Lee <pete.a.lee@gmail.com> writes:
> You could use a regexp...
>
> (defun name-me ()
>   (interactive)
>   (when mark-active
>     (replace-regexp "myvar_\\(.*\\) *" "m_\\1.SetBounds(0, 0, m_\\1.Width, m_\\1.Height)\nm_\\1.Show()\nSplitContainer.Panel2.Controls.Add(m_\\1)\n" nil (region-beginning) (region-end))
>     ))
>
> Paste your var declarations..
>
> myvar_Asometext
> myvar_B1foo
>
> Select them in a region... and run M-x name-me

Very nice, thanks a lot Peter!

Cheers,

Patrick
-- 
"Science knows only one commandment: contribute to science."
   -- Bertolt Brecht, "Galileo".

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

end of thread, other threads:[~2007-06-09  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-07  0:18 keyboard macro create function from list Patrick Drechsler
2007-06-07 19:33 ` Peter Lee
2007-06-09  7:54   ` Patrick Drechsler

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.