unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: philippe.waroquiers@eurocontrol.int
Cc: bug-gnu-emacs@gnu.org
Subject: Re: ada-mode ada-initialize-properties has an error with read-only files
Date: Sun, 12 Aug 2007 11:19:45 +0200	[thread overview]
Message-ID: <46BED0B1.6030008@gmx.at> (raw)
In-Reply-To: <200708101117.NAA25787@gull.cfmu.corp.eurocontrol.int>

 > 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	other threads:[~2007-08-12  9:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-10 11:17 ada-mode ada-initialize-properties has an error with read-only files Philippe Waroquiers
2007-08-12  9:19 ` martin rudalics [this message]
2007-08-14 12:31 ` martin rudalics
2007-08-14 19:51   ` WAROQUIERS Philippe
2007-08-14 21:16     ` martin rudalics
2007-08-16 21:42       ` WAROQUIERS Philippe
2007-08-17  7:16         ` Stephen Leake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46BED0B1.6030008@gmx.at \
    --to=rudalics@gmx.at \
    --cc=bug-gnu-emacs@gnu.org \
    --cc=philippe.waroquiers@eurocontrol.int \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).