From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Roehler Newsgroups: gmane.emacs.devel,gmane.emacs.xemacs.beta Subject: Re: simplifying beginning-of-defun Date: Tue, 29 Sep 2009 10:29:59 +0200 Message-ID: <4AC1C587.8020507@online.de> References: <4ABE54F9.7090107@online.de> <4ABF1DED.6050906@online.de> <4AC05C9A.2010802@online.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1254213098 8399 80.91.229.12 (29 Sep 2009 08:31:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Sep 2009 08:31:38 +0000 (UTC) Cc: Alan Mackenzie , "Stephen J. Turnbull" , XEmacs-Beta@xemacs.org, emacs-devel@gnu.org, "Eric M. Ludlam" To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 29 10:31:31 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MsY7M-0004jA-Km for ged-emacs-devel@m.gmane.org; Tue, 29 Sep 2009 10:31:28 +0200 Original-Received: from localhost ([127.0.0.1]:56178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsY7M-00043h-6D for ged-emacs-devel@m.gmane.org; Tue, 29 Sep 2009 04:31:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsY7G-00043c-BP for emacs-devel@gnu.org; Tue, 29 Sep 2009 04:31:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsY7B-00043K-KI for emacs-devel@gnu.org; Tue, 29 Sep 2009 04:31:21 -0400 Original-Received: from [199.232.76.173] (port=42273 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsY7B-00043H-DI for emacs-devel@gnu.org; Tue, 29 Sep 2009 04:31:17 -0400 Original-Received: from moutng.kundenserver.de ([212.227.17.9]:61894) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsY7A-0001fU-Qe for emacs-devel@gnu.org; Tue, 29 Sep 2009 04:31:17 -0400 Original-Received: from [192.168.178.27] (p54BE8E18.dip0.t-ipconnect.de [84.190.142.24]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MJnBU-1Mte2d1V2K-0019Sb; Tue, 29 Sep 2009 10:31:13 +0200 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: X-Provags-ID: V01U2FsdGVkX18o+zEs3SXmYplwo4zpFQ1ndGuZJmyjzuNmZqv fBYolwdwjbOCRH7zjOcbTTLyX0LJBBk0O2zlRwR2y4xzsmgnjN yDX2T3g9f7to0axc/vLcyLgjPkj3ziK X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:115779 gmane.emacs.xemacs.beta:30620 Archived-At: ... > > It's definitely meant to be buffer-local. That doesn't mean there > shouldn't be a meaningful default Hi Stefan, you are indicating the appropriate name, thanks. Below a slightly revisited code again. Renamed beginning/end-of-defun-raw into beginning/end-of-defun-default Declared beginning/end-of-defun-function buffer-local Updated the docstrings, Enjoy! Andreas ;;;;;;;;;;;;;; ;; For modes other than Emacs-Lisp only, remove wrongly set value (when (featurep 'emacs) (setq end-of-defun-function nil)) (defvar beginning-of-defun-function nil "If non-nil, called by `beginning-of-defun' instead of `beginning-of-defun-default'. Useful, if `defun-prompt-regexp' is not sufficient to handle a mode's needs. It's buffer-local. ") (make-variable-buffer-local 'beginning-of-defun-function) (defvar end-of-defun-function nil "If non-nil, called by `end-of-defun' instead of `end-of-defun-default'. Useful if default function is not appropriate. It's buffer-local. ") (make-variable-buffer-local 'end-of-defun-function) (setq defun-searchform '(if defun-prompt-regexp (concat "^\\s(\\|" "\\(" defun-prompt-regexp "\\)\\s(") "^\\s(")) (defun beginning-of-defun (&optional arg) "Move backward to the beginning of a functions definition. For ARGUMENT see documentation in `beginning-of-defun-default' resp. in `beginning-of-defun-function', if set. " (interactive "P") (if beginning-of-defun-function (funcall beginning-of-defun-function arg) (beginning-of-defun-default arg))) (defun beginning-of-defun-default (&optional arg) "Move backward to next beginning of function definition. With argument, do it that many times. Called if modes didn't set beginning-of-defun-function. " (or arg (setq arg 1)) (when (re-search-backward (eval defun-searchform) nil 'move (or arg 1)) (goto-char (match-beginning 0)))) (defun end-of-defun (&optional arg) "Move forward to the end of a function. For ARGUMENT see documentation in `end-of-defun-default' resp. in `end-of-defun-function', if set. " (interactive "P") (if end-of-defun-function (funcall end-of-defun-function arg) (end-of-defun-default arg))) (defun end-of-defun-default (&optional arg) "Move forward to next end of function definition. With argument, do it that many times. Called if modes didn't set end-of-defun-function. " (or arg (setq arg 1)) (skip-chars-forward " \t\r\n\f") (unless (looking-at (eval defun-searchform)) (beginning-of-defun 1)) (when (re-search-forward (eval defun-searchform) nil t arg) (goto-char (match-beginning 0)) (forward-sexp 1))) ;;;;;;;;;;;; for those buffers which don't want to > bother to set it themselves. > > > Stefan > > >