[Emacs-ada-mode] FW: ada-mode ada-initialize-properties has an error with read-only files
WAROQUIERS Philippe
philippe.waroquiers at eurocontrol.int
Mon Aug 13 03:08:35 PDT 2007
Forward of a feedback received on bug-gnu-emacs.
>-----Original Message-----
>From: martin rudalics [mailto:rudalics at gmx.at]
>Sent: Sunday 12 August 2007 11:20
>To: WAROQUIERS Philippe
>Cc: bug-gnu-emacs at gnu.org
>Subject: Re: ada-mode ada-initialize-properties has an error
>with read-only files
>
>
> > 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 #<buffer
>flight.adb>)
> >
> > 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
> , at body)
> (unless ,modified
> (restore-buffer-modified-p nil)))))
>
>
____
This message and any files transmitted with it are legally privileged and intended for the sole use of the individual(s) or entity to whom they are addressed. If you are not the intended recipient, please notify the sender by reply and delete the message and any attachments from your system. Any unauthorised use or disclosure of the content of this message is strictly prohibited and may be unlawful.
Nothing in this e-mail message amounts to a contractual or legal commitment on the part of EUROCONTROL, unless it is confirmed by appropriately signed hard copy.
Any views expressed in this message are those of the sender.
More information about the Emacs-ada-mode
mailing list