[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mysterious fontification/C++ context issue
From: |
martin rudalics |
Subject: |
Re: Mysterious fontification/C++ context issue |
Date: |
Wed, 06 Dec 2006 10:04:23 +0100 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
> Here's a tentative fix for the bug, not that well tested, but tested a
> little bit:
>
> 2006-12-04 Alan Mackenzie <address@hidden>
>
> * emacs-lisp/lisp.el (beginning-of-defun-raw): In the seeking a
> non-nested open-paren case, check there are enough lists to move
> over. Return the correct value.
Thanks for taking care of this. Please note:
1. You don't widen the buffer before calling `syntax-ppss'.
2. A construct built along
(foo
) (bar)
with point at "bar" might derail font-lock (remember,
`c-beginning-of-defun-1' calls `beginning-of-defun', not
`beginning-of-defun-raw').
3. All this is still awfully slow and expensive: Open a larger buffer
like xdisp.c, jump to its end, hit M-v a couple of times, and look at
CPU consumption.
4. You could avoid the tedious `up-list' steps by using a variant of the
tentative fix I attached.
5. Consider making `open-paren-in-column-0-is-defun-start' a real user
option in C mode. Let, for example, users decide whether they want to
respect GNU coding standards as mentioned in
http://lists.gnu.org/archive/html/bug-gnu-emacs/2006-11/msg00037.html
This should also permit binding C-M-a / C-M-e to `c-beginning-of-defun'
/ `c-end-of-defun' when `open-paren-in-column-0-is-defun-start' is nil.
6. In any case, the new behavior should be documented since it applies
whenever `open-paren-in-column-0-is-defun-start' is set to nil.
*** lisp.el Thu Nov 9 07:55:26 2006
--- lisp.el Wed Dec 6 08:53:18 2006
***************
*** 229,271 ****
"^\\s(")
nil 'move arg)
(progn (goto-char (1- (match-end 0)))) t))
-
(t
! ;; Column 0 has no significance - so scan forward from BOB to see how
! ;; nested point is, then carry on from there.
! (let* ((floor (point-min))
! (ceiling (point-max))
! (pps-state (let (syntax-begin-function
! font-lock-beginning-of-syntax-function)
! (syntax-ppss)))
! (nesting-depth (nth 0 pps-state)))
(save-restriction
(widen)
! ;; Get outside of any string or comment.
! (if (nth 8 pps-state)
! (goto-char (nth 8 pps-state)))
!
! (cond
! ((> arg 0)
! (when (> nesting-depth 0)
! (up-list (- nesting-depth))
! (setq arg (1- arg)))
! ;; We're now outside of any defun.
! (backward-list arg)
! (if (< (point) floor) (goto-char floor)))
!
! ((< arg 0)
! (cond
! ((> nesting-depth 0)
! (up-list nesting-depth)
! (setq arg (1+ arg)))
! ((not (looking-at "\\s("))
! ;; We're between defuns, and not at the start of one.
! (setq arg (1+ arg))))
! (forward-list (- arg))
! (down-list)
! (backward-char)
! (if (> (point) ceiling) (goto-char ceiling)))))))))
(defvar end-of-defun-function nil
"If non-nil, function for function `end-of-defun' to call.
--- 229,263 ----
"^\\s(")
nil 'move arg)
(progn (goto-char (1- (match-end 0)))) t))
(t
! (let ((floor (point-min))
! (ceiling (point-max)))
(save-restriction
(widen)
! (let* ((ppss (let (syntax-begin-function
! font-lock-beginning-of-syntax-function)
! (syntax-ppss)))
! (pos (or (let ((pos (car (nth 9 ppss))))
! (when pos ; Within defun.
! (when (> arg 0) (setq arg (1- arg)))
! pos))
! (nth 8 ppss) ; Within string or comment.
! (point)))) ; Must be at outermost level.
! (goto-char pos)
! (condition-case nil
! (progn
! (forward-list (- arg))
! (cond
! ((< pos floor)
! (goto-char floor)
! nil)
! ((> pos ceiling)
! (goto-char ceiling)
! nil)
! (t)))
! (error
! (goto-char (if (< arg 0) ceiling floor))
! nil))))))))
(defvar end-of-defun-function nil
"If non-nil, function for function `end-of-defun' to call.
- Re: Mysterious fontification/C++ context issue, Alan Mackenzie, 2006/12/04
- Re: Mysterious fontification/C++ context issue, Richard Stallman, 2006/12/05
- Re: Mysterious fontification/C++ context issue,
martin rudalics <=
- Re: Mysterious fontification/C++ context issue, Kim F. Storm, 2006/12/06
- Re: Mysterious fontification/C++ context issue, Chong Yidong, 2006/12/06
- Re: Mysterious fontification/C++ context issue, Richard Stallman, 2006/12/06
- Re: Mysterious fontification/C++ context issue, Chong Yidong, 2006/12/09
- Re: Mysterious fontification/C++ context issue, Stefan Monnier, 2006/12/09
- Re: Mysterious fontification/C++ context issue, Richard Stallman, 2006/12/10
- Re: Mysterious fontification/C++ context issue, Stefan Monnier, 2006/12/10
- Re: Mysterious fontification/C++ context issue, Stefan Monnier, 2006/12/10
- Re: Mysterious fontification/C++ context issue, Chong Yidong, 2006/12/12
- Re: Mysterious fontification/C++ context issue, Stefan Monnier, 2006/12/12