[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible problem with looking-back function
From: |
Stefan Monnier |
Subject: |
Re: Possible problem with looking-back function |
Date: |
Fri, 20 Aug 2010 15:07:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> Ok, so looking-back should be replaced by:
> (progn
> (goto-char 11) ; go to end of buffer
> ;; ---- looking-back replacement --- BEGIN
> (save-excursion
> (when (/= 0 (skip-chars-backward " \t\n" 1))
> (unless (bolp)
> (forward-line 1))
> (looking-at "^\\([ \t\n]+\\)")))
> ;; ---- looking-back replacement --- END
> (match-beginning 1))
> Now it returns 1.
Or you can still use a regexp, with something like
(defun other-looking-back (re limit)
(save-restriction
(narrow-to-region (point-min) (point))
(goto-char limit)
(re-search-forward (concat "\\(?:" re "\\)\\'") nil t)))
Note that it imposes a few different constraints on the regexp, mostly
it can't use things like \> or \< or \b at the end because
narrow-to-region will prevent it from peeking at the next char.
Stefan