From: Andreas Roehler <andreas.roehler@online.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Alan Mackenzie <acm@muc.de>,
"Stephen J. Turnbull" <stephen@xemacs.org>,
XEmacs-Beta@xemacs.org, emacs-devel@gnu.org,
"Eric M. Ludlam" <eric@siege-engine.com>
Subject: Re: simplifying beginning-of-defun
Date: Tue, 29 Sep 2009 10:29:59 +0200 [thread overview]
Message-ID: <4AC1C587.8020507@online.de> (raw)
In-Reply-To: <jwvtyym8zjl.fsf-monnier+emacs@gnu.org>
...
>
> 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
>
>
>
next prev parent reply other threads:[~2009-09-29 8:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-26 17:52 simplifying beginning-of-defun Andreas Roehler
2009-09-26 21:44 ` Stefan Monnier
2009-09-27 8:10 ` Andreas Roehler
2009-09-27 18:40 ` Stefan Monnier
2009-09-28 6:50 ` Andreas Roehler
2009-09-28 22:46 ` Stefan Monnier
2009-09-29 6:53 ` Andreas Roehler
2009-09-29 8:29 ` Andreas Roehler [this message]
2009-09-27 10:26 ` Andreas Roehler
2009-09-27 11:17 ` Eric M. Ludlam
2009-09-27 18:53 ` Stefan Monnier
2009-09-27 20:07 ` Eric M. Ludlam
2009-09-27 22:52 ` Stefan Monnier
2009-09-28 2:04 ` Eric M. Ludlam
2009-09-28 4:06 ` Stefan Monnier
2009-09-28 11:20 ` Eric M. Ludlam
2009-09-29 6:50 ` Alan Mackenzie
2009-09-27 19:06 ` Glenn Morris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AC1C587.8020507@online.de \
--to=andreas.roehler@online.de \
--cc=XEmacs-Beta@xemacs.org \
--cc=acm@muc.de \
--cc=emacs-devel@gnu.org \
--cc=eric@siege-engine.com \
--cc=monnier@iro.umontreal.ca \
--cc=stephen@xemacs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.