emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

simplifying beginning-of-defun


From: Andreas Roehler
Subject: simplifying beginning-of-defun
Date: Sat, 26 Sep 2009 19:52:57 +0200
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

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

;;;;;;;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]