unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* ada-mode ada-initialize-properties has an error with read-only files
@ 2007-08-10 11:17 Philippe Waroquiers
  2007-08-12  9:19 ` martin rudalics
  2007-08-14 12:31 ` martin rudalics
  0 siblings, 2 replies; 7+ messages in thread
From: Philippe Waroquiers @ 2007-08-10 11:17 UTC (permalink / raw)
  To: bug-gnu-emacs


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 ?


(defun ada-initialize-properties ()
  "Initialize some special text properties in the whole buffer.
In particular, character constants are said to be strings, #...# are treated
as numbers instead of gnatprep comments."
  (message "1")
  (save-excursion
    (save-restriction
      (widen)
      (goto-char (point-min))
      (message "2")
      (while (re-search-forward "'.'" nil t)
        (progn
          (message "2.1")
          (add-text-properties (match-beginning 0) (match-end 0)
                               '(syntax-table ("'" . ?\")))))
      (goto-char (point-min))
      (message "3")
      (while (re-search-forward "^[ \t]*#" nil t)
	(add-text-properties (match-beginning 0) (match-end 0)
			     '(syntax-table (11 . 10))))
      (message "4")
      (set-buffer-modified-p nil)
      (message "5")

      ;;  Setting this only if font-lock is not set won't work
      ;;  if the user activates or deactivates font-lock-mode,
      ;;  but will make things faster most of the time
      (add-hook 'after-change-functions 'ada-after-change-function nil t)
      (message "6")
      )))


In GNU Emacs 22.1.1 (hppa1.1-hp-hpux11.11, Motif Version 2.1.0)
 of 2007-08-04 on bobcat
Windowing system distributor `Hewlett-Packard Company', version 11.0.600000
configured using `configure  'hppa1.1-hp-hpux11.11' '--prefix=/cm/ot/TOOL/GNU!12.43/build_G!67.IP.11/generated' '--exec-prefix=/cm/ot/TOOL/GNU!12.43/build_G!67.IP.11/generated/libexec/emacs-22.1' '--mandir=/cm/ot/TOOL/GNU!12.43/build_G!67.IP.11/generated/man' '--with-gcc=no' '--with-xpm' '--with-x11r6' '--with-x-toolkit=motif' '--x-libraries=/usr/lib/X11R6:/usr/contrib/X11R6/lib' 'build_alias=hppa1.1-hp-hpux11.11' 'host_alias=hppa1.1-hp-hpux11.11' 'target_alias=hppa1.1-hp-hpux11.11' 'CFLAGS=-g -Ae +O0 +DA1.1' 'LDFLAGS= -L/cm/ot/TOOL/GNU!12.43/build_G!67.IP.11/generated/work/emacs-22.1/xpm-3.4k/lib' 'CPPFLAGS=-I/cm/ot/TOOL/GNU!12.43/build_G!67.IP.11/generated/work/emacs-22.1/xpm-3.4k ''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: C
  locale-coding-system: nil
  default-enable-multibyte-characters: nil


-- 
Philippe WAROQUIERS                  Eurocontrol - Central Flow Management Unit
philippe.waroquiers@eurocontrol.int  Rue de la fusee, 96
Tel: +32 2 729 97 35                 1130 Brussels
Fax: +32 2 729 90 22                 Belgium
____

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: ada-mode ada-initialize-properties has an error with read-only files
  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
  2007-08-14 12:31 ` martin rudalics
  1 sibling, 0 replies; 7+ messages in thread
From: martin rudalics @ 2007-08-12  9:19 UTC (permalink / raw)
  To: philippe.waroquiers; +Cc: bug-gnu-emacs

 > 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)))))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: ada-mode ada-initialize-properties has an error with read-only files
  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
@ 2007-08-14 12:31 ` martin rudalics
  2007-08-14 19:51   ` WAROQUIERS Philippe
  1 sibling, 1 reply; 7+ messages in thread
From: martin rudalics @ 2007-08-14 12:31 UTC (permalink / raw)
  To: philippe.waroquiers; +Cc: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 712 bytes --]

 > 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.

I've been looking into this and noted that handling syntax-table
properties seems completely broken unless done by font-lock.  Could you
please try the attached patch and tell me whether it gives good results
with font-lock-mode enabled _and_ disabled.  Thanks.

[-- Attachment #2: ada-mode.patch --]
[-- Type: text/plain, Size: 8602 bytes --]

*** progmodes/ada-mode.el	Wed Jul 25 06:29:40 2007
--- progmodes/ada-mode.el	Tue Aug 14 14:22:14 2007
***************
*** 829,841 ****
  ;; Thus their syntax property is changed automatically, and we can still use
  ;; the standard Emacs functions for sexp (see `ada-in-string-p')
  ;;
! ;; On Emacs, this is done through the `syntax-table' text property. The
! ;; modification is done automatically each time the user as typed a new
! ;; character. This is already done in `font-lock-mode' (in
! ;; `font-lock-syntactic-keywords', so we take advantage of the existing
! ;; mechanism. If font-lock-mode is not activated, we do it by hand in
! ;; `ada-after-change-function', thanks to `ada-deactivate-properties' and
! ;; `ada-initialize-properties'.
  ;;
  ;; on XEmacs, the `syntax-table' property does not exist and we have to use a
  ;; slow advice to `parse-partial-sexp' to do the same thing.
--- 829,840 ----
  ;; Thus their syntax property is changed automatically, and we can still use
  ;; the standard Emacs functions for sexp (see `ada-in-string-p')
  ;;
! ;; On Emacs, this is done through the `syntax-table' text property.  The
! ;; corresponding action is applied automatically each time the buffer
! ;; changes.  If `font-lock-mode' is enabled (the default) the action is
! ;; set up by `font-lock-syntactic-keywords'.  Otherwise, we do it
! ;; manually in `ada-after-change-function'.  The proper method is
! ;; installed by `ada-handle-syntax-table-properties'.
  ;;
  ;; on XEmacs, the `syntax-table' property does not exist and we have to use a
  ;; slow advice to `parse-partial-sexp' to do the same thing.
***************
*** 852,858 ****
  declares it as a word constituent."
    (interactive)
    (setq ada-mode-syntax-table (make-syntax-table))
-   (set-syntax-table  ada-mode-syntax-table)
  
    ;; define string brackets (`%' is alternative string bracket, but
    ;; almost never used as such and throws font-lock and indentation
--- 851,856 ----
***************
*** 936,985 ****
  	    (insert (caddar change))
  	    (setq change (cdr change)))))))
  
