[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: convert current working directory to perl package name
From: |
Andreas Politz |
Subject: |
Re: convert current working directory to perl package name |
Date: |
Tue, 04 May 2010 15:44:05 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux) |
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