all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* convert current working directory to perl package name
@ 2010-04-05 14:32 metaperl
  2010-04-05 15:00 ` Andreas Politz
  2010-05-04 20:03 ` Drew Adams
  0 siblings, 2 replies; 3+ messages in thread
From: metaperl @ 2010-04-05 14:32 UTC (permalink / raw)
  To: help-gnu-emacs

hello,

I would like to create a simple interactive Emacs Lisp function.

When invoked, this command will obtain the current directory as a full
pathname:

/home/metaperl/prg/DBIx-Cookbook/lib/DBIx/Cookbook/Recipe/Searching

It will then get rid of everything from the start of line to (and
including) lib:

DBIx/Cookbook/Recipe/Searching

Then it will replace each forward slash with "::"

DBIx::Cookbook::Recipe::Searching

The resulting string will be put into the buffer at point.

I've written a macro to do this, but dont know how to save a macro as
a command to my .emacs.el file



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

* Re: convert current working directory to perl package name
  2010-04-05 14:32 convert current working directory to perl package name metaperl
@ 2010-04-05 15:00 ` Andreas Politz
  2010-05-04 20:03 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Politz @ 2010-04-05 15:00 UTC (permalink / raw)
  To: help-gnu-emacs

metaperl <schemelab@gmail.com> writes:

> hello,
>
> I would like to create a simple interactive Emacs Lisp function.
>
> When invoked, this command will obtain the current directory as a full
> pathname:
>
> /home/metaperl/prg/DBIx-Cookbook/lib/DBIx/Cookbook/Recipe/Searching
>
> It will then get rid of everything from the start of line to (and
> including) lib:
>
> DBIx/Cookbook/Recipe/Searching
>
> Then it will replace each forward slash with "::"
>
> DBIx::Cookbook::Recipe::Searching
>
> The resulting string will be put into the buffer at point.
>
> I've written a macro to do this, but dont know how to save a macro as
> a command to my .emacs.el file


If you name your macro (`kmacro-name-last-macro'), you can insert
it as a command in your init-file with `insert-kbd-macro'.

Or use a function.

(defun insert-perl-foo ()
  (interactive)
  (save-restriction
    (narrow-to-region
     (point) (progn
               (insert (expand-file-name default-directory))
               (point)))
    (goto-char (point-min))
    (when (re-search-forward ".*?/lib/" nil t)
      (delete-region (point-min) (point))) 
    (while (re-search-forward "/" nil 'move)
      (replace-match "::")))))

-ap


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

* RE: convert current working directory to perl package name
  2010-04-05 14:32 convert current working directory to perl package name metaperl
  2010-04-05 15:00 ` Andreas Politz
@ 2010-05-04 20:03 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: Drew Adams @ 2010-05-04 20:03 UTC (permalink / raw)
  To: 'metaperl', help-gnu-emacs

> I've written a [keyboard] macro to do this, but dont
> know how to save a macro as a command to my .emacs.el file

Visit the Emacs manual, node `Save Keyboard Macro':

C-h i Emacs g save ke TAB RET





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

end of thread, other threads:[~2010-05-04 20:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-05 14:32 convert current working directory to perl package name metaperl
2010-04-05 15:00 ` Andreas Politz
2010-05-04 20:03 ` Drew Adams

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.