all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: WAROQUIERS Philippe <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 23:16:00 +0200	[thread overview]
Message-ID: <46C21B90.4010404@gmx.at> (raw)
In-Reply-To: <1B2B2EF98D55CB41BD16F13B18B9B0080303EE75@FFBRUE001.cfmu.corp.eurocontrol.int>

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

  reply	other threads:[~2007-08-14 21:16 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
2007-08-14 19:51   ` WAROQUIERS Philippe
2007-08-14 21:16     ` martin rudalics [this message]
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

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

  git send-email \
    --in-reply-to=46C21B90.4010404@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.