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 23:16:00 +0200 Message-ID: <46C21B90.4010404@gmx.at> References: <1B2B2EF98D55CB41BD16F13B18B9B0080303EE75@FFBRUE001.cfmu.corp.eurocontrol.int> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090700090104090502030708" X-Trace: sea.gmane.org 1187126169 1846 80.91.229.12 (14 Aug 2007 21:16:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 14 Aug 2007 21:16:09 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org To: WAROQUIERS Philippe Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 14 23:16:07 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 1IL3kC-0004FQ-1G for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 Aug 2007 23:16:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IL3kB-0000M7-CK for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 Aug 2007 17:16:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IL3ji-0008Su-Mr for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 17:15:34 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IL3jg-0008Qn-OF for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 17:15:33 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IL3jg-0008QU-Ba for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 17:15:32 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IL3jf-0002sa-IX for bug-gnu-emacs@gnu.org; Tue, 14 Aug 2007 17:15:32 -0400 Original-Received: (qmail invoked by alias); 14 Aug 2007 21:15:29 -0000 Original-Received: from N751P018.adsl.highway.telekom.at (EHLO [62.47.37.210]) [62.47.37.210] by mail.gmx.net (mp015) with SMTP; 14 Aug 2007 23:15:29 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX1+V9IV2xIqVIC3T8nUr8+fyPOR4/4sAPjf8/70WpO xPmLIT10wpj61c User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: <1B2B2EF98D55CB41BD16F13B18B9B0080303EE75@FFBRUE001.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:16360 Archived-At: This is a multi-part message in MIME format. --------------090700090104090502030708 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit > 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. --------------090700090104090502030708 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 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 --------------090700090104090502030708 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 --------------090700090104090502030708--