[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mysterious fontification/C++ context issue - Patch for beginning-of-
From: |
Alan Mackenzie |
Subject: |
Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw. |
Date: |
13 Dec 2006 22:29:43 +0100 |
Date: |
Wed, 13 Dec 2006 22:40:09 +0000 |
User-agent: |
Mutt/1.5.9i |
Hi, Richard, Chong, Martin, and Steffan!
On Sun, Dec 10, 2006 at 03:30:49PM -0500, Chong Yidong wrote:
> Alan Mackenzie <address@hidden> writes:
> The slowdown [scrolling in very big files.c, e.g. xdisp.c] has been a
> big distraction for me.
> As I understand, in CC mode the o-p-i-c-0-i-d-s variable is only
> relevant for Emacs hackers. Now:
> - If o-p-i-c-0-i-d-s is t, some Emacs source files may get
> misfontified. But as Martin has pointed out, we can tweak these
> files to follow the o-p-i-c-0-i-d-s standard. Thus no problem.
> - If o-p-i-c-0-i-d-s is nil, there's just no way to avoid a noticeable
> slowdown in the bigger Emacs source file.
> So let's make o-p-i-c-0-i-d-s default to t for the release.
The right default for opic0ids in CC Mode is nil. Please believe me on
this point.
> If someone later comes up with a clever c-beginning-of-defun function,
> we can switch it back.
There is already an exceptionally clever c-beginning-of-defun function.
Martin Stjernholm put a _lot_ of work into it. It depends essentially on
beginning-of-defun working "correctly" (i.e. syntactically) when opic0ids
is set to nil.
> In any case, could someone check in Martin's optimization to
> c-beginning-of-defun-raw, or send me the patch with a changelog so
> that I can check it in?
Chong, especially: Please load xdisp.c with the following patch, and tell
me whether or not its slowness is still a problem.
Everybody: this patch is quite intricate, so could you please review it
and tell me if you find any bugs.
2006-12-13 Alan Mackenzie <address@hidden>
* emacs-lisp/lisp.el (beginning-of-defun-raw): Optimise (for
speed) the case when open-paren-in-column-0-is-defun-start is nil.
Based on code by Martin Rudalics.
Index: lisp.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/lisp.el,v
retrieving revision 1.76
diff -c -r1.76 lisp.el
*** lisp.el 7 Dec 2006 04:47:47 -0000 1.76
--- lisp.el 13 Dec 2006 21:08:25 -0000
***************
*** 185,197 ****
means move forward to Nth following beginning of defun.
Returns t unless search stops due to beginning or end of buffer.
- Normally a defun starts when there is a char with open-parenthesis
- syntax at the beginning of a line. If `defun-prompt-regexp' is
- non-nil, then a string which matches that regexp may precede the
- open-parenthesis, and point ends up at the beginning of the line.
-
If variable `beginning-of-defun-function' is non-nil, its value
! is called as a function to find the defun's beginning."
(interactive "p")
(or (not (eq this-command 'beginning-of-defun))
(eq last-command 'beginning-of-defun)
--- 185,202 ----
means move forward to Nth following beginning of defun.
Returns t unless search stops due to beginning or end of buffer.
If variable `beginning-of-defun-function' is non-nil, its value
! is called as a function to find the defun's beginning.
!
! Normally a defun is assumed to start where there is a char with
! open-parenthesis syntax at the beginning of a line. If
! `defun-prompt-regexp' is non-nil, then a string which matches
! that regexp may precede the open-parenthesis, and point ends up
! at the beginning of the line.
!
! If `defun-prompt-regexp' and `open-paren-in-column-0-is-defun-start'
! are both nil, the function instead finds an open-paren at the
! outermost level."
(interactive "p")
(or (not (eq this-command 'beginning-of-defun))
(eq last-command 'beginning-of-defun)
***************
*** 208,215 ****
If variable `beginning-of-defun-function' is non-nil, its value
is called as a function to find the defun's beginning."
! (interactive "p") ; change this to "P", maybe, if we ever come to pass ARG
! ; to beginning-of-defun-function.
(unless arg (setq arg 1)) ; The call might not be interactive.
(cond
(beginning-of-defun-function
--- 213,220 ----
If variable `beginning-of-defun-function' is non-nil, its value
is called as a function to find the defun's beginning."
! (interactive "p") ; change this to "P", maybe, if we ever come to pass ARG
! ; to beginning-of-defun-function.
(unless arg (setq arg 1)) ; The call might not be interactive.
(cond
(beginning-of-defun-function
***************
*** 230,271 ****
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.
--- 235,284 ----
nil 'move arg)
(progn (goto-char (1- (match-end 0)))) t))
;; Column 0 has no significance - so scan forward from BOB to see how
;; nested point is, then carry on from there.
! ((eq arg 0))
! (t
! (let ((floor (point-min))
! (ceiling (point-max))
! (arg-+ve (> arg 0)))
(save-restriction
(widen)
! (let ((ppss (let (syntax-begin-function
! font-lock-beginning-of-syntax-function)
! (syntax-ppss)))
! encl-pos) ; position of least enclosing paren, or nil.
! ;; Back out of any comment/string, so that encl-pos will always
! ;; become nil if we're at top-level.
! (when (nth 8 ppss)
! (goto-char (nth 8 ppss))
! (setq ppss (syntax-ppss))) ; should be fast, due to cache.
! (setq encl-pos (syntax-ppss-toplevel-pos ppss))
! (if encl-pos (goto-char encl-pos))
!
! (if (and encl-pos arg-+ve)
! (setq arg (1- arg)))
! (if (and (not encl-pos) (not arg-+ve) (not (looking-at "\\s(")))
! (setq arg (1+ arg)))
!
! (condition-case nil ; to catch there being crazy parens.
! (progn
! (goto-char (scan-lists (point) (- arg) 0)) ; will work or
trigger
! ; the condition-case.
! (if arg-+ve
! (if (>= (point) floor)
! t
! (goto-char floor)
! nil)
! (goto-char (1- (scan-lists (point) 1 -1))) ; forward to next
(,
! ; or trigger the
c-c
! (if (<= (point) ceiling)
! t
! (goto-char ceiling)
! nil)))
! (error
! (goto-char (if arg-+ve floor ceiling))
! nil))))))))
(defvar end-of-defun-function nil
"If non-nil, function for function `end-of-defun' to call.
--
Alan.
- Re: Mysterious fontification/C++ context issue, (continued)
- Re: Mysterious fontification/C++ context issue, Richard Stallman, 2006/12/09
- Re: Mysterious fontification/C++ context issue, Alan Mackenzie, 2006/12/09
- Re: Mysterious fontification/C++ context issue, Chong Yidong, 2006/12/09
- Re: Mysterious fontification/C++ context issue, Alan Mackenzie, 2006/12/10
- Re: Mysterious fontification/C++ context issue, David Kastrup, 2006/12/10
- Re: Mysterious fontification/C++ context issue, Alan Mackenzie, 2006/12/10
- Re: Mysterious fontification/C++ context issue, David Kastrup, 2006/12/10
- Re: Mysterious fontification/C++ context issue, Chong Yidong, 2006/12/10
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw.,
Alan Mackenzie <=
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., Chong Yidong, 2006/12/13
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., Alan Mackenzie, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., martin rudalics, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., Alan Mackenzie, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., David Kastrup, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., Chong Yidong, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., Chong Yidong, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., Alan Mackenzie, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., Chong Yidong, 2006/12/14
- Re: Mysterious fontification/C++ context issue - Patch for beginning-of-defun-raw., David Kastrup, 2006/12/14