From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Mackenzie, Alan" Newsgroups: gmane.emacs.devel Subject: Re: font-locking and open parens in column 0 Date: Thu, 2 Nov 2006 09:49:12 +0100 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1162497554 15691 80.91.229.2 (2 Nov 2006 19:59:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 2 Nov 2006 19:59:14 +0000 (UTC) Cc: Martin Rudalics , Richard Stallman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 02 20:59:05 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GfiaY-0000TC-6P for ged-emacs-devel@m.gmane.org; Thu, 02 Nov 2006 20:51:02 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GfiaX-0008Fu-E0 for ged-emacs-devel@m.gmane.org; Thu, 02 Nov 2006 14:50:57 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GfYGH-0000US-P5 for emacs-devel@gnu.org; Thu, 02 Nov 2006 03:49:21 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GfYGG-0000S8-W9 for emacs-devel@gnu.org; Thu, 02 Nov 2006 03:49:21 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GfYGG-0000RT-DO for emacs-devel@gnu.org; Thu, 02 Nov 2006 03:49:20 -0500 Original-Received: from [64.18.1.189] (helo=exprod6og54.obsmtp.com) by monty-python.gnu.org with smtp (Exim 4.52) id 1GfYGF-0004oG-1f; Thu, 02 Nov 2006 03:49:19 -0500 Original-Received: from source ([194.121.90.51]) by exprod6ob54.postini.com ([64.18.5.12]) with SMTP; Thu, 02 Nov 2006 00:49:13 PST Original-Received: from oekaw2ex01.hbi.ad.harman.com (unverified [172.16.1.72]) by oekaw2vw01.hbi.ad.harman.com (Content Technologies SMTPRS 4.3.10) with ESMTP id ; Thu, 2 Nov 2006 09:42:33 +0100 Original-Received: from OEKAW2EXVS03.hbi.ad.harman.com ([172.16.1.97]) by oekaw2ex01.hbi.ad.harman.com with Microsoft SMTPSVC (5.0.2195.6713); Thu, 2 Nov 2006 09:49:12 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Re: font-locking and open parens in column 0 Thread-Index: Acb+W8TT65bxHtX3SXC63INyFgSRCw== Original-To: X-OriginalArrivalTime: 02 Nov 2006 08:49:12.0968 (UTC) FILETIME=[C5256880:01C6FE5B] X-Mailman-Approved-At: Thu, 02 Nov 2006 14:50:42 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:61621 Archived-At: 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 acm@muc.de 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 * 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 **** =20 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))) =20 (defvar end-of-defun-function nil "If non-nil, function for function `end-of-defun' to call. --- 208,270 ---- =20 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)))) !=20 ! ((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)) !=20 ! (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))) !=20 ! (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))) !=20 ! ((< 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))))))))) =20 (defvar end-of-defun-function nil "If non-nil, function for function `end-of-defun' to call. --=20 Alan Mackenzie (Ittersbach, Germany). ******************************************* Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte Informati= onen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtuemli= ch erhalten haben, informieren Sie bitte sofort den Absender und loeschen S= ie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe diese= r Mail ist nicht gestattet. =20 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) plea= se notify the sender immediately and delete this e-mail. Any unauthorized c= opying, disclosure or distribution of the contents in this e-mail is strict= ly forbidden. *******************************************