emacs-devel
[Top][All Lists]
Advanced

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

simplifying beginning-of-defun (2)


From: Andreas Roehler
Subject: simplifying beginning-of-defun (2)
Date: Sun, 27 Sep 2009 18:07:31 +0200
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

Below again the code, as end-of-defun-raw had a bug last times


;; GNU's lisp.el
;; unhappily sets this var globally, ignoring its use for progmodes
(when (featurep 'emacs) (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. "
    (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)))





reply via email to

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