From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: Re: ada-mode ada-initialize-properties has an error with read-only files Date: Tue, 14 Aug 2007 14:31:59 +0200 Message-ID: <46C1A0BF.1090509@gmx.at> References: <200708101117.NAA25787@gull.cfmu.corp.eurocontrol.int> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010808060300030900090005" X-Trace: sea.gmane.org 1187094955 11978 80.91.229.12 (14 Aug 2007 12:35:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 14 Aug 2007 12:35:55 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org To: philippe.waroquiers@eurocontrol.int Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 14 14:35:52 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IKvcj-0002Eu-E4 for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 Aug 2007 14:35:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IKvci-0003Qw-Mo for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 Aug 2007 08:35:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IKvad-0002hN-Hz for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 08:33:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IKvac-0002gm-H7 for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 08:33:38 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IKvab-0002gb-R5 for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 08:33:38 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IKvab-0000eG-3z for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 08:33:37 -0400 Original-Received: (qmail invoked by alias); 14 Aug 2007 12:33:34 -0000 Original-Received: from N906P009.adsl.highway.telekom.at (EHLO [62.47.57.41]) [62.47.57.41] by mail.gmx.net (mp034) with SMTP; 14 Aug 2007 14:33:34 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX1/jv8QrFRrji3+fsX9RM3x+iB83iE5KVZhMvWWtKH nmXFW4COhomcvu User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: <200708101117.NAA25787@gull.cfmu.corp.eurocontrol.int> X-Y-GMX-Trusted: 0 X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:16354 Archived-At: This is a multi-part message in MIME format. --------------010808060300030900090005 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit > 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 #) > > 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. --------------010808060300030900090005 Content-Type: text/plain; name="ada-mode.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ada-mode.patch" *** 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 --------------010808060300030900090005 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ bug-gnu-emacs mailing list bug-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs --------------010808060300030900090005--