unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* simplifying beginning-of-defun
@ 2009-09-26 17:52 Andreas Roehler
  2009-09-26 21:44 ` Stefan Monnier
  2009-09-27 19:06 ` Glenn Morris
  0 siblings, 2 replies; 18+ messages in thread
From: Andreas Roehler @ 2009-09-26 17:52 UTC (permalink / raw)
  To: XEmacs-Beta; +Cc: emacs-devel


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)))

;;;;;;;




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

end of thread, other threads:[~2009-09-29  8:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).