! (defun ada-deactivate-properties ()
!   "Deactivate Ada mode's properties handling.
! This would be a duplicate of font-lock if both are used at the same time."
!   (remove-hook 'after-change-functions 'ada-after-change-function t))
! 
! (defun ada-initialize-properties ()
!   "Initialize some special text properties in the whole buffer.
! In particular, character constants are said to be strings, #...# are treated
! as numbers instead of gnatprep comments."
!   (save-excursion
!     (save-restriction
!       (widen)
!       (goto-char (point-min))
!       (while (re-search-forward "'.'" nil t)
! 	(add-text-properties (match-beginning 0) (match-end 0)
! 			     '(syntax-table ("'" . ?\"))))
!       (goto-char (point-min))
!       (while (re-search-forward "^[ \t]*#" nil t)
! 	(add-text-properties (match-beginning 0) (match-end 0)
! 			     '(syntax-table (11 . 10))))
!       (set-buffer-modified-p nil)
! 
!       ;;  Setting this only if font-lock is not set won't work
!       ;;  if the user activates or deactivates font-lock-mode,
!       ;;  but will make things faster most of the time
!       (add-hook 'after-change-functions 'ada-after-change-function nil t)
!       )))
  
  (defun ada-after-change-function (beg end old-len)
    "Called when the region between BEG and END was changed in the buffer.
  OLD-LEN indicates what the length of the replaced text was."
!   (let ((inhibit-point-motion-hooks t)
! 	(eol (point)))
!     (save-excursion
        (save-match-data
! 	(beginning-of-line)
! 	(remove-text-properties (point) eol '(syntax-table nil))
! 	(while (re-search-forward "'.'" eol t)
! 	  (add-text-properties (match-beginning 0) (match-end 0)
! 			       '(syntax-table ("'" . ?\"))))
! 	(beginning-of-line)
! 	(if (looking-at "^[ \t]*#")
! 	    (add-text-properties (match-beginning 0) (match-end 0)
! 				 '(syntax-table (11 . 10))))))))
  
  ;;------------------------------------------------------------------
  ;;  Testing the grammatical context
--- 934,992 ----
  	    (insert (caddar change))
  	    (setq change (cdr change)))))))
  
! (defun ada-set-syntax-table-properties (beg end)
!   "Assign `syntax-table' properties between BEG and END.
! In particular, character constants are said to be strings, #...#
! are treated as numbers instead of gnatprep comments."
!   (let ((modified (buffer-modified-p))
! 	(buffer-undo-list t)
! 	(inhibit-read-only t)
! 	(inhibit-point-motion-hooks t)
! 	(inhibit-modification-hooks t))
!     (remove-text-properties beg end '(syntax-table nil))
!     (goto-char beg)
!     (while (re-search-forward
! 	    ;; The following regexp was adapted from
! 	    ;; `ada-font-lock-syntactic-keywords'.
! 	    "^[ \t]*\\(#\\(?:if\\|else\\|elsif\\|end\\)\\)\\|[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)"
! 	    nil t)
!       (if (match-beginning 1)
! 	  (put-text-property
! 	       (match-beginning 1) (match-end 1) 'syntax-table '(11 . ?\n))
! 	(put-text-property
! 	     (match-beginning 2) (match-end 2) 'syntax-table '(7 . ?'))
! 	(put-text-property
! 	     (match-beginning 3) (match-end 3) 'syntax-table '(7 . ?'))))
!     (unless modified
!       (restore-buffer-modified-p nil))))
  
  (defun ada-after-change-function (beg end old-len)
    "Called when the region between BEG and END was changed in the buffer.
  OLD-LEN indicates what the length of the replaced text was."
!   (save-excursion
!     (save-restriction
!       (widen)
        (save-match-data
! 	(ada-set-syntax-table-properties
! 	 (progn (goto-char beg) (line-beginning-position))
! 	 (progn (goto-char end) (line-end-position)))))))
! 
! (defun ada-initialize-syntax-table-properties ()
!   "Assign `syntax-table' properties in current buffer."
!     (save-excursion
!       (save-restriction
! 	(widen)
! 	(save-match-data
! 	  (ada-set-syntax-table-properties (point-min) (point-max)))))
!     (add-hook 'after-change-functions 'ada-after-change-function nil t))
! 
! (defun ada-handle-syntax-table-properties ()
!   "Handle `syntax-table' properties."
!   (if font-lock-mode
!       ;; `font-lock-mode' will take care of `syntax-table' properties.
!       (remove-hook 'after-change-functions 'ada-after-change-function t)
!     ;; Take care of `syntax-table' properties manually.
!     (ada-initialize-syntax-table-properties)))
  
  ;;------------------------------------------------------------------
  ;;  Testing the grammatical context
***************
*** 1150,1155 ****
--- 1157,1164 ----
  
    (interactive)
    (kill-all-local-variables)
+   
+   (set-syntax-table ada-mode-syntax-table)
  
    (set (make-local-variable 'require-final-newline) mode-require-final-newline)
  
***************
*** 1340,1346 ****
    (setq which-func-functions '(ada-which-function))
  
    ;;  Support for indent-new-comment-line (Especially for XEmacs)
!   (setq comment-multi-line nil)
  
    (setq major-mode 'ada-mode
  	mode-name "Ada")
--- 1349,1355 ----
    (setq which-func-functions '(ada-which-function))
  
    ;;  Support for indent-new-comment-line (Especially for XEmacs)
!   (set (make-local-variable 'comment-multi-line) nil)
  
    (setq major-mode 'ada-mode
  	mode-name "Ada")
***************
*** 1377,1385 ****
    ;;  font-lock-mode
  
    (unless (featurep 'xemacs)
!     (progn
!       (ada-initialize-properties)
!       (add-hook 'font-lock-mode-hook 'ada-deactivate-properties nil t)))
  
    ;; the following has to be done after running the ada-mode-hook
    ;; because users might want to set the values of these variable
--- 1386,1393 ----
    ;;  font-lock-mode
  
    (unless (featurep 'xemacs)
!     (ada-initialize-syntax-table-properties)
!     (add-hook 'font-lock-mode-hook 'ada-handle-syntax-table-properties nil t))
  
    ;; the following has to be done after running the ada-mode-hook
    ;; because users might want to set the values of these variable
***************
*** 5200,5207 ****
    ;; This sets the properties of the characters, so that ada-in-string-p
    ;; correctly handles '"' too...
    '(("[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?')))
!     ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n)))
!     ))
  
  (defvar ada-font-lock-keywords
    (eval-when-compile
--- 5208,5214 ----
    ;; This sets the properties of the characters, so that ada-in-string-p
    ;; correctly handles '"' too...
    '(("[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?')))
!     ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n)))))
  
  (defvar ada-font-lock-keywords
    (eval-when-compile

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: ada-mode ada-initialize-properties has an error with read-only files
  2007-08-14 12:31 ` martin rudalics
@ 2007-08-14 19:51   ` WAROQUIERS Philippe
  2007-08-14 21:16     ` martin rudalics
  0 siblings, 1 reply; 7+ messages in thread
From: WAROQUIERS Philippe @ 2007-08-14 19:51 UTC (permalink / raw)
  To: martin rudalics; +Cc: stephen_leake, bug-gnu-emacs

> > 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.
>
>I've been looking into this and noted that handling syntax-table
>properties seems completely broken unless done by font-lock.  Could you
>please try the attached patch and tell me whether it gives good results
>with font-lock-mode enabled _and_ disabled.  Thanks.

I have done the following:
  * applied the patch on ada-mode.el
  * started emacs -Q
  * M-x load-file ada-mode.el
  * loaded an Ada file
  * re-indented the complete buffer (with font-lock enabled)
     => indentation was correctly done.
  * put the cursor inside a single character (e.g. 'a')
     + evaluated (ada-in-string-p) before a, on a, after a.
      => expected result obtained.
  * did the same tests after having disabled font-lock mode
    Obtained same results except that re-indenting without font-lock
    is a *lot* slower.

So, from what I can see with this little test, the patch seems ok
(assuming I have done some relevant tests).

Thanks for your work ...

____

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: ada-mode ada-initialize-properties has an error with read-only files
  2007-08-14 19:51   ` WAROQUIERS Philippe
@ 2007-08-14 21:16     ` martin rudalics
  2007-08-16 21:42       ` WAROQUIERS Philippe
  0 siblings, 1 reply; 7+ messages in thread
From: martin rudalics @ 2007-08-14 21:16 UTC (permalink / raw)
  To: WAROQUIERS Philippe; +Cc: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

 > I have done the following:
[...]
 >   * did the same tests after having disabled font-lock mode
 >     Obtained same results except that re-indenting without font-lock
 >     is a *lot* slower.

Very good, thanks.  My patch was very silly in this regard.  Please try
again.

[-- Attachment #2: ada-mode.patch --]
[-- Type: text/plain, Size: 8642 bytes --]

*** progmodes/ada-mode.el	Wed Jul 25 06:29:40 2007
--- progmodes/ada-mode.el	Tue Aug 14 23:06:14 2007
***************
*** 829,841 ****
  ;; Thus their syntax property is changed automatically, and we can still use
  ;; the standard Emacs functions for sexp (see `ada-in-string-p')
  ;;
! ;; On Emacs, this is done through the `syntax-table' text property. The
! ;; modification is done automatically each time the user as typed a new
! ;; character. This is already done in `font-lock-mode' (in
! ;; `font-lock-syntactic-keywords', so we take advantage of the existing
! ;; mechanism. If font-lock-mode is not activated, we do it by hand in
! ;; `ada-after-change-function', thanks to `ada-deactivate-properties' and
! ;; `ada-initialize-properties'.
  ;;
  ;; on XEmacs, the `syntax-table' property does not exist and we have to use a
  ;; slow advice to `parse-partial-sexp' to do the same thing.
--- 829,840 ----
  ;; Thus their syntax property is changed automatically, and we can still use
  ;; the standard Emacs functions for sexp (see `ada-in-string-p')
  ;;
! ;; On Emacs, this is done through the `syntax-table' text property.  The
! ;; corresponding action is applied automatically each time the buffer
! ;; changes.  If `font-lock-mode' is enabled (the default) the action is
! ;; set up by `font-lock-syntactic-keywords'.  Otherwise, we do it
! ;; manually in `ada-after-change-function'.  The proper method is
! ;; installed by `ada-handle-syntax-table-properties'.
  ;;
  ;; on XEmacs, the `syntax-table' property does not exist and we have to use a
  ;; slow advice to `parse-partial-sexp' to do the same thing.
***************
*** 852,858 ****
  declares it as a word constituent."
    (interactive)
    (setq ada-mode-syntax-table (make-syntax-table))
-   (set-syntax-table  ada-mode-syntax-table)
  
    ;; define string brackets (`%' is alternative string bracket, but
    ;; almost never used as such and throws font-lock and indentation
--- 851,856 ----
***************
*** 936,985 ****
  	    (insert (caddar change))
  	    (setq change (cdr change)))))))
  
! (defun ada-deactivate-properties ()
!   "Deactivate Ada mode's properties handling.
! This would be a duplicate of font-lock if both are used at the same time."
!   (remove-hook 'after-change-functions 'ada-after-change-function t))
! 
! (defun ada-initialize-properties ()
!   "Initialize some special text properties in the whole buffer.
! In particular, character constants are said to be strings, #...# are treated
! as numbers instead of gnatprep comments."
!   (save-excursion
!     (save-restriction
!       (widen)
!       (goto-char (point-min))
!       (while (re-search-forward "'.'" nil t)
! 	(add-text-properties (match-beginning 0) (match-end 0)
! 			     '(syntax-table ("'" . ?\"))))
!       (goto-char (point-min))
!       (while (re-search-forward "^[ \t]*#" nil t)
! 	(add-text-properties (match-beginning 0) (match-end 0)
! 			     '(syntax-table (11 . 10))))
!       (set-buffer-modified-p nil)
! 
!       ;;  Setting this only if font-lock is not set won't work
!       ;;  if the user activates or deactivates font-lock-mode,
!       ;;  but will make things faster most of the time
!       (add-hook 'after-change-functions 'ada-after-change-function nil t)
!       )))
  
  (defun ada-after-change-function (beg end old-len)
    "Called when the region between BEG and END was changed in the buffer.
  OLD-LEN indicates what the length of the replaced text was."
!   (let ((inhibit-point-motion-hooks t)
! 	(eol (point)))
      (save-excursion
!       (save-match-data
! 	(beginning-of-line)
! 	(remove-text-properties (point) eol '(syntax-table nil))
! 	(while (re-search-forward "'.'" eol t)
! 	  (add-text-properties (match-beginning 0) (match-end 0)
! 			       '(syntax-table ("'" . ?\"))))
! 	(beginning-of-line)
! 	(if (looking-at "^[ \t]*#")
! 	    (add-text-properties (match-beginning 0) (match-end 0)
! 				 '(syntax-table (11 . 10))))))))
  
  ;;------------------------------------------------------------------
  ;;  Testing the grammatical context
--- 934,992 ----
  	    (insert (caddar change))
  	    (setq change (cdr change)))))))
  
! (defun ada-set-syntax-table-properties ()
!   "Assign `syntax-table' properties in accessible part of buffer.
! In particular, character constants are said to be strings, #...#
! are treated as numbers instead of gnatprep comments."
!   (let ((modified (buffer-modified-p))
! 	(buffer-undo-list t)
! 	(inhibit-read-only t)
! 	(inhibit-point-motion-hooks t)
! 	(inhibit-modification-hooks t))
!     (remove-text-properties (point-min) (point-max) '(syntax-table nil))
!     (goto-char (point-min))
!     (while (re-search-forward
! 	    ;; The following regexp was adapted from
! 	    ;; `ada-font-lock-syntactic-keywords'.
! 	    "^[ \t]*\\(#\\(?:if\\|else\\|elsif\\|end\\)\\)\\|[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)"
! 	    nil t)
!       (if (match-beginning 1)
! 	  (put-text-property
! 	       (match-beginning 1) (match-end 1) 'syntax-table '(11 . ?\n))
! 	(put-text-property
! 	     (match-beginning 2) (match-end 2) 'syntax-table '(7 . ?'))
! 	(put-text-property
! 	     (match-beginning 3) (match-end 3) 'syntax-table '(7 . ?'))))
!     (unless modified
!       (restore-buffer-modified-p nil))))
  
  (defun ada-after-change-function (beg end old-len)
    "Called when the region between BEG and END was changed in the buffer.
  OLD-LEN indicates what the length of the replaced text was."
!   (save-excursion
!     (save-restriction
!       (let ((from (progn (goto-char beg) (line-beginning-position)))
! 	    (to (progn (goto-char end) (line-end-position))))
! 	(narrow-to-region from to)
! 	(save-match-data
! 	  (ada-set-syntax-table-properties))))))
! 
! (defun ada-initialize-syntax-table-properties ()
!   "Assign `syntax-table' properties in current buffer."
      (save-excursion
!       (save-restriction
! 	(widen)
! 	(save-match-data
! 	  (ada-set-syntax-table-properties))))
!     (add-hook 'after-change-functions 'ada-after-change-function nil t))
! 
! (defun ada-handle-syntax-table-properties ()
!   "Handle `syntax-table' properties."
!   (if font-lock-mode
!       ;; `font-lock-mode' will take care of `syntax-table' properties.
!       (remove-hook 'after-change-functions 'ada-after-change-function t)
!     ;; Take care of `syntax-table' properties manually.
!     (ada-initialize-syntax-table-properties)))
  
  ;;------------------------------------------------------------------
  ;;  Testing the grammatical context
***************
*** 1150,1155 ****
--- 1157,1164 ----
  
    (interactive)
    (kill-all-local-variables)
+   
+   (set-syntax-table ada-mode-syntax-table)
  
    (set (make-local-variable 'require-final-newline) mode-require-final-newline)
  
***************
*** 1340,1346 ****
    (setq which-func-functions '(ada-which-function))
  
    ;;  Support for indent-new-comment-line (Especially for XEmacs)
!   (setq comment-multi-line nil)
  
    (setq major-mode 'ada-mode
  	mode-name "Ada")
--- 1349,1355 ----
    (setq which-func-functions '(ada-which-function))
  
    ;;  Support for indent-new-comment-line (Especially for XEmacs)
!   (set (make-local-variable 'comment-multi-line) nil)
  
    (setq major-mode 'ada-mode
  	mode-name "Ada")
***************
*** 1377,1385 ****
    ;;  font-lock-mode
  
    (unless (featurep 'xemacs)
!     (progn
!       (ada-initialize-properties)
!       (add-hook 'font-lock-mode-hook 'ada-deactivate-properties nil t)))
  
    ;; the following has to be done after running the ada-mode-hook
    ;; because users might want to set the values of these variable
--- 1386,1393 ----
    ;;  font-lock-mode
  
    (unless (featurep 'xemacs)
!     (ada-initialize-syntax-table-properties)
!     (add-hook 'font-lock-mode-hook 'ada-handle-syntax-table-properties nil t))
  
    ;; the following has to be done after running the ada-mode-hook
    ;; because users might want to set the values of these variable
***************
*** 5200,5207 ****
    ;; This sets the properties of the characters, so that ada-in-string-p
    ;; correctly handles '"' too...
    '(("[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?')))
!     ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n)))
!     ))
  
  (defvar ada-font-lock-keywords
    (eval-when-compile
--- 5208,5214 ----
    ;; This sets the properties of the characters, so that ada-in-string-p
    ;; correctly handles '"' too...
    '(("[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?')))
!     ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n)))))
  
  (defvar ada-font-lock-keywords
    (eval-when-compile

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: ada-mode ada-initialize-properties has an error with read-only files
  2007-08-14 21:16     ` martin rudalics
@ 2007-08-16 21:42       ` WAROQUIERS Philippe
  2007-08-17  7:16         ` Stephen Leake
  0 siblings, 1 reply; 7+ messages in thread
From: WAROQUIERS Philippe @ 2007-08-16 21:42 UTC (permalink / raw)
  To: martin rudalics; +Cc: bug-gnu-emacs, stephen_leake

> > I have done the following:
>[...]
> >   * did the same tests after having disabled font-lock mode
> >     Obtained same results except that re-indenting without font-lock
> >     is a *lot* slower.
>
>Very good, thanks.  My patch was very silly in this regard.  Please try
>again.
I have tested the new patch version, and re-indenting with or without
font-lock is now more or less the same speed.

Thanks

____

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: ada-mode ada-initialize-properties has an error with read-only files
  2007-08-16 21:42       ` WAROQUIERS Philippe
@ 2007-08-17  7:16         ` Stephen Leake
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Leake @ 2007-08-17  7:16 UTC (permalink / raw)
  To: martin rudalics; +Cc: Barranquero, Juanma, bug-gnu-emacs, WAROQUIERS Philippe

Martin,

I'm the Emacs Ada mode maintainer. Thanks for finding a good fix to
this bug. Please commit it to Emacs CVS, on both the release branch
and main.

Juanma; you can ignore the version I sent you earlier.

"WAROQUIERS Philippe" <philippe.waroquiers@eurocontrol.int> writes:

>> > I have done the following:
>>[...]
>> >   * did the same tests after having disabled font-lock mode
>> >     Obtained same results except that re-indenting without font-lock
>> >     is a *lot* slower.
>>
>>Very good, thanks.  My patch was very silly in this regard.  Please try
>>again.
> I have tested the new patch version, and re-indenting with or without
> font-lock is now more or less the same speed.
>
> Thanks
>
> ____
>
> 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.
> 

>

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-08-17  7:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).