bug-gnu-emacs
[Top][All Lists]
Advanced

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

Re: ada-mode ada-initialize-properties has an error with read-only files


From: martin rudalics
Subject: Re: ada-mode ada-initialize-properties has an error with read-only files
Date: Sun, 12 Aug 2007 11:19:45 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

> 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
           ,@body)
         (unless ,modified
           (restore-buffer-modified-p nil)))))





reply via email to

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