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: simplifying beginning-of-defun Date: Sat, 26 Sep 2009 19:52:57 +0200 Message-ID: <4ABE54F9.7090107@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 1253987723 10304 80.91.229.12 (26 Sep 2009 17:55:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Sep 2009 17:55:23 +0000 (UTC) Cc: emacs-devel@gnu.org To: XEmacs-Beta@xemacs.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 26 19:55:16 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 1MrbTU-0002eh-RT for ged-emacs-devel@m.gmane.org; Sat, 26 Sep 2009 19:54:25 +0200 Original-Received: from localhost ([127.0.0.1]:56849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrbTT-0000Gp-WA for ged-emacs-devel@m.gmane.org; Sat, 26 Sep 2009 13:54:24 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MrbTP-0000Gb-2m for emacs-devel@gnu.org; Sat, 26 Sep 2009 13:54:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MrbTK-0000Ec-LB for emacs-devel@gnu.org; Sat, 26 Sep 2009 13:54:18 -0400 Original-Received: from [199.232.76.173] (port=51045 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrbTK-0000EP-Fn for emacs-devel@gnu.org; Sat, 26 Sep 2009 13:54:14 -0400 Original-Received: from moutng.kundenserver.de ([212.227.17.10]:56151) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MrbTJ-0006Kb-NZ for emacs-devel@gnu.org; Sat, 26 Sep 2009 13:54:14 -0400 Original-Received: from [192.168.178.27] (p54BE8BC6.dip0.t-ipconnect.de [84.190.139.198]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0M7VWZ-1MUHKg09iB-00wkAw; Sat, 26 Sep 2009 19:54:09 +0200 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) X-Provags-ID: V01U2FsdGVkX1+luSXSZpaLI6QPTiTNNIIZtusnk0Q4cHuCY1n mEVVM87+/h4n5/KU+tawRy9PQYoUv7UgdII/N33SUufE+ZSp+c pudaacIpP2FZmmaRO7fFHk0syB8UG2U 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:115666 gmane.emacs.xemacs.beta:30580 Archived-At: Hi, simplifying forms as below should ease maintenance and speed up execution. With var `beginning-of-defun-function' its not necessary to fix all at once at a single place: progmodes may write their own functions and M-x `beginning-of-defun' will work with them. Just to present the code for the moment. If agreed so far, I'll send a patch next days. Cheers Andreas -- https://code.launchpad.net/s-x-emacs-werkstatt/ http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/ ;;;;;;;;;;; ;; Works with XEmacs as with GNU. ;; GNU-folks: ;; de-comment line below before checking. GNU's lisp.el ;; sets this var globally, which seems not useful for me... ;; (setq end-of-defun-function nil) (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. " (interactive "P") (or arg (setq arg 1)) (if beginning-of-defun-function (funcall beginning-of-defun-function arg) (beginning-of-defun-raw arg))) (defun beginning-of-defun-raw (&optional arg) "Called if progmodes didn't set beginning-of-defun-function. " (when (re-search-backward (eval defun-searchform) nil 'move (or arg 1)) (goto-char (match-beginning 0)))) (defun end-of-defun (&optional arg) "Move backward to the end of a function. " (interactive "P") (or arg (setq arg 1)) (if end-of-defun-function (funcall end-of-defun-function arg) (end-of-defun-raw arg))) (defun end-of-defun-raw (&optional arg) "Called if progmodes didn't set end-of-defun-function. " (unless (looking-at (eval defun-searchform)) (beginning-of-defun 1)) (forward-sexp 1) (when (re-search-forward (eval defun-searchform) nil t arg) (goto-char (match-beginning 0)) (forward-sexp 1))) ;;;;;;;