From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: Re: ada-mode ada-initialize-properties has an error with read-only files Date: Sun, 12 Aug 2007 11:19:45 +0200 Message-ID: <46BED0B1.6030008@gmx.at> References: <200708101117.NAA25787@gull.cfmu.corp.eurocontrol.int> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1186910437 20219 80.91.229.12 (12 Aug 2007 09:20:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 12 Aug 2007 09:20:37 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org To: philippe.waroquiers@eurocontrol.int Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 12 11:20:35 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IK9ce-0007z0-2V for geb-bug-gnu-emacs@m.gmane.org; Sun, 12 Aug 2007 11:20:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IK9cd-0001aO-Cm for geb-bug-gnu-emacs@m.gmane.org; Sun, 12 Aug 2007 05:20:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IK9cb-0001XM-51 for bug-gnu-emacs@gnu.org; Sun, 12 Aug 2007 05:20:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IK9ca-0001V7-AZ for bug-gnu-emacs@gnu.org; Sun, 12 Aug 2007 05:20:28 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IK9ca-0001Uu-6O for bug-gnu-emacs@gnu.org; Sun, 12 Aug 2007 05:20:28 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IK9cZ-0001AR-NV for bug-gnu-emacs@gnu.org; Sun, 12 Aug 2007 05:20:28 -0400 Original-Received: (qmail invoked by alias); 12 Aug 2007 09:20:24 -0000 Original-Received: from N809P010.adsl.highway.telekom.at (EHLO [62.47.45.10]) [62.47.45.10] by mail.gmx.net (mp020) with SMTP; 12 Aug 2007 11:20:24 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX1/Exgkfl3DExvGNVjcy5YaMCaSsPdF/z43scvFxr2 mYdeeWER7wPa+A User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: <200708101117.NAA25787@gull.cfmu.corp.eurocontrol.int> X-Y-GMX-Trusted: 0 X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:16326 Archived-At: > We have encountered a small problem with the ada-mode and emacs 22. > When an Ada file is visited in emacs (in this case, I find this file > with M-x find-tag) and this Ada file is a read-only file, > we see an error message appearing in the mini-buffer/*Messages*: > File mode specification error: (buffer-read-only #) > > After investigation, we see that this error message is produced > by ada-initialize-properties. > > To see what is going wrong, I have added various calls to (message) inside > ada-initialize-properties (see modified code below). > > We get the messages "1", "2", "2.1" but not "3" .. "6" > => so this looks to be the indication of a real problem > as ada-initialize-properties does not finish its work. > (NB: I tested with emacs 21 the same "message" modifications. With emacs 21, > ada-initialize-properties properly does the loops. E.g. it gives > multiple messages "2.1", and then gives the messages "3" .. "6". > > The consequences of this problem are not clear to me. I suspect I see > not much consequences because font-lock-mode is also enabled, and > this may "repair" the properties. > I however highly suspect that in case font-lock-mode is not active, > that ada-mode has a bug. > > I suspect that one way or another, in emacs 21, ada-initialize-properties > was called in a context where the buffer could be temporarily modified, > while with emacs 22, this is not the case anymore. > I see that ada-initialize-properties is doing things similar to font-lock. > font-lock has defined a macro save-buffer-state to save/set/restore buffer state when > setting properties. A.o., it sets and then restores inhibit-read-only > and other things. Maybe ada-mode should use this macro or a similar logic ? Thanks for finding and investigating this. Indeed ada-mode should use such a macro here. Also because `ada-initialize-properties' and `ada-after-change-function' may create undo entries which are completely useless. However, I'd strongly favour a canonical macro in subr.el which could be used by other programming modes as well: antlr-mode, Delphi, cperl-mode, or c-mode which has theses lines in cc-defs.el ;; The following is essentially `save-buffer-state' from lazy-lock.el. ;; It ought to be a standard macro. (defmacro c-save-buffer-state (varlist &rest body) .... Something like the following: (eval-when-compile (require 'cl) (defmacro with-buffer-state-unmodified (varlist &rest body) "Bind variables according to VARLIST and eval BODY restoring buffer state. Evaluating BODY does not alter the current buffer's modified state and undo list. In addition this macro permits BODY to modify read-only text and inhibits running any hooks related to buffer changes or character properties. Avoid leaving the current buffer in BODY since this may lead to unpredictable results." (declare (indent 1) (debug let)) (let ((modified (make-symbol "modified"))) `(let* ,(append varlist `((,modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-point-motion-hooks t) (inhibit-modification-hooks t) deactivate-mark buffer-file-name buffer-file-truename)) (progn ,@body) (unless ,modified (restore-buffer-modified-p nil)))))