emacs-devel
[Top][All Lists]
Advanced

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

Re: font-locking and open parens in column 0


From: Mackenzie, Alan
Subject: Re: font-locking and open parens in column 0
Date: Thu, 2 Nov 2006 09:49:12 +0100

Hi, Emacs!

[Apologies for not being able to reply with proper headers, since I'm
still without a network connection at home.  Please send any CCs to
address@hidden as well as my work address.]

Martin Rudalics wrote on Monday 11th September 2006, 15:05:55 +0200:

> (1) With emacs -Q open ~/src/syntax.c

> (2) Execute

>(defun foo ()
>  (interactive)
>  (re-search-forward "string-to-syntax")
>  (forward-line 6)
>  (recenter 0))

>This will fontify the entire body of `string_to_syntax' as a C string
>due to the left paren in column zero of the doc-string.

The cause of this (as Martin (almost) discerned) is that the handling of
(eq open-paren-in-column-0-is-defun-start nil) in begining-of-defun-raw
hasn't been implemented.  The function just looks for a "(" in C0
regardless of that variable.

"Clearly", when that variable is nil, a defun can begin at no place
other
than a paren at the outermost level.  Therefore, the function must scan
the entire source file from BOB, as in the earliest days.

The patch below implements this.  When applied (don't forget to rebuild
Emacs or M-x load-file lisp.elc, since lisp.elc is a preloaded file),
Emacs fontifies string-to-syntax properly after jumping there with M-x
foo.


2006-11-01  Alan Mackenzie  <address@hidden>

        * emacs-lisp/lisp.el (beginning-of-defun-raw): Code up the case
        (eq open-paren-in-column-0-is-defun-start nil) by searching for
        least nested open-paren.


*** lisp-1.74.el        2006-02-19 12:51:43.000000000 +0000
--- lisp.el     2006-11-01 22:03:56.313088952 +0000
***************
*** 208,229 ****
  
  If variable `beginning-of-defun-function' is non-nil, its value
  is called as a function to find the defun's beginning."
!   (interactive "p")
!   (if beginning-of-defun-function
!       (if (> (setq arg (or arg 1)) 0)
!         (dotimes (i arg)
!           (funcall beginning-of-defun-function))
!       ;; Better not call end-of-defun-function directly, in case
!       ;; it's not defined.
!       (end-of-defun (- arg)))
!     (and arg (< arg 0) (not (eobp)) (forward-char 1))
      (and (re-search-backward (if defun-prompt-regexp
                                 (concat (if
open-paren-in-column-0-is-defun-start
                                             "^\\s(\\|" "")
                                         "\\(?:" defun-prompt-regexp
"\\)\\s(")
                               "^\\s(")
!                            nil 'move (or arg 1))
!        (progn (goto-char (1- (match-end 0)))) t)))
  
  (defvar end-of-defun-function nil
    "If non-nil, function for function `end-of-defun' to call.
--- 208,270 ----
  
  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
!     (if (> arg 0)
!       (dotimes (i arg)
!         (funcall beginning-of-defun-function))
!       ;; Better not call end-of-defun-function directly, in case
!       ;; it's not defined.
!       (end-of-defun (- arg))))
! 
!    ((or defun-prompt-regexp open-paren-in-column-0-is-defun-start)
!     (and (< arg 0) (not (eobp)) (forward-char 1))
      (and (re-search-backward (if defun-prompt-regexp
                                 (concat (if
open-paren-in-column-0-is-defun-start
                                             "^\\s(\\|" "")
                                         "\\(?:" defun-prompt-regexp
"\\)\\s(")
                               "^\\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 nesting-depth)
!       (save-restriction
!       (widen)
!       (setq pps-state (parse-partial-sexp (point-min) (point))
!             nesting-depth (nth 0 pps-state))
!       ;; 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.


-- 
Alan Mackenzie (Ittersbach, Germany).



*******************************************
Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte 
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail 
irrtuemlich erhalten haben, informieren Sie bitte sofort den Absender und 
loeschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe 
dieser Mail ist nicht gestattet.
 
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and delete this e-mail. Any unauthorized copying, 
disclosure or distribution of the contents in this e-mail is strictly forbidden.
*******************************************





reply via email to

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