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: Tue, 14 Aug 2007 14:31:59 +0200	[thread overview]
Message-ID: <46C1A0BF.1090509@gmx.at> (raw)
In-Reply-To: <200708101117.NAA25787@gull.cfmu.corp.eurocontrol.int>

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

  parent reply	other threads:[~2007-08-14 12:31 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
2007-08-14 12:31 ` martin rudalics [this message]
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=46C1A0BF.1090509@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).