all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* copy-defun
@ 2006-07-01 15:50 Andreas Roehler
  2006-07-03 19:05 ` copy-defun Stefan Reichör
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Roehler @ 2006-07-01 15:50 UTC (permalink / raw)



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?

__
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

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

* Re: copy-defun
  2006-07-01 15:50 copy-defun Andreas Roehler
@ 2006-07-03 19:05 ` Stefan Reichör
  2006-07-04  7:41   ` copy-defun Andreas Roehler
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Reichör @ 2006-07-03 19:05 UTC (permalink / raw)


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

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

* Re: copy-defun
  2006-07-03 19:05 ` copy-defun Stefan Reichör
@ 2006-07-04  7:41   ` Andreas Roehler
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Roehler @ 2006-07-04  7:41 UTC (permalink / raw)


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

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

end of thread, other threads:[~2006-07-04  7:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-01 15:50 copy-defun Andreas Roehler
2006-07-03 19:05 ` copy-defun Stefan Reichör
2006-07-04  7:41   ` copy-defun Andreas Roehler

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.