all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: convert current working directory to perl package name
Date: Mon, 05 Apr 2010 17:00:16 +0200	[thread overview]
Message-ID: <874ojqhrlr.fsf@fh-trier.de> (raw)
In-Reply-To: b9c50470-4715-4388-9a5b-b0cbaa887f40@z4g2000yqa.googlegroups.com

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


  reply	other threads:[~2010-04-05 15:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-05 14:32 convert current working directory to perl package name metaperl
2010-04-05 15:00 ` Andreas Politz [this message]
2010-05-04 20:03 ` Drew Adams

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=874ojqhrlr.fsf@fh-trier.de \
    --to=politza@fh-trier.de \
    --cc=help-gnu-emacs@gnu.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.