[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: copy-defun
From: |
Andreas Roehler |
Subject: |
Re: copy-defun |
Date: |
Tue, 04 Jul 2006 09:41:19 +0200 |
User-agent: |
KNode/0.9.2 |
Stefan Reichör wrote:
> Andreas Roehler <andreas.roehler@online.de> writes:
>
>> Was looking for a function to copy (kill-ring-save) the
>> function the point is in.
>>
>> Wrote the following. Maybe it's already written somewhere?
>
> What about M-x mark-defun followed by M-x kill-ring-save:
> C-M-h M-w
>
> Stefan.
>
>> __
>> Andreas Roehler
>>
>> (defun defun-beginning-position-interactive ()
>> "Print the position where the current defun starts"
>> (interactive)
>> (let ((pos
>> (save-excursion
>> (progn
>> (beginning-of-defun) (point)))))
>> (message "%s" pos)))
>>
>> (defun defun-beginning-position ()
>> "Return the position where the current defun starts"
>> (save-excursion
>> (progn
>> (beginning-of-defun) (point))))
>>
>> (defun defun-end-position-interactive ()
>> "Print the position where the current defun ends"
>> (interactive)
>> (let ((pos
>> (save-excursion
>> (progn
>> (end-of-defun) (point)))))
>> (message "%s" pos)))
>>
>> (defun defun-end-position ()
>> "Return the position where the current defun ends"
>> (save-excursion
>> (progn
>> (end-of-defun) (point))))
>>
>> (defun copy-defun ()
>> (interactive)
>> (save-excursion
>> (kill-ring-save
>> (defun-beginning-position) (defun-end-position))))
>>
>> ;;;;; end
That's great. Always good to remember.
Had two ideas while writing this
- to have just one key to do operations I often do
- to establish a collection of general-purpose
functions (therefor the copying).
So we can avoid `push-mark' and have just one function
to call.
BTW. AFAIS `(beginning-of-defun)' needs to be re-written,
as it fails if `(defun' doesn't start in the first
column (see icicles.el i.e.).
Danke!
__
Andreas Roehler