From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Roehler Newsgroups: gmane.emacs.help Subject: Re: copy-defun Date: Tue, 04 Jul 2006 09:41:19 +0200 Organization: 1&1 Internet AG Message-ID: References: <87k66uzeya.fsf@utanet.at> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit X-Trace: sea.gmane.org 1151998892 1102 80.91.229.2 (4 Jul 2006 07:41:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 4 Jul 2006 07:41:32 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 04 09:41:31 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FxfWz-0003e3-Kp for geh-help-gnu-emacs@m.gmane.org; Tue, 04 Jul 2006 09:41:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FxfWz-0003je-6X for geh-help-gnu-emacs@m.gmane.org; Tue, 04 Jul 2006 03:41:13 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!npeer1.de.kpn-eurorings.net!npeer-devel!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 75 Original-NNTP-Posting-Host: p54bec15d.dip0.t-ipconnect.de Original-X-Trace: online.de 1151998814 31056 84.190.193.93 (4 Jul 2006 07:40:14 GMT) Original-X-Complaints-To: abuse@einsundeins.com Original-NNTP-Posting-Date: Tue, 4 Jul 2006 07:40:14 +0000 (UTC) User-Agent: KNode/0.9.2 Original-Xref: shelby.stanford.edu gnu.emacs.help:140182 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:35807 Archived-At: Stefan Reichör wrote: > Andreas Roehler 